Skip to content

Commit

Permalink
[fix] GH-7 Compare by id MST references
Browse files Browse the repository at this point in the history
  • Loading branch information
amivanoff committed Aug 31, 2021
1 parent 3799845 commit 0b64a34
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('/') || [];
Expand All @@ -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'] || '';
}
Expand Down
6 changes: 3 additions & 3 deletions src/util/ContextToProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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'] || '';
}
Expand All @@ -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);
}
};
Expand Down

0 comments on commit 0b64a34

Please sign in to comment.