From 81e421ddc2e36dfd3c9b7e141d917fabf5c30d65 Mon Sep 17 00:00:00 2001 From: Alexey Date: Sun, 8 Aug 2021 23:18:14 +0300 Subject: [PATCH] [refactor] GH-5 Move ViewDescr here, add aldkg ns --- src/Form.tsx | 7 +- src/stores/ViewCollConstrs.ts | 28 +++ src/stores/ViewDescr.ts | 88 +++++++++ src/stores/ViewShapeSchema.ts | 62 ++++++ src/util/ContextToProps.tsx | 8 +- stories/AntdCardCell.stories.tsx | 243 +++++++++++++++++++++--- stories/Form.stories.tsx | 28 +-- stories/TreeAndForm.stories.tsx | 36 ++-- stories/TreeAndFormArtifact.stories.tsx | 36 ++-- stories/TreeAndFormColumns.stories.tsx | 32 ++-- test/schema/TestSchemas.ts | 26 --- 11 files changed, 470 insertions(+), 124 deletions(-) create mode 100644 src/stores/ViewCollConstrs.ts create mode 100644 src/stores/ViewDescr.ts create mode 100644 src/stores/ViewShapeSchema.ts diff --git a/src/Form.tsx b/src/Form.tsx index f4de30c..8cebe37 100644 --- a/src/Form.tsx +++ b/src/Form.tsx @@ -164,12 +164,13 @@ export const Form: React.FC = observer //const collSS = getSnapshot(coll); const views = coll?.data; const viewObs: any = coll?.dataByIri(viewIri); - + if (!viewObs) { + return ; + } const view = getSnapshot(viewObs); - const viewElement = view; return ( {}}> - + ); }); diff --git a/src/stores/ViewCollConstrs.ts b/src/stores/ViewCollConstrs.ts new file mode 100644 index 0000000..fe98988 --- /dev/null +++ b/src/stores/ViewCollConstrs.ts @@ -0,0 +1,28 @@ +/******************************************************************************** + * Copyright (c) 2021 Agentlab and others. + * + * This program and the accompanying materials are made available under the + * terms of the GNU General Public License v. 3.0 which is available at + * https://www.gnu.org/licenses/gpl-3.0.html. + * + * SPDX-License-Identifier: GPL-3.0-only + ********************************************************************************/ +export const viewDescrCollConstr = { + '@id': 'rm:Views_Coll', + entConstrs: [ + { + '@id': 'rm:Views_EntConstr0', + schema: 'rm:ViewShape', + }, + ], +}; + +export const viewKindCollConstr = { + '@id': 'aldkg:ViewKinds_Coll', + entConstrs: [ + { + '@id': 'aldkg:ViewKinds_EntConstr0', + schema: 'aldkg:ViewKindShape', + }, + ], +}; diff --git a/src/stores/ViewDescr.ts b/src/stores/ViewDescr.ts new file mode 100644 index 0000000..3d85a0d --- /dev/null +++ b/src/stores/ViewDescr.ts @@ -0,0 +1,88 @@ +/******************************************************************************** + * Copyright (c) 2020 Agentlab and others. + * + * This program and the accompanying materials are made available under the + * terms of the GNU General Public License v. 3.0 which is available at + * https://www.gnu.org/licenses/gpl-3.0.html. + * + * SPDX-License-Identifier: GPL-3.0-only + ********************************************************************************/ +import { reaction } from 'mobx'; +import { getParent, getRoot, IAnyModelType, IAnyStateTreeNode, SnapshotIn, types } from 'mobx-state-tree'; + +import { arrDiff, CollConstr, JsObject } from '@agentlab/sparql-jsld-client'; + +export const ViewElement = types.model('ViewElement', { + '@id': types.maybe(types.string), // JSON-LD object id of a view + '@type': types.maybe(types.string), // JSON-LD class id of a View + title: types.maybe(types.string), + description: types.maybe(types.string), + viewKind: types.maybe(types.string), + + type: types.string, + scope: types.maybe(types.string), + resultsScope: types.maybe(types.string), + options: types.maybe(types.frozen()), + + // Container-specific (e.g. Layout, type: 'xxxLayout') + elements: types.maybe(types.array(types.late((): IAnyModelType => ViewElement))), +}); + +/** + * View Description, which could be persisted in DB + */ +export const ViewDescr = types + .model('ViewDescr', { + '@id': types.identifier, // JSON-LD object id of a view + '@type': types.string, // JSON-LD class id of a View + viewKind: types.maybe(types.string), + + title: types.maybe(types.string), // mandatory title + description: types.maybe(types.string), + + type: types.string, + scope: types.maybe(types.string), + resultsScope: types.maybe(types.string), + options: types.maybe(types.frozen()), + + // Container-specific (e.g. Layout, type: 'xxxLayout') + elements: types.array(ViewElement), + + collsConstrs: types.array(CollConstr), // former 'queries' + }) + .actions((self) => { + const rep: IAnyStateTreeNode = getRoot(self); + const coll: IAnyStateTreeNode = getParent(self, 2); + let disp: any; + return { + afterAttach() { + console.log('ViewDescr afterAttach, @id=', self['@id']); + if (coll.resolveCollConstrs) { + disp = reaction( + () => self.collsConstrs, + (newArr: any[], oldArr: any[]) => { + console.log('ViewDescr reaction, add coll ref, @id=', self['@id']); + const { deleted, added } = arrDiff(newArr, oldArr); + console.log('ViewDescr reaction, add coll ref, {deleted,added}=', { deleted, added }); + deleted.forEach((e: any) => rep.colls.delete(e['@id'])); + added.forEach((e: any) => rep.addCollByConstrRef(e)); + }, + { fireImmediately: true }, + ); + } + }, + beforeDetach() { + console.log('ViewDescr beforeDetach, @id=', self['@id']); + if (coll.resolveCollConstrs) { + if (disp) disp(); + self.collsConstrs.forEach((e) => rep.colls.delete(e['@id'])); + } + }, + setCollConstrs(collsConstrs: any[]) { + const ccso = collsConstrs.map((cc) => CollConstr.create(cc)); + self.collsConstrs.push(...ccso); + }, + }; + }); + +export type IViewDescrSnapshotIn = SnapshotIn; diff --git a/src/stores/ViewShapeSchema.ts b/src/stores/ViewShapeSchema.ts new file mode 100644 index 0000000..376e181 --- /dev/null +++ b/src/stores/ViewShapeSchema.ts @@ -0,0 +1,62 @@ +/******************************************************************************** + * Copyright (c) 2020 Agentlab and others. + * + * This program and the accompanying materials are made available under the + * terms of the GNU General Public License v. 3.0 which is available at + * https://www.gnu.org/licenses/gpl-3.0.html. + * + * SPDX-License-Identifier: GPL-3.0-only + ********************************************************************************/ +import { JSONSchema6forRdf } from '@agentlab/sparql-jsld-client'; + +export const ViewShapeSchema: JSONSchema6forRdf = { + $schema: 'http://json-schema.org/draft-07/schema#', + '@id': 'rm:ViewShape', + '@type': 'sh:NodeShape', + title: 'View Shape', + description: 'Artifact Shape', + targetClass: 'aldkg:ViewDescr', + type: 'object', + '@context': { + '@type': 'rdf:type', + }, + properties: { + '@id': { + title: 'URI', + type: 'string', + format: 'iri', + }, + '@type': { + title: 'Тип', + type: 'string', + format: 'iri', + }, + }, + required: ['@id', '@type'], +}; + +export const ViewKindShapeSchema: JSONSchema6forRdf = { + $schema: 'http://json-schema.org/draft-07/schema#', + '@id': 'rm:ViewShape', + '@type': 'sh:NodeShape', + title: 'View Shape', + description: 'Artifact Shape', + targetClass: 'aldkg:ViewDescr', + type: 'object', + '@context': { + '@type': 'rdf:type', + }, + properties: { + '@id': { + title: 'URI', + type: 'string', + format: 'iri', + }, + '@type': { + title: 'Тип', + type: 'string', + format: 'iri', + }, + }, + required: ['@id', '@type'], +}; diff --git a/src/util/ContextToProps.tsx b/src/util/ContextToProps.tsx index db366d1..bc3ae0c 100644 --- a/src/util/ContextToProps.tsx +++ b/src/util/ContextToProps.tsx @@ -52,15 +52,15 @@ export interface ButtonComponent { export const withStoreToControlProps = (Component: React.FC): React.FC => observer((props) => { - const succesValidation = { - validateStatus: 'succes', + const successValidation = { + validateStatus: 'success', }; const { form, viewElement } = props; const id = viewElement.resultsScope; const [validateObj, setValidateObj] = useState<{ validateStatus: string; help?: string; - }>(succesValidation); + }>(successValidation); const [req] = id?.split('/') || []; const [testReq, testUri] = viewElement.resultsScope?.split('/') || []; const { store } = useContext(MstContext); @@ -86,7 +86,7 @@ export const withStoreToControlProps = (Component: React.FC): help, }); } else { - setValidateObj(succesValidation); + setValidateObj(successValidation); store.setOnValidate(form, viewElement.resultsScope, true); } } diff --git a/stories/AntdCardCell.stories.tsx b/stories/AntdCardCell.stories.tsx index 319a580..c58393e 100644 --- a/stories/AntdCardCell.stories.tsx +++ b/stories/AntdCardCell.stories.tsx @@ -13,7 +13,13 @@ import { Story, Meta } from '@storybook/react/types-6-0'; import { Provider } from 'react-redux'; import { asReduxStore, connectReduxDevtools } from 'mst-middlewares'; -import { SparqlClientImpl, rootModelInitialState, createModelFromState, CollState } from '@agentlab/sparql-jsld-client'; +import { + SparqlClientImpl, + rootModelInitialState, + createModelFromState, + CollState, + mstSchemas, +} from '@agentlab/sparql-jsld-client'; import { antdCells, @@ -24,6 +30,8 @@ import { MstContextProvider, RendererRegistryEntry, } from '../src'; +import { viewKindCollConstr, viewDescrCollConstr } from '../src/stores/ViewCollConstrs'; +import { ViewDescr } from '../src/stores/ViewDescr'; const antdRenderers: RendererRegistryEntry[] = [ ...antdControlRenderers, @@ -31,27 +39,220 @@ const antdRenderers: RendererRegistryEntry[] = [ ...antdDataControlRenderers, ]; +const viewKinds = [ + { + '@id': 'rm:CardCellGridViewKind', + '@type': 'aldkg:ViewKind', + type: 'VerticalLayout', + collsConstrs: [ + { + '@id': 'rm:Cards_Coll', + '@type': 'aldkg:CollConstr', + entConstrs: [ + { + '@id': 'rm:Cards_Coll_Shape0', + '@type': 'aldkg:EntConstr', + schema: 'hs:ProductCardShape', + }, + ], + }, + ], + options: { + //width: 'all-empty-space', + }, + // child ui elements configs + elements: [ + { + type: 'DataControl', + resultsScope: 'rm:Cards_Coll', + options: { + renderType: 'grid', + grid: { + gutter: 16, + xs: 2, + sm: 2, + md: 3, + lg: 3, + xl: 4, + xxl: 7, + }, + elementTemplate: [ + { + type: 'CardLayout', + elements: [ + { + type: 'ImageCell', + scope: 'imageUrl', + }, + { + type: 'Control', + scope: 'name', + options: { + editable: false, + style: { + height: '3.5em', + textAlign: 'left', + fontFamily: 'Lato,Tahoma,sans-serif', + overflow: 'hidden', + textOverflow: 'ellipsis', + margin: 0, + }, + }, + }, + { + type: 'Rate', + scope: 'starsValue', + options: { + editable: false, + }, + }, + { + type: 'CellHorizontalLayout', + options: { + justify: 'space-between', + }, + elements: [ + { + type: 'Control', + scope: 'price', + options: { + formater: 'labeledValue', + editable: false, + label: 'Цена', + specialChar: '₽', + style: { + textAlign: 'left', + fontFamily: 'Lato,Tahoma,sans-serif', + color: 'gray', + }, + }, + }, + { + type: 'Control', + scope: 'totalSales', + options: { + formater: 'labeledValue', + editable: false, + label: 'Всего продано', + style: { + textAlign: 'right', + fontFamily: 'Lato,Tahoma,sans-serif', + color: 'gray', + }, + }, + }, + ], + }, + { + type: 'Control', + scope: 'lastMonthSalesAmount', + options: { + editable: false, + formater: 'сomparison', + dataToFormater: { + prevValue: 'prevMonthSalesAmount', + }, + label: 'Продажи за месяц', + style: { + textAlign: 'left', + fontFamily: 'Lato,Tahoma,sans-serif', + color: 'gray', + }, + }, + }, + { + type: 'Control', + scope: 'lastMonthSalesValue', + options: { + formater: 'сomparison', + editable: false, + dataToFormater: { + prevValue: 'prevMonthSalesValue', + }, + label: 'Объем продаж', + style: { + textAlign: 'left', + fontFamily: 'Lato,Tahoma,sans-serif', + color: 'gray', + }, + }, + }, + { + type: 'G2', + }, + { + type: 'CellHorizontalLayout', + options: { + justify: 'space-around', + }, + elements: [ + { + type: 'Control', + scope: '@id', + options: { + style: { + border: '1.5px solid black', + borderRadius: '2px', + height: '2em', + textAlign: 'center', + fontWeight: 500, + width: '90px', + color: 'black', + }, + specialImage: 'https://www.meme-arsenal.com/memes/f8e9bfb9fdf368272b21a5dac8f01ec1.jpg', + editable: false, + formater: 'link', + dataToFormater: { + link: '@id', + }, + label: 'Wildberries', + }, + }, + { + type: 'Button', + options: { + label: 'Добавить', + style: { + border: '1.5px solid black', + borderRadius: '2px', + width: '90px', + fontWeight: 500, + color: 'black', + }, + }, + }, + ], + }, + ], + }, + ], + }, + }, + ], + }, +]; + const viewDescrs = [ { '@id': 'mktp:CardCellViewDescr', - '@type': 'rm:View', + '@type': 'aldkg:ViewDescr', + viewKind: 'rm:CardCellGridViewKind', + type: 'VerticalLayout', title: 'CardCellGrid', description: 'CardCellGrid', - viewKind: 'rm:CardCellGridViewKind', collsConstrs: [ { '@id': 'rm:Cards_Coll', - '@type': 'rm:CollConstr', + '@type': 'aldkg:CollConstr', entConstrs: [ { '@id': 'rm:Cards_Coll_Shape0', - '@type': 'rm:EntConstr', + '@type': 'aldkg:EntConstr', schema: 'hs:ProductCardShape', }, ], }, ], - type: 'VerticalLayout', options: { //width: 'all-empty-space', }, @@ -227,27 +428,17 @@ const viewDescrs = [ }, ]; -const viewDescrCollConstr = { - '@id': 'rm:Views_Coll', - entConstrs: [ - { - '@id': 'rm:Views_EntConstr0', - schema: 'rm:ViewShape', - }, - ], -}; - const additionalColls: CollState[] = [ // ViewKinds Collection - /*{ - constr: viewKindCollConstr, - data: viewKinds, - opt: { - updPeriod: undefined, - lastSynced: moment.now(), - resolveCollConstrs: false, // disable data loading from the server for viewKinds.collConstrs - }, - },*/ + { + constr: viewKindCollConstr, + data: viewKinds, + opt: { + updPeriod: undefined, + lastSynced: moment.now(), + resolveCollConstrs: false, // disable data loading from the server for viewKinds.collConstrs + }, + }, // ViewDescrs Collection { constr: viewDescrCollConstr, @@ -261,6 +452,8 @@ const additionalColls: CollState[] = [ }, ]; +mstSchemas['aldkg:ViewDescr'] = ViewDescr; + const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server'); const rootStore = createModelFromState('mktp', client, rootModelInitialState, additionalColls); console.log('rootStore', rootStore); diff --git a/stories/Form.stories.tsx b/stories/Form.stories.tsx index 21e26cf..2fd172b 100644 --- a/stories/Form.stories.tsx +++ b/stories/Form.stories.tsx @@ -14,7 +14,13 @@ import { Meta, Story } from '@storybook/react'; import { Provider } from 'react-redux'; import { asReduxStore, connectReduxDevtools } from 'mst-middlewares'; -import { SparqlClientImpl, rootModelInitialState, createModelFromState, CollState } from '@agentlab/sparql-jsld-client'; +import { + SparqlClientImpl, + rootModelInitialState, + createModelFromState, + CollState, + mstSchemas, +} from '@agentlab/sparql-jsld-client'; import { RendererRegistryEntry, @@ -24,13 +30,15 @@ import { antdControlRenderers, antdLayoutRenderers, } from '../src'; +import { viewKindCollConstr, viewDescrCollConstr } from '../src/stores/ViewCollConstrs'; +import { ViewDescr } from '../src/stores/ViewDescr'; const antdRenderers: RendererRegistryEntry[] = [...antdControlRenderers, ...antdLayoutRenderers]; const viewDescrs = [ { '@id': 'rm:FormView', - '@type': 'rm:View', + '@type': 'aldkg:ViewDescr', //'viewKind': 'rm:FormViewClass', title: 'Малая форма', description: 'Small form', @@ -38,11 +46,11 @@ const viewDescrs = [ collsConstrs: [ { '@id': 'rm:FormView_Artifacts_Coll', - '@type': 'rm:CollConstr', + '@type': 'aldkg:CollConstr', entConstrs: [ { '@id': 'rm:FormView_Artifacts_Coll_Ent0', - '@type': 'rm:EntConstr', + '@type': 'aldkg:EntConstr', schema: 'rm:ArtifactShape', }, ], @@ -78,16 +86,6 @@ const viewDescrs = [ }, ]; -const viewDescrCollConstr = { - '@id': 'rm:Views_Coll', - entConstrs: [ - { - '@id': 'rm:Views_EntConstr0', - schema: 'rm:ViewShape', - }, - ], -}; - const additionalColls: CollState[] = [ // ViewKinds Collection /*{ @@ -112,6 +110,8 @@ const additionalColls: CollState[] = [ }, ]; +mstSchemas['aldkg:ViewDescr'] = ViewDescr; + const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server'); const rootStore = createModelFromState('reqs2', client, rootModelInitialState, additionalColls); const store: any = asReduxStore(rootStore); diff --git a/stories/TreeAndForm.stories.tsx b/stories/TreeAndForm.stories.tsx index e18766e..cfbd53e 100644 --- a/stories/TreeAndForm.stories.tsx +++ b/stories/TreeAndForm.stories.tsx @@ -13,7 +13,13 @@ import { Story, Meta } from '@storybook/react/types-6-0'; import { Provider } from 'react-redux'; import { asReduxStore, connectReduxDevtools } from 'mst-middlewares'; -import { SparqlClientImpl, rootModelInitialState, createModelFromState, CollState } from '@agentlab/sparql-jsld-client'; +import { + SparqlClientImpl, + rootModelInitialState, + createModelFromState, + CollState, + mstSchemas, +} from '@agentlab/sparql-jsld-client'; import { antdCells, @@ -24,6 +30,8 @@ import { MstContextProvider, RendererRegistryEntry, } from '../src'; +import { viewKindCollConstr, viewDescrCollConstr } from '../src/stores/ViewCollConstrs'; +import { ViewDescr } from '../src/stores/ViewDescr'; const antdRenderers: RendererRegistryEntry[] = [ ...antdControlRenderers, @@ -34,29 +42,29 @@ const antdRenderers: RendererRegistryEntry[] = [ const viewDescrs = [ { '@id': 'mktp:TreeAndFormViewDescr', - '@type': 'rm:View', + '@type': 'aldkg:ViewDescr', title: 'TreeAndForm', description: 'TreeAndForm', viewKind: 'rm:TreeAndFormViewKind', collsConstrs: [ { '@id': 'rm:Categories_Coll', - '@type': 'rm:CollConstr', + '@type': 'aldkg:CollConstr', entConstrs: [ { '@id': 'rm:Categories_Coll_Shape0', - '@type': 'rm:EntConstr', + '@type': 'aldkg:EntConstr', schema: 'hs:CategoryShape', }, ], }, { '@id': 'rm:Category_Coll', - '@type': 'rm:CollConstr', + '@type': 'aldkg:CollConstr', entConstrs: [ { '@id': 'rm:Cards_Coll_Ent0', - '@type': 'rm:EntConstr', + '@type': 'aldkg:EntConstr', schema: 'hs:CategoryShape', conditions: { '_@id': 'https://www.wildberries.ru/catalog/zdorove/ozdorovlenie', @@ -67,11 +75,11 @@ const viewDescrs = [ }, { '@id': 'rm:Cards_Coll', - '@type': 'rm:CollConstr', + '@type': 'aldkg:CollConstr', entConstrs: [ { '@id': 'rm:Cards_Coll_Ent0', - '@type': 'rm:EntConstr', + '@type': 'aldkg:EntConstr', schema: 'hs:ProductCardShape', }, ], @@ -279,16 +287,6 @@ const viewDescrs = [ }, ]; -const viewDescrCollConstr = { - '@id': 'rm:Views_Coll', - entConstrs: [ - { - '@id': 'rm:Views_EntConstr0', - schema: 'rm:ViewShape', - }, - ], -}; - const additionalColls: CollState[] = [ // ViewKinds Collection /*{ @@ -313,6 +311,8 @@ const additionalColls: CollState[] = [ }, ]; +mstSchemas['aldkg:ViewDescr'] = ViewDescr; + const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server'); const rootStore = createModelFromState('mktp', client, rootModelInitialState, additionalColls); const store: any = asReduxStore(rootStore); diff --git a/stories/TreeAndFormArtifact.stories.tsx b/stories/TreeAndFormArtifact.stories.tsx index 5ef0696..9707522 100644 --- a/stories/TreeAndFormArtifact.stories.tsx +++ b/stories/TreeAndFormArtifact.stories.tsx @@ -13,50 +13,58 @@ import { Story, Meta } from '@storybook/react/types-6-0'; import { Provider } from 'react-redux'; import { asReduxStore, connectReduxDevtools } from 'mst-middlewares'; -import { SparqlClientImpl, rootModelInitialState, createModelFromState, CollState } from '@agentlab/sparql-jsld-client'; +import { + SparqlClientImpl, + rootModelInitialState, + createModelFromState, + CollState, + mstSchemas, +} from '@agentlab/sparql-jsld-client'; import { antdCells, antdControlRenderers, antdLayoutRenderers, - antdRataControlRenderers, + antdDataControlRenderers, Form, MstContextProvider, RendererRegistryEntry, } from '../src'; +import { viewKindCollConstr, viewDescrCollConstr } from '../src/stores/ViewCollConstrs'; +import { ViewDescr } from '../src/stores/ViewDescr'; const antdRenderers: RendererRegistryEntry[] = [ ...antdControlRenderers, ...antdLayoutRenderers, - ...antdRataControlRenderers, + ...antdDataControlRenderers, ]; const viewDescrs = [ { '@id': 'mktp:TreeAndFormViewDescr', - '@type': 'rm:View', + '@type': 'aldkg:ViewDescr', title: 'TreeAndForm', description: 'TreeAndForm', viewKind: 'rm:TreeAndFormViewKind', collsConstrs: [ { '@id': 'rm:Folders_Coll', - '@type': 'rm:CollConstr', + '@type': 'aldkg:CollConstr', entConstrs: [ { '@id': 'rm:Folders_Coll_Shape0', - '@type': 'rm:EntConstr', + '@type': 'aldkg:EntConstr', schema: 'nav:folderShape', }, ], }, { '@id': 'rm:Artifacts_Coll', - '@type': 'rm:CollConstr', + '@type': 'aldkg:CollConstr', entConstrs: [ { '@id': 'rm:Artifacts_Coll_Ent0', - '@type': 'rm:EntConstr', + '@type': 'aldkg:EntConstr', schema: 'rm:ArtifactShape', }, ], @@ -118,16 +126,6 @@ const viewDescrs = [ }, ]; -const viewDescrCollConstr = { - '@id': 'rm:Views_Coll', - entConstrs: [ - { - '@id': 'rm:Views_EntConstr0', - schema: 'rm:ViewShape', - }, - ], -}; - const additionalColls: CollState[] = [ // ViewKinds Collection /*{ @@ -152,6 +150,8 @@ const additionalColls: CollState[] = [ }, ]; +mstSchemas['aldkg:ViewDescr'] = ViewDescr; + const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server'); const rootStore = createModelFromState('reqs2', client, rootModelInitialState, additionalColls); const store: any = asReduxStore(rootStore); diff --git a/stories/TreeAndFormColumns.stories.tsx b/stories/TreeAndFormColumns.stories.tsx index e060d79..947f020 100644 --- a/stories/TreeAndFormColumns.stories.tsx +++ b/stories/TreeAndFormColumns.stories.tsx @@ -13,39 +13,47 @@ import { Story, Meta } from '@storybook/react/types-6-0'; import { Provider } from 'react-redux'; import { asReduxStore, connectReduxDevtools } from 'mst-middlewares'; -import { SparqlClientImpl, rootModelInitialState, createModelFromState, CollState } from '@agentlab/sparql-jsld-client'; +import { + SparqlClientImpl, + rootModelInitialState, + createModelFromState, + CollState, + mstSchemas, +} from '@agentlab/sparql-jsld-client'; import { antdCells, antdControlRenderers, antdLayoutRenderers, - antdRataControlRenderers, + antdDataControlRenderers, Form, MstContextProvider, RendererRegistryEntry, } from '../src'; +import { viewKindCollConstr, viewDescrCollConstr } from '../src/stores/ViewCollConstrs'; +import { ViewDescr } from '../src/stores/ViewDescr'; const antdRenderers: RendererRegistryEntry[] = [ ...antdControlRenderers, ...antdLayoutRenderers, - ...antdRataControlRenderers, + ...antdDataControlRenderers, ]; const viewDescrs = [ { '@id': 'mktp:TreeAndFormViewDescr', - '@type': 'rm:View', + '@type': 'aldkg:ViewDescr', title: 'TreeAndForm', description: 'TreeAndForm', viewKind: 'rm:TreeAndFormViewKind', collsConstrs: [ { '@id': 'rm:Cards_Coll', - '@type': 'rm:CollConstr', + '@type': 'aldkg:CollConstr', entConstrs: [ { '@id': 'rm:Cards_Coll_Ent0', - '@type': 'rm:EntConstr', + '@type': 'aldkg:EntConstr', schema: 'hs:ProductCardShape', }, ], @@ -223,16 +231,6 @@ const viewDescrs = [ }, ]; -const viewDescrCollConstr = { - '@id': 'rm:Views_Coll', - entConstrs: [ - { - '@id': 'rm:Views_EntConstr0', - schema: 'rm:ViewShape', - }, - ], -}; - const additionalColls: CollState[] = [ // ViewKinds Collection /*{ @@ -257,6 +255,8 @@ const additionalColls: CollState[] = [ }, ]; +mstSchemas['aldkg:ViewDescr'] = ViewDescr; + const client = new SparqlClientImpl('https://rdf4j.agentlab.ru/rdf4j-server'); const rootStore = createModelFromState('mktp', client, rootModelInitialState, additionalColls); const store: any = asReduxStore(rootStore); diff --git a/test/schema/TestSchemas.ts b/test/schema/TestSchemas.ts index 2c18905..dc43a9d 100644 --- a/test/schema/TestSchemas.ts +++ b/test/schema/TestSchemas.ts @@ -601,30 +601,4 @@ export const usedInModuleSchema: JSONSchema6forRdf = { required: [...(usedInSchema.required || []), 'parentBinding', 'depth', 'bookOrder', 'sectionNumber'], }; -export const ViewShapeSchema: JSONSchema6forRdf = { - $schema: 'http://json-schema.org/draft-07/schema#', - '@id': 'rm:ViewShape', - '@type': 'sh:NodeShape', - title: 'View Shape', - description: 'Artifact Shape', - targetClass: 'rm:View', - type: 'object', - '@context': { - '@type': 'rdf:type', - }, - properties: { - '@id': { - title: 'URI', - type: 'string', - format: 'iri', - }, - '@type': { - title: 'Тип', - type: 'string', - format: 'iri', - }, - }, - required: ['@id', '@type'], -}; - export const { property: artifactShapeProperty, ...artifactShapeNoProperty } = artifactShape;