Skip to content

An open source alternative to Tableau. Embeddable visual analytic

fix: add report compuation error (#199)

islxyqwe6dce4bd22cbb
diff --git a/packages/graphic-walker/src/App.tsx b/packages/graphic-walker/src/App.tsx
index 28caf60d..0e6a2918 100644
--- a/packages/graphic-walker/src/App.tsx
+++ b/packages/graphic-walker/src/App.tsx
@@ -9,7 +9,7 @@ import PosFields from './fields/posFields';
import AestheticFields from './fields/aestheticFields';
import DatasetFields from './fields/datasetFields/index';
import ReactiveRenderer from './renderer/index';
-import { ComputationContext, VizStoreWrapper, useVizStore, withTimeout } from './store';
+import { ComputationContext, VizStoreWrapper, useVizStore, withErrorReport, withTimeout } from './store';
import VisNav from './segments/visNav';
import { mergeLocaleRes, setLocaleLanguage } from './locales/i18n';
import FilterField from './fields/filterField';
@@ -33,6 +33,7 @@ import { ErrorBoundary } from 'react-error-boundary';
import Errorpanel from './components/errorpanel';
import { GWGlobalConfig } from './vis/theme';
import { useCurrentMediaTheme } from './utils/media';
+import { parseErrorMessage } from './utils';
export interface BaseVizProps {
i18nLang?: string;
@@ -117,7 +118,7 @@ export const VizApp = observer(function VizApp(props: BaseVizProps) {
console.error(err);
onError?.(err);
if (code) {
- vizStore.updateShowErrorResolutionPanel(code);
+ vizStore.updateShowErrorResolutionPanel(code, msg);
}
},
[vizStore, onError]
@@ -125,11 +126,17 @@ export const VizApp = observer(function VizApp(props: BaseVizProps) {
const { segmentKey, vizEmbededMenu } = vizStore;
- const c = useMemo(() => (computation ? withTimeout(computation, computationTimeout) : async () => []), [computation, computationTimeout]);
+ const wrappedComputation = useMemo(
+ () =>
+ computation
+ ? withErrorReport(withTimeout(computation, computationTimeout), (err) => reportError(parseErrorMessage(err), 501))
+ : async () => [],
+ [reportError, computation, computationTimeout]
+ );
return (
<ErrorContext value={{ reportError }}>
<ErrorBoundary fallback={<div>Something went wrong</div>} onError={props.onError}>
- <ComputationContext.Provider value={c}>
+ <ComputationContext.Provider value={wrappedComputation}>
<div className={`${darkMode === 'dark' ? 'dark' : ''} App font-sans bg-white dark:bg-zinc-900 dark:text-white m-0 p-0`}>
<div className="bg-white dark:bg-zinc-900 dark:text-white">
{props.dataSelection}
@@ -186,7 +193,7 @@ export const VizApp = observer(function VizApp(props: BaseVizProps) {
themeKey={themeKey}
dark={darkMode}
themeConfig={themeConfig}
- computationFunction={computation}
+ computationFunction={wrappedComputation}
channelScales={props.channelScales}
/>
)}
diff --git a/packages/graphic-walker/src/components/errorpanel/index.tsx b/packages/graphic-walker/src/components/errorpanel/index.tsx
index 145375c4..5a00e1d0 100644
--- a/packages/graphic-walker/src/components/errorpanel/index.tsx
+++ b/packages/graphic-walker/src/components/errorpanel/index.tsx
@@ -8,6 +8,10 @@ import DefaultButton from '../button/default';
export default observer(function ErrorPanel() {
const vizStore = useVizStore();
const { t } = useTranslation();
+ const closeModal = () => {
+ vizStore.updateShowErrorResolutionPanel(0);
+ return;
+ };
switch (vizStore.showErrorResolutionPanel) {
case 0:
return null;
@@ -23,7 +27,7 @@ export default observer(function ErrorPanel() {
className="mx-2 cursor-pointer font-semibold text-indigo-600 hover:text-indigo-500"
onClick={() => {
vizStore.setVisualLayout('size', { mode: 'fixed', width: 800, height: 600 });
- vizStore.updateShowErrorResolutionPanel(0);
+ closeModal();
}}
>
Set Now
@@ -35,7 +39,7 @@ export default observer(function ErrorPanel() {
className="mx-2 cursor-pointer font-semibold text-indigo-600 hover:text-indigo-500"
onClick={() => {
vizStore.setVisualLayout('useSvg', true);
- vizStore.updateShowErrorResolutionPanel(0);
+ closeModal();
}}
>
Set Now
@@ -47,10 +51,27 @@ export default observer(function ErrorPanel() {
<DefaultButton
text={`Close`}
className="mr-2 px-2"
- onClick={() => {
- vizStore.updateShowErrorResolutionPanel(0);
- return;
- }}
+ onClick={closeModal}
+ />
+ </div>
+ </fieldset>
+ </div>
+ </Modal>
+ );
+ case 501:
+ return (
+ <Modal show={true}>
+ <div className="flex flex-col justify-center items-start">
+ <h2 className="font-medium text-xl my-2">Oops!</h2>
+ <p className="font-normal my-2">There is some error with Computation service. Here is the Error message:</p>
+ <p className="font-normal my-2">{vizStore.lastErrorMessage}</p>
+
+ <fieldset className="mt-2 gap-1 flex flex-col justify-center items-end w-full">
+ <div className="mt-2">
+ <DefaultButton
+ text={`Close`}
+ className="mr-2 px-2"
+ onClick={closeModal}
/>
</div>
</fieldset>
diff --git a/packages/graphic-walker/src/store/index.tsx b/packages/graphic-walker/src/store/index.tsx
index b1eded52..5dc532d5 100644
--- a/packages/graphic-walker/src/store/index.tsx
+++ b/packages/graphic-walker/src/store/index.tsx
@@ -105,3 +105,11 @@ export function withTimeout<T extends any[], U>(f: (...args: T) => Promise<U>, t
}),
]);
}
+
+export function withErrorReport<T extends any[], U>(f: (...args: T) => Promise<U>, onError: (err: string | Error) => void) {
+ return (...args: T) =>
+ f(...args).catch((err) => {
+ onError(err);
+ throw err;
+ });
+}
diff --git a/packages/graphic-walker/src/store/visualSpecStore.ts b/packages/graphic-walker/src/store/visualSpecStore.ts
index edb85993..0331c58a 100644
--- a/packages/graphic-walker/src/store/visualSpecStore.ts
+++ b/packages/graphic-walker/src/store/visualSpecStore.ts
@@ -92,6 +92,7 @@ export class VizSpecStore {
createField: ICreateField | undefined = undefined;
localGeoJSON: FeatureCollection | undefined = undefined;
showErrorResolutionPanel: number = 0;
+ lastErrorMessage: string = "";
private onMetaChange?: (fid: string, diffMeta: Partial<IMutField>) => void;
@@ -596,8 +597,9 @@ export class VizSpecStore {
this.selectedMarkObject = newMarkObj;
}
- updateShowErrorResolutionPanel(errCode: number) {
+ updateShowErrorResolutionPanel(errCode: number, msg = "") {
this.showErrorResolutionPanel = errCode;
+ this.lastErrorMessage = msg;
}
}
diff --git a/packages/graphic-walker/src/utils/index.ts b/packages/graphic-walker/src/utils/index.ts
index 083e174f..8ee55734 100644
--- a/packages/graphic-walker/src/utils/index.ts
+++ b/packages/graphic-walker/src/utils/index.ts
@@ -315,3 +315,13 @@ const defaultValueComparator = (a: any, b: any) => {
export function parseCmpFunction(str?: string): (a: any, b: any) => number {
return defaultValueComparator;
}
+
+export function parseErrorMessage(errorLike: any): string {
+ if (errorLike instanceof Error) {
+ return errorLike.message;
+ }
+ if (typeof errorLike === 'string') {
+ return errorLike;
+ }
+ return String(errorLike);
+}
diff --git a/packages/graphic-walker/src/utils/reportError.ts b/packages/graphic-walker/src/utils/reportError.ts
index 76f0c659..95364fa8 100644
--- a/packages/graphic-walker/src/utils/reportError.ts
+++ b/packages/graphic-walker/src/utils/reportError.ts
@@ -2,6 +2,7 @@ import React from 'react';
export const Errors = {
canvasExceedSize: 500,
+ computationError: 501,
} as const;
export const errorContext = React.createContext({