Skip to content

Commit 20559f3

Browse files
authored
Merge pull request #545 from railmapgen/#544
#544 Update param schema version before exporting via app clip view
2 parents 770f781 + 5622d6f commit 20559f3

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/components/param-selector-view/app-clip-view.tsx

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import ParamSelector from './param-selector';
33
import React, { useEffect, useRef, useState } from 'react';
44
import { Events, LocalStorageKey, ParamConfig } from '../../constants/constants';
55
import { getParamRegistry } from '../../util/param-manager-utils';
6-
import { Button, HStack, IconButton, SystemStyleObject } from '@chakra-ui/react';
6+
import { Alert, AlertIcon, Button, HStack, IconButton, SystemStyleObject } from '@chakra-ui/react';
77
import { useTranslation } from 'react-i18next';
88
import { useSearchParams } from 'react-router-dom';
99
import rmgRuntime from '@railmapgen/rmg-runtime';
1010
import { MdRefresh, MdSettings } from 'react-icons/md';
11+
import { updateParam } from '../../util/param-updater-utils';
1112

1213
const CHANNEL_PREFIX = 'rmg-bridge--';
1314

@@ -40,6 +41,7 @@ export default function AppClipView() {
4041

4142
const [paramRegistry, setParamRegistry] = useState<ParamConfig[]>([]);
4243
const [selectedParam, setSelectedParam] = useState<string>();
44+
const [isError, setIsError] = useState(false);
4345

4446
const channelRef = useRef<BroadcastChannel>();
4547

@@ -65,14 +67,21 @@ export default function AppClipView() {
6567
const handleImport = () => {
6668
const paramConfigStr = window.localStorage.getItem(LocalStorageKey.PARAM_CONFIG_BY_ID + selectedParam);
6769
const paramStr = window.localStorage.getItem(LocalStorageKey.PARAM_BY_ID + selectedParam);
68-
channelRef.current?.postMessage({
69-
event: 'IMPORT',
70-
meta: paramConfigStr ? JSON.parse(paramConfigStr) : null,
71-
data: paramStr ? JSON.parse(paramStr) : null,
72-
});
73-
rmgRuntime.event(Events.APP_CLIP_VIEW_IMPORT, { parentComponent });
7470

75-
setSelectedParam(undefined);
71+
try {
72+
const updatedParam = paramStr ? updateParam(JSON.parse(paramStr)) : null;
73+
channelRef.current?.postMessage({
74+
event: 'IMPORT',
75+
meta: paramConfigStr ? JSON.parse(paramConfigStr) : null,
76+
data: updatedParam,
77+
});
78+
rmgRuntime.event(Events.APP_CLIP_VIEW_IMPORT, { parentComponent });
79+
80+
setSelectedParam(undefined);
81+
setIsError(false);
82+
} catch (e) {
83+
setIsError(true);
84+
}
7685
};
7786

7887
const handleClose = () => {
@@ -82,6 +91,7 @@ export default function AppClipView() {
8291
rmgRuntime.event(Events.APP_CLIP_VIEW_CLOSED, { parentComponent });
8392

8493
setSelectedParam(undefined);
94+
setIsError(false);
8595
};
8696

8797
const handleManage = () => {
@@ -90,6 +100,12 @@ export default function AppClipView() {
90100

91101
return (
92102
<RmgPage>
103+
{isError && (
104+
<Alert status="error" variant="solid" size="xs" pl={3} pr={1} py={1}>
105+
<AlertIcon />
106+
{t('Project selected is invalid or corrupted.')}
107+
</Alert>
108+
)}
93109
<RmgCard sx={styles}>
94110
<ParamSelector
95111
paramRegistry={paramRegistry}

0 commit comments

Comments
 (0)