Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/components/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@labkey/components",
"version": "6.45.0",
"version": "6.45.1",
"description": "Components, models, actions, and utility functions for LabKey applications and pages",
"sideEffects": false,
"files": [
Expand Down
6 changes: 6 additions & 0 deletions packages/components/releaseNotes/components.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# @labkey/components
Components, models, actions, and utility functions for LabKey applications and pages

### version 6.45.1
*Released*: 3 June 2025
- Issue 52959: LKSM/LKB: Existing file not shown in Bulk Edit
- Update `getCommonDataValues` to retain full data map for file fields
- Update `FileInput` to set init value so diff can be generated correctly

### version 6.45.0
*Released*: 2 June 2025
- Export Loader type
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import React from 'react';
import { render, waitFor } from '@testing-library/react';
import { fromJS, List } from 'immutable';

import { QueryColumn } from '../../../public/QueryColumn';
import { QueryInfo } from '../../../public/QueryInfo';

import { GridResponse } from '../editable/models';

import { getTestAPIWrapper } from '../../APIWrapper';

import { BulkUpdateForm, BulkUpdateFormProps } from './BulkUpdateForm';

const COLUMN_CAN_UPDATE = new QueryColumn({
fieldKey: 'update',
name: 'update',
caption: 'update',
fieldKeyArray: ['update'],
shownInUpdateView: true,
userEditable: true,
});
const COLUMN_CANNOT_UPDATE = new QueryColumn({
fieldKey: 'neither',
name: 'neither',
caption: 'neither',
fieldKeyArray: ['neither'],
shownInUpdateView: false,
userEditable: true,
});
const COLUMN_FILE_INPUT = new QueryColumn({
fieldKey: 'fileInput',
name: 'fileInput',
caption: 'fileInput',
fieldKeyArray: ['fileInput'],
shownInUpdateView: true,
userEditable: true,
inputType: 'file',
});
const SCHEMA = 'samples';
const QUERY = 'testST';
const QUERY_INFO = QueryInfo.fromJsonForTests({
name: QUERY,
schemaName: SCHEMA,
columns: {
update: COLUMN_CAN_UPDATE,
neither: COLUMN_CANNOT_UPDATE,
fileInput: COLUMN_FILE_INPUT,
},
});

const DEFAULT_PROPS: BulkUpdateFormProps = {
api: getTestAPIWrapper(jest.fn),
onComplete: jest.fn(),
onCancel: jest.fn(),
onSubmitForEdit: jest.fn(),
queryInfo: QUERY_INFO,
viewName: undefined,
selectedIds: [],
updateRows: jest.fn(),
};

const mockGridResponse: GridResponse = {
data: fromJS({
'127796': {
update: {
value: 'abc',
},
fileInput: {
value: '/trunk/build/deploy/files/LKSM/@files/sampletype/test.txt',
url: '/LKSM-dan/core-downloadFileLink.view?propertyId=82852',
displayValue: 'sampletype/test.txt',
},
},
'127797': {
update: {
value: 'abc',
},
fileInput: {
value: '/trunk/build/deploy/files/LKSM/@files/sampletype/test.txt',
url: '/LKSM-dan/core-downloadFileLink.view?propertyId=82852',
displayValue: 'sampletype/test.txt',
},
},
}),
dataIds: List(['127796', '127797']),
};

jest.mock('../../actions', () => ({
...jest.requireActual('../../actions'),
getSelectedDataDeprecated: jest.fn().mockImplementation(() => mockGridResponse),
}));

describe('BulkUpdateForm', () => {
// TODO missing test cases for main functionality of component
describe('columnFilter', () => {
test('filters without uniqueKeyField', async () => {
render(<BulkUpdateForm {...DEFAULT_PROPS} />);

await waitFor(() => {
expect(document.querySelectorAll('.query-info-form')).toHaveLength(1);
});
expect(document.querySelectorAll('.toggle-group-icon')).toHaveLength(2);
expect(document.querySelectorAll('input#update')).toHaveLength(1);
expect(document.querySelector('input#update').getAttribute('value')).toBe('abc');
expect(document.querySelectorAll('.attachment-card__name')).toHaveLength(1);
expect(document.querySelector('.attachment-card__name')).toHaveTextContent('test.txt');
});

test('filters with uniqueFieldKey', async () => {
render(<BulkUpdateForm {...DEFAULT_PROPS} uniqueFieldKey="update" />);

await waitFor(() => {
expect(document.querySelectorAll('.query-info-form')).toHaveLength(1);
});
expect(document.querySelectorAll('.toggle-group-icon')).toHaveLength(1);
expect(document.querySelectorAll('input#update')).toHaveLength(0);
expect(document.querySelectorAll('.attachment-card__name')).toHaveLength(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { getSelectedDataDeprecated } from '../../actions';

import { capitalizeFirstChar, caseInsensitive, getCommonDataValues, getUpdatedData } from '../../util/utils';

import { ComponentsAPIWrapper } from '../../APIWrapper';

import { QueryInfoForm } from './QueryInfoForm';

type UpdateRows = (schemaQuery: SchemaQuery, rows: any[], comment?: string) => Promise<any>;
Expand All @@ -20,7 +22,8 @@ function isUpdateModel(fn: UpdateRows | UpdateModel): fn is UpdateModel {
return fn.length === 1; // UpdateModel has only one parameter
}

interface Props {
export interface BulkUpdateFormProps {
api?: ComponentsAPIWrapper;
containerFilter?: Query.ContainerFilter;
disabled?: boolean;
header?: ReactNode;
Expand Down Expand Up @@ -59,7 +62,7 @@ interface State {
originalDataForSelection: Map<string, any>;
}

export class BulkUpdateForm extends PureComponent<Props, State> {
export class BulkUpdateForm extends PureComponent<BulkUpdateFormProps, State> {
static defaultProps = {
pluralNoun: 'rows',
singularNoun: 'row',
Expand Down Expand Up @@ -196,6 +199,7 @@ export class BulkUpdateForm extends PureComponent<Props, State> {
render() {
const { formData, isLoadingDataForSelection, dataForSelection, containerPaths } = this.state;
const {
api,
containerFilter,
onCancel,
onComplete,
Expand All @@ -207,8 +211,11 @@ export class BulkUpdateForm extends PureComponent<Props, State> {
includeCommentField,
onSubmitForEdit,
} = this.props;
const fileFields = queryInfo.columns.valueArray.filter(col => col.isFileInput).map(col => col.name);
const fieldValues =
isLoadingDataForSelection || !dataForSelection ? undefined : getCommonDataValues(dataForSelection);
isLoadingDataForSelection || !dataForSelection
? undefined
: getCommonDataValues(dataForSelection, fileFields);

// if all selectedIds are from the same containerPath, use that for the lookups via QueryFormInputs > QuerySelect,
// if selections are from multiple containerPaths, disable the lookup and file field inputs
Expand All @@ -221,6 +228,7 @@ export class BulkUpdateForm extends PureComponent<Props, State> {
return (
<QueryInfoForm
allowFieldDisable
api={api}
asModal
checkRequiredFields={false}
columnFilter={this.columnFilter}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ class FileInputImpl extends DisableableInput<FileInputImplProps, State> {
error: '',
isDisabled: props.initiallyDisabled,
};

if (Map.isMap(props.initialValue)) {
// call setValue so to populate form data (for diff compare)
props.setValue?.(props.initialValue.get('value'));
}
}

getInputName(): string {
Expand Down
35 changes: 35 additions & 0 deletions packages/components/src/internal/util/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ describe('getCommonDataForSelection', () => {
Other: {
value: 'other1',
},
Pdf: {
value: '/root/lk/Sample%20Management/blood.pdf',
displayValue: 'sampletype/blood.pdf',
url: '/labkey/Sample%20Management/core-downloadFileLink.view?propertyId=552',
},
},
'447': {
RowId: {
Expand All @@ -275,6 +280,11 @@ describe('getCommonDataForSelection', () => {
Other: {
value: 'other2',
},
Pdf: {
value: '/root/lk/Sample%20Management/blood.pdf',
displayValue: 'sampletype/blood.pdf',
url: '/labkey/Sample%20Management/core-downloadFileLink.view?propertyId=552',
},
},
'446': {
RowId: {
Expand All @@ -297,6 +307,11 @@ describe('getCommonDataForSelection', () => {
Other: {
value: 'other3',
},
Pdf: {
value: '/root/lk/Sample%20Management/blood.pdf',
displayValue: 'sampletype/blood.pdf',
url: '/labkey/Sample%20Management/core-downloadFileLink.view?propertyId=552',
},
},
'445': {
RowId: {
Expand All @@ -319,6 +334,11 @@ describe('getCommonDataForSelection', () => {
Other: {
value: null,
},
Pdf: {
value: '/root/lk/Sample%20Management/blood.pdf',
displayValue: 'sampletype/blood.pdf',
url: '/labkey/Sample%20Management/core-downloadFileLink.view?propertyId=552',
},
},
'367': {
RowId: {
Expand All @@ -341,11 +361,26 @@ describe('getCommonDataForSelection', () => {
Other: {
value: null,
},
Pdf: {
value: '/root/lk/Sample%20Management/blood.pdf',
displayValue: 'sampletype/blood.pdf',
url: '/labkey/Sample%20Management/core-downloadFileLink.view?propertyId=552',
},
},
});
expect(getCommonDataValues(data)).toEqual({
AndAgain: 'again',
Data: 'data1',
Pdf: '/root/lk/Sample%20Management/blood.pdf',
});
expect(getCommonDataValues(data, ['Pdf'])).toEqual({
AndAgain: 'again',
Data: 'data1',
Pdf: fromJS({
value: '/root/lk/Sample%20Management/blood.pdf',
displayValue: 'sampletype/blood.pdf',
url: '/labkey/Sample%20Management/core-downloadFileLink.view?propertyId=552',
}),
});
});
});
Expand Down
Loading