Skip to content

Commit 3fb2aa2

Browse files
committed
feat(validate_image): update form for validate image project & tutorial creation
- add io-ts for validation (with typescript types) - fix conditional issue with street project
1 parent c28bea1 commit 3fb2aa2

File tree

23 files changed

+1031
-94
lines changed

23 files changed

+1031
-94
lines changed

manager-dashboard/app/Base/configs/projectTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
PROJECT_TYPE_CHANGE_DETECTION,
66
PROJECT_TYPE_STREET,
77
PROJECT_TYPE_COMPLETENESS,
8+
PROJECT_TYPE_VALIDATE_IMAGE,
89
} from '#utils/common';
910

1011
const PROJECT_CONFIG_NAME = process.env.REACT_APP_PROJECT_CONFIG_NAME as string;
@@ -15,6 +16,7 @@ const mapswipeProjectTypeOptions: {
1516
}[] = [
1617
{ value: PROJECT_TYPE_BUILD_AREA, label: 'Find' },
1718
{ value: PROJECT_TYPE_FOOTPRINT, label: 'Validate' },
19+
{ value: PROJECT_TYPE_VALIDATE_IMAGE, label: 'Validate Image' },
1820
{ value: PROJECT_TYPE_CHANGE_DETECTION, label: 'Compare' },
1921
{ value: PROJECT_TYPE_STREET, label: 'Street' },
2022
{ value: PROJECT_TYPE_COMPLETENESS, label: 'Completeness' },

manager-dashboard/app/Base/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ p {
105105
--height-mobile-preview-builarea-content: 30rem;
106106
--height-mobile-preview-footprint-content: 22rem;
107107
--height-mobile-preview-change-detection-content: 14rem;
108+
--height-mobile-preview-validate-image-content: 22rem;
108109

109110
--radius-popup-border: 0.25rem;
110111
--radius-scrollbar-border: 0.25rem;

manager-dashboard/app/components/Calendar/CalendarDate/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { _cs } from '@togglecorp/fujs';
33

44
import RawButton, { Props as RawButtonProps } from '../../RawButton';
5-
import { ymdToDateString, typedMemo } from '../../../utils/common.tsx';
5+
import { ymdToDateString, typedMemo } from '../../../utils/common';
66

77
import styles from './styles.css';
88

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import Button from '../Button';
1515
import NumberInput from '../NumberInput';
1616
import SelectInput from '../SelectInput';
1717
import useInputState from '../../hooks/useInputState';
18-
import { typedMemo } from '../../utils/common.tsx';
18+
import { typedMemo } from '../../utils/common';
1919

2020
import CalendarDate, { Props as CalendarDateProps } from './CalendarDate';
2121

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Button from '../Button';
1919
import Popup from '../Popup';
2020
import Calendar, { Props as CalendarProps } from '../Calendar';
2121
import CalendarDate, { Props as CalendarDateProps } from '../Calendar/CalendarDate';
22-
import { ymdToDateString, dateStringToDate } from '../../utils/common.tsx';
22+
import { ymdToDateString, dateStringToDate } from '../../utils/common';
2323

2424
import {
2525
predefinedDateRangeOptions,

manager-dashboard/app/components/InputSection/styles.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
display: flex;
2525
flex-direction: column;
2626
border-radius: var(--radius-card-border);
27-
gap: var(--spacing-extra-large);
27+
gap: var(--spacing-large);
2828
background-color: var(--color-foreground);
2929
padding: var(--spacing-large);
3030
min-height: 14rem;

manager-dashboard/app/utils/common.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ export const PROJECT_TYPE_FOOTPRINT = 2;
6666
export const PROJECT_TYPE_CHANGE_DETECTION = 3;
6767
export const PROJECT_TYPE_COMPLETENESS = 4;
6868
export const PROJECT_TYPE_STREET = 7;
69+
export const PROJECT_TYPE_VALIDATE_IMAGE = 10;
6970

70-
export type ProjectType = 1 | 2 | 3 | 4 | 7;
71+
export type ProjectType = 1 | 2 | 3 | 4 | 7 | 10;
7172

7273
export const projectTypeLabelMap: {
7374
[key in ProjectType]: string
@@ -77,6 +78,7 @@ export const projectTypeLabelMap: {
7778
[PROJECT_TYPE_CHANGE_DETECTION]: 'Compare',
7879
[PROJECT_TYPE_COMPLETENESS]: 'Completeness',
7980
[PROJECT_TYPE_STREET]: 'Street',
81+
[PROJECT_TYPE_VALIDATE_IMAGE]: 'Validate Image',
8082
};
8183

8284
export type IconKey = 'add-outline'
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import React from 'react';
2+
3+
import {
4+
SetValueArg,
5+
Error,
6+
useFormObject,
7+
getErrorObject,
8+
} from '@togglecorp/toggle-form';
9+
import TextInput from '#components/TextInput';
10+
11+
import {
12+
ImageType,
13+
} from '../utils';
14+
15+
import styles from './styles.css';
16+
17+
const defaultImageValue: ImageType = {
18+
sourceIdentifier: '<unique-identifier>',
19+
};
20+
21+
interface Props {
22+
value: ImageType;
23+
onChange: (value: SetValueArg<ImageType>, index: number) => void | undefined;
24+
index: number;
25+
error: Error<ImageType> | undefined;
26+
disabled?: boolean;
27+
readOnly?: boolean;
28+
}
29+
30+
export default function ImageInput(props: Props) {
31+
const {
32+
value,
33+
onChange,
34+
index,
35+
error: riskyError,
36+
disabled,
37+
readOnly,
38+
} = props;
39+
40+
const onImageChange = useFormObject(index, onChange, defaultImageValue);
41+
42+
const error = getErrorObject(riskyError);
43+
44+
return (
45+
<div className={styles.imageInput}>
46+
<TextInput
47+
label="Identifier"
48+
value={value?.sourceIdentifier}
49+
name={'sourceIdentifier' as const}
50+
// onChange={onImageChange}
51+
error={error?.sourceIdentifier}
52+
disabled={disabled}
53+
readOnly
54+
/>
55+
<TextInput
56+
label="File name"
57+
value={value.fileName}
58+
name={'fileName' as const}
59+
onChange={onImageChange}
60+
error={error?.fileName}
61+
disabled={disabled || readOnly}
62+
/>
63+
<TextInput
64+
label="URL"
65+
value={value?.url}
66+
name={'url' as const}
67+
onChange={onImageChange}
68+
error={error?.url}
69+
disabled={disabled || readOnly}
70+
/>
71+
</div>
72+
);
73+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.image-input {
2+
display: flex;
3+
flex-direction: column;
4+
gap: var(--spacing-medium);
5+
}

0 commit comments

Comments
 (0)