Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show correct content in ChoiceInput (fixes #1930) #1931

Merged
merged 3 commits into from
Feb 4, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,67 @@ import { FormCard } from '../templates/FormCard';
import { NodeProps } from '../nodeProps';
import { getUserAnswersTitle } from '../utils';

export const ChoiceInputChoices = ({ choices }) => {
if (!Array.isArray(choices)) {
return null;
}

return (
<div data-testid="ChoiceInput" css={{ padding: '0 0 8px 45px' }}>
{choices.map(({ value }, index) => {
if (index < 3) {
return (
<div
key={index}
role="choice"
css={{
height: ChoiceInputSize.height,
width: ChoiceInputSize.width,
marginTop: ChoiceInputMarginTop,
paddingLeft: '7px',
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden',
fontFamily: 'Segoe UI',
fontSize: '12px',
lineHeight: '19px',
border: '1px solid #B3B0AD',
boxSizing: 'border-box',
borderRadius: '2px',
}}
title={typeof value === 'string' ? value : ''}
>
{value}
</div>
);
}
})}
{Array.isArray(choices) && choices.length > 3 ? (
<div
data-testid="hasMore"
css={{
height: ChoiceInputSize.height,
width: ChoiceInputSize.width,
marginTop: ChoiceInputMarginTop,
textAlign: 'center',
fontFamily: 'Segoe UI',
fontSize: '12px',
lineHeight: '19px',
boxSizing: 'border-box',
}}
>
{`${choices.length - 3} more`}
</div>
) : null}
</div>
);
};

export const ChoiceInput: FC<NodeProps> = ({ id, data, onEvent }): JSX.Element => {
const boundary = measureJsonBoundary(data);
const { choices } = data;
let children: any = null;
const children = <ChoiceInputChoices choices={choices} />;

if (Array.isArray(choices)) {
children = (
<div data-testid="ChoiceInput" css={{ padding: '0 0 8px 45px' }}>
{choices.map(({ value }, index) => {
if (index < 3) {
return (
<div
key={index}
role="choice"
css={{
height: ChoiceInputSize.height,
width: ChoiceInputSize.width,
marginTop: ChoiceInputMarginTop,
paddingLeft: '7px',
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden',
fontFamily: 'Segoe UI',
fontSize: '12px',
lineHeight: '19px',
border: '1px solid #B3B0AD',
boxSizing: 'border-box',
borderRadius: '2px',
}}
title={typeof value === 'string' ? value : ''}
>
{value}
</div>
);
}
})}
{Array.isArray(choices) && choices.length > 3 ? (
<div
data-testid="hasMore"
css={{
height: ChoiceInputSize.height,
width: ChoiceInputSize.width,
marginTop: ChoiceInputMarginTop,
textAlign: 'center',
fontFamily: 'Segoe UI',
fontSize: '12px',
lineHeight: '19px',
boxSizing: 'border-box',
}}
>
{`${choices.length - 3} more`}
</div>
) : null}
</div>
);
}
return (
<FormCard
nodeColors={NodeColors[DialogGroup.INPUT]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function measureSwitchConditionBoundary(json): Boundary {
);
}

function measureChoiceInputDetailBoundary(data): Boundary {
export function measureChoiceInputDetailBoundary(data): Boundary {
const width = InitNodeSize.width;
const height =
InitNodeSize.height +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { SwitchConditionWidget } from '../widgets/SwitchConditionWidget';
import { ForeachWidget } from '../widgets/ForeachWidget';
import { ElementIcon } from '../utils/obiPropertyResolver';
import { ObiColors } from '../constants/ElementColors';
import { ChoiceInputChoices } from '../components/nodes';
import { measureChoiceInputDetailBoundary } from '../layouters/measureJsonBoundary';

import { UISchema, UIWidget } from './uischema.types';

Expand All @@ -38,6 +40,8 @@ const BaseInputSchema: UIWidget = {
icon: ElementIcon.User,
menu: 'none',
content: data => data.property || '<property>',
children: data => (data.$type === SDKTypes.ChoiceInput ? <ChoiceInputChoices choices={data.choices} /> : null),
size: data => measureChoiceInputDetailBoundary(data),
colors: {
theme: ObiColors.LightBlue,
icon: ObiColors.AzureBlue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export interface ActionCardProps extends WidgetContainerProps {
icon: string;
content: string | number | JSX.Element;
menu?: JSX.Element | string;
children?: JSX.Element;
size?: {
width: number;

height: number;
};
colors?: {
theme: string;
icon: string;
Expand All @@ -35,6 +41,8 @@ export const ActionCard: WidgetComponent<ActionCardProps> = ({
icon,
menu,
content,
children,
size,
colors = DefaultCardColor,
}) => {
const header = disableSDKTitle ? title : generateSDKTitle(data, title);
Expand All @@ -46,6 +54,9 @@ export const ActionCard: WidgetComponent<ActionCardProps> = ({
icon={icon}
label={content}
nodeColors={nodeColors}
/>
styles={{ ...size }}
>
{children}
</FormCard>
);
};