Skip to content

Commit c1ec327

Browse files
authored
FilterList: Improve "No values" display (grafana#90032)
* FilterList: Improve "No values" display * Switch to ternary
1 parent 675457f commit c1ec327

File tree

1 file changed

+39
-35
lines changed

1 file changed

+39
-35
lines changed

packages/grafana-ui/src/components/Table/FilterList.tsx

+39-35
Original file line numberDiff line numberDiff line change
@@ -184,41 +184,42 @@ export const FilterList = ({
184184
<FilterInput placeholder="Filter values" onChange={setSearchFilter} value={searchFilter} />
185185
</Stack>
186186
)}
187-
{!items.length && <Label>No values</Label>}
188-
{items.length && (
189-
<List
190-
height={height}
191-
itemCount={items.length}
192-
itemSize={ITEM_HEIGHT}
193-
width="100%"
194-
className={styles.filterList}
195-
>
196-
{({ index, style }) => {
197-
const option = items[index];
198-
const { value, label } = option;
199-
const isChecked = values.find((s) => s.value === value) !== undefined;
200-
201-
return (
202-
<div className={styles.filterListRow} style={style} title={label}>
203-
<Checkbox value={isChecked} label={label} onChange={onCheckedChanged(option)} />
204-
</div>
205-
);
206-
}}
207-
</List>
208-
)}
209-
{items.length && (
210-
<Stack direction="column" gap={0.25}>
211-
<div className={cx(styles.selectDivider)} />
212-
<div className={cx(styles.filterListRow)}>
213-
<Checkbox
214-
value={selectCheckValue}
215-
indeterminate={selectCheckIndeterminate}
216-
label={selectCheckLabel}
217-
description={selectCheckDescription}
218-
onChange={onSelectChanged}
219-
/>
220-
</div>
221-
</Stack>
187+
{items.length > 0 ? (
188+
<>
189+
<List
190+
height={height}
191+
itemCount={items.length}
192+
itemSize={ITEM_HEIGHT}
193+
width="100%"
194+
className={styles.filterList}
195+
>
196+
{({ index, style }) => {
197+
const option = items[index];
198+
const { value, label } = option;
199+
const isChecked = values.find((s) => s.value === value) !== undefined;
200+
201+
return (
202+
<div className={styles.filterListRow} style={style} title={label}>
203+
<Checkbox value={isChecked} label={label} onChange={onCheckedChanged(option)} />
204+
</div>
205+
);
206+
}}
207+
</List>
208+
<Stack direction="column" gap={0.25}>
209+
<div className={cx(styles.selectDivider)} />
210+
<div className={cx(styles.filterListRow)}>
211+
<Checkbox
212+
value={selectCheckValue}
213+
indeterminate={selectCheckIndeterminate}
214+
label={selectCheckLabel}
215+
description={selectCheckDescription}
216+
onChange={onSelectChanged}
217+
/>
218+
</div>
219+
</Stack>
220+
</>
221+
) : (
222+
<Label className={styles.noValuesLabel}>No values</Label>
222223
)}
223224
</Stack>
224225
);
@@ -246,4 +247,7 @@ const getStyles = (theme: GrafanaTheme2) => ({
246247
borderTop: `1px solid ${theme.colors.border.medium}`,
247248
padding: theme.spacing(0.5, 2),
248249
}),
250+
noValuesLabel: css({
251+
paddingTop: theme.spacing(1),
252+
}),
249253
});

0 commit comments

Comments
 (0)