allow setting date format using an env var at boot time w/ burnettk

This commit is contained in:
jasquat 2023-04-11 17:25:46 -04:00
parent 4707a030d7
commit cafc7209a0
4 changed files with 88 additions and 35 deletions

View File

@ -75,9 +75,26 @@ export const PROCESS_STATUSES = [
]; ];
// with time: yyyy-MM-dd HH:mm:ss // with time: yyyy-MM-dd HH:mm:ss
export const DATE_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss'; let generalDateFormat = 'yyyy-MM-dd';
if (
'spiffworkflowFrontendJsenv' in window &&
'DATE_FORMAT' in window.spiffworkflowFrontendJsenv
) {
generalDateFormat = window.spiffworkflowFrontendJsenv.DATE_FORMAT;
}
const supportedDateFormats = ['yyyy-MM-dd', 'dd-MM-yyyy', 'MM-dd-yyyy'];
if (!supportedDateFormats.includes(generalDateFormat)) {
throw new Error(
`Given SPIFFWORKFLOW_FRONTEND_RUNTIME_CONFIG_DATE_FORMAT is not supported. Given: ${generalDateFormat}. Valid options are: ${supportedDateFormats}`
);
}
const carbonDateFormat = generalDateFormat
.replace('yyyy', 'Y')
.replace('MM', 'm')
.replace('dd', 'd');
export const DATE_TIME_FORMAT = `${generalDateFormat} HH:mm:ss`;
export const TIME_FORMAT_HOURS_MINUTES = 'HH:mm'; export const TIME_FORMAT_HOURS_MINUTES = 'HH:mm';
export const DATE_FORMAT = 'yyyy-MM-dd'; export const DATE_FORMAT = generalDateFormat;
export const DATE_FORMAT_CARBON = 'Y-m-d'; export const DATE_FORMAT_CARBON = carbonDateFormat;
export const SPIFF_ENVIRONMENT = spiffEnvironment; export const SPIFF_ENVIRONMENT = spiffEnvironment;

View File

@ -1,5 +1,5 @@
// @ts-ignore // @ts-ignore
import { TextInput } from '@carbon/react'; import { DatePicker, DatePickerInput, TextInput } from '@carbon/react';
import { import {
getInputProps, getInputProps,
FormContextType, FormContextType,
@ -101,7 +101,35 @@ export default function BaseInputTemplate<
} }
} }
return ( let component = null;
if (type === 'date') {
component = (
<DatePicker
className="date-input"
dateFormat="m-d-Y"
datePickerType="single"
>
<DatePickerInput
id={id}
placeholder="m-d-Y"
helperText={helperText}
type="text"
size="md"
autocomplete="off"
allowInput={false}
onChange={_onChange}
value={value || value === 0 ? value : ''}
invalid={invalid}
invalidText={errorMessageForField}
autoFocus={autofocus}
disabled={disabled || readonly}
onBlur={_onBlur}
onFocus={_onFocus}
/>
</DatePicker>
);
} else {
component = (
<> <>
<TextInput <TextInput
id={id} id={id}
@ -132,4 +160,6 @@ export default function BaseInputTemplate<
)} )}
</> </>
); );
}
return component;
} }

View File

@ -8,9 +8,11 @@ function DateWidget(props: WidgetProps) {
registry, registry,
options options
); );
return ( return (
<BaseInputTemplate <BaseInputTemplate
type="date" type="date"
dateFormat="Y-m-d"
InputLabelProps={{ InputLabelProps={{
shrink: true, shrink: true,
}} }}

View File

@ -25,3 +25,7 @@
.rjsf .text-input { .rjsf .text-input {
padding-top: 8px; padding-top: 8px;
} }
.rjsf .date-input {
padding-top: 8px;
}