Skip to content

Commit 8705297

Browse files
committed
make sure selected filters are shown below the filter select
previously they were shown right of the filter select
1 parent 1c0ce61 commit 8705297

File tree

1 file changed

+56
-52
lines changed

1 file changed

+56
-52
lines changed

src/ui/components.tsx

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -538,57 +538,61 @@ export const OnlyActiveChildren = (props: OnlyActiveChildrenProps): React.JSX.El
538538
}
539539

540540
return (
541-
<InlineFieldRow>
542-
{(props.showAddFilterDropdown === undefined || props.showAddFilterDropdown === true) && (
543-
<InlineField label="Filter" labelWidth={8}>
544-
<GrafanaSelect
545-
width={32}
546-
options={availableComponentsOptions()}
547-
// We know that the `value` prop will always be defined since `availableComponentsOptions` returns
548-
// an array of type `{value: string; label: string}`.
549-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
550-
onChange={(value) => setActiveComponents((c) => [...c, value.value!])}
551-
value={{ label: 'Add Filter' }}
552-
inputId="input_add_filter"
553-
/>
554-
</InlineField>
555-
)}
556-
<Stack direction="column">
557-
{props.children
558-
.filter((elem: ChildComponent) => {
559-
if (!React.isValidElement(elem)) {
560-
return false;
561-
}
562-
return activeComponents.includes(getKey(elem));
563-
})
564-
.map((elem: ChildComponent) => {
565-
if (props.showRemoveButton === undefined || props.showRemoveButton === true) {
566-
return (
567-
<Stack key={getKey(elem)}>
568-
<Button
569-
icon="minus"
570-
data-test-id={'cmk-oac-minus-button-' + getLabel(elem)}
571-
variant="secondary"
572-
onClick={() =>
573-
setActiveComponents((c) => {
574-
if (!React.isValidElement(elem)) {
575-
return c;
576-
}
577-
const result = [...c];
578-
result.splice(result.indexOf(elem.props.requestSpecKey), 1);
579-
elem.props.onChange(undefined);
580-
return result;
581-
})
582-
}
583-
/>
584-
{elem}
585-
</Stack>
586-
);
587-
} else {
588-
return elem;
589-
}
590-
})}
591-
</Stack>
592-
</InlineFieldRow>
541+
<Stack direction="column">
542+
<InlineFieldRow>
543+
{(props.showAddFilterDropdown === undefined || props.showAddFilterDropdown === true) && (
544+
<InlineField label="Filter" labelWidth={8}>
545+
<GrafanaSelect
546+
width={32}
547+
options={availableComponentsOptions()}
548+
// We know that the `value` prop will always be defined since `availableComponentsOptions` returns
549+
// an array of type `{value: string; label: string}`.
550+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
551+
onChange={(value) => setActiveComponents((c) => [...c, value.value!])}
552+
value={{ label: 'Add Filter' }}
553+
inputId="input_add_filter"
554+
/>
555+
</InlineField>
556+
)}
557+
</InlineFieldRow>
558+
<InlineFieldRow>
559+
<Stack direction="column">
560+
{props.children
561+
.filter((elem: ChildComponent) => {
562+
if (!React.isValidElement(elem)) {
563+
return false;
564+
}
565+
return activeComponents.includes(getKey(elem));
566+
})
567+
.map((elem: ChildComponent) => {
568+
if (props.showRemoveButton === undefined || props.showRemoveButton === true) {
569+
return (
570+
<Stack key={getKey(elem)}>
571+
<Button
572+
icon="minus"
573+
data-test-id={'cmk-oac-minus-button-' + getLabel(elem)}
574+
variant="secondary"
575+
onClick={() =>
576+
setActiveComponents((c) => {
577+
if (!React.isValidElement(elem)) {
578+
return c;
579+
}
580+
const result = [...c];
581+
result.splice(result.indexOf(elem.props.requestSpecKey), 1);
582+
elem.props.onChange(undefined);
583+
return result;
584+
})
585+
}
586+
/>
587+
{elem}
588+
</Stack>
589+
);
590+
} else {
591+
return elem;
592+
}
593+
})}
594+
</Stack>
595+
</InlineFieldRow>
596+
</Stack>
593597
);
594598
};

0 commit comments

Comments
 (0)