Skip to content

Commit

Permalink
Merge pull request #20 from agentlab/issue-16-read-only-form
Browse files Browse the repository at this point in the history
GH-16 readOnly property for Form Layout
  • Loading branch information
amivanoff authored Sep 29, 2021
2 parents d79b4c0 + 920127f commit eacb266
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/util/ContextToProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ 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 });

const data = collData.length !== 0 ? collData[0] : {};
const controlProps = mapStateToControlProps({ ...props, data: data || {} });
const onValidate = (data: any) => {
if (viewKindElement.options && Array.isArray(viewKindElement.options.validation)) {
const validation = viewKindElement.options.validation;
Expand Down Expand Up @@ -589,7 +588,7 @@ export const withStoreToSaveDialogProps = (Component: React.FC<SaveDialog>): Rea
});

const mapStateToControlProps = ({ id, schema, viewKindElement, viewKind, data }: ToControlProps & { data: any }) => {
const pathSegments = id.split('/');
const pathSegments = viewKindElement?.resultsScope?.split('/') || [];
const path = pathSegments.join('.properties.');
const visible = checkProperty('visible', path, viewKindElement, viewKind);
const editable =
Expand All @@ -600,7 +599,7 @@ const mapStateToControlProps = ({ id, schema, viewKindElement, viewKind, data }:
const labelDesc = createLabelDescriptionFrom(viewKindElement as any, schema);
const label = labelDesc.show ? (labelDesc.text as string) : '';
const key = pathSegments[1];
const enabled = data && (editable ?? true);
const enabled = data[key] && (editable ?? true);
return {
description,
label,
Expand Down
2 changes: 1 addition & 1 deletion stories/Form.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ EditableEmptyObject.args = {

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

Expand Down

0 comments on commit eacb266

Please sign in to comment.