@camunda/ccma-saas-frontend 0.7.2 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/components/c4-api-client-scope-picker/c4-api-client-scope-picker.d.ts +10 -0
- package/lib/esm/components/c4-api-client-scope-picker/c4-api-client-scope-picker.js +78 -0
- package/lib/esm/components/c4-api-client-scope-picker/c4-api-client-scope-picker.mocks.d.ts +6 -0
- package/lib/esm/components/c4-api-client-scope-picker/c4-api-client-scope-picker.mocks.js +90 -0
- package/lib/esm/components/c4-api-client-scope-picker/c4-api-client-scope-picker.types.d.ts +25 -0
- package/lib/esm/components/c4-breadcrumb/c4-breadcrumb.js +5 -1
- package/lib/esm/components/c4-cluster-details-clients/c4-cluster-details-clients.js +9 -0
- package/lib/esm/components/c4-cluster-details-clients/c4-cluster-details-clients.mocks.js +6 -3
- package/lib/esm/components/c4-cluster-details-clients/c4-cluster-details-clients.types.d.ts +3 -0
- package/lib/esm/components/c4-cluster-details-connector-secrets/c4-cluster-details-connector-secrets.js +9 -0
- package/lib/esm/components/c4-cluster-details-connector-secrets/c4-cluster-details-connector-secrets.mocks.js +2 -0
- package/lib/esm/components/c4-cluster-details-connector-secrets/c4-cluster-details-connector-secrets.types.d.ts +2 -0
- package/lib/esm/components/c4-cluster-details-encryption/c4-cluster-details-encryption.d.ts +1 -1
- package/lib/esm/components/c4-cluster-details-encryption/c4-cluster-details-encryption.js +11 -18
- package/lib/esm/components/c4-cluster-details-encryption/c4-cluster-details-encryption.types.d.ts +19 -2
- package/lib/esm/components/c4-cluster-overview/applications.d.ts +12 -0
- package/lib/esm/components/c4-cluster-overview/applications.js +10 -2
- package/lib/esm/components/c4-cluster-overview/c4-cluster-overview.mocks.d.ts +6 -1
- package/lib/esm/components/c4-cluster-overview/c4-cluster-overview.mocks.js +15 -2
- package/lib/esm/components/c4-cluster-overview/cluster-load.d.ts +1 -0
- package/lib/esm/components/c4-cluster-overview/cluster-load.js +14 -6
- package/lib/esm/components/c4-cluster-settings/c4-cluster-settings.d.ts +1 -1
- package/lib/esm/components/c4-cluster-settings/c4-cluster-settings.js +4 -2
- package/lib/esm/components/c4-cluster-settings/c4-cluster-settings.types.d.ts +4 -0
- package/lib/esm/components/c4-cluster-settings/elements/cluster-settings.d.ts +3 -1
- package/lib/esm/components/c4-cluster-settings/elements/cluster-settings.js +7 -3
- package/lib/esm/components/c4-cluster-settings/elements/external-identity-provider-modal.d.ts +9 -1
- package/lib/esm/components/c4-cluster-settings/elements/external-identity-provider-modal.js +69 -12
- package/lib/esm/components/c4-cluster-settings/elements/external-identity-provider.d.ts +10 -1
- package/lib/esm/components/c4-cluster-settings/elements/external-identity-provider.js +16 -2
- package/lib/esm/components/c4-cluster-settings/elements/optional-telemetry-toggle.d.ts +14 -0
- package/lib/esm/components/c4-cluster-settings/elements/optional-telemetry-toggle.js +12 -0
- package/lib/esm/components/c4-cluster-settings/elements/secrets-filter-mode-toggle.d.ts +15 -0
- package/lib/esm/components/c4-cluster-settings/elements/secrets-filter-mode-toggle.js +10 -0
- package/lib/esm/components/c4-create-cluster/c4-create-cluster-tile-grid.d.ts +4 -2
- package/lib/esm/components/c4-create-cluster/c4-create-cluster-tile-grid.js +24 -3
- package/lib/esm/components/c4-create-cluster/c4-create-cluster.js +1 -1
- package/lib/esm/components/c4-create-cluster/c4-create-cluster.mocks.js +1 -0
- package/lib/esm/components/c4-create-cluster/c4-create-cluster.types.d.ts +2 -0
- package/lib/esm/components/c4-create-console-api-client-modal/c4-create-console-api-client-modal.js +13 -30
- package/lib/esm/components/c4-job-dashboard-details-page/c4-job-dashboard-details-page.mocks.js +10 -5
- package/lib/esm/components/c4-job-dashboard-overview-page/c4-job-dashboard-overview.mocks.js +10 -5
- package/lib/esm/components/c4-tile-with-title-and-action/c4-tile-with-title-and-action.js +1 -1
- package/lib/esm/components/c4-tile-with-title-and-action/c4-tile-with-title-and-action.types.d.ts +5 -0
- package/lib/esm/components/c4-usage-metrics-per-cluster/c4-usage-metrics-per-cluster.js +2 -1
- package/lib/esm/externalUrls.const.d.ts +1 -1
- package/lib/esm/externalUrls.const.js +1 -1
- package/lib/esm/i18n/c4-console-i18n.js +6 -0
- package/lib/esm/i18n/en/modals/apiclients.json +4 -0
- package/lib/esm/i18n/en/pages/clusterdetails.json +25 -3
- package/lib/esm/i18n/en/pages/orgmanagement.json +1 -0
- package/lib/esm/index.d.ts +3 -3
- package/lib/esm/index.js +2 -3
- package/lib/esm/runtime/build-cluster-sso-callback-url.d.ts +34 -0
- package/lib/esm/runtime/build-cluster-sso-callback-url.js +49 -0
- package/lib/esm/runtime/build-cluster-swagger-url.d.ts +7 -2
- package/lib/esm/runtime/build-cluster-swagger-url.js +20 -5
- package/lib/esm/runtime/c4-console-runtime-context.d.ts +10 -0
- package/lib/esm/runtime/c4-console-runtime-context.js +12 -0
- package/lib/esm/runtime/index.d.ts +2 -1
- package/lib/esm/runtime/index.js +2 -1
- package/lib/esm/runtime/use-hub-api-naming.d.ts +17 -0
- package/lib/esm/runtime/use-hub-api-naming.js +23 -0
- package/lib/esm/ui/families.d.ts +4 -0
- package/lib/esm/ui/families.js +22 -2
- package/lib/esm/widgets/cluster-details/c4-cluster-details-app.d.ts +16 -1
- package/lib/esm/widgets/cluster-details/c4-cluster-details-app.js +70 -21
- package/lib/esm/widgets/cluster-details/c4-cluster-details-page.d.ts +1 -1
- package/lib/esm/widgets/cluster-details/c4-cluster-details-page.js +54 -13
- package/lib/esm/widgets/cluster-details/c4-cluster-details-page.types.d.ts +10 -0
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-clients-tab.d.ts +1 -0
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-clients-tab.js +3 -0
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-connector-secrets-tab.d.ts +11 -0
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-connector-secrets-tab.js +8 -3
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-encryption-tab.d.ts +7 -0
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-encryption-tab.js +26 -5
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-overview-tab.js +43 -16
- package/lib/esm/widgets/cluster-details/tabs/c4-cluster-details-settings-tab.js +174 -3
- package/lib/esm/widgets/cluster-details/tabs/cluster-load-texts.d.ts +13 -0
- package/lib/esm/widgets/cluster-details/tabs/cluster-load-texts.js +29 -0
- package/lib/esm/widgets/cluster-health-override.d.ts +16 -0
- package/lib/esm/widgets/cluster-health-override.js +33 -0
- package/lib/esm/widgets/clusters/c4-clusters-page.js +8 -8
- package/lib/esm/widgets/create-cluster/c4-create-cluster-page.js +1 -1
- package/lib/esm/widgets/environment/c4-cluster-api-clients-widget.js +6 -1
- package/lib/esm/widgets/environment/c4-cluster-connector-secrets-widget.js +2 -1
- package/lib/esm/widgets/environment/use-cluster-swagger-url.d.ts +7 -4
- package/lib/esm/widgets/environment/use-cluster-swagger-url.js +7 -4
- package/lib/esm/widgets/management/c4-management-app.js +6 -2
- package/lib/esm/widgets/management/tabs/c4-management-api-tab.js +16 -31
- package/package.json +24 -24
- package/lib/esm/components/c4-advanced-search-filters/ArrayFieldContainer.d.ts +0 -16
- package/lib/esm/components/c4-advanced-search-filters/ArrayFieldContainer.js +0 -40
- package/lib/esm/components/c4-advanced-search-filters/AutosuggestInput.d.ts +0 -16
- package/lib/esm/components/c4-advanced-search-filters/AutosuggestInput.js +0 -142
- package/lib/esm/components/c4-advanced-search-filters/FieldRow.d.ts +0 -14
- package/lib/esm/components/c4-advanced-search-filters/FieldRow.js +0 -136
- package/lib/esm/components/c4-advanced-search-filters/FiltersSection.d.ts +0 -13
- package/lib/esm/components/c4-advanced-search-filters/FiltersSection.js +0 -58
- package/lib/esm/components/c4-advanced-search-filters/OrSection.d.ts +0 -16
- package/lib/esm/components/c4-advanced-search-filters/OrSection.js +0 -118
- package/lib/esm/components/c4-advanced-search-filters/c4-advanced-search-filters.d.ts +0 -3
- package/lib/esm/components/c4-advanced-search-filters/c4-advanced-search-filters.js +0 -408
- package/lib/esm/components/c4-advanced-search-filters/c4-advanced-search-filters.types.d.ts +0 -32
- package/lib/esm/components/c4-advanced-search-filters/state.types.d.ts +0 -14
- package/lib/esm/components/c4-advanced-search-filters/state.types.js +0 -6
- package/lib/esm/components/c4-advanced-search-filters/utils.d.ts +0 -5
- package/lib/esm/components/c4-advanced-search-filters/utils.js +0 -58
- /package/lib/esm/components/{c4-advanced-search-filters/c4-advanced-search-filters.types.js → c4-api-client-scope-picker/c4-api-client-scope-picker.types.js} +0 -0
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
|
|
4
|
-
* under one or more contributor license agreements. Licensed under a commercial license.
|
|
5
|
-
* You may not use this file except in compliance with the commercial license.
|
|
6
|
-
*/
|
|
7
|
-
import { Close } from '@carbon/react/icons/index.esm.js';
|
|
8
|
-
import { Button } from '../../ui/index.js';
|
|
9
|
-
import { useSelectFamily } from '../../ui/families.js';
|
|
10
|
-
import { ArrayFieldContainer } from './ArrayFieldContainer.js';
|
|
11
|
-
export const OrSection = ({ sectionId, fieldsConfig, filterFields, addArrayItem, removeOrSection, addOptionalFieldToSection, updateFilter, renderFieldRow, }) => {
|
|
12
|
-
const { Select, SelectItem } = useSelectFamily();
|
|
13
|
-
const sectionFields = filterFields;
|
|
14
|
-
const availableFields = Object.entries(fieldsConfig)
|
|
15
|
-
.filter(([fieldName, spec]) => {
|
|
16
|
-
const addedInSection = sectionFields.some((f) => (f.fieldName === fieldName && !f.parentArrayField) ||
|
|
17
|
-
f.parentArrayField === fieldName);
|
|
18
|
-
return spec.optional && !addedInSection;
|
|
19
|
-
})
|
|
20
|
-
.map(([fieldName, spec]) => ({ fieldName, spec }))
|
|
21
|
-
.sort((a, b) => a.spec.label.localeCompare(b.spec.label));
|
|
22
|
-
const groupedFields = sectionFields.reduce((groups, field) => {
|
|
23
|
-
if (field.parentArrayField) {
|
|
24
|
-
const key = `${field.parentArrayField}-${field.arrayIndex}`;
|
|
25
|
-
if (!groups[key]) {
|
|
26
|
-
groups[key] = [];
|
|
27
|
-
}
|
|
28
|
-
groups[key].push(field);
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
const key = field.fieldName;
|
|
32
|
-
if (!groups[key]) {
|
|
33
|
-
groups[key] = [];
|
|
34
|
-
}
|
|
35
|
-
groups[key].push(field);
|
|
36
|
-
}
|
|
37
|
-
return groups;
|
|
38
|
-
}, {});
|
|
39
|
-
const regularFields = Object.entries(groupedFields)
|
|
40
|
-
.filter(([, groupFields]) => !groupFields[0].parentArrayField)
|
|
41
|
-
.map(([, groupFields]) => {
|
|
42
|
-
const firstField = groupFields[0];
|
|
43
|
-
const spec = fieldsConfig[firstField.fieldName];
|
|
44
|
-
if (!spec || spec.matchType === 'array') {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
return groupFields.map((field) => renderFieldRow(field, spec));
|
|
48
|
-
})
|
|
49
|
-
.filter(Boolean);
|
|
50
|
-
const arrayFieldsInSection = new Set(sectionFields
|
|
51
|
-
.filter((f) => f.parentArrayField)
|
|
52
|
-
.map((f) => f.parentArrayField));
|
|
53
|
-
const arrayFieldElements = Array.from(arrayFieldsInSection).map((fieldName) => {
|
|
54
|
-
const spec = fieldsConfig[fieldName];
|
|
55
|
-
if (!spec || spec.matchType !== 'array') {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
const arrayFields = sectionFields.filter((f) => f.parentArrayField === fieldName);
|
|
59
|
-
const arrayGroups = new Map();
|
|
60
|
-
arrayFields.forEach((field) => {
|
|
61
|
-
const index = field.arrayIndex ?? 0;
|
|
62
|
-
if (!arrayGroups.has(index)) {
|
|
63
|
-
arrayGroups.set(index, []);
|
|
64
|
-
}
|
|
65
|
-
arrayGroups.get(index)?.push(field);
|
|
66
|
-
});
|
|
67
|
-
return (_jsx(ArrayFieldContainer, { fieldName: fieldName, spec: spec, title: `${spec.label} Array`, groups: Array.from(arrayGroups.entries()), onAddItem: () => addArrayItem(fieldName, sectionId), onRemoveItem: (arrayIndex) => {
|
|
68
|
-
const updatedFields = filterFields.filter((f) => !(f.parentArrayField === fieldName &&
|
|
69
|
-
f.arrayIndex === arrayIndex &&
|
|
70
|
-
f.orSectionId === sectionId));
|
|
71
|
-
updateFilter(updatedFields);
|
|
72
|
-
}, onRemoveAll: spec.optional
|
|
73
|
-
? () => {
|
|
74
|
-
const updatedFields = filterFields.filter((f) => !(f.parentArrayField === fieldName &&
|
|
75
|
-
f.orSectionId === sectionId));
|
|
76
|
-
updateFilter(updatedFields);
|
|
77
|
-
}
|
|
78
|
-
: undefined, renderRow: (f, s) => renderFieldRow(f, s) }, fieldName));
|
|
79
|
-
});
|
|
80
|
-
return (_jsxs("div", { style: {
|
|
81
|
-
border: '2px solid var(--cds-border-accent)',
|
|
82
|
-
borderRadius: 8,
|
|
83
|
-
padding: '1rem',
|
|
84
|
-
backgroundColor: 'var(--cds-layer-01)',
|
|
85
|
-
position: 'relative',
|
|
86
|
-
}, children: [_jsxs("div", { style: {
|
|
87
|
-
display: 'flex',
|
|
88
|
-
justifyContent: 'space-between',
|
|
89
|
-
alignItems: 'center',
|
|
90
|
-
marginBottom: '1rem',
|
|
91
|
-
paddingBottom: '0.5rem',
|
|
92
|
-
borderBottom: '1px solid var(--cds-border-subtle)',
|
|
93
|
-
}, children: [_jsxs("div", { style: {
|
|
94
|
-
fontSize: '0.875rem',
|
|
95
|
-
fontWeight: 600,
|
|
96
|
-
color: 'var(--cds-text-primary)',
|
|
97
|
-
display: 'flex',
|
|
98
|
-
alignItems: 'center',
|
|
99
|
-
gap: '0.5rem',
|
|
100
|
-
}, children: [_jsx("span", { style: {
|
|
101
|
-
backgroundColor: 'var(--cds-support-info)',
|
|
102
|
-
color: 'white',
|
|
103
|
-
padding: '0.25rem 0.5rem',
|
|
104
|
-
borderRadius: 4,
|
|
105
|
-
fontSize: '0.75rem',
|
|
106
|
-
fontWeight: 500,
|
|
107
|
-
}, children: "OR" }), "Alternative Filter Conditions"] }), _jsx(Button, { kind: 'ghost', size: 'sm', renderIcon: Close, iconDescription: 'Remove OR section', onClick: () => removeOrSection(sectionId), hasIconOnly: true })] }), sectionFields.length === 0 ? (_jsx("div", { style: {
|
|
108
|
-
textAlign: 'center',
|
|
109
|
-
padding: '1rem',
|
|
110
|
-
color: 'var(--cds-text-secondary)',
|
|
111
|
-
fontSize: '0.875rem',
|
|
112
|
-
}, children: "No conditions added to this OR section. Add fields below to create alternative filter conditions." })) : (_jsxs("div", { children: [regularFields, arrayFieldElements] })), availableFields.length > 0 && (_jsx("div", { style: { marginTop: '1rem' }, children: _jsxs(Select, { id: `or-section-${sectionId}-field-select`, labelText: 'Add Field to OR Section', value: '', onChange: (e) => {
|
|
113
|
-
const fieldName = e.target.value;
|
|
114
|
-
if (fieldName) {
|
|
115
|
-
addOptionalFieldToSection(fieldName, sectionId);
|
|
116
|
-
}
|
|
117
|
-
}, children: [_jsx(SelectItem, { value: '', text: 'Select field to add...' }), availableFields.map((field) => (_jsx(SelectItem, { value: field.fieldName, text: field.spec.label }, field.fieldName)))] }) }))] }, sectionId));
|
|
118
|
-
};
|
|
@@ -1,408 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
|
|
4
|
-
* under one or more contributor license agreements. Licensed under a commercial license.
|
|
5
|
-
* You may not use this file except in compliance with the commercial license.
|
|
6
|
-
*/
|
|
7
|
-
import { Add } from '@carbon/react/icons/index.esm.js';
|
|
8
|
-
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
9
|
-
import { Button, Stack } from '../../ui/index.js';
|
|
10
|
-
import { useSelectFamily } from '../../ui/families.js';
|
|
11
|
-
import { FieldRow } from './FieldRow.js';
|
|
12
|
-
import { FiltersSection } from './FiltersSection.js';
|
|
13
|
-
import { OrSection } from './OrSection.js';
|
|
14
|
-
import { convertDateToISOString, getInitialValue, isArrayOperator, validateComparisonOperatorValue, } from './utils.js';
|
|
15
|
-
export const C4AdvancedSearchFilters = ({ fields, onFilterChange, }) => {
|
|
16
|
-
const { Select, SelectItem } = useSelectFamily();
|
|
17
|
-
const [filterFields, setFilterFields] = useState([]);
|
|
18
|
-
const [orSections, setOrSections] = useState([]);
|
|
19
|
-
const [nextId, setNextId] = useState(1);
|
|
20
|
-
// Initialize with non-optional fields in the root section
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
const initialFields = [];
|
|
23
|
-
Object.entries(fields)
|
|
24
|
-
.filter(([, spec]) => !spec.optional)
|
|
25
|
-
.forEach(([fieldName, spec], index) => {
|
|
26
|
-
if (spec.matchType === 'array' && spec.arrayItems) {
|
|
27
|
-
Object.entries(spec.arrayItems).forEach(([arrayFieldName, arrayFieldSpec]) => {
|
|
28
|
-
initialFields.push({
|
|
29
|
-
id: `field-init-${index}-0-${arrayFieldName}`,
|
|
30
|
-
fieldName: arrayFieldName,
|
|
31
|
-
matchType: arrayFieldSpec.matchType === 'exact-match'
|
|
32
|
-
? 'exact-match'
|
|
33
|
-
: arrayFieldSpec.matchType === 'advanced-filter'
|
|
34
|
-
? 'advanced-filter'
|
|
35
|
-
: undefined,
|
|
36
|
-
operator: arrayFieldSpec.matchType === 'advanced-filter'
|
|
37
|
-
? arrayFieldSpec.operators?.[0]
|
|
38
|
-
: undefined,
|
|
39
|
-
value: getInitialValue(arrayFieldSpec),
|
|
40
|
-
arrayIndex: 0,
|
|
41
|
-
arrayFieldName,
|
|
42
|
-
parentArrayField: fieldName,
|
|
43
|
-
orSectionId: 'root',
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
initialFields.push({
|
|
49
|
-
id: `field-init-${index}`,
|
|
50
|
-
fieldName,
|
|
51
|
-
matchType: spec.matchType === 'exact-match'
|
|
52
|
-
? 'exact-match'
|
|
53
|
-
: spec.matchType === 'advanced-filter'
|
|
54
|
-
? 'advanced-filter'
|
|
55
|
-
: undefined,
|
|
56
|
-
operator: spec.matchType === 'advanced-filter'
|
|
57
|
-
? spec.operators?.[0]
|
|
58
|
-
: undefined,
|
|
59
|
-
value: getInitialValue(spec),
|
|
60
|
-
orSectionId: 'root',
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
setFilterFields(initialFields);
|
|
65
|
-
setNextId(1000);
|
|
66
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
67
|
-
}, [fields]);
|
|
68
|
-
const createInitialField = useCallback((fieldName, spec, arrayIndex, arrayFieldName, parentArrayField, orSectionId = 'root') => {
|
|
69
|
-
const id = `field-${nextId}-${Date.now()}-${Math.random()}`;
|
|
70
|
-
setNextId((prev) => prev + 1);
|
|
71
|
-
return {
|
|
72
|
-
id,
|
|
73
|
-
fieldName,
|
|
74
|
-
matchType: spec.matchType === 'exact-match'
|
|
75
|
-
? 'exact-match'
|
|
76
|
-
: spec.matchType === 'advanced-filter'
|
|
77
|
-
? 'advanced-filter'
|
|
78
|
-
: spec.matchType === 'both'
|
|
79
|
-
? undefined
|
|
80
|
-
: undefined,
|
|
81
|
-
operator: spec.matchType === 'advanced-filter' && spec.operators?.length
|
|
82
|
-
? spec.operators[0]
|
|
83
|
-
: undefined,
|
|
84
|
-
value: getInitialValue(spec),
|
|
85
|
-
arrayIndex,
|
|
86
|
-
arrayFieldName,
|
|
87
|
-
parentArrayField,
|
|
88
|
-
orSectionId,
|
|
89
|
-
};
|
|
90
|
-
}, [nextId]);
|
|
91
|
-
const generatePayload = useCallback((fieldsToProcess) => {
|
|
92
|
-
const payload = {};
|
|
93
|
-
const rootFields = fieldsToProcess.filter((field) => field.orSectionId === 'root');
|
|
94
|
-
const orSectionFields = fieldsToProcess.filter((field) => field.orSectionId !== 'root');
|
|
95
|
-
const processFieldsToPayload = (fieldsList) => {
|
|
96
|
-
const sectionPayload = {};
|
|
97
|
-
const arrayFieldGroups = new Map();
|
|
98
|
-
fieldsList.forEach((field) => {
|
|
99
|
-
const isExistsOperator = field.operator === '$exists';
|
|
100
|
-
if (!isExistsOperator &&
|
|
101
|
-
!['$in', '$notIn'].includes(field.operator || '') &&
|
|
102
|
-
(field.value === undefined ||
|
|
103
|
-
field.value === null ||
|
|
104
|
-
(typeof field.value === 'string' && !field.value.trim()))) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
if (['$in', '$notIn'].includes(field.operator || '') &&
|
|
108
|
-
(!field.arrayValues || field.arrayValues.length === 0)) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
if (field.parentArrayField &&
|
|
112
|
-
field.arrayIndex !== undefined &&
|
|
113
|
-
field.arrayFieldName) {
|
|
114
|
-
if (!arrayFieldGroups.has(field.parentArrayField)) {
|
|
115
|
-
arrayFieldGroups.set(field.parentArrayField, new Map());
|
|
116
|
-
}
|
|
117
|
-
const arrayItems = arrayFieldGroups.get(field.parentArrayField);
|
|
118
|
-
if (!arrayItems.has(field.arrayIndex)) {
|
|
119
|
-
arrayItems.set(field.arrayIndex, {});
|
|
120
|
-
}
|
|
121
|
-
const arrayItem = arrayItems.get(field.arrayIndex);
|
|
122
|
-
let fieldValue;
|
|
123
|
-
if (field.matchType === 'exact-match' || !field.operator) {
|
|
124
|
-
fieldValue = convertDateToISOString(field.value);
|
|
125
|
-
}
|
|
126
|
-
else if (['$in', '$notIn'].includes(field.operator)) {
|
|
127
|
-
fieldValue = {
|
|
128
|
-
[field.operator]: convertDateToISOString(field.arrayValues),
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
fieldValue = {
|
|
133
|
-
[field.operator]: convertDateToISOString(field.value),
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
arrayItem[field.arrayFieldName] = fieldValue;
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
let fieldValue;
|
|
140
|
-
if (field.matchType === 'exact-match' || !field.operator) {
|
|
141
|
-
fieldValue = convertDateToISOString(field.value);
|
|
142
|
-
}
|
|
143
|
-
else if (['$in', '$notIn'].includes(field.operator)) {
|
|
144
|
-
fieldValue = {
|
|
145
|
-
[field.operator]: convertDateToISOString(field.arrayValues),
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
fieldValue = {
|
|
150
|
-
[field.operator]: convertDateToISOString(field.value),
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
sectionPayload[field.fieldName] = fieldValue;
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
arrayFieldGroups.forEach((arrayItems, parentFieldName) => {
|
|
157
|
-
const sortedArrayItems = Array.from(arrayItems.entries())
|
|
158
|
-
.sort(([a], [b]) => a - b)
|
|
159
|
-
.map(([, item]) => item)
|
|
160
|
-
.filter((item) => Object.keys(item).length > 0);
|
|
161
|
-
if (sortedArrayItems.length > 0) {
|
|
162
|
-
sectionPayload[parentFieldName] = sortedArrayItems;
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
return sectionPayload;
|
|
166
|
-
};
|
|
167
|
-
const rootPayload = processFieldsToPayload(rootFields);
|
|
168
|
-
Object.assign(payload, rootPayload);
|
|
169
|
-
if (orSectionFields.length > 0) {
|
|
170
|
-
const orSectionMap = new Map();
|
|
171
|
-
orSectionFields.forEach((field) => {
|
|
172
|
-
const sectionId = field.orSectionId;
|
|
173
|
-
if (!orSectionMap.has(sectionId)) {
|
|
174
|
-
orSectionMap.set(sectionId, []);
|
|
175
|
-
}
|
|
176
|
-
orSectionMap.get(sectionId)?.push(field);
|
|
177
|
-
});
|
|
178
|
-
const orPayloads = [];
|
|
179
|
-
orSectionMap.forEach((fields) => {
|
|
180
|
-
const orPayload = processFieldsToPayload(fields);
|
|
181
|
-
if (Object.keys(orPayload).length > 0) {
|
|
182
|
-
orPayloads.push(orPayload);
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
if (orPayloads.length > 0) {
|
|
186
|
-
payload.$or = orPayloads;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return payload;
|
|
190
|
-
}, []);
|
|
191
|
-
const updateFilter = useCallback((updatedFields) => {
|
|
192
|
-
setFilterFields(updatedFields);
|
|
193
|
-
const payload = generatePayload(updatedFields);
|
|
194
|
-
onFilterChange(payload);
|
|
195
|
-
}, [generatePayload, onFilterChange]);
|
|
196
|
-
const addOrSection = useCallback(() => {
|
|
197
|
-
const newSectionId = `or-${Date.now()}`;
|
|
198
|
-
setOrSections((prev) => [...prev, newSectionId]);
|
|
199
|
-
}, []);
|
|
200
|
-
const removeOrSection = useCallback((sectionId) => {
|
|
201
|
-
const updatedFields = filterFields.filter((field) => field.orSectionId !== sectionId);
|
|
202
|
-
updateFilter(updatedFields);
|
|
203
|
-
setOrSections((prev) => prev.filter((id) => id !== sectionId));
|
|
204
|
-
}, [filterFields, updateFilter]);
|
|
205
|
-
const addOptionalFieldToSection = useCallback((fieldName, sectionId = 'root') => {
|
|
206
|
-
const spec = fields[fieldName];
|
|
207
|
-
if (!spec) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
if (spec.matchType === 'array' && spec.arrayItems) {
|
|
211
|
-
const newFields = [];
|
|
212
|
-
Object.entries(spec.arrayItems).forEach(([arrayFieldName, arrayFieldSpec]) => {
|
|
213
|
-
newFields.push(createInitialField(arrayFieldName, arrayFieldSpec, 0, arrayFieldName, fieldName, sectionId));
|
|
214
|
-
});
|
|
215
|
-
updateFilter([...filterFields, ...newFields]);
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
const newField = createInitialField(fieldName, spec, undefined, undefined, undefined, sectionId);
|
|
219
|
-
updateFilter([...filterFields, newField]);
|
|
220
|
-
}
|
|
221
|
-
}, [fields, filterFields, createInitialField, updateFilter]);
|
|
222
|
-
const handleFieldChange = useCallback((fieldId, updates) => {
|
|
223
|
-
const updatedFields = filterFields.map((field) => {
|
|
224
|
-
if (field.id === fieldId) {
|
|
225
|
-
const updatedField = { ...field, ...updates };
|
|
226
|
-
// Get field spec to determine field type
|
|
227
|
-
const spec = field.parentArrayField
|
|
228
|
-
? fields[field.parentArrayField]?.arrayItems?.[field.arrayFieldName]
|
|
229
|
-
: fields[field.fieldName];
|
|
230
|
-
// Validate comparison operators for number and date-time fields
|
|
231
|
-
if (updatedField.operator && updatedField.value && spec) {
|
|
232
|
-
const fieldType = spec.type || 'string';
|
|
233
|
-
const error = validateComparisonOperatorValue(updatedField.value, updatedField.operator, fieldType);
|
|
234
|
-
updatedField.inputError = error;
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
updatedField.inputError = undefined;
|
|
238
|
-
}
|
|
239
|
-
// Reset operator-specific data when operator changes
|
|
240
|
-
if (updates.operator && updates.operator !== field.operator) {
|
|
241
|
-
if (isArrayOperator(updates.operator)) {
|
|
242
|
-
updatedField.arrayValues = updatedField.arrayValues || [];
|
|
243
|
-
updatedField.value = '';
|
|
244
|
-
}
|
|
245
|
-
else {
|
|
246
|
-
updatedField.arrayValues = undefined;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
return updatedField;
|
|
250
|
-
}
|
|
251
|
-
return field;
|
|
252
|
-
});
|
|
253
|
-
updateFilter(updatedFields);
|
|
254
|
-
}, [filterFields, updateFilter, fields]);
|
|
255
|
-
const addArrayValue = useCallback((fieldId, value) => {
|
|
256
|
-
// For dates, use ISO string for comparison and storage
|
|
257
|
-
const comparisonValue = value instanceof Date ? value.toISOString() : String(value).trim();
|
|
258
|
-
if (comparisonValue.length === 0) {
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
const updatedFields = filterFields.map((field) => {
|
|
262
|
-
if (field.id === fieldId) {
|
|
263
|
-
const currentArrayValues = field.arrayValues || [];
|
|
264
|
-
// Check if value already exists (use ISO string for dates)
|
|
265
|
-
const valueExists = currentArrayValues.some((v) => {
|
|
266
|
-
const existingValue = v instanceof Date ? v.toISOString() : String(v);
|
|
267
|
-
return existingValue === comparisonValue;
|
|
268
|
-
});
|
|
269
|
-
if (!valueExists) {
|
|
270
|
-
return {
|
|
271
|
-
...field,
|
|
272
|
-
arrayValues: [...currentArrayValues, value],
|
|
273
|
-
value: getInitialValue(fields[field.fieldName] || fields[field.arrayFieldName]), // Clear input after adding
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return field;
|
|
278
|
-
});
|
|
279
|
-
updateFilter(updatedFields);
|
|
280
|
-
}, [filterFields, updateFilter, fields]);
|
|
281
|
-
const removeArrayValue = useCallback((fieldId, valueToRemove) => {
|
|
282
|
-
const comparisonValue = valueToRemove instanceof Date
|
|
283
|
-
? valueToRemove.toISOString()
|
|
284
|
-
: String(valueToRemove);
|
|
285
|
-
const updatedFields = filterFields.map((field) => {
|
|
286
|
-
if (field.id === fieldId && field.arrayValues) {
|
|
287
|
-
return {
|
|
288
|
-
...field,
|
|
289
|
-
arrayValues: field.arrayValues.filter((v) => {
|
|
290
|
-
const existingValue = v instanceof Date ? v.toISOString() : String(v);
|
|
291
|
-
return existingValue !== comparisonValue;
|
|
292
|
-
}),
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
return field;
|
|
296
|
-
});
|
|
297
|
-
updateFilter(updatedFields);
|
|
298
|
-
}, [filterFields, updateFilter]);
|
|
299
|
-
const addOptionalField = useCallback((fieldName) => {
|
|
300
|
-
const spec = fields[fieldName];
|
|
301
|
-
if (!spec) {
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
if (spec.matchType === 'array' && spec.arrayItems) {
|
|
305
|
-
// For array fields, create initial empty array items
|
|
306
|
-
// Start with one array item by default
|
|
307
|
-
const newFields = [];
|
|
308
|
-
Object.entries(spec.arrayItems).forEach(([arrayFieldName, arrayFieldSpec]) => {
|
|
309
|
-
newFields.push(createInitialField(arrayFieldName, arrayFieldSpec, 0, // Start with index 0
|
|
310
|
-
arrayFieldName, fieldName, // parentArrayField
|
|
311
|
-
'root'));
|
|
312
|
-
});
|
|
313
|
-
updateFilter([...filterFields, ...newFields]);
|
|
314
|
-
}
|
|
315
|
-
else {
|
|
316
|
-
// Regular fields
|
|
317
|
-
const newField = createInitialField(fieldName, spec);
|
|
318
|
-
updateFilter([...filterFields, newField]);
|
|
319
|
-
}
|
|
320
|
-
}, [fields, filterFields, createInitialField, updateFilter]);
|
|
321
|
-
const removeField = useCallback((fieldId) => {
|
|
322
|
-
const updatedFields = filterFields.filter((field) => field.id !== fieldId);
|
|
323
|
-
updateFilter(updatedFields);
|
|
324
|
-
}, [filterFields, updateFilter]);
|
|
325
|
-
const addArrayItem = useCallback((parentFieldName, orSectionId = 'root') => {
|
|
326
|
-
const spec = fields[parentFieldName];
|
|
327
|
-
if (!spec?.arrayItems) {
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
const existingArrayItems = filterFields.filter((f) => f.parentArrayField === parentFieldName &&
|
|
331
|
-
f.orSectionId === orSectionId);
|
|
332
|
-
// Find the highest array index for this parent field in this OR section
|
|
333
|
-
const maxIndex = existingArrayItems.reduce((max, field) => field.arrayIndex !== undefined
|
|
334
|
-
? Math.max(max, field.arrayIndex)
|
|
335
|
-
: max, -1);
|
|
336
|
-
const nextIndex = maxIndex + 1;
|
|
337
|
-
// Create new fields for all array item properties
|
|
338
|
-
const newFields = [];
|
|
339
|
-
Object.entries(spec.arrayItems).forEach(([arrayFieldName, arrayFieldSpec]) => {
|
|
340
|
-
newFields.push(createInitialField(arrayFieldName, arrayFieldSpec, nextIndex, arrayFieldName, parentFieldName, orSectionId));
|
|
341
|
-
});
|
|
342
|
-
updateFilter([...filterFields, ...newFields]);
|
|
343
|
-
}, [fields, filterFields, createInitialField, updateFilter]);
|
|
344
|
-
const renderFieldRow = (field, spec) => (_jsx(FieldRow, { field: field, spec: spec, onFieldChange: handleFieldChange, onRemove: spec.optional ? removeField : undefined, onAddArrayValue: addArrayValue, onRemoveArrayValue: removeArrayValue }, field.id));
|
|
345
|
-
// Root-section fields and the still-available optional fields are both pure
|
|
346
|
-
// functions of `filterFields`/`fields` but were recomputed several times per
|
|
347
|
-
// render; memoize them so each render does the work at most once.
|
|
348
|
-
const rootFilterFields = useMemo(() => filterFields.filter((f) => f.orSectionId === 'root'), [filterFields]);
|
|
349
|
-
const availableOptionalFields = useMemo(() => {
|
|
350
|
-
const addedFields = new Set(filterFields
|
|
351
|
-
.filter((f) => f.orSectionId === 'root' && !f.parentArrayField)
|
|
352
|
-
.map((f) => f.fieldName));
|
|
353
|
-
// Also include array fields that have been added
|
|
354
|
-
const addedArrayFields = new Set(filterFields
|
|
355
|
-
.filter((f) => f.orSectionId === 'root' && f.parentArrayField)
|
|
356
|
-
.map((f) => f.parentArrayField));
|
|
357
|
-
return Object.entries(fields)
|
|
358
|
-
.filter(([fieldName, spec]) => spec.optional &&
|
|
359
|
-
!addedFields.has(fieldName) &&
|
|
360
|
-
!addedArrayFields.has(fieldName))
|
|
361
|
-
.map(([fieldName, spec]) => ({ fieldName, spec }))
|
|
362
|
-
.sort((a, b) => a.spec.label.localeCompare(b.spec.label));
|
|
363
|
-
}, [filterFields, fields]);
|
|
364
|
-
return (_jsx(Stack, { gap: 5, children: Object.keys(fields).length === 0 ? (_jsx("div", { style: {
|
|
365
|
-
textAlign: 'center',
|
|
366
|
-
padding: '2rem',
|
|
367
|
-
color: 'var(--cds-text-secondary)',
|
|
368
|
-
fontSize: '0.875rem',
|
|
369
|
-
}, children: "No fields are configured for this filter component." })) : (_jsxs(_Fragment, { children: [rootFilterFields.length === 0 &&
|
|
370
|
-
availableOptionalFields.length > 0 ? (_jsx("div", { style: {
|
|
371
|
-
textAlign: 'center',
|
|
372
|
-
padding: '1rem',
|
|
373
|
-
color: 'var(--cds-text-secondary)',
|
|
374
|
-
fontSize: '0.875rem',
|
|
375
|
-
marginBottom: '1rem',
|
|
376
|
-
}, children: "No fields are currently selected. Add optional fields below to start filtering." })) : (_jsxs("div", { children: [_jsxs("div", { style: {
|
|
377
|
-
fontSize: '1rem',
|
|
378
|
-
fontWeight: '600',
|
|
379
|
-
color: 'var(--cds-text-primary)',
|
|
380
|
-
marginBottom: '1rem',
|
|
381
|
-
display: 'flex',
|
|
382
|
-
alignItems: 'center',
|
|
383
|
-
gap: '0.5rem',
|
|
384
|
-
}, children: [_jsx("span", { style: {
|
|
385
|
-
backgroundColor: 'var(--cds-support-success)',
|
|
386
|
-
color: 'white',
|
|
387
|
-
padding: '0.25rem 0.5rem',
|
|
388
|
-
borderRadius: '4px',
|
|
389
|
-
fontSize: '0.75rem',
|
|
390
|
-
fontWeight: '500',
|
|
391
|
-
}, children: "AND" }), "Main Filter Conditions"] }), _jsx(FiltersSection, { fields: fields, filterFields: rootFilterFields, addArrayItem: addArrayItem, updateFilter: updateFilter, renderFieldRow: renderFieldRow })] })), availableOptionalFields.length > 0 && (_jsxs("div", { style: {
|
|
392
|
-
marginTop: rootFilterFields.length === 0 ? '0' : '1rem',
|
|
393
|
-
}, children: [rootFilterFields.length === 0 && (_jsx("div", { style: {
|
|
394
|
-
marginBottom: '1rem',
|
|
395
|
-
color: 'var(--cds-text-primary)',
|
|
396
|
-
fontSize: '0.875rem',
|
|
397
|
-
fontWeight: '500',
|
|
398
|
-
}, children: "Add fields to create your filter:" })), _jsxs(Select, { id: 'optional-field-select', labelText: 'Add Fields to Main Filter', value: '', onChange: (e) => {
|
|
399
|
-
const fieldName = e.target.value;
|
|
400
|
-
if (fieldName) {
|
|
401
|
-
addOptionalField(fieldName);
|
|
402
|
-
}
|
|
403
|
-
}, children: [_jsx(SelectItem, { value: '', text: 'Select field to add...' }), availableOptionalFields.map((field) => (_jsx(SelectItem, { value: field.fieldName, text: field.spec.label }, field.fieldName)))] })] })), orSections.map((sectionId) => (_jsx(OrSection, { sectionId: sectionId, fieldsConfig: fields, filterFields: filterFields.filter((f) => f.orSectionId === sectionId), addArrayItem: addArrayItem, removeOrSection: removeOrSection, addOptionalFieldToSection: addOptionalFieldToSection, updateFilter: updateFilter, renderFieldRow: renderFieldRow }, sectionId))), _jsxs("div", { style: { marginTop: '1rem' }, children: [_jsx(Button, { kind: 'tertiary', size: 'sm', renderIcon: Add, onClick: addOrSection, children: "Add OR Condition" }), _jsx("div", { style: {
|
|
404
|
-
fontSize: '0.75rem',
|
|
405
|
-
color: 'var(--cds-text-secondary)',
|
|
406
|
-
marginTop: '0.5rem',
|
|
407
|
-
}, children: "OR conditions provide alternative filter criteria. Records matching ANY of these conditions will be included." })] })] })) }));
|
|
408
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export type AdvancedFilterOperator = '$eq' | '$neq' | '$exists' | '$gt' | '$gte' | '$lt' | '$lte' | '$like' | '$in' | '$notIn';
|
|
2
|
-
export type FieldMatchType = 'exact-match' | 'advanced-filter' | 'both' | 'array';
|
|
3
|
-
export type FieldDataType = 'string' | 'number' | 'date-time' | 'enum' | 'boolean';
|
|
4
|
-
export interface FieldSpec {
|
|
5
|
-
label: string;
|
|
6
|
-
description: string;
|
|
7
|
-
matchType: FieldMatchType;
|
|
8
|
-
type?: FieldDataType;
|
|
9
|
-
optional: boolean;
|
|
10
|
-
operators?: AdvancedFilterOperator[];
|
|
11
|
-
enumValues?: string[];
|
|
12
|
-
arrayItems?: FieldSpecMap;
|
|
13
|
-
/**
|
|
14
|
-
* Optional async suggestion provider. If present (and the field data type is string),
|
|
15
|
-
* it will be invoked (debounced) after the user stops typing for 500ms.
|
|
16
|
-
* Returned suggestions (string array) will be rendered beneath the input allowing
|
|
17
|
-
* quick selection. An empty / falsy result clears the suggestions list.
|
|
18
|
-
*/
|
|
19
|
-
fetchSuggestions?: (input: string) => Promise<string[]>;
|
|
20
|
-
}
|
|
21
|
-
export interface FieldSpecMap {
|
|
22
|
-
[fieldName: string]: FieldSpec;
|
|
23
|
-
}
|
|
24
|
-
export interface FilterPayload {
|
|
25
|
-
[fieldName: string]: unknown;
|
|
26
|
-
$or?: FilterPayload[];
|
|
27
|
-
}
|
|
28
|
-
export interface C4AdvancedSearchFiltersProps {
|
|
29
|
-
fields: FieldSpecMap;
|
|
30
|
-
onFilterChange: (payload: FilterPayload) => void;
|
|
31
|
-
initialFilters?: FilterPayload;
|
|
32
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { AdvancedFilterOperator } from './c4-advanced-search-filters.types.js';
|
|
2
|
-
export interface FilterFieldState {
|
|
3
|
-
id: string;
|
|
4
|
-
fieldName: string;
|
|
5
|
-
matchType?: 'exact-match' | 'advanced-filter';
|
|
6
|
-
operator?: AdvancedFilterOperator;
|
|
7
|
-
value: string | number | boolean | Date;
|
|
8
|
-
arrayValues?: (string | number | boolean | Date)[];
|
|
9
|
-
inputError?: string;
|
|
10
|
-
arrayIndex?: number;
|
|
11
|
-
arrayFieldName?: string;
|
|
12
|
-
parentArrayField?: string;
|
|
13
|
-
orSectionId?: string;
|
|
14
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { AdvancedFilterOperator, FieldDataType, FieldSpec } from './c4-advanced-search-filters.types.js';
|
|
2
|
-
export declare const validateComparisonOperatorValue: (value: string | number | boolean | Date, operator: AdvancedFilterOperator, fieldType?: FieldDataType) => string | undefined;
|
|
3
|
-
export declare const isArrayOperator: (operator?: AdvancedFilterOperator) => boolean;
|
|
4
|
-
export declare const convertDateToISOString: (value: unknown) => unknown;
|
|
5
|
-
export declare const getInitialValue: (spec: FieldSpec) => string | number | boolean | Date;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
|
|
3
|
-
* under one or more contributor license agreements. Licensed under a commercial license.
|
|
4
|
-
* You may not use this file except in compliance with the commercial license.
|
|
5
|
-
*/
|
|
6
|
-
export const validateComparisonOperatorValue = (value, operator, fieldType = 'string') => {
|
|
7
|
-
if (!['$gt', '$gte', '$lt', '$lte'].includes(operator)) {
|
|
8
|
-
return undefined;
|
|
9
|
-
}
|
|
10
|
-
const stringValue = String(value).trim();
|
|
11
|
-
if (stringValue === '') {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
if (fieldType === 'number') {
|
|
15
|
-
const numValue = parseFloat(stringValue);
|
|
16
|
-
if (Number.isNaN(numValue)) {
|
|
17
|
-
return 'Value must be a valid number for comparison operators';
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
else if (fieldType === 'date-time') {
|
|
21
|
-
if (!(value instanceof Date) || Number.isNaN(value.getTime())) {
|
|
22
|
-
return 'Value must be a valid date for comparison operators';
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return undefined;
|
|
26
|
-
};
|
|
27
|
-
export const isArrayOperator = (operator) => operator === '$in' || operator === '$notIn';
|
|
28
|
-
export const convertDateToISOString = (value) => {
|
|
29
|
-
if (value instanceof Date) {
|
|
30
|
-
return value.toISOString();
|
|
31
|
-
}
|
|
32
|
-
if (Array.isArray(value)) {
|
|
33
|
-
return value.map(convertDateToISOString);
|
|
34
|
-
}
|
|
35
|
-
if (value && typeof value === 'object') {
|
|
36
|
-
const converted = {};
|
|
37
|
-
for (const [key, val] of Object.entries(value)) {
|
|
38
|
-
converted[key] = convertDateToISOString(val);
|
|
39
|
-
}
|
|
40
|
-
return converted;
|
|
41
|
-
}
|
|
42
|
-
return value;
|
|
43
|
-
};
|
|
44
|
-
export const getInitialValue = (spec) => {
|
|
45
|
-
const fieldType = spec.type || 'string';
|
|
46
|
-
switch (fieldType) {
|
|
47
|
-
case 'number':
|
|
48
|
-
return 0;
|
|
49
|
-
case 'boolean':
|
|
50
|
-
return true;
|
|
51
|
-
case 'date-time':
|
|
52
|
-
return new Date();
|
|
53
|
-
case 'enum':
|
|
54
|
-
return spec.enumValues?.[0] || '';
|
|
55
|
-
default:
|
|
56
|
-
return '';
|
|
57
|
-
}
|
|
58
|
-
};
|