Skip to content

Commit 0e9d01c

Browse files
committed
fix(variable-editing): fix bulk edit not working.
fix quick add to group bug that made it possible to add the same group more than once. fix bug that removes weight from selected variables when no weight selected.
1 parent dc72adf commit 0e9d01c

9 files changed

Lines changed: 343 additions & 274 deletions

File tree

src/app/components/body/variables/data/table/bulk-edit-modal/bulk-edit-modal.component.html

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
<button (click)="openModal()" class="btn border border-slate-300 bg-transparent">
1+
<button
2+
(click)="openModal()"
3+
class="btn border border-slate-300 bg-transparent"
4+
>
25
{{ 'BULK_EDIT_MODAL.BULK_EDIT' | translate }}
36
</button>
47
<dialog #bulkEdit class="modal modal-bottom sm:modal-middle font-normal">
@@ -22,7 +25,9 @@
2225
</svg>
2326
<span class="sr-only">{{ 'COMMON.CLOSE' | translate }}</span>
2427
</button>
25-
<h2 class="text-2xl">{{ 'BULK_EDIT_MODAL.BULK_EDIT_VARIABLES' | translate }}</h2>
28+
<h2 class="text-2xl">
29+
{{ 'BULK_EDIT_MODAL.BULK_EDIT_VARIABLES' | translate }}
30+
</h2>
2631
</div>
2732
<hr class="divider" />
2833
</div>
@@ -109,18 +114,15 @@ <h2 class="text-2xl">{{ 'BULK_EDIT_MODAL.BULK_EDIT_VARIABLES' | translate }}</h2
109114
/>
110115
</svg>
111116
<span class="">
112-
{{ 'BULK_EDIT_MODAL.UPDATE' | translate }}
117+
{{ 'BULK_EDIT_MODAL.UPDATE' | translate }}
113118
{{ selectedVariables().length }}
114119
{{ 'BULK_EDIT_MODAL.VARS' | translate }}
115120
</span>
116121
</button>
117122
</form>
118123
</div>
119124
<div class="flex flex-col w-full my-3">
120-
<button
121-
(click)="handleCancel()"
122-
class="btn btn-outline justify-start"
123-
>
125+
<button (click)="handleCancel()" class="btn btn-outline justify-start">
124126
<svg
125127
class="w-6 h-6"
126128
fill="none"
@@ -140,7 +142,7 @@ <h2 class="text-2xl">{{ 'BULK_EDIT_MODAL.BULK_EDIT_VARIABLES' | translate }}</h2
140142
</div>
141143
</div>
142144
</dialog>
143-
<div [ngClass]="{'hide-toast': !saved, 'show-toast': saved}" class="toast toast-top toast-end">
145+
<!-- <div [ngClass]="{'hide-toast': !saved, 'show-toast': saved}" class="toast toast-top toast-end">
144146
<div class="alert rounded alert-success" role="alert" aria-atomic="true" aria-live="polite">
145147
<span class="text-base-100">{{ 'COMMON.CHANGES_APPLIED' | translate }}</span>
146148
<button (click)="closeLoadedToast()">
@@ -149,4 +151,4 @@ <h2 class="text-2xl">{{ 'BULK_EDIT_MODAL.BULK_EDIT_VARIABLES' | translate }}</h2
149151
</svg>
150152
</button>
151153
</div>
152-
</div>
154+
</div> -->

src/app/components/body/variables/data/table/bulk-edit-modal/bulk-edit-modal.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class BulkEditModalComponent {
6060
notes: this.variableForm.value.notes || '',
6161
};
6262
this.store.dispatch(
63-
XmlManipulationActions.bulkSaveVariableModal({
63+
XmlManipulationActions.startBulkVariableModalSave({
6464
variableIDs: this.selectedVariables(),
6565
newVariableValue,
6666
allVariables: this.allVariables(),

src/app/new.state/dataset/dataset.reducer.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,24 @@ export const datasetReducer = createReducer(
150150
},
151151
};
152152
}),
153+
on(XmlManipulationActions.bulkSaveWeightAndGroupChange, (state) => {
154+
return {
155+
...state,
156+
operationStatus: {
157+
...state.operationStatus,
158+
save: 'pending' as const,
159+
},
160+
};
161+
}),
162+
on(XmlManipulationActions.bulkSaveWeightAndGroupChangeSuccess, (state) => {
163+
return {
164+
...state,
165+
operationStatus: {
166+
...state.operationStatus,
167+
save: 'success' as const,
168+
},
169+
};
170+
}),
153171
on(XmlManipulationActions.startImportMetadata, (state) => {
154172
return {
155173
...state,
@@ -223,6 +241,33 @@ export const datasetReducer = createReducer(
223241
};
224242
},
225243
),
244+
on(XmlManipulationActions.startBulkVariableModalSave, (state) => {
245+
return {
246+
...state,
247+
operationStatus: {
248+
...state.operationStatus,
249+
save: 'pending' as const,
250+
},
251+
};
252+
}),
253+
on(XmlManipulationActions.bulkSaveVariableModalSuccess, (state) => {
254+
return {
255+
...state,
256+
operationStatus: {
257+
...state.operationStatus,
258+
save: 'success' as const,
259+
},
260+
};
261+
}),
262+
on(XmlManipulationActions.clearSaveVariableModalSuccess, (state) => {
263+
return {
264+
...state,
265+
operationStatus: {
266+
...state.operationStatus,
267+
save: 'idle' as const,
268+
},
269+
};
270+
}),
226271
on(DatasetActions.saveVariableStatusPending, (state) => {
227272
return {
228273
...state,

src/app/new.state/xml/xml.actions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export const XmlManipulationActions = createActionGroup({
140140
isWeight: boolean;
141141
};
142142
}>(),
143-
bulkSaveVariableModal: props<{
143+
startBulkVariableModalSave: props<{
144144
variableIDs: string[];
145145
newVariableValue: {
146146
label: string;
@@ -153,6 +153,10 @@ export const XmlManipulationActions = createActionGroup({
153153
variablesWithCrossTabMetadata: { [variableID: string]: string[] };
154154
allVariables: { [variableID: string]: Variable };
155155
}>(),
156+
bulkSaveVariableModalSuccess: props<{
157+
updatedVariables: Variable[];
158+
}>(),
159+
clearSaveVariableModalSuccess: emptyProps,
156160
bulkSaveWeightAndGroupChange: props<{
157161
variableIDs: string[];
158162
allVariables: { [variableID: string]: Variable };

src/app/new.state/xml/xml.effects.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
changeAssignedWeightForMultipleVariables,
99
changeGroupsForMultipleVariables,
1010
changeWeightForSelectedVariables,
11+
fullyChangeMultipleVariables,
1112
} from './xml.util';
1213

1314
@Injectable()
@@ -161,6 +162,32 @@ export class XmlEffects {
161162
},
162163
);
163164

165+
bulkVariableModalSave$ = createEffect(() => {
166+
return this.actions$.pipe(
167+
ofType(XmlManipulationActions.startBulkVariableModalSave),
168+
exhaustMap(({ variableIDs, newVariableValue, allVariables }) => {
169+
const updatedVariables = fullyChangeMultipleVariables(
170+
Object.values(structuredClone(allVariables)),
171+
variableIDs,
172+
newVariableValue,
173+
);
174+
return of(
175+
XmlManipulationActions.bulkSaveVariableModalSuccess({
176+
updatedVariables,
177+
}),
178+
);
179+
}),
180+
);
181+
});
182+
183+
clearBulkVariableSaveStatus$ = createEffect(() => {
184+
return this.actions$.pipe(
185+
ofType(XmlManipulationActions.bulkSaveVariableModalSuccess),
186+
delay(10000),
187+
map(() => XmlManipulationActions.clearSaveVariableModalSuccess()),
188+
);
189+
});
190+
164191
bulkSaveWeightAndGroupChange$ = createEffect(() => {
165192
return this.actions$.pipe(
166193
ofType(XmlManipulationActions.bulkSaveWeightAndGroupChange),
@@ -211,13 +238,6 @@ export class XmlEffects {
211238
);
212239
});
213240

214-
saveBulkVariableStatusPending$ = createEffect(() => {
215-
return this.actions$.pipe(
216-
ofType(XmlManipulationActions.bulkSaveWeightAndGroupChange),
217-
map(() => DatasetActions.saveVariableStatusPending()),
218-
);
219-
});
220-
221241
clearBulkVariableStatusSuccess$ = createEffect(() => {
222242
return this.actions$.pipe(
223243
ofType(XmlManipulationActions.bulkSaveWeightAndGroupChangeSuccess),

src/app/new.state/xml/xml.reducer.ts

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -330,36 +330,24 @@ export const xmlReducer = createReducer(
330330
};
331331
},
332332
),
333-
// on(
334-
// XmlManipulationActions.weightProcessSuccess,
335-
// (
336-
// state,
337-
// { selectedVariables, allVariables, variablesWithCrossTabMetadata },
338-
// ) => {
339-
// const duplicateVariables =
340-
// structuredClone(state.dataset?.codeBook.dataDscr.var) || [];
341-
// if (duplicateVariables) {
342-
// duplicateVariables.forEach((variable) => {
343-
// if (selectedVariables.includes(variable['@_ID'])) {
344-
// variable.catgry = allVariables[variable['@_ID']].catgry;
345-
// }
346-
// });
347-
// }
348-
// return {
349-
// ...state,
350-
// dataset: !state.dataset
351-
// ? null
352-
// : {
353-
// ...state.dataset,
354-
// codeBook: {
355-
// ...state.dataset?.codeBook,
356-
// dataDscr: {
357-
// ...state.dataset?.codeBook.dataDscr,
358-
// var: duplicateVariables,
359-
// },
360-
// },
361-
// },
362-
// };
363-
// },
364-
// ),
333+
on(
334+
XmlManipulationActions.bulkSaveVariableModalSuccess,
335+
(state, { updatedVariables }) => {
336+
return {
337+
...state,
338+
dataset: !state.dataset
339+
? null
340+
: {
341+
...state.dataset,
342+
codeBook: {
343+
...state.dataset?.codeBook,
344+
dataDscr: {
345+
...state.dataset?.codeBook.dataDscr,
346+
var: updatedVariables,
347+
},
348+
},
349+
},
350+
};
351+
},
352+
),
365353
);

src/app/new.state/xml/xml.util.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ function updateGivenVariable(
4141
'#text': newVariableValue.label,
4242
};
4343
}
44-
if (updatedVariable['@_wgt']) {
44+
if (newVariableValue.isWeight && updatedVariable['@_wgt']) {
4545
updatedVariable['@_wgt'] = newVariableValue.isWeight ? 'wgt' : '';
4646
} else {
4747
updatedVariable = {
4848
...updatedVariable,
4949
'@_wgt': newVariableValue.isWeight ? 'wgt' : '',
5050
};
5151
}
52-
if (updatedVariable['@_wgt-var']) {
52+
if (newVariableValue.isWeight && updatedVariable['@_wgt-var']) {
5353
updatedVariable['@_wgt-var'] = newVariableValue.isWeight
5454
? ''
5555
: newVariableValue.assignedWeight;
@@ -85,7 +85,9 @@ function updateGivenVariable(
8585
}
8686
updatedVariable = {
8787
...updatedVariable,
88-
universe: newVariableValue.universe,
88+
universe: newVariableValue.universe.length
89+
? newVariableValue.universe
90+
: updatedVariable.universe,
8991
};
9092
return updatedVariable;
9193
}
@@ -130,7 +132,7 @@ export function changeWeightForSelectedVariables(
130132
category.catStat[0],
131133
{
132134
'#text':
133-
weightID && weightID !== 'remove'
135+
weightID.length && weightID !== 'remove'
134136
? frequencyTableForSelectedVariables[variableID][
135137
category.catValu
136138
] || 0
@@ -145,14 +147,15 @@ export function changeWeightForSelectedVariables(
145147
category.catStat,
146148
{
147149
'#text':
148-
weightID && weightID !== 'remove'
150+
weightID.length && weightID !== 'remove'
149151
? frequencyTableForSelectedVariables[variableID][
150152
category.catValu
151153
] || 0
152154
: 0,
153155
'@_type': 'freq',
154156
'@_wgtd': 'wgtd',
155-
'@_wgt-var': weightID && weightID !== 'remove' ? weightID : '',
157+
'@_wgt-var':
158+
weightID.length && weightID !== 'remove' ? weightID : '',
156159
},
157160
];
158161
}
@@ -291,7 +294,12 @@ export function changeGroupsForMultipleVariables(
291294
const variablesAsArray = variableGroup['@_var']?.length
292295
? variableGroup['@_var']?.split(' ') || []
293296
: [];
294-
variablesAsArray.push(...variableIDs);
297+
// Add variables that are not already in the group
298+
for (const variableID of variableIDs) {
299+
if (!variablesAsArray.includes(variableID)) {
300+
variablesAsArray.push(variableID);
301+
}
302+
}
295303
variableGroup['@_var'] = variablesAsArray.join(' ');
296304
}
297305
updatedGroupArray.push(variableGroup);

0 commit comments

Comments
 (0)