Skip to content

Commit

Permalink
refactor: update document preview properties panel
Browse files Browse the repository at this point in the history
  • Loading branch information
vsgoulart committed Dec 12, 2024
1 parent 0aa4d03 commit aaf4713
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TableHeaderGroups,
LayoutGroup,
SecurityAttributesGroup,
DownloadSettings,
} from './groups';

import { hasEntryConfigured } from './Util';
Expand Down Expand Up @@ -57,6 +58,7 @@ export class PropertiesProvider {
groups = [
...groups,
GeneralGroup(field, editField, getService),
DownloadSettings(field, editField),
...OptionsGroups(field, editField, getService),
...TableHeaderGroups(field, editField),
SecurityAttributesGroup(field, editField),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,18 @@ function DocumentsDataSource(props) {
setValue,
variables,
tooltip,
validate,
});
}

// helpers //////////

/**
* @param {string|undefined} value
* @returns {string|null}
*/
const validate = (value) => {
if (typeof value !== 'string' || value.length === 0) {
return 'The document data source is required.';
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,27 @@ function EndpointKey(props) {
element: field,
getValue,
id,
label: 'Document API endpoint key',
label: 'Document URL',
feel: 'required',
singleLine: true,
setValue,
variables,
description,
tooltip,
validate,
});
}

// helpers //////////

const description = <>An API endpoint for downloading a document</>;
/**
* @param {string|undefined} value
* @returns {string|null}
*/
const validate = (value) => {
if (typeof value !== 'string' || value.length === 0) {
return 'The document reference is required.';
}
};

const description = <>Define an API URL for downloading a document</>;
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ function MaxHeight(props) {

return NumberFieldEntry({
debounce,
label: 'Max height',
label: 'Max height of preview container',
element: field,
id,
getValue,
setValue,
validate,
description,
});
}

Expand All @@ -70,3 +71,5 @@ const validate = (value) => {
return 'Should be greater than zero.';
}
};

const description = <>Documents with height that exceeds the defined value will be vertically scrollable</>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { EndpointKeyEntry } from '../entries';

export function DownloadSettings(field, editField) {
const entries = [...EndpointKeyEntry({ field, editField })];

if (!entries.length) {
return null;
}

return {
id: 'downloadSettings',
label: 'Download settings',
entries,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
AcceptEntry,
MultipleEntry,
DocumentsDataSourceEntry,
EndpointKeyEntry,
} from '../entries';

export function GeneralGroup(field, editField, getService) {
Expand Down Expand Up @@ -60,7 +59,6 @@ export function GeneralGroup(field, editField, getService) {
...PaginationEntry({ field, editField }),
...RowCountEntry({ field, editField }),
...DocumentsDataSourceEntry({ field, editField }),
...EndpointKeyEntry({ field, editField }),
];

if (entries.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export { LayoutGroup } from './LayoutGroup';
export { SecurityAttributesGroup } from './SecurityAttributesGroup';
export { ConditionGroup } from './ConditionGroup';
export { TableHeaderGroups } from './TableHeaderGroups';
export { DownloadSettings } from './DownloadSettings';
Original file line number Diff line number Diff line change
Expand Up @@ -3449,9 +3449,10 @@ describe('properties panel', function () {

// then
expectPanelStructure(container, {
General: ['Title', 'Documents metadata source', 'Document API endpoint key'],
General: ['Title', 'Documents metadata source'],
'Download settings': ['Document URL'],
Condition: [],
Appearance: ['Max height'],
Appearance: ['Max height of preview container'],
'Custom properties': [],
});
});
Expand Down

0 comments on commit aaf4713

Please sign in to comment.