Merge branch 'workflow-project'

This commit is contained in:
Simon Larsen 2023-03-22 11:28:35 +00:00
commit 72e9229914
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
11 changed files with 56 additions and 50 deletions

View File

@ -46,7 +46,7 @@ export default class FileModel extends BaseModel {
type: TableColumnType.ShortText,
title: 'Name',
description: 'Any friendly name of this object',
canReadOnPopulate: true
canReadOnPopulate: true,
})
@Column({
nullable: false,

View File

@ -484,6 +484,7 @@ export default class StatusPageAPI extends BaseAPI<
displayName: true,
showStatusHistoryChart: true,
showCurrentStatus: true,
order: true,
},
populate: {
monitor: {
@ -491,6 +492,9 @@ export default class StatusPageAPI extends BaseAPI<
currentMonitorStatusId: true,
},
},
sort: {
order: SortOrder.Ascending,
},
skip: 0,
limit: LIMIT_PER_PROJECT,
props: {

View File

@ -1,10 +1,12 @@
import React, {
forwardRef,
ForwardRefExoticComponent,
MutableRefObject,
ReactElement,
Ref,
useEffect,
useImperativeHandle,
useRef,
useState,
} from 'react';
import Button, { ButtonStyleType } from '../Button/Button';
@ -102,9 +104,16 @@ const BasicForm: ForwardRefExoticComponent<any> = forwardRef(
props: ComponentProps<T>,
ref: Ref<any>
): ReactElement => {
const isSubmitting: MutableRefObject<boolean> = useRef(false);
const refCurrentValue: MutableRefObject<FormValues<T>> = useRef(
props.initialValues
);
const [currentValue, setCurrentValue] = useState<FormValues<T>>(
props.initialValues
);
const [errors, setErrors] = useState<Dictionary<string>>({});
const [touched, setTouched] = useState<Dictionary<boolean>>({});
@ -117,11 +126,11 @@ const BasicForm: ForwardRefExoticComponent<any> = forwardRef(
setTouched({ ...touched, [fieldName]: value });
};
const [isInitialValuesInitialized, setIsInitialValuesInitialized] =
useState<boolean>(false);
useEffect(() => {
validate(currentValue);
if (props.onChange) {
props.onChange(currentValue);
}
}, [currentValue]);
useImperativeHandle(
@ -163,26 +172,29 @@ const BasicForm: ForwardRefExoticComponent<any> = forwardRef(
value: JSONValue
): void => {
const updatedValue: FormValues<T> = {
...currentValue,
...refCurrentValue.current,
[fieldName]: value as any,
};
setCurrentValue(updatedValue);
if (props.onChange) {
props.onChange(updatedValue);
}
refCurrentValue.current = updatedValue;
setCurrentValue(refCurrentValue.current);
};
const submitForm: Function = (): void => {
// check for any boolean values and if they dont exist in values - mark them as false.
isSubmitting.current = true;
setAllTouched();
const validationErrors: Dictionary<string> = validate(currentValue);
const validationErrors: Dictionary<string> = validate(
refCurrentValue.current
);
if (Object.keys(validationErrors).length > 0) {
// errors on form, do not submit.
return;
}
const values: FormValues<T> = currentValue;
const values: FormValues<T> = refCurrentValue.current;
for (const field of formFields) {
if (field.fieldType === FormFieldSchemaType.Toggle) {
@ -320,11 +332,6 @@ const BasicForm: ForwardRefExoticComponent<any> = forwardRef(
| Array<DropdownValue>
| null
) => {
setCurrentValue({
...currentValue,
[fieldName]: value,
});
field.onChange && field.onChange(value);
setFieldValue(fieldName, value);
}}
@ -355,10 +362,6 @@ const BasicForm: ForwardRefExoticComponent<any> = forwardRef(
: undefined
}
onChange={async (value: string) => {
setCurrentValue({
...currentValue,
[fieldName]: value,
});
field.onChange && field.onChange(value);
setFieldValue(fieldName, value);
}}
@ -468,10 +471,6 @@ const BasicForm: ForwardRefExoticComponent<any> = forwardRef(
}
tabIndex={index}
onChange={async (value: string) => {
setCurrentValue({
...currentValue,
[fieldName]: value,
});
field.onChange && field.onChange(value);
setFieldValue(fieldName, value);
}}
@ -524,10 +523,7 @@ const BasicForm: ForwardRefExoticComponent<any> = forwardRef(
fileResult = null;
}
}
setCurrentValue({
...currentValue,
fieldName: fileResult,
});
field.onChange &&
field.onChange(fileResult);
setFieldValue(fieldName, fileResult);
@ -577,7 +573,7 @@ const BasicForm: ForwardRefExoticComponent<any> = forwardRef(
(currentValue as any)[fieldName] ===
false)
? (currentValue as any)[fieldName]
: field.defaultValue || false
: false
}
/>
)}
@ -612,10 +608,7 @@ const BasicForm: ForwardRefExoticComponent<any> = forwardRef(
dataTestId={fieldType}
type={fieldType as InputType}
onChange={(value: string) => {
setCurrentValue({
...currentValue,
[fieldName]: value,
});
field.onChange && field.onChange(value);
setFieldValue(fieldName, value);
}}
onEnterPress={() => {
@ -941,7 +934,7 @@ const BasicForm: ForwardRefExoticComponent<any> = forwardRef(
};
useEffect(() => {
if (!props.initialValues || isInitialValuesInitialized) {
if (isSubmitting.current) {
return;
}
@ -983,10 +976,19 @@ const BasicForm: ForwardRefExoticComponent<any> = forwardRef(
}
);
}
// if the field is still null but has a default value then... have the default inital value
if (
field.defaultValue &&
(values as any)[fieldName] === undefined
) {
(values as any)[fieldName] = field.defaultValue;
}
}
setCurrentValue(values);
setIsInitialValuesInitialized(true);
}, [props.initialValues]);
refCurrentValue.current = values;
setCurrentValue(refCurrentValue.current);
}, [props.initialValues, formFields]);
const primaryButtonStyle: React.CSSProperties = {};

View File

@ -22,12 +22,12 @@ const Toggle: FunctionComponent<ComponentProps> = (
const [isChecked, setIsChecked] = useState<boolean>(false);
useEffect(() => {
if (props.initialValue) {
setIsChecked(props.initialValue);
props.onChange(true);
} else {
setIsChecked(false);
props.onChange(false);
if (props !== undefined) {
if (props.initialValue) {
setIsChecked(true);
} else {
setIsChecked(false);
}
}
}, [props.initialValue]);
@ -64,6 +64,7 @@ const Toggle: FunctionComponent<ComponentProps> = (
props.onBlur();
}
handleChange(!isChecked);
props.onChange(!isChecked);
}}
tabIndex={props.tabIndex}
type="button"

View File

@ -150,7 +150,7 @@ export default class ApiKey extends BaseModel {
type: TableColumnType.ShortText,
title: 'Name',
description: 'Any friendly name of this object',
canReadOnPopulate: true
canReadOnPopulate: true,
})
@Column({
nullable: false,

View File

@ -156,7 +156,6 @@ export default class Label extends AccessControlModel {
canReadOnPopulate: true,
title: 'Name',
description: 'Any friendly name of this object',
})
@Column({
nullable: false,

View File

@ -175,7 +175,7 @@ export default class Monitor extends BaseModel {
type: TableColumnType.ShortText,
title: 'Name',
description: 'Any friendly name of this object',
canReadOnPopulate: true
canReadOnPopulate: true,
})
@Column({
nullable: false,

View File

@ -165,7 +165,7 @@ export default class OnCallDuty extends BaseModel {
type: TableColumnType.ShortText,
title: 'Name',
description: 'Any friendly name of this object',
canReadOnPopulate: true
canReadOnPopulate: true,
})
@Column({
nullable: false,

View File

@ -74,7 +74,7 @@ export default class Model extends TenantModel {
type: TableColumnType.ShortText,
title: 'Name',
description: 'Any friendly name of this object',
canReadOnPopulate: true
canReadOnPopulate: true,
})
@Column({
nullable: false,

View File

@ -175,7 +175,7 @@ export default class StatusPage extends BaseModel {
type: TableColumnType.ShortText,
title: 'Name',
description: 'Any friendly name of this object',
canReadOnPopulate: true
canReadOnPopulate: true,
})
@Column({
nullable: false,

View File

@ -157,7 +157,7 @@ export default class Team extends BaseModel {
type: TableColumnType.ShortText,
title: 'Name',
description: 'Any friendly name of this object',
canReadOnPopulate: true
canReadOnPopulate: true,
})
@Column({
nullable: false,