Skip to content

Commit eb3d434

Browse files
committed
Issue 52959: LKSM/LKB: Existing file not shown in Bulk Edit
1 parent aa0774a commit eb3d434

5 files changed

Lines changed: 60 additions & 2 deletions

File tree

packages/components/releaseNotes/components.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# @labkey/components
22
Components, models, actions, and utility functions for LabKey applications and pages
33

4+
### version 6.X
5+
*Released*: X May 2025
6+
- Issue 52959: LKSM/LKB: Existing file not shown in Bulk Edit
7+
- Update `getCommonDataValues` to retain full data map for file fields
8+
- Update `FileInput` to set init value so diff can be generated correctly
9+
410
### version 6.43.3
511
*Released*: 26 May 2025
612
- Migrate `isSetEqual` to `@labkey/components`. Extend with additional support for deep comparison.

packages/components/src/internal/components/forms/BulkUpdateForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ export class BulkUpdateForm extends PureComponent<Props, State> {
207207
includeCommentField,
208208
onSubmitForEdit,
209209
} = this.props;
210+
const fileFields = queryInfo.columns.valueArray.filter(col => col.inputType === 'file').map(col => col.name);
210211
const fieldValues =
211-
isLoadingDataForSelection || !dataForSelection ? undefined : getCommonDataValues(dataForSelection);
212+
isLoadingDataForSelection || !dataForSelection ? undefined : getCommonDataValues(dataForSelection, fileFields);
212213

213214
// if all selectedIds are from the same containerPath, use that for the lookups via QueryFormInputs > QuerySelect,
214215
// if selections are from multiple containerPaths, disable the lookup and file field inputs

packages/components/src/internal/components/forms/input/FileInput.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ class FileInputImpl extends DisableableInput<FileInputImplProps, State> {
9292
error: '',
9393
isDisabled: props.initiallyDisabled,
9494
};
95+
96+
if (Map.isMap(props.initialValue)) {
97+
props.setValue?.(props.initialValue.get('value'));
98+
}
9599
}
96100

97101
getInputName(): string {

packages/components/src/internal/util/utils.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ describe('getCommonDataForSelection', () => {
253253
Other: {
254254
value: 'other1',
255255
},
256+
Pdf: {
257+
value: '/root/lk/Sample%20Management/blood.pdf',
258+
displayValue: 'sampletype/blood.pdf',
259+
url: '/labkey/Sample%20Management/core-downloadFileLink.view?propertyId=552'
260+
}
256261
},
257262
'447': {
258263
RowId: {
@@ -275,6 +280,11 @@ describe('getCommonDataForSelection', () => {
275280
Other: {
276281
value: 'other2',
277282
},
283+
Pdf: {
284+
value: '/root/lk/Sample%20Management/blood.pdf',
285+
displayValue: 'sampletype/blood.pdf',
286+
url: '/labkey/Sample%20Management/core-downloadFileLink.view?propertyId=552'
287+
}
278288
},
279289
'446': {
280290
RowId: {
@@ -297,6 +307,11 @@ describe('getCommonDataForSelection', () => {
297307
Other: {
298308
value: 'other3',
299309
},
310+
Pdf: {
311+
value: '/root/lk/Sample%20Management/blood.pdf',
312+
displayValue: 'sampletype/blood.pdf',
313+
url: '/labkey/Sample%20Management/core-downloadFileLink.view?propertyId=552'
314+
}
300315
},
301316
'445': {
302317
RowId: {
@@ -319,6 +334,11 @@ describe('getCommonDataForSelection', () => {
319334
Other: {
320335
value: null,
321336
},
337+
Pdf: {
338+
value: '/root/lk/Sample%20Management/blood.pdf',
339+
displayValue: 'sampletype/blood.pdf',
340+
url: '/labkey/Sample%20Management/core-downloadFileLink.view?propertyId=552'
341+
}
322342
},
323343
'367': {
324344
RowId: {
@@ -341,11 +361,26 @@ describe('getCommonDataForSelection', () => {
341361
Other: {
342362
value: null,
343363
},
364+
Pdf: {
365+
value: '/root/lk/Sample%20Management/blood.pdf',
366+
displayValue: 'sampletype/blood.pdf',
367+
url: '/labkey/Sample%20Management/core-downloadFileLink.view?propertyId=552'
368+
}
344369
},
345370
});
346371
expect(getCommonDataValues(data)).toEqual({
347372
AndAgain: 'again',
348373
Data: 'data1',
374+
Pdf: '/root/lk/Sample%20Management/blood.pdf'
375+
});
376+
expect(getCommonDataValues(data, ['Pdf'])).toEqual({
377+
AndAgain: 'again',
378+
Data: 'data1',
379+
Pdf: fromJS({
380+
value: '/root/lk/Sample%20Management/blood.pdf',
381+
displayValue: 'sampletype/blood.pdf',
382+
url: '/labkey/Sample%20Management/core-downloadFileLink.view?propertyId=552'
383+
})
349384
});
350385
});
351386
});

packages/components/src/internal/util/utils.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,18 @@ export function valueIsEmpty(value: any): boolean {
200200
*
201201
* @param data Map between ids and a map of data for the ids (i.e, a row of data for that id)
202202
*/
203-
export function getCommonDataValues(data: Map<any, any>): any {
203+
export function getCommonDataValues(data: Map<any, any>, fileFields?: string[]): any {
204204
let valueMap = Map<string, any>(); // map from fields to the value shared by all rows
205205
let fieldsInConflict = ImmutableSet<string>();
206206
let emptyFields = ImmutableSet<string>(); // those fields that are empty
207+
const fileMap = {};
207208
data.map((rowData, id) => {
208209
if (rowData) {
209210
rowData.forEach((data, key) => {
210211
if (!fieldsInConflict.has(key)) {
211212
// skip fields that are already in conflict
212213
let value = data;
214+
let rawValue = data;
213215

214216
// Convert from immutable to regular JS
215217
if (Iterable.isIterable(data)) {
@@ -233,6 +235,9 @@ export function getCommonDataValues(data: Map<any, any>): any {
233235
fieldsInConflict = fieldsInConflict.add(key);
234236
} else if (!havePreviousValue) {
235237
valueMap = valueMap.set(key, value);
238+
if (fileFields?.indexOf(key) > -1) {
239+
fileMap[key] = rawValue;
240+
}
236241
}
237242
if (arrayNotEqual) {
238243
fieldsInConflict = fieldsInConflict.add(key);
@@ -254,6 +259,13 @@ export function getCommonDataValues(data: Map<any, any>): any {
254259
console.error('Unable to find data for selection id ' + id);
255260
}
256261
});
262+
263+
// return full file data map (url, displayValue, value) for file fields
264+
fileFields?.forEach(fileField => {
265+
if (valueMap.has(fileField))
266+
valueMap = valueMap.set(fileField, fileMap[fileField]);
267+
});
268+
257269
return valueMap.toObject();
258270
}
259271

0 commit comments

Comments
 (0)