From b052c0a38d01dc68c1f0d84d39f83c69fa229f6b Mon Sep 17 00:00:00 2001 From: Eliav Maimon <135841794+Eliav-Maimon@users.noreply.github.com> Date: Mon, 30 Dec 2024 12:00:58 +0200 Subject: [PATCH] fix: delete typename from metadata.recordModel and send to bff only necessary fields (#578) --- .../components/layer-details/entity.dialog.tsx | 15 +++++++++++++-- .../layer-details/layer-datails-form.tsx | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/discrete-layer/components/layer-details/entity.dialog.tsx b/src/discrete-layer/components/layer-details/entity.dialog.tsx index 20ff6a26..ffc0e125 100644 --- a/src/discrete-layer/components/layer-details/entity.dialog.tsx +++ b/src/discrete-layer/components/layer-details/entity.dialog.tsx @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ -import React, { useEffect, useCallback, useState, useLayoutEffect, useRef } from 'react'; +import React, { useEffect, useCallback, useState, useLayoutEffect, useRef, useMemo } from 'react'; import { useIntl } from 'react-intl'; import { observer } from 'mobx-react'; import { FormikValues } from 'formik'; @@ -44,6 +44,7 @@ import { LayersDetailsComponent } from './layer-details'; import { IRecordFieldInfo } from './layer-details.field-info'; import EntityForm from './layer-datails-form'; import { + cleanUpEntityPayload, clearSyncWarnings, getFlatEntityDescriptors, getPartialRecord, @@ -189,6 +190,16 @@ export const EntityDialog: React.FC = observer( ); }; + const metadataPayloadKeys = useMemo( + () => { + return getFlatEntityDescriptors( + 'Layer3DRecord', + store.discreteLayersStore.entityDescriptors as EntityDescriptorModelType[] + ) + .map(descriptor => descriptor.fieldName); + }, + [store.discreteLayersStore.entityDescriptors]); + const handleIngestQueries = (): void => { // eslint-disable-next-line @typescript-eslint/naming-convention const { directory, fileNames, __typename, ...metadata } = inputValues; @@ -211,7 +222,7 @@ export const EntityDialog: React.FC = observer( data: { directory: directory as string, fileNames: [fileNames as string], - metadata: metadata as Layer3DRecordInput, + metadata: cleanUpEntityPayload(metadata, metadataPayloadKeys as string[]) as unknown as Layer3DRecordInput, type: RecordType.RECORD_3D, }, }) diff --git a/src/discrete-layer/components/layer-details/layer-datails-form.tsx b/src/discrete-layer/components/layer-details/layer-datails-form.tsx index 9ff6d633..25914003 100644 --- a/src/discrete-layer/components/layer-details/layer-datails-form.tsx +++ b/src/discrete-layer/components/layer-details/layer-datails-form.tsx @@ -192,6 +192,8 @@ const InnerForm = ( metadata: MetadataFile ): void => { setIsSelectedFiles(!!ingestionFields.fileNames); + + delete ((metadata.recordModel as unknown) as Record)['__typename']; // Check update related fields in metadata obj const updateFields = extractDescriptorRelatedFieldNames('updateRules', getFlatEntityDescriptors(layerRecord.__typename, entityDescriptors));