From fab7ca460ebdec59e1acf2e10a65968574751657 Mon Sep 17 00:00:00 2001 From: Elias Bruvik Date: Mon, 5 Aug 2024 13:49:06 +0200 Subject: [PATCH] FIX-2515 Add required properties for creating new objects --- .../Modals/LogHeaderDateTimeField.tsx | 6 ++++- .../Properties/BhaRunProperties.ts | 3 ++- .../Properties/FormationMarkerProperties.ts | 3 ++- .../Properties/MessageProperties.ts | 27 +++++++++++++++++-- .../Properties/RiskProperties.ts | 6 +++-- .../Properties/WbGeometryProperties.ts | 3 ++- .../Properties/getFluidsReportProperties.ts | 6 +++-- .../PropertiesModal/PropertiesRenderer.tsx | 1 + .../models/messageTypes.ts | 7 +++++ 9 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 Src/WitsmlExplorer.Frontend/models/messageTypes.ts diff --git a/Src/WitsmlExplorer.Frontend/components/Modals/LogHeaderDateTimeField.tsx b/Src/WitsmlExplorer.Frontend/components/Modals/LogHeaderDateTimeField.tsx index 057773658..34acbfd51 100644 --- a/Src/WitsmlExplorer.Frontend/components/Modals/LogHeaderDateTimeField.tsx +++ b/Src/WitsmlExplorer.Frontend/components/Modals/LogHeaderDateTimeField.tsx @@ -15,6 +15,7 @@ interface DateTimeFieldProps { minValue?: string; maxValue?: string; disabled?: boolean; + required?: boolean; } /** @@ -31,7 +32,8 @@ interface DateTimeFieldProps { export const LogHeaderDateTimeField = ( props: DateTimeFieldProps ): React.ReactElement => { - const { disabled, value, label, updateObject, minValue, maxValue } = props; + const { disabled, required, value, label, updateObject, minValue, maxValue } = + props; const { operationState: { timeZone } } = useOperationState(); @@ -46,6 +48,7 @@ export const LogHeaderDateTimeField = ( }, []); const validate = (current: string) => { + if (required && !current) return false; return ( ((!minValue || current >= minValue) && (!maxValue || current <= maxValue)) || @@ -55,6 +58,7 @@ export const LogHeaderDateTimeField = ( const getHelperText = () => { if (!validate(value)) { + if (required && !value) return "This field is required"; if (!initiallyEmpty && (value == null || value === "")) { return "This field cannot be deleted."; } diff --git a/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/BhaRunProperties.ts b/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/BhaRunProperties.ts index 4ba7211d6..b34e80a4c 100644 --- a/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/BhaRunProperties.ts +++ b/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/BhaRunProperties.ts @@ -28,7 +28,8 @@ export const getBhaRunProperties = ( property: "tubular", propertyType: PropertyType.RefNameString, validator: validRefNameString, - helperText: getRefNameStringHelperText("tubular") + helperText: getRefNameStringHelperText("tubular"), + required: true }, { property: "dTimStart", diff --git a/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/FormationMarkerProperties.ts b/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/FormationMarkerProperties.ts index e5a52bff3..db4b23b00 100644 --- a/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/FormationMarkerProperties.ts +++ b/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/FormationMarkerProperties.ts @@ -45,7 +45,8 @@ export const getFormationMarkerProperties = ( property: "mdTopSample", propertyType: PropertyType.Measure, validator: validMeasure, - helperText: getMeasureHelperText("mdTopSample") + helperText: getMeasureHelperText("mdTopSample"), + required: true }, { property: "tvdTopSample", diff --git a/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/MessageProperties.ts b/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/MessageProperties.ts index 1abaec62a..45b2b2b3d 100644 --- a/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/MessageProperties.ts +++ b/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/MessageProperties.ts @@ -1,15 +1,38 @@ -import { PropertiesModalMode, validText } from "components/Modals/ModalParts"; +import { + PropertiesModalMode, + validOption, + validText +} from "components/Modals/ModalParts"; import { getCommonObjectOnWellboreProperties } from "components/Modals/PropertiesModal/Properties/CommonObjectOnWellboreProperties"; import { PropertiesModalProperty } from "components/Modals/PropertiesModal/propertiesModalProperty"; import { PropertyType } from "components/Modals/PropertiesModal/PropertyTypes"; -import { getMaxLengthHelperText } from "components/Modals/PropertiesModal/ValidationHelpers"; +import { + getMaxLengthHelperText, + getOptionHelperText +} from "components/Modals/PropertiesModal/ValidationHelpers"; import MaxLength from "models/maxLength"; import MessageObject from "models/messageObject"; +import { messageTypes } from "models/messageTypes"; export const getMessageProperties = ( mode: PropertiesModalMode ): PropertiesModalProperty[] => [ ...getCommonObjectOnWellboreProperties(mode), + { + property: "dTim", + propertyType: PropertyType.DateTime, + required: true, + disabled: mode !== PropertiesModalMode.New + }, + { + property: "typeMessage", + propertyType: PropertyType.Options, + validator: (value: string) => validOption(value, messageTypes), + helperText: getOptionHelperText("typeMessage"), + options: messageTypes, + required: true, + disabled: mode !== PropertiesModalMode.New + }, { property: "messageText", propertyType: PropertyType.String, diff --git a/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/RiskProperties.ts b/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/RiskProperties.ts index ce1660058..02ff91e5f 100644 --- a/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/RiskProperties.ts +++ b/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/RiskProperties.ts @@ -41,14 +41,16 @@ export const getRiskProperties = ( propertyType: PropertyType.Options, validator: (value: string) => validOption(value, riskType), helperText: getOptionHelperText("type"), - options: riskType + options: riskType, + required: true }, { property: "category", propertyType: PropertyType.Options, validator: (value: string) => validOption(value, riskCategory), helperText: getOptionHelperText("category"), - options: riskCategory + options: riskCategory, + required: true }, { property: "subCategory", diff --git a/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/WbGeometryProperties.ts b/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/WbGeometryProperties.ts index 5dc1e9b9f..1581c8e3c 100644 --- a/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/WbGeometryProperties.ts +++ b/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/WbGeometryProperties.ts @@ -33,7 +33,8 @@ export const getWbGeometryProperties = ( { property: "dTimReport", propertyType: PropertyType.DateTime, - disabled: true + required: true, + disabled: mode !== PropertiesModalMode.New }, { property: "commonData.sourceName", diff --git a/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/getFluidsReportProperties.ts b/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/getFluidsReportProperties.ts index 85f390cf2..ed861323a 100644 --- a/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/getFluidsReportProperties.ts +++ b/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/Properties/getFluidsReportProperties.ts @@ -23,13 +23,15 @@ export const getFluidsReportProperties = ( ...getCommonObjectOnWellboreProperties(mode), { property: "dTim", - propertyType: PropertyType.DateTime + propertyType: PropertyType.DateTime, + required: true }, { property: "md", propertyType: PropertyType.Measure, validator: validMeasure, - helperText: getMeasureHelperText("md") + helperText: getMeasureHelperText("md"), + required: true }, { property: "tvd", diff --git a/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/PropertiesRenderer.tsx b/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/PropertiesRenderer.tsx index 134cecd5e..81c40c976 100644 --- a/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/PropertiesRenderer.tsx +++ b/Src/WitsmlExplorer.Frontend/components/Modals/PropertiesModal/PropertiesRenderer.tsx @@ -157,6 +157,7 @@ export const PropertiesRenderer = ({ } label={prop.property} disabled={prop.disabled} + required={prop.required} updateObject={(dateTime: string) => { onChangeProperty(prop.property, prop.propertyType, dateTime); }} diff --git a/Src/WitsmlExplorer.Frontend/models/messageTypes.ts b/Src/WitsmlExplorer.Frontend/models/messageTypes.ts new file mode 100644 index 000000000..884acff20 --- /dev/null +++ b/Src/WitsmlExplorer.Frontend/models/messageTypes.ts @@ -0,0 +1,7 @@ +export const messageTypes = [ + "alarm", + "event", + "informational", + "warning", + "unknown" +];