Skip to content

Commit

Permalink
Merge pull request #233 from zimmerman-team/feat/DX-1615
Browse files Browse the repository at this point in the history
feat:DX-1615; implement 404 logic
  • Loading branch information
Psami-wondah authored Sep 12, 2024
2 parents 3a80e59 + 719db91 commit 8927e28
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 150 deletions.
14 changes: 11 additions & 3 deletions src/app/modules/chart-module/components/toolbox/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* third-party */
import React from "react";
import { useRecoilState } from "recoil";
import { useAuth0 } from "@auth0/auth0-react";
import { useHistory, useParams } from "react-router-dom";
import { useStoreActions, useStoreState } from "app/state/store/hooks";
Expand All @@ -15,12 +14,17 @@ import {
} from "app/modules/chart-module/components/toolbox/data";
import { ChartToolBoxSteps } from "app/modules/chart-module/components/toolbox/steps";
import { TriangleXSIcon } from "app/assets/icons/TriangleXS";
import { emptyChartAPI, ChartAPIModel } from "app/modules/chart-module/data";
import {
emptyChartAPI,
ChartAPIModel,
chartViews,
} from "app/modules/chart-module/data";
import ToolboxNav from "app/modules/chart-module/components/toolbox/steps/navbar";
import { InfoSnackbar } from "../chartSubheaderToolbar/infoSnackbar";

export function ChartModuleToolBox(props: Readonly<ChartToolBoxProps>) {
const { page, view } = useParams<{ page: string; view?: string }>();
const isValidView = Object.values(chartViews).find((v) => v === view);
const history = useHistory();
const { isAuthenticated, user } = useAuth0();
const isMobile = useMediaQuery("(max-width: 767px)");
Expand Down Expand Up @@ -114,7 +118,11 @@ export function ChartModuleToolBox(props: Readonly<ChartToolBoxProps>) {
};

React.useEffect(() => {
if (location.pathname === `/chart/${page}` || view == "preview") {
if (
location.pathname === `/chart/${page}` ||
view == "preview" ||
!isValidView
) {
setDisplayToolbar("none");
props.setToolboxOpen(false);
} else {
Expand Down
20 changes: 20 additions & 0 deletions src/app/modules/chart-module/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,23 @@ export const emptyChartAPI: ChartAPIModel = {
isMappingValid: false,
isAIAssisted: false,
};
export const chartViews = {
customize: "customize",
preview: "preview",
previewData: "preview-data",
filters: "filters",
data: "data",
mapping: "mapping",
chartType: "chart-type",
};

export const chartPaths = {
detail: "/chart/:page",
customize: `/chart/:page/${chartViews.customize}`,
preview: `/chart/:page/${chartViews.preview}`,
previewData: `/chart/:page/${chartViews.previewData}`,
filters: `/chart/:page/${chartViews.filters}`,
data: `/chart/:page/${chartViews.data}`,
mapping: `/chart/:page/${chartViews.mapping}`,
chartType: `/chart/:page/${chartViews.chartType}`,
};
23 changes: 13 additions & 10 deletions src/app/modules/chart-module/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { PageLoader } from "app/modules/common/page-loader";
import { useChartsRawData } from "app/hooks/useChartsRawData";
import { NoMatchPage } from "app/modules/common/no-match-page";
import ChartModuleDataView from "app/modules/chart-module/routes/data";
import ChartModuleDataView from "app/modules/chart-module/routes/select-data";
import { ChartSubheaderToolbar } from "./components/chartSubheaderToolbar";
import ChartBuilderMapping from "app/modules/chart-module/routes/mapping";
import ChartBuilderFilters from "app/modules/chart-module/routes/filters";
Expand All @@ -38,6 +38,8 @@ import {
routeToConfig,
ChartRenderedItem,
defaultChartOptions,
chartViews,
chartPaths,
} from "app/modules/chart-module/data";
import { NotAuthorizedMessageModule } from "app/modules/common/not-authorized-message";
import { isEmpty } from "lodash";
Expand All @@ -64,6 +66,7 @@ export default function ChartModule() {
const token = useStoreState((state) => state.AuthToken.value);
const history = useHistory();
const { page, view } = useParams<{ page: string; view?: string }>();
const isValidView = Object.values(chartViews).find((v) => v === view);
const [chartFromAPI, setChartFromAPI] =
React.useState<ChartRenderedItem | null>(null);
const [visualOptions, setVisualOptions] = useSessionStorage<any>(
Expand All @@ -74,7 +77,7 @@ export default function ChartModule() {
const setPlanDialog = useSetRecoilState(planDialogAtom);

const [rawViz, setRawViz] = React.useState<any>(null);
const [toolboxOpen, setToolboxOpen] = React.useState(Boolean(view));
const [toolboxOpen, setToolboxOpen] = React.useState(Boolean(isValidView));
const [savedChanges, setSavedChanges] = React.useState<boolean>(false);

const [chartName, setChartName] = React.useState("Untitled Chart");
Expand Down Expand Up @@ -600,7 +603,7 @@ export default function ChartModule() {
ref={ref}
>
<Switch>
<Route path="/chart/:page/customize">
<Route exact path={chartPaths.customize}>
<ChartBuilderCustomize
loading={loading}
dimensions={dimensions}
Expand All @@ -620,7 +623,7 @@ export default function ChartModule() {
/>
</Route>

<Route path="/chart/:page/filters">
<Route exact path={chartPaths.filters}>
<ChartBuilderFilters
loading={loading}
renderedChart={content}
Expand All @@ -638,7 +641,7 @@ export default function ChartModule() {
chartErrorMessage={chartErrorMessage}
/>
</Route>
<Route path="/chart/:page/mapping">
<Route exact path={chartPaths.mapping}>
<ChartBuilderMapping
loading={loading}
visualOptions={visualOptions}
Expand All @@ -656,7 +659,7 @@ export default function ChartModule() {
chartErrorMessage={chartErrorMessage}
/>
</Route>
<Route path="/chart/:page/chart-type">
<Route exact path={chartPaths.chartType}>
<ChartBuilderChartType
loading={loading}
loadDataset={loadDataset}
Expand All @@ -666,7 +669,7 @@ export default function ChartModule() {
setVisualOptionsOnChange={setVisualOptionsOnChange}
/>
</Route>
<Route path="/chart/:page/preview-data">
<Route exact path={chartPaths.previewData}>
<ChartBuilderPreview
loading={loading}
data={sampleData}
Expand All @@ -679,14 +682,14 @@ export default function ChartModule() {
chartErrorMessage={chartErrorMessage}
/>
</Route>
<Route path="/chart/:page/data">
<Route exact path={chartPaths.data}>
<ChartModuleDataView
loadDataset={loadDataset}
toolboxOpen={toolboxOpen}
setChartFromAPI={setChartFromAPI}
/>
</Route>
<Route path="/chart/:page/preview">
<Route exact path={chartPaths.preview}>
<ChartBuilderPreviewTheme
loading={loading || isChartLoading}
visualOptions={visualOptions}
Expand All @@ -705,7 +708,7 @@ export default function ChartModule() {
chartErrorMessage={chartErrorMessage}
/>
</Route>
<Route path="/chart/:page">
<Route exact path={chartPaths.detail}>
<ChartBuilderPreviewTheme
loading={loading || isChartLoading}
visualOptions={visualOptions}
Expand Down
3 changes: 3 additions & 0 deletions src/app/modules/common/no-match-page/asset/404.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions src/app/modules/common/no-match-page/asset/bg-ellipse.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8927e28

Please sign in to comment.