Skip to content

Commit

Permalink
fix(components): gs-sequences-by-location: don't crash table view whe…
Browse files Browse the repository at this point in the history
…n there is no data
  • Loading branch information
fengelniederhammer committed Feb 11, 2025
1 parent 3544e51 commit d07b85a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useEffect, useRef } from 'preact/hooks';
import type { EnhancedGeoJsonFeatureProperties } from '../../query/computeMapLocationData';
import { InfoHeadline1, InfoParagraph } from '../components/info';
import { Modal, useModalRef } from '../components/modal';
import { NoDataDisplay } from '../components/no-data-display';

Check warning on line 9 in components/src/preact/sequencesByLocation/sequences-by-location-map.tsx

View workflow job for this annotation

GitHub Actions / Run checks and build

'NoDataDisplay' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 9 in components/src/preact/sequencesByLocation/sequences-by-location-map.tsx

View workflow job for this annotation

GitHub Actions / Run checks and build

'NoDataDisplay' is defined but never used
import { AspectRatio } from '../shared/aspectRatio/AspectRatio';
import { formatProportion } from '../shared/table/formatProportion';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const SequencesByLocationTable: FunctionComponent<SequencesByLocationTabl
sort: true,
formatter: (cell: number) => formatProportion(cell),
},
...('isShownOnMap' in tableData[0]
...(tableData.length > 0 && 'isShownOnMap' in tableData[0]
? [{ id: 'isShownOnMap', name: 'shown on map', sort: true, width: '20%' }]
: []),
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Meta, type StoryObj } from '@storybook/preact';
import { expect, waitFor, within } from '@storybook/test';

import worldAtlas from './__mockData__/worldAtlas.json';
import { AGGREGATED_ENDPOINT, LAPIS_URL } from '../../constants';
Expand Down Expand Up @@ -91,6 +92,48 @@ export const Default: StoryObj<SequencesByLocationProps> = {
},
};

export const NoData: StoryObj<SequencesByLocationProps> = {
...Default,
parameters: {
fetchMock: {
mocks: [
{
matcher: {
name: 'worldMap',
url: worldMapUrl,
},
response: {
status: 200,
body: worldAtlas,
},
},
{
matcher: {
name: 'aggregatedData',
url: AGGREGATED_ENDPOINT,
body: {
fields: ['country'],
dateFrom: '2022-01-01',
dateTo: '2022-04-01',
},
},
response: {
status: 200,
body: { data: [] },
},
},
],
},
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);

await waitFor(async () => {
await expect(canvas.getByText('No data available.')).toBeVisible();
});
},
};

export const InvalidTopoJsonTopology: StoryObj<SequencesByLocationProps> = {
...Default,
parameters: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { mapSourceSchema } from './loadMapSource';
import { lapisFilterSchema, views } from '../../types';
import Tabs from '../components/tabs';
import { getMaintainAspectRatio } from '../shared/charts/getMaintainAspectRatio';
import { NoDataDisplay } from '../components/no-data-display';

Check failure on line 25 in components/src/preact/sequencesByLocation/sequences-by-location.tsx

View workflow job for this annotation

GitHub Actions / Run checks and build

`../components/no-data-display` import should occur before import of `../components/tabs`

export const sequencesByLocationViewSchema = z.union([z.literal(views.map), z.literal(views.table)]);
export type SequencesByLocationMapView = z.infer<typeof sequencesByLocationViewSchema>;
Expand Down Expand Up @@ -76,6 +77,10 @@ const SequencesByLocationMapInner: FunctionComponent<SequencesByLocationProps> =
throw error;
}

if (data.tableData.length === 0) {
return <NoDataDisplay />;
}

return <SequencesByLocationMapTabs data={data} originalComponentProps={props} />;
};

Expand Down

0 comments on commit d07b85a

Please sign in to comment.