From 0b64a341a801577a61c73dc93e5ba69141737505 Mon Sep 17 00:00:00 2001 From: Alexey Date: Wed, 1 Sep 2021 00:57:28 +0300 Subject: [PATCH] [fix] GH-7 Compare by id MST references --- src/Form.tsx | 10 ++++++++-- src/util/ContextToProps.tsx | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Form.tsx b/src/Form.tsx index 3ef7415..5d1b826 100644 --- a/src/Form.tsx +++ b/src/Form.tsx @@ -87,13 +87,19 @@ export function createViewDescrElementIri(viewKindElementIri: string): string { return viewKindElementIri + '_' + uuid62.v4(); } +export function compareByIri(iri1: string | any, iri2: string | any): boolean { + if (typeof iri1 === 'object') iri1 = iri1['@id']; + if (typeof iri2 === 'object') iri2 = iri2['@id']; + return iri1 === iri2; +} + export const processViewKindOverride = ( props: { viewKindElement: IViewKindElement; viewDescr: IViewDescr }, store: any, ): [string, string, string, string, IViewKindElement, IViewDescrElement | undefined] => { const { viewKindElement, viewDescr } = props; // if ViewElement extend-override exists - const viewDescrElement = viewDescr.elements?.find((el) => el['@parent'] === viewKindElement['@id']); + const viewDescrElement = viewDescr.elements?.find((el) => compareByIri(el['@parent'], viewKindElement['@id'])); const id = viewDescrElement ? viewDescrElement['@id'] : createViewDescrElementIri(viewKindElement['@id']); const [collIri, inCollPath] = viewKindElement.resultsScope?.split('/') || []; @@ -102,7 +108,7 @@ export const processViewKindOverride = ( if (collIriOverride) { // if CollConstr extend-override exists switch to extCollConstr if (viewDescr.collsConstrs) { - const extCollConstr = viewDescr.collsConstrs?.find((el) => el['@parent'] === collIri); + const extCollConstr = viewDescr.collsConstrs?.find((el) => compareByIri(el['@parent'], collIri)); if (extCollConstr) { collIriOverride = extCollConstr['@id'] || ''; } diff --git a/src/util/ContextToProps.tsx b/src/util/ContextToProps.tsx index d71e301..9d754e1 100644 --- a/src/util/ContextToProps.tsx +++ b/src/util/ContextToProps.tsx @@ -17,7 +17,7 @@ import { observer } from 'mobx-react-lite'; import { createLabelDescriptionFrom } from './label'; import { LayoutComponent } from '../layouts/LayoutComponent'; import { IViewKindElement, IViewKind } from '../models/uischema'; -import { ControlComponent, processViewKindOverride, RenderProps } from '../Form'; +import { compareByIri, ControlComponent, processViewKindOverride, RenderProps } from '../Form'; //import { FilterType } from '../complex/Query'; import { validators } from '../validation'; import { MstContext } from '../MstContext'; @@ -464,7 +464,7 @@ export const withStoreToArrayProps = (Component: any): any => let targetData: any = null; if (targetIri) { if (viewDescr.collsConstrs) { - const extCollConstr = viewDescr.collsConstrs?.find((el) => el['@parent'] === targetIri); + const extCollConstr = viewDescr.collsConstrs?.find((el: any) => compareByIri(el['@parent'], targetIri)); if (extCollConstr) { targetIri = extCollConstr['@id'] || ''; } @@ -491,7 +491,7 @@ export const withStoreToArrayProps = (Component: any): any => }; const onDeleteRows = (del: any) => { if (data) { - const newData = data.filter((el) => del.filter((e) => e['@id'] === el['@id']).length === 0); + const newData = data.filter((el: any) => del.filter((e: any) => e['@id'] === el['@id']).length === 0); applySnapshot(coll?.data, newData); } };