Skip to content

Commit e4fbdc3

Browse files
committed
Clean up format dropdown in Short Answer input
- Move Time and Date time out of Short Answer format into their own input types. - Rename "Time" to "Date-Time". Add a "Time" Input Type. - Add matchIf entries for the Format entries in Short Answer. - Remove Format menu from Long Answer, which never really worked is not very appropriate.
1 parent 91e57db commit e4fbdc3

File tree

3 files changed

+69
-74
lines changed

3 files changed

+69
-74
lines changed

src/formBuilder/defaults/defaultInputs.js

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,29 @@ export function CardDefaultParameterInputs({
2626
return <div />;
2727
}
2828

29-
function TimeField({
30-
parameters,
31-
onChange,
32-
}: {
33-
parameters: Parameters,
34-
onChange: (newParams: Parameters) => void,
35-
}) {
36-
return (
37-
<React.Fragment>
38-
<h5>Default time</h5>
39-
<Input
40-
value={parameters.default || ''}
41-
placeholder='Default'
42-
type='datetime-local'
43-
onChange={(ev: SyntheticInputEvent<HTMLInputElement>) =>
44-
onChange({ ...parameters, default: ev.target.value })
45-
}
46-
className='card-text'
47-
/>
48-
</React.Fragment>
49-
);
50-
}
29+
const getInputCardBodyComponent = ({ type }: { type: string }) =>
30+
function InputCardBodyComponent({
31+
parameters,
32+
onChange,
33+
}: {
34+
parameters: Parameters,
35+
onChange: (newParams: Parameters) => void,
36+
}) {
37+
return (
38+
<React.Fragment>
39+
<h5>Default value</h5>
40+
<Input
41+
value={parameters.default || ''}
42+
placeholder='Default'
43+
type={type}
44+
onChange={(ev: SyntheticInputEvent<HTMLInputElement>) =>
45+
onChange({ ...parameters, default: ev.target.value })
46+
}
47+
className='card-text'
48+
/>
49+
</React.Fragment>
50+
);
51+
};
5152

5253
function Checkbox({
5354
parameters,
@@ -205,8 +206,8 @@ function RefChoice({
205206
}
206207

207208
const defaultInputs: { [string]: FormInput } = {
208-
time: {
209-
displayName: 'Time',
209+
dateTime: {
210+
displayName: 'Date-Time',
210211
matchIf: [
211212
{
212213
types: ['string'],
@@ -218,7 +219,39 @@ const defaultInputs: { [string]: FormInput } = {
218219
},
219220
defaultUiSchema: {},
220221
type: 'string',
221-
cardBody: TimeField,
222+
cardBody: getInputCardBodyComponent({ type: 'datetime-local' }),
223+
modalBody: CardDefaultParameterInputs,
224+
},
225+
date: {
226+
displayName: 'Date',
227+
matchIf: [
228+
{
229+
types: ['string'],
230+
format: 'date',
231+
},
232+
],
233+
defaultDataSchema: {
234+
format: 'date',
235+
},
236+
defaultUiSchema: {},
237+
type: 'string',
238+
cardBody: getInputCardBodyComponent({ type: 'date' }),
239+
modalBody: CardDefaultParameterInputs,
240+
},
241+
time: {
242+
displayName: 'Time',
243+
matchIf: [
244+
{
245+
types: ['string'],
246+
format: 'time',
247+
},
248+
],
249+
defaultDataSchema: {
250+
format: 'time',
251+
},
252+
defaultUiSchema: {},
253+
type: 'string',
254+
cardBody: getInputCardBodyComponent({ type: 'time' }),
222255
modalBody: CardDefaultParameterInputs,
223256
},
224257
checkbox: {

src/formBuilder/defaults/longAnswerInputs.js

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@ import Tooltip from '../Tooltip';
88
import { getRandomId } from '../utils';
99
import type { Parameters, FormInput } from '../types';
1010

11-
const formatDictionary = {
12-
'': 'None',
13-
'date-time': 'Date-Time',
14-
email: 'Email',
15-
hostname: 'Hostname',
16-
time: 'Time',
17-
uri: 'URI',
18-
regex: 'Regular Expression',
19-
};
20-
2111
// specify the inputs required for a string type object
2212
function CardLongAnswerParameterInputs({
2313
parameters,
@@ -80,41 +70,6 @@ function CardLongAnswerParameterInputs({
8070
}}
8171
className='card-modal-text'
8272
/>
83-
<h4>
84-
Format{' '}
85-
<Tooltip
86-
id={`${elementId}_format`}
87-
type='help'
88-
text='Require string input to match a certain common format'
89-
/>
90-
</h4>
91-
<Select
92-
value={{
93-
value: parameters.format
94-
? formatDictionary[
95-
typeof parameters.format === 'string' ? parameters.format : ''
96-
]
97-
: '',
98-
label: parameters.format
99-
? formatDictionary[
100-
typeof parameters.format === 'string' ? parameters.format : ''
101-
]
102-
: 'None',
103-
}}
104-
placeholder='Format'
105-
key='format'
106-
options={Object.keys(formatDictionary).map((key) => ({
107-
value: key,
108-
label: formatDictionary[key],
109-
}))}
110-
onChange={(val: any) => {
111-
onChange({
112-
...parameters,
113-
format: val.value,
114-
});
115-
}}
116-
className='card-modal-select'
117-
/>
11873
<div className='card-modal-boolean'>
11974
<FBCheckbox
12075
onChangeValue={() => {
@@ -146,7 +101,7 @@ function LongAnswer({
146101
}) {
147102
return (
148103
<React.Fragment>
149-
<h5>Default input</h5>
104+
<h5>Default value</h5>
150105
<Input
151106
value={parameters.default}
152107
placeholder='Default'

src/formBuilder/defaults/shortAnswerInputs.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ import type { Parameters, FormInput } from '../types';
1010

1111
const formatDictionary = {
1212
'': 'None',
13-
'date-time': 'Date-Time',
1413
email: 'Email',
1514
hostname: 'Hostname',
16-
time: 'Time',
1715
uri: 'URI',
1816
regex: 'Regular Expression',
1917
};
2018

19+
const formatTypeDictionary = {
20+
email: 'email',
21+
url: 'uri',
22+
};
23+
2124
const autoDictionary = {
2225
'': 'None',
2326
email: 'Email',
@@ -208,7 +211,7 @@ function ShortAnswerField({
208211
<Input
209212
value={parameters.default}
210213
placeholder='Default'
211-
type='text'
214+
type={formatTypeDictionary[parameters.format] || 'text'}
212215
onChange={(ev: SyntheticInputEvent<HTMLInputElement>) =>
213216
onChange({ ...parameters, default: ev.target.value })
214217
}
@@ -248,6 +251,10 @@ const shortAnswerInput: { [string]: FormInput } = {
248251
{
249252
types: ['string'],
250253
},
254+
...['email', 'hostname', 'uri', 'regex'].map((format) => ({
255+
types: ['string'],
256+
format,
257+
})),
251258
],
252259
defaultDataSchema: {},
253260
defaultUiSchema: {},

0 commit comments

Comments
 (0)