Skip to content

Commit 6f4648c

Browse files
tnagorrafrozenhelium
authored andcommitted
Copy tutorial json when submitting tutorial
1 parent 1e57685 commit 6f4648c

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

manager-dashboard/app/Base/components/SmartLink/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Link, LinkProps } from 'react-router-dom';
33

44
import {
55
useButtonFeatures,
6-
Props as ButtonProps,
6+
ButtonProps,
77
} from '#components/Button';
88

99
import useRouteMatching, {

manager-dashboard/app/components/GeoJsonPreview/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66

77
TileLayer,
88
Coords,
9-
Util,
109
} from 'leaflet';
1110
import { _cs } from '@togglecorp/fujs';
1211

@@ -34,14 +33,13 @@ const toQuadKey = (x: number, y: number, z: number) => {
3433
const BingTileLayer = TileLayer.extend({
3534
getTileUrl(coords: Coords) {
3635
const quadkey = toQuadKey(coords.x, coords.y, coords.z);
37-
const subdomains = this.options.subdomains;
36+
const { subdomains } = this.options;
3837

3938
// eslint-disable-next-line no-underscore-dangle
4039
const url = this._url
4140
.replace('{subdomain}', subdomains[(coords.x + coords.y) % subdomains.length])
4241
.replace('{quad_key}', quadkey);
4342

44-
console.log(url);
4543
return url;
4644
},
4745
toQuadKey,

manager-dashboard/app/views/NewTutorial/index.tsx

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import {
5151
TabPanel,
5252
} from '#components/Tabs';
5353
import TileServerInput, {
54-
TILE_SERVER_ESRI,
54+
TILE_SERVER_BING,
5555
tileServerDefaultCredits,
5656
} from '#components/TileServerInput';
5757
import InputSection from '#components/InputSection';
@@ -73,10 +73,10 @@ import {
7373
tutorialFormSchema,
7474
TutorialFormType,
7575
PartialTutorialFormType,
76+
PartialInformationPagesType,
7677
ScenarioPagesType,
7778
CustomOptionType,
7879
InformationPagesType,
79-
PartialInformationPagesType,
8080
colorKeyToColorMap,
8181
InformationPageTemplateKey,
8282
infoPageTemplateoptions,
@@ -90,6 +90,22 @@ import ScenarioPageInput from './ScenarioPageInput';
9090
import InformationPageInput from './InformationPageInput';
9191
import styles from './styles.css';
9292

93+
type CustomScreen = Omit<TutorialFormType['scenarioPages'][number], 'scenarioId'>;
94+
function sanitizeScreens(scenarioPages: TutorialFormType['scenarioPages']) {
95+
const screens = scenarioPages.reduce<Record<string, CustomScreen>>(
96+
(acc, currentValue) => {
97+
const { scenarioId, ...other } = currentValue;
98+
acc[scenarioId] = {
99+
...other,
100+
};
101+
102+
return acc;
103+
},
104+
{},
105+
);
106+
return screens;
107+
}
108+
93109
const defaultCustomOptions: PartialTutorialFormType['customOptions'] = [
94110
{
95111
optionId: 1,
@@ -116,16 +132,17 @@ const defaultCustomOptions: PartialTutorialFormType['customOptions'] = [
116132
description: 'if you\'re not sure or there is cloud cover / bad imagery',
117133
},
118134
];
135+
119136
const defaultTutorialFormValue: PartialTutorialFormType = {
120137
projectType: PROJECT_TYPE_BUILD_AREA,
121138
zoomLevel: 18,
122139
tileServer: {
123-
name: TILE_SERVER_ESRI,
124-
credits: tileServerDefaultCredits[TILE_SERVER_ESRI],
140+
name: TILE_SERVER_BING,
141+
credits: tileServerDefaultCredits[TILE_SERVER_BING],
125142
},
126143
tileServerB: {
127-
name: TILE_SERVER_ESRI,
128-
credits: tileServerDefaultCredits[TILE_SERVER_ESRI],
144+
name: TILE_SERVER_BING,
145+
credits: tileServerDefaultCredits[TILE_SERVER_BING],
129146
},
130147
customOptions: defaultCustomOptions,
131148
};
@@ -223,21 +240,15 @@ function NewTutorial(props: Props) {
223240
informationPages: informationPagesFromForm,
224241
...valuesToCopy
225242
} = finalValues;
226-
type Screens = typeof finalValues.scenarioPages;
227-
type Screen = Screens[number];
228-
type CustomScreen = Omit<Screen, 'scenarioId'>;
229-
230-
const screens = scenarioPages.reduce(
231-
(acc, currentValue) => {
232-
const { scenarioId, ...other } = currentValue;
233-
acc[scenarioId] = {
234-
...other,
235-
};
236243

237-
return acc;
238-
},
239-
{} as Record<string, CustomScreen>,
240-
);
244+
const screens = sanitizeScreens(scenarioPages);
245+
246+
try {
247+
await navigator.clipboard.writeText(JSON.stringify(screens, null, 2));
248+
alert('Tutorial JSON copied to clipboard.');
249+
} catch (err) {
250+
alert(`Tutorial JSON could not be copied ${err}`);
251+
}
241252

242253
const storage = getStorage();
243254
const timestamp = (new Date()).getTime();

0 commit comments

Comments
 (0)