Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/lib/kit/components/Inputs/CardOneOf/CardOneOf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {Row} from '../../Layouts';
import {RemoveButton} from '../../RemoveButton';

export const CardOneOf: ObjectIndependentInput = (props) => {
const {input, meta, spec, name} = props;
const {input, meta, spec, name, Layout} = props;

const [open, setOpen] = React.useState(true);

Expand All @@ -27,14 +27,19 @@ export const CardOneOf: ObjectIndependentInput = (props) => {
onTogglerChange: onOpen,
});

const toggler = React.useMemo(
() => (
<Row {...props} name="__stub-name">
{togglerInput}
</Row>
),
[togglerInput, props],
);
const toggler = React.useMemo(() => {
const togglerProps = {
...props,
name: '__stub-name',
children: togglerInput,
} as const;

if (Layout) {
return <Layout {...togglerProps} />;
}

return <Row {...togglerProps} />;
}, [togglerInput, props, Layout]);

const actions = React.useMemo(() => {
if (isArrayItem(name)) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ test.describe('Card OneOf', () => {

await expectScreenshot();
});

test('column layout', async ({mount, expectScreenshot}) => {
const specWithColumnLayout = {
...CARD_ONEOF.default,
viewSpec: {
...CARD_ONEOF.default.viewSpec,
layout: 'column',
},
} as const;

await mount(<DynamicForm spec={specWithColumnLayout} />);

await expectScreenshot();
});
});

test.describe('Card OneOf view', () => {
Expand All @@ -50,4 +64,18 @@ test.describe('Card OneOf view', () => {

await expectScreenshot();
});

test('column layout', async ({mount, expectScreenshot}) => {
const specWithColumnLayout = {
...CARD_ONEOF.default,
viewSpec: {
...CARD_ONEOF.default.viewSpec,
layout: 'column',
},
} as const;

await mount(<DynamicView spec={specWithColumnLayout} value={VALUE.string} />);

await expectScreenshot();
});
});
26 changes: 16 additions & 10 deletions src/lib/kit/components/Views/CardOneOfView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import React from 'react';
import isObjectLike from 'lodash/isObjectLike';

import {Card, ViewRow} from '../';
import {ObjectIndependentView, StringSpec, ViewController} from '../../../core';
import {ObjectIndependentView, ViewController} from '../../../core';

export const CardOneOfView: ObjectIndependentView = (props) => {
const {value = {}, spec, name} = props;
const {value = {}, spec, name, Layout} = props;

const [open, setOpen] = React.useState(true);

Expand All @@ -27,14 +27,20 @@ export const CardOneOfView: ObjectIndependentView = (props) => {
);
}, [valueKey, spec.description, specProperties]);

const title = React.useMemo(
() => (
<ViewRow spec={spec as unknown as StringSpec} value={valueName} name={name}>
<>{valueName}</>
</ViewRow>
),
[spec, name, valueName],
);
const title = React.useMemo(() => {
const titleProps = {
spec: spec,
value: valueName as any,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like

<Layout {...props} value={valueName as any}>

name: name,
children: <>{valueName}</>,
} as const;

if (Layout) {
return <Layout {...titleProps} />;
}

return <ViewRow {...titleProps} />;
}, [spec, name, valueName, Layout]);

if (!value || !Object.keys(value).length) {
return null;
Expand Down
Loading