Skip to content

Commit

Permalink
feat: Handle dataset loading error
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrowne committed Feb 1, 2022
1 parent 74c2bc6 commit fcbda35
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
19 changes: 13 additions & 6 deletions app/components/hint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const NoDataHint = () => (
</Text>
</Flex>
);
export const LoadingDataError = () => (
export const LoadingDataError = ({ message }: { message?: string }) => (
<Flex
sx={{
width: "100%",
Expand All @@ -169,11 +169,18 @@ export const LoadingDataError = () => (
<Text as="h5" variant="heading2" sx={{ my: 3 }}>
<Trans id="hint.dataloadingerror.title">Data loading error</Trans>
</Text>
<Text as="p" variant="paragraph2" sx={{ maxWidth: "40rem" }}>
<Trans id="hint.dataloadingerror.message">
The data could not be loaded.
</Trans>
</Text>
<Box sx={{ "& > * + *:not([data-no-margin])": { marginTop: 2 } }}>
<Text as="p" variant="paragraph2" sx={{ maxWidth: "40rem" }}>
<Trans id="hint.dataloadingerror.message">
The data could not be loaded.
</Trans>
</Text>
{message ? (
<Text as="p" variant="paragraph2" sx={{ maxWidth: "40rem" }}>
{message}
</Text>
) : null}
</Box>
</Flex>
);

Expand Down
19 changes: 16 additions & 3 deletions app/configurator/components/dataset-preview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";
import { Box, Text, Flex } from "theme-ui";
import { HintRed, Loading } from "../../components/hint";
import { HintRed, Loading, LoadingDataError } from "../../components/hint";
import { DataSetPreviewTable } from "./datatable";
import { Trans } from "@lingui/macro";
import { useDataCubePreviewQuery } from "../../graphql/query-hooks";
Expand All @@ -15,7 +15,7 @@ export interface Preview {
}
export const DataSetPreview = ({ dataSetIri }: { dataSetIri: string }) => {
const locale = useLocale();
const [{ data: metaData }] = useDataCubePreviewQuery({
const [{ data: metaData, fetching, error }] = useDataCubePreviewQuery({
variables: { iri: dataSetIri, locale },
});

Expand Down Expand Up @@ -108,7 +108,7 @@ export const DataSetPreview = ({ dataSetIri }: { dataSetIri: string }) => {
</Box>
</Flex>
);
} else {
} else if (fetching) {
return (
<Flex
sx={{
Expand All @@ -121,5 +121,18 @@ export const DataSetPreview = ({ dataSetIri }: { dataSetIri: string }) => {
<Loading />
</Flex>
);
} else {
return (
<Flex
sx={{
flexDirection: "column",
justifyContent: "space-between",
flexGrow: 1,
p: 5,
}}
>
<LoadingDataError message={error?.message} />
</Flex>
);
}
};
12 changes: 4 additions & 8 deletions app/configurator/components/select-dataset-step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,11 @@ export const SelectDatasetStepContent = () => {
<SearchDatasetBox browseState={browseState} searchResult={data} />
</Box>
)}
{dataset || !data ? (
{dataset ? (
<>
{dataset ? (
<Box>
<DataSetPreview dataSetIri={dataset} />
</Box>
) : (
<DataSetHint />
)}
<Box>
<DataSetPreview dataSetIri={dataset} />
</Box>
</>
) : (
<DatasetResults fetching={fetching} data={data} />
Expand Down

0 comments on commit fcbda35

Please sign in to comment.