diff --git a/src/common/i18n/en.json b/src/common/i18n/en.json index 9842ed13..df28d832 100644 --- a/src/common/i18n/en.json +++ b/src/common/i18n/en.json @@ -1,4 +1,5 @@ { + "general.empty-string": " ", "general.whats-new.tooltip": "What's new?", "general.logo.text": "Catalog App", "general.version.tooltip": "Catalog App version", diff --git a/src/common/i18n/he.json b/src/common/i18n/he.json index deccea4b..bcc491bb 100644 --- a/src/common/i18n/he.json +++ b/src/common/i18n/he.json @@ -1,4 +1,5 @@ { + "general.empty-string": " ", "general.whats-new.tooltip": "מה חדש?", "general.logo.text": "אפליקצית קטלוג", "general.version.tooltip": "אפליקצית קטלוג גרסה", diff --git a/src/discrete-layer/components/layer-details/field-value-presentors/lookup.options-presentor.tsx b/src/discrete-layer/components/layer-details/field-value-presentors/lookup.options-presentor.tsx index e833e7b2..d96a8ba3 100644 --- a/src/discrete-layer/components/layer-details/field-value-presentors/lookup.options-presentor.tsx +++ b/src/discrete-layer/components/layer-details/field-value-presentors/lookup.options-presentor.tsx @@ -39,7 +39,10 @@ export const LookupOptionsPresentorComponent: React.FC { - if (!formik?.getFieldProps(`${fieldNamePrefix ?? ''}${fieldInfo.dependentField.name}`).value && lookupOptions) { + if (lookupOptions) { const filteredOptions = lookupOptions?.filter(option => option.properties[fieldInfo.lookupTableBinding.valueFromPropertyName] === Number(value)); if (!!filteredOptions?.length) { formik?.setFieldValue(`${fieldNamePrefix ?? ''}${fieldInfo.dependentField.name}` as string, filteredOptions[0].properties[fieldInfo.dependentField.valueFromPropertyName]); diff --git a/src/discrete-layer/components/layer-details/ingestion-fields.tsx b/src/discrete-layer/components/layer-details/ingestion-fields.tsx index ca7e1ffc..47652243 100644 --- a/src/discrete-layer/components/layer-details/ingestion-fields.tsx +++ b/src/discrete-layer/components/layer-details/ingestion-fields.tsx @@ -42,7 +42,8 @@ interface IngestionFieldsProps { validateSources?: boolean; reloadFormMetadata?: ( ingestionFields: FormValues, - metadata: MetadataFile + metadata: MetadataFile, + removePrevData?: boolean ) => void; formik?: EntityFormikHandlers; manageMetadata?: boolean; @@ -357,7 +358,8 @@ export const IngestionFields: React.FC> directory: directory, fileNames: fileNames.join(','), }, - selected.metadata as MetadataFile + selected.metadata as MetadataFile, + true // ONLY WHEN (RE-)SELECTING FILE, removePrevData should be TRUE ); } }; diff --git a/src/discrete-layer/components/layer-details/layer-details.tsx b/src/discrete-layer/components/layer-details/layer-details.tsx index d502ff13..406d05e4 100644 --- a/src/discrete-layer/components/layer-details/layer-details.tsx +++ b/src/discrete-layer/components/layer-details/layer-details.tsx @@ -24,7 +24,7 @@ import { ValidationConfigModelType, ValidationValueType, } from '../../models'; -import { getEnumKeys } from '../../components/layer-details/utils'; +import { DEFAULT_ENUM, getEnumKeys, isEnumType } from '../../components/layer-details/utils'; import { ILayerImage } from '../../models/layerImage'; import { links } from '../../models/links'; import { getLinkUrl, getLinkUrlWithToken } from '../helpers/layersUtils'; @@ -155,13 +155,7 @@ export const getValuePresentor = ( formik={formik} fieldNamePrefix={fieldNamePrefix}/> ); - case 'DemDataType': - case 'NoDataValue': - case 'VerticalDatum': - case 'Units': - case 'UndulationModel': - case 'Transparency': - case 'ProductType': { + case (isEnumType(basicType) ? basicType : DEFAULT_ENUM): { let options: string[] = []; if (basicType === 'ProductType') { options = getEnumKeys(enumsMap as IEnumsMapType, basicType, layerRecord.__typename); diff --git a/src/discrete-layer/components/layer-details/raster/entity.raster.dialog.tsx b/src/discrete-layer/components/layer-details/raster/entity.raster.dialog.tsx index 1a96a9e6..ea79a2a1 100644 --- a/src/discrete-layer/components/layer-details/raster/entity.raster.dialog.tsx +++ b/src/discrete-layer/components/layer-details/raster/entity.raster.dialog.tsx @@ -13,6 +13,7 @@ import { Box } from '@map-colonies/react-components'; import { emphasizeByHTML } from '../../../../common/helpers/formatters'; import { getStatusColoredBackground } from '../../../../common/helpers/style'; import { Mode } from '../../../../common/models/mode.enum'; +import { removePropertiesWithPrefix } from '../../../../common/helpers/object'; import { EntityDescriptorModelType, LayerMetadataMixedUnion, @@ -36,16 +37,17 @@ import { LayerRecordTypes, } from '../entity-types-keys'; import { LayersDetailsComponent } from '../layer-details'; -import { IRecordFieldInfo } from '../layer-details.field-info'; +import { FieldInfoName, IRecordFieldInfo } from '../layer-details.field-info'; import EntityRasterForm from './layer-datails-form.raster'; import { clearSyncWarnings, cleanUpEntityPayload, filterModeDescriptors, getFlatEntityDescriptors, - // getRecordForUpdate, getValidationType, - getYupFieldConfig + getYupFieldConfig, + getBasicType, + isEnumType } from '../utils'; import suite from '../validate'; import { getUIIngestionFieldDescriptors } from './ingestion.utils'; @@ -54,6 +56,7 @@ import './entity.raster.dialog.css'; const IS_EDITABLE = 'isManuallyEditable'; const DEFAULT_ID = 'DEFAULT_UI_ID'; +const DEFAULT_TYPE_NAME = 'DEFAULT_TYPE_NAME'; const IMMEDIATE_EXECUTION = 0; const NONE = 0; const START = 0; @@ -71,33 +74,32 @@ const setDefaultValues = (record: Record, descriptors: EntityDe getFlatEntityDescriptors( record['__typename'] as LayerRecordTypes, descriptors - ).filter( - field => field.default - ).forEach( - descriptor => record[descriptor.fieldName as string] = descriptor.default - ); + ).forEach((field) => { + const fieldName = field.fieldName as string; + const fieldNameType = getBasicType(field.fieldName as FieldInfoName, DEFAULT_TYPE_NAME); + if((field.lookupTable || isEnumType(fieldNameType))) { + record[fieldName] = ''; + } + if (field.default){ + record[fieldName] = field.default; + } + } + ) }; export const NESTED_FORMS_PRFIX = 'polygonPart_'; export const buildRecord = (recordType: RecordType, descriptors: EntityDescriptorModelType[]): ILayerImage => { const record = {} as Record; - switch (recordType) { - case RecordType.RECORD_RASTER: - LayerRasterRecordModelKeys.forEach((key) => { - record[key as string] = undefined; - }); - // record.updateDate = moment(); - record.sensors = []; - record.productType = ProductType.ORTHOPHOTO; - record['__typename'] = LayerRasterRecordModel.properties['__typename'].name.replaceAll('"',''); - break; - default: - break; - } + + LayerRasterRecordModelKeys.forEach((key) => { + record[key as string] = undefined; + }); setDefaultValues(record, descriptors); - + + record.productType = ProductType.ORTHOPHOTO; + record['__typename'] = LayerRasterRecordModel.properties['__typename'].name.replaceAll('"',''); record.id = DEFAULT_ID; record.type = recordType; @@ -368,7 +370,8 @@ export const EntityRasterDialog: React.FC = observer( } }); - const newSchema = {...schema}; + const newSchema = removePropertiesWithPrefix(schema, NESTED_FORMS_PRFIX); + for(let i=0; i < partsNumber; i++ ){ newSchema[`${NESTED_FORMS_PRFIX}${i+startIndex}`] = Yup.object().shape({...nestedYupSchema}); } @@ -514,13 +517,6 @@ export const EntityRasterDialog: React.FC = observer( layerRecord={ mode === Mode.UPDATE ? {...props.layerRecord} as LayerMetadataMixedUnion : layerRecord - - // ? getRecordForUpdate( - // props.layerRecord as LayerMetadataMixedUnion, - // layerRecord, - // descriptors as FieldConfigModelType[] - // ) - // : layerRecord } schemaUpdater = {schemaUpdater} yupSchema={Yup.object({ diff --git a/src/discrete-layer/components/layer-details/raster/layer-datails-form.raster.tsx b/src/discrete-layer/components/layer-details/raster/layer-datails-form.raster.tsx index e0916be6..b3ba857f 100644 --- a/src/discrete-layer/components/layer-details/raster/layer-datails-form.raster.tsx +++ b/src/discrete-layer/components/layer-details/raster/layer-datails-form.raster.tsx @@ -461,7 +461,8 @@ export const InnerRasterForm = ( const reloadFormMetadata = ( ingestionFields: FormValues, - metadata: MetadataFile + metadata: MetadataFile, + removePrevData = false ): void => { setIsSelectedFiles(!!ingestionFields.fileNames); @@ -514,8 +515,15 @@ export const InnerRasterForm = ( resetForm(); + if(removePrevData){ + setPolygonPartsMode('MANUAL'); + setExpandedParts([]); + } + + const relevantValues = removePrevData ? removePropertiesWithPrefix(values, NESTED_FORMS_PRFIX) : values; + setValues({ - ...values, + ...relevantValues, ...transformEntityToFormFields((isEmpty(metadata.recordModel) ? layerRecord : metadata.recordModel)), ...ingestionFields, }); @@ -675,13 +683,12 @@ export const InnerRasterForm = ( ppList = ref; } const updateListRowHeights = (idx=0) => { - ppList.recomputeRowHeights(idx); - ppList.forceUpdate(); + ppList?.recomputeRowHeights(idx); + ppList?.forceUpdate(); } const renderRow: ListRowRenderer = ({ index, key, style }) => { const data = Object.values(layerPolygonParts); - console.log('***** RENDERROW *****', index); let polygon_part = data[index]; if(!polygon_part){ @@ -804,6 +811,10 @@ export const InnerRasterForm = ( const ppDataKeys = Object.keys(parsedPPData); schemaUpdater(ppDataKeys.length); + + setTimeout(async () => { + await validateForm(); + }, 0); setExpandedParts(new Array(ppDataKeys.length).fill(false)); diff --git a/src/discrete-layer/components/layer-details/utils.ts b/src/discrete-layer/components/layer-details/utils.ts index 14b82ce2..e1c9d787 100644 --- a/src/discrete-layer/components/layer-details/utils.ts +++ b/src/discrete-layer/components/layer-details/utils.ts @@ -53,6 +53,14 @@ import { const JSON_INDENTATION = 4; +export const DEFAULT_ENUM = 'DEFAULT_ENUM'; + +export const ENUM_TYPES = ['DemDataType', 'DemDataType', 'NoDataValue', 'VerticalDatum', 'Units', 'UndulationModel', 'Transparency', 'ProductType' ] + +export const isEnumType = (typeName: string) => { + return ENUM_TYPES.some(enumType => enumType === typeName); +} + export const getEntityDescriptors = ( layerRecordTypename: LayerRecordTypes, entityDescriptors: EntityDescriptorModelType[]