Skip to content

Commit

Permalink
fix: Loading state when cols for drill by are loading
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje committed Apr 26, 2023
1 parent 40ae074 commit 5efca21
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ test('render disabled menu item for supported chart, no columns', async () => {
fetchMock.get(DATASET_ENDPOINT, { result: { columns: [] } });
renderMenu({});
await waitFor(() => fetchMock.called(DATASET_ENDPOINT));
await expectDrillByDisabled('No dimensions available for drill by');
await expectDrillByEnabled();
screen.getByText('No columns found');
});

test('render menu item with submenu without searchbox', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
import Icons from 'src/components/Icons';
import { Input } from 'src/components/Input';
import { useToasts } from 'src/components/MessageToasts/withToasts';
import Loading from 'src/components/Loading';
import {
cachedSupersetGet,
supersetGetCache,
Expand Down Expand Up @@ -78,6 +79,7 @@ export const DrillByMenuItems = ({
}: DrillByMenuItemsProps) => {
const theme = useTheme();
const { addDangerToast } = useToasts();
const [isLoadingColumns, setIsLoadingColumns] = useState(true);
const [searchInput, setSearchInput] = useState('');
const [dataset, setDataset] = useState<Dataset>();
const [columns, setColumns] = useState<Column[]>([]);
Expand Down Expand Up @@ -143,6 +145,9 @@ export const DrillByMenuItems = ({
.catch(() => {
supersetGetCache.delete(`/api/v1/dataset/${datasetId}`);
addDangerToast(t('Failed to load dimensions for drill by'));
})
.finally(() => {
setIsLoadingColumns(false);
});
}
}, [
Expand Down Expand Up @@ -190,11 +195,9 @@ export const DrillByMenuItems = ({
tooltip = t('Drill by is not yet supported for this chart type');
} else if (!hasDrillBy) {
tooltip = t('Drill by is not available for this data point');
} else if (columns.length === 0) {
tooltip = t('No dimensions available for drill by');
}

if (!handlesDimensionContextMenu || !hasDrillBy || columns.length === 0) {
if (!handlesDimensionContextMenu || !hasDrillBy) {
return (
<Menu.Item key="drill-by-disabled" disabled {...rest}>
<div>
Expand Down Expand Up @@ -239,7 +242,15 @@ export const DrillByMenuItems = ({
`}
/>
)}
{filteredColumns.length ? (
{isLoadingColumns ? (
<div
css={css`
padding: ${theme.gridUnit * 3}px 0;
`}
>
<Loading position="inline-centered" />
</div>
) : filteredColumns.length ? (
<div
css={css`
max-height: ${MAX_SUBMENU_HEIGHT}px;
Expand Down

0 comments on commit 5efca21

Please sign in to comment.