Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Keep errors in one container #1508

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions app/components/chart-preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import {
import { Trans } from "@lingui/macro";
import { Box } from "@mui/material";
import Head from "next/head";
import React, { forwardRef, useCallback, useMemo, useState } from "react";
import React, {
ReactNode,
forwardRef,
useCallback,
useMemo,
useState,
} from "react";

import { DataSetTable } from "@/browse/datatable";
import { ChartDataFilters } from "@/charts/shared/chart-data-filters";
Expand Down Expand Up @@ -346,7 +352,7 @@ const SingleURLsPreview = (props: SingleURLsPreviewProps) => {

type ChartPreviewInnerProps = ChartPreviewProps & {
chartKey?: string | null;
actionElementSlot?: React.ReactNode;
actionElementSlot?: ReactNode;
disableMetadataPanel?: boolean;
children?: React.ReactNode;
};
Expand Down Expand Up @@ -403,20 +409,21 @@ export const ChartPreviewInner = (props: ChartPreviewInnerProps) => {
<Box className={chartClasses.root}>
{props.children}
<ChartErrorBoundary resetKeys={[state]}>
{/* FIXME: adapt to design */}
{metadata?.dataCubesMetadata.some(
(d) => d.publicationStatus === DataCubePublicationStatus.Draft
) && (
<Box sx={{ mb: 4 }}>
<HintYellow iconName="datasetError" iconSize={64}>
<Trans id="dataset.publicationStatus.draft.warning">
Careful, this dataset is only a draft.
<br />
<strong>Don&apos;t use for reporting!</strong>
</Trans>
</HintYellow>
</Box>
)}
<div>
{metadata?.dataCubesMetadata.some(
(d) => d.publicationStatus === DataCubePublicationStatus.Draft
) && (
<Box sx={{ mb: 4 }}>
<HintYellow iconName="datasetError" iconSize={64}>
<Trans id="dataset.publicationStatus.draft.warning">
Careful, this dataset is only a draft.
<br />
<strong>Don&apos;t use for reporting!</strong>
</Trans>
</HintYellow>
</Box>
)}
</div>
{hasChartConfigs(state) && (
<>
<Head>
Expand Down
88 changes: 45 additions & 43 deletions app/components/chart-published.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,49 +245,51 @@ const ChartPublishedInner = (props: ChartPublishInnerProps) => {
ref={rootRef}
>
<ChartErrorBoundary resetKeys={[chartConfig]}>
{metadata?.some(
(d) => d.publicationStatus === DataCubePublicationStatus.Draft
) && (
<Box sx={{ mb: 4 }}>
<HintRed iconName="datasetError" iconSize={64}>
<Trans id="dataset.publicationStatus.draft.warning">
Careful, this dataset is only a draft.
<br />
<strong>Don&apos;t use for reporting!</strong>
</Trans>
</HintRed>
</Box>
)}
{metadata?.some((d) => d.expires) && (
<Box sx={{ mb: 4 }}>
<HintRed iconName="datasetError" iconSize={64}>
<Trans id="dataset.publicationStatus.expires.warning">
Careful, the data for this chart has expired.
<br />
<strong>Don&apos;t use for reporting!</strong>
</Trans>
</HintRed>
</Box>
)}
{!isTrustedDataSource && (
<Box sx={{ mb: 4 }}>
<HintYellow iconName="hintWarning">
<Trans id="data.source.notTrusted">
This chart is not using a trusted data source.
</Trans>
</HintYellow>
</Box>
)}
{isUsingImputation(chartConfig) && (
<Box sx={{ mb: 4 }}>
<HintBlue iconName="hintWarning">
<Trans id="dataset.hasImputedValues">
Some data in this dataset is missing and has been interpolated
to fill the gaps.
</Trans>
</HintBlue>
</Box>
)}
<div>
{metadata?.some(
(d) => d.publicationStatus === DataCubePublicationStatus.Draft
) && (
<Box sx={{ mb: 4 }}>
<HintRed iconName="datasetError" iconSize={64}>
<Trans id="dataset.publicationStatus.draft.warning">
Careful, this dataset is only a draft.
<br />
<strong>Don&apos;t use for reporting!</strong>
</Trans>
</HintRed>
</Box>
)}
{metadata?.some((d) => d.expires) && (
<Box sx={{ mb: 4 }}>
<HintRed iconName="datasetError" iconSize={64}>
<Trans id="dataset.publicationStatus.expires.warning">
Careful, the data for this chart has expired.
<br />
<strong>Don&apos;t use for reporting!</strong>
</Trans>
</HintRed>
</Box>
)}
{!isTrustedDataSource && (
<Box sx={{ mb: 4 }}>
<HintYellow iconName="hintWarning">
<Trans id="data.source.notTrusted">
This chart is not using a trusted data source.
</Trans>
</HintYellow>
</Box>
)}
{isUsingImputation(chartConfig) && (
<Box sx={{ mb: 4 }}>
<HintBlue iconName="hintWarning">
<Trans id="dataset.hasImputedValues">
Some data in this dataset is missing and has been
interpolated to fill the gaps.
</Trans>
</HintBlue>
</Box>
)}
</div>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could have a ChartWarnings here that would have the logic to extract errors, display, and wrap them ?

This way we would not have to repeat the logic ? I guess we would need to have a way to filter some errors ?

<ChartWarnings ignore={['imputation']} /> // in preview

<LoadingStateProvider>
<InteractiveFiltersChartProvider chartConfigKey={chartConfig.key}>
<Flex
Expand Down
2 changes: 1 addition & 1 deletion app/components/chart-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const useChartStyles = makeStyles<Theme>((theme) => ({
display: "grid",
gridTemplateRows: "subgrid",
/** Should stay in sync with the number of rows contained in a chart */
gridRow: "span 6",
gridRow: "span 7",
height: "100%",
padding: theme.spacing(6),
backgroundColor: theme.palette.background.paper,
Expand Down
Loading