Skip to content

Commit

Permalink
poc: Property filter enum props POC
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-kot committed Sep 20, 2024
1 parent 337ca48 commit 9e32565
Show file tree
Hide file tree
Showing 15 changed files with 546 additions and 110 deletions.
1 change: 1 addition & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"start:watch": "gulp watch",
"start:dev": "cross-env NODE_ENV=development webpack serve --config pages/webpack.config.js",
"start:integ": "cross-env NODE_ENV=development webpack serve --config pages/webpack.config.integ.js",
"prepare": "husky"
"prepare": "husky",
"postinstall": "node ./scripts/install-peer-dependency.js collection-hooks:feat-property-filter-enum-props-2"
},
"dependencies": {
"@cloudscape-design/collection-hooks": "^1.0.0",
Expand Down
9 changes: 6 additions & 3 deletions pages/property-filter/common-props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const columnDefinitions = [
sortingField: 'state',
header: 'State',
type: 'enum',
getLabel: getStateLabel,
getLabel: (value: any) => (Array.isArray(value) ? value.map(getStateLabel).join(', ') : getStateLabel(value)),
propertyLabel: 'State',
cell: (item: TableItem) => getStateLabel(item.state),
},
Expand All @@ -40,7 +40,7 @@ export const columnDefinitions = [
header: 'Stopped',
type: 'boolean',
propertyLabel: 'Stopped',
cell: (item: TableItem) => item.state === 0,
cell: (item: TableItem) => item.state === 'STOPPED',
},
{
id: 'instancetype',
Expand Down Expand Up @@ -236,7 +236,10 @@ export const filteringProperties: readonly PropertyFilterProps.FilteringProperty
let groupValuesLabel = `${def.propertyLabel} values`;

if (def.type === 'enum') {
operators = ['=', '!='].map(operator => ({ operator, format: def.getLabel }));
operators = [
...['=', '!='].map(operator => ({ operator, format: def.getLabel, valueType: 'enum' })),
...[':', '!:'].map(operator => ({ operator, format: def.getLabel, valueType: 'auto' })),
];
}

if (def.type === 'text') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const nameProperty: InternalFilteringProperty = {
groupValuesLabel: 'Name values',
operators: ['=', '!='],
defaultOperator: '=',
getValueType: () => 'auto',
getValueFormatter: () => null,
getValueFormRenderer: () => null,
externalProperty,
Expand All @@ -43,6 +44,7 @@ const dateProperty: InternalFilteringProperty = {
groupValuesLabel: 'Date values',
operators: ['=', '!='],
defaultOperator: '=',
getValueType: () => 'auto',
getValueFormatter: () => (value: Date) => (value ? format(value, 'yyyy-MM-dd') : ''),
getValueFormRenderer:
() =>
Expand All @@ -60,6 +62,7 @@ const dateTimeProperty: InternalFilteringProperty = {
groupValuesLabel: 'Date time values',
operators: ['=', '!='],
defaultOperator: '=',
getValueType: () => 'auto',
getValueFormatter: () => (value: Date) => (value ? format(value, 'yyyy-MM-dd hh:mm') : ''),
getValueFormRenderer:
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function () {

const filteringOptions = propertyFilterProps.filteringOptions.map(option => {
if (option.propertyKey === 'state') {
option.label = states[parseInt(option.value)];
option.label = states[option.value];
}
return option;
});
Expand Down
Loading

0 comments on commit 9e32565

Please sign in to comment.