Files
Ashley Harrison 0e28d6143b Nested folders: Improve loading states (#69556)
* loading states!

* fix uncontrolled checkbox

* cleaner css

* improve flickering title

* make sure @grafana/ui has the same version of react-loading-skeleton

* fix unit test + add tooltip text

* better way of restoring focus

* only restore focus when loading

* missing !

* use aria-label instead of tooltip
2023-06-07 11:21:44 +01:00

48 lines
1.3 KiB
TypeScript

import { css } from '@emotion/css';
import React from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { selectors } from '@grafana/e2e-selectors';
import { Checkbox, useStyles2 } from '@grafana/ui';
import { DashboardsTreeCellProps, SelectionState } from '../types';
export default function CheckboxCell({
row: { original: row },
isSelected,
onItemSelectionChange,
}: DashboardsTreeCellProps) {
const styles = useStyles2(getStyles);
const item = row.item;
if (!isSelected) {
return <span className={styles.checkboxSpacer} />;
}
if (item.kind === 'ui') {
if (item.uiKind === 'pagination-placeholder') {
return <Checkbox disabled value={false} />;
} else {
return <span className={styles.checkboxSpacer} />;
}
}
const state = isSelected(item);
return (
<Checkbox
data-testid={selectors.pages.BrowseDashbards.table.checkbox(item.uid)}
value={state === SelectionState.Selected}
indeterminate={state === SelectionState.Mixed}
onChange={(ev) => onItemSelectionChange?.(item, ev.currentTarget.checked)}
/>
);
}
const getStyles = (theme: GrafanaTheme2) => ({
// Should be the same size as the <IconButton /> so Dashboard name is aligned to Folder name siblings
checkboxSpacer: css({
paddingLeft: theme.spacing(2),
}),
});