Skip to content

Commit c1a418a

Browse files
adityathebemoshloop
authored andcommitted
todo
1 parent a9ebaf1 commit c1a418a

File tree

4 files changed

+44
-19
lines changed

4 files changed

+44
-19
lines changed

src/pages/audit-report/components/View/GlobalFilters.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,19 @@ import { useField } from "formik";
1010
interface DropdownProps {
1111
label: string;
1212
paramsKey: string;
13-
options: string[];
13+
options: GroupByOptions[];
1414
}
1515

1616
const Dropdown: React.FC<DropdownProps> = ({ label, paramsKey, options }) => {
1717
const [field] = useField({
1818
name: paramsKey
1919
});
20-
const dropdownOptions = useMemo(() => {
21-
const mappedOptions = options.map(
22-
(option) =>
23-
({
24-
value: option,
25-
label: option
26-
}) satisfies GroupByOptions
27-
);
28-
29-
return mappedOptions;
30-
}, [options]);
3120

3221
return (
3322
<MultiSelectDropdown
3423
label={label}
35-
options={dropdownOptions}
36-
value={dropdownOptions.find((option) => option.value === field.value)}
24+
options={options}
25+
value={options.find((option) => option.value === field.value)}
3726
onChange={(selectedOption: unknown) => {
3827
const option = selectedOption as GroupByOptions;
3928
field.onChange({
@@ -62,7 +51,17 @@ const GlobalFilters: React.FC<GlobalFiltersProps> = ({ variables }) => {
6251
key={variable.key}
6352
label={variable.label || formatDisplayLabel(variable.key)}
6453
paramsKey={variable.key}
65-
options={variable.options}
54+
options={
55+
variable.optionItems && variable.optionItems.length > 0
56+
? variable.optionItems.map((item) => ({
57+
label: item.label,
58+
value: item.value
59+
}))
60+
: variable.options.map((option) => ({
61+
label: option,
62+
value: option
63+
}))
64+
}
6665
/>
6766
));
6867
}, [variables]);

src/pages/audit-report/components/View/GlobalFiltersForm.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ function GlobalFiltersListener({
4242
variables.forEach((variable) => {
4343
const urlValue = globalParams.get(variable.key);
4444
const currentValue = currentVariables[variable.key];
45+
const optionItems = variable.optionItems ?? [];
4546
const defaultValue =
4647
variable.default ??
47-
(variable.options.length > 0 ? variable.options[0] : "");
48+
(optionItems.length > 0
49+
? optionItems[0].value
50+
: variable.options.length > 0
51+
? variable.options[0]
52+
: "");
4853

4954
const valueToUse = urlValue || currentValue || defaultValue;
5055
if (valueToUse) {

src/pages/audit-report/types/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ export interface ViewVariable {
389389
value: string;
390390
type: string;
391391
options: string[];
392+
optionItems?: {
393+
label: string;
394+
value: string;
395+
}[];
392396
default?: string;
393397
label?: string;
394398
}

src/pages/views/utils/aggregateVariables.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,30 @@ export function aggregateVariables(
1616
for (const variable of variables) {
1717
const existing = variableMap.get(variable.key);
1818
if (existing) {
19-
// Merge options (union of both arrays)
19+
const existingOptionItems = existing.optionItems ?? [];
20+
const nextOptionItems = variable.optionItems ?? [];
21+
const optionItemsByValue = new Map(
22+
existingOptionItems.map((item) => [item.value, item])
23+
);
24+
for (const item of nextOptionItems) {
25+
if (!optionItemsByValue.has(item.value)) {
26+
optionItemsByValue.set(item.value, item);
27+
}
28+
}
29+
30+
const mergedOptionItems = Array.from(optionItemsByValue.values());
2031
const mergedOptions = [
21-
...new Set([...existing.options, ...variable.options])
32+
...new Set([
33+
...existing.options,
34+
...variable.options,
35+
...mergedOptionItems.map((item) => item.value)
36+
])
2237
];
2338
variableMap.set(variable.key, {
2439
...existing,
25-
options: mergedOptions
40+
options: mergedOptions,
41+
optionItems:
42+
mergedOptionItems.length > 0 ? mergedOptionItems : undefined
2643
});
2744
} else {
2845
variableMap.set(variable.key, { ...variable });

0 commit comments

Comments
 (0)