Skip to content

Commit

Permalink
Merge branch 'main' into issue-16-read-only-form
Browse files Browse the repository at this point in the history
  • Loading branch information
amivanoff committed Sep 22, 2021
2 parents c4f928f + b5cbcd6 commit eb68ef7
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 53 deletions.
7 changes: 0 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch App in Chrome",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}",
},
{
"type": "chrome",
"request": "launch",
Expand Down
4 changes: 1 addition & 3 deletions src/layouts/SplitPaneLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ const renderSplitElements = ({ viewKind, viewKindElement, viewDescr, enabled, Re
const style = el.options && el.options.style;
return (
<Pane key={idx} style={style} initialSize={defaultSize[id]}>
<div>
<FormsDispatch viewKind={viewKind} viewKindElement={el} viewDescr={viewDescr} enabled={enabled} />
</div>
<FormsDispatch viewKind={viewKind} viewKindElement={el} viewDescr={viewDescr} enabled={enabled} />
</Pane>
);
})
Expand Down
18 changes: 8 additions & 10 deletions src/util/ContextToProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export const withStoreToControlProps = (Component: React.FC<ControlComponent>):
}>(successValidation);

const { form } = props;
const controlProps = mapStateToControlProps(props);

const [id, collIri, collIriOverride, inCollPath, viewKindElement, viewDescrElement] = processViewKindOverride(
props,
Expand All @@ -69,12 +68,9 @@ export const withStoreToControlProps = (Component: React.FC<ControlComponent>):
const coll = collIriOverride ? store.getColl(collIriOverride) : undefined;
let collData = coll?.data;
if (collData) collData = getSnapshot(collData);
const controlProps = mapStateToControlProps({ ...props, data: collData });

if (!collData || collData.length === 0) {
return <Spin />;
}

const data = collData[0];
const data = collData.length !== 0 ? collData[0] : {};
const onValidate = (data: any) => {
if (viewKindElement.options && Array.isArray(viewKindElement.options.validation)) {
const validation = viewKindElement.options.validation;
Expand Down Expand Up @@ -221,16 +217,17 @@ export const withStoreToCellProps = (Component: React.FC<any>): React.FC<any> =>
observer<any>((props: any) => {
const { data, onMeasureChange, height, uri, CKey, rowData, viewKindElement } = props;
const path = viewKindElement.scope ? viewKindElement.scope.split('/').join('.') : null;
const controlProps = mapStateToControlProps(props);
/*const { store } = useRootCtx();
const onSave = (data: any) => {
let newData: any = {};
newData[CKey] = data;
store.saveCellData(newData, uri, rowData['@id']);
};*/
const cellData = path ? get(data, path) : data;
const controlProps = mapStateToControlProps({ ...props, data: cellData });
return (
<Component
data={path ? get(data, path) : data}
data={cellData}
height={height}
rowData={rowData}
onMeasureChange={onMeasureChange}
Expand Down Expand Up @@ -591,7 +588,7 @@ export const withStoreToSaveDialogProps = (Component: React.FC<SaveDialog>): Rea
return <Component visible={visible} onOk={onSave} onCancel={onCancel} />;
});

const mapStateToControlProps = ({ id, schema, viewKindElement, viewKind, enabled }: ToControlProps) => {
const mapStateToControlProps = ({ id, schema, viewKindElement, viewKind, data }: ToControlProps & { data: any }) => {
const pathSegments = id.split('/');
const path = pathSegments.join('.properties.');
const visible = checkProperty('visible', path, viewKindElement, viewKind);
Expand All @@ -603,11 +600,12 @@ const mapStateToControlProps = ({ id, schema, viewKindElement, viewKind, enabled
const labelDesc = createLabelDescriptionFrom(viewKindElement as any, schema);
const label = labelDesc.show ? (labelDesc.text as string) : '';
const key = pathSegments[1];
const enabled = data && (editable ?? true);
return {
description,
label,
visible,
enabled: editable === 'undefined' ? true : editable,
enabled,
required,
uiOptions,
key,
Expand Down
88 changes: 63 additions & 25 deletions stories/Form.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
*
* SPDX-License-Identifier: GPL-3.0-only
********************************************************************************/
import { cloneDeep } from 'lodash';
import moment from 'moment';
import React from 'react';
import { Meta, Story } from '@storybook/react';

import { Provider } from 'react-redux';
import { asReduxStore, connectReduxDevtools } from 'mst-middlewares';
import { SparqlClientImpl, rootModelInitialState, CollState } from '@agentlab/sparql-jsld-client';
import { cloneDeep } from 'lodash';
import { SparqlClientImpl, rootModelInitialState, CollState, JsObject } from '@agentlab/sparql-jsld-client';

import {
RendererRegistryEntry,
Expand Down Expand Up @@ -102,29 +102,44 @@ const viewDescrs = [
},
];

const createAdditionalColls = (viewKinds: any): CollState[] => [
// ViewKinds Collection
{
constr: viewKindCollConstr,
data: viewKinds,
opt: {
updPeriod: undefined,
lastSynced: moment.now(),
//resolveCollConstrs: false, // disable data loading from the server for viewKinds.collConstrs
const createAdditionalColls = (viewKinds: any, data: JsObject[] | undefined): CollState[] => {
const additionalColls = [
// ViewKinds Collection
{
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,
data: viewDescrs,
opt: {
updPeriod: undefined,
lastSynced: moment.now(),
//resolveCollConstrs: false, // 'true' here (by default) triggers data loading from the server
// for viewDescrs.collConstrs (it loads lazily -- after the first access)
// ViewDescrs Collection
{
constr: viewDescrCollConstr,
data: viewDescrs,
opt: {
updPeriod: undefined,
lastSynced: moment.now(),
//resolveCollConstrs: false, // 'true' here (by default) triggers data loading from the server
// for viewDescrs.collConstrs (it loads lazily -- after the first access)
},
},
},
];
];
if (data) {
additionalColls.push({
constr: viewKinds[0].collsConstrs[0],
data,
opt: {
updPeriod: undefined,
lastSynced: moment.now(),
//resolveCollConstrs: false, // 'true' here (by default) triggers data loading from the server
// for viewDescrs.collConstrs (it loads lazily -- after the first access)
},
});
}
return additionalColls;
};

export default {
title: 'Form/ArtifactForm',
Expand All @@ -142,7 +157,7 @@ const Template: Story<any> = (args: any) => {
'reqs2',
client,
rootModelInitialState,
createAdditionalColls(args.viewKinds),
createAdditionalColls(args.viewKinds, args.data),
);
const store: any = asReduxStore(rootStore);
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand All @@ -164,9 +179,32 @@ RemoteData.args = {
};

export const ReadOnlyForm = Template.bind({});

const readOnlyFormViewKinds = cloneDeep(viewKinds);
readOnlyFormViewKinds[0].elements[0].options.readOnly = true;
ReadOnlyForm.args = {
viewKinds: readOnlyFormViewKinds,
};

export const ObjectWithNullProperty = Template.bind({});
ObjectWithNullProperty.args = {
viewKinds,
data: [
{
creator: null,
assetFolder: null,
description: 'TestDescr',
},
],
};

export const EmptyObject = Template.bind({});
EmptyObject.args = {
viewKinds,
data: [{}],
};

export const NoObject = Template.bind({});
NoObject.args = {
viewKinds,
data: [],
};
12 changes: 6 additions & 6 deletions stories/TableRemoteMktp.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ import { tableRenderers } from '../src';

const viewKinds = [
{
'@id': 'rm:TableViewKind',
'@id': 'mktp:TableViewKind',
'@type': 'aldkg:ViewKind',
title: 'Карточки',
description: 'Big table View with form',
collsConstrs: [
{
'@id': 'rm:ProductCard_Coll',
'@id': 'mktp:ProductCard_Coll',
'@type': 'aldkg:CollConst',
entConstrs: [
{
'@id': 'rm:ProductCard_Coll_Shape0',
'@id': 'mktp:ProductCard_Coll_Shape0',
'@type': 'aldkg:EntConstr',
schema: 'hs:ProductCardShape',
/*conditions: {
Expand All @@ -57,7 +57,7 @@ const viewKinds = [
],
elements: [
{
'@id': 'rm:_934jHd67',
'@id': 'mktp:_934jHd67',
'@type': 'aldkg:VerticalLayout',
options: {
height: 'all-empty-space',
Expand All @@ -66,7 +66,7 @@ const viewKinds = [
{
'@id': 'ProductCardTable',
'@type': 'aldkg:Array',
resultsScope: 'rm:ProductCard_Coll',
resultsScope: 'mktp:ProductCard_Coll',
options: {
draggable: true,
resizeableHeader: true,
Expand Down Expand Up @@ -256,7 +256,7 @@ const viewDescrs = [
{
'@id': 'rm:TableViewDescr',
'@type': 'aldkg:ViewDescr',
viewKind: 'rm:TableViewKind',
viewKind: 'mktp:TableViewKind',
title: 'CardCellGrid',
description: 'CardCellGrid',
collsConstrs: [],
Expand Down
4 changes: 2 additions & 2 deletions stories/TreeTableFormMktp.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ const viewKinds = [
schema: 'hs:ProductCardShape',
conditions: {
'@id': 'mktp:ProductCards_in_Category_Coll_Ent0_con',
CardInCatLink: 'https://www.wildberries.ru/catalog/zdorove/ozdorovlenie?sort=popular&page=1&xsubject=594',
CardInCatLink: 'https://www.wildberries.ru/catalog/igrushki/antistress',
},
},
],
limit: 1000,
limit: 100,
},
{
'@id': 'mktp:Cards_Coll',
Expand Down

0 comments on commit eb68ef7

Please sign in to comment.