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: Moved field descriptions into tooltip #1858

Merged
merged 6 commits into from
Feb 3, 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 @@ -37,11 +37,13 @@ describe('<ObjectArray />', () => {
expect(title).toBeTruthy();
});

it('renders a DescriptionField', async () => {
const { findByText } = renderDefault();
it('renders a DescriptionField in tooltip', async () => {
const { baseElement, findAllByRole } = renderDefault();
const [icon] = await findAllByRole('presentation');

fireEvent.mouseOver(icon);

const description = await findByText('My array description.');
expect(description).toBeTruthy();
expect(baseElement).toHaveTextContent('My array description.');
});

it('renders a StringItem for each item', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ describe('<StringArray />', () => {
expect(title).toBeTruthy();
});

it('renders a DescriptionField', async () => {
const { findByText } = renderDefault();
it('renders a DescriptionField in tooltip', async () => {
const { baseElement, findAllByRole } = renderDefault();
const [icon] = await findAllByRole('presentation');

fireEvent.mouseOver(icon);

const description = await findByText('My array description.');
expect(description).toBeTruthy();
expect(baseElement).toHaveTextContent('My array description.');
});

it('renders a StringItem for each item', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import get from 'lodash/get';
import classnames from 'classnames';

import { FormContext } from '../types';
import { WidgetLabel } from '../widgets/WidgetLabel';

import { RootField } from './RootField';

Expand Down Expand Up @@ -75,23 +76,13 @@ export function BaseField<T = any>(props: BaseFieldProps<T>): JSX.Element {
) : (
<div className={classnames({ BaseField: !displayInline }, className)} key={key} id={key.replace(/\.|#/g, '')}>
{!hideDescription && (
<div>
<h3 className="BaseFieldTitle">{getTitle()}</h3>
{descriptionOverride !== false && (descriptionOverride || description || schema.description) && (
<p className="BaseFieldDescription">
{getDescription()}
{helpLink && helpLinkText && (
<>
<br />
<br />
<a href={helpLink} target="_blank" rel="noopener noreferrer">
{helpLinkText}
</a>
</>
)}
</p>
)}
</div>
<WidgetLabel
label={getTitle()}
description={getDescription()}
helpLink={helpLink}
helpLinkText={helpLinkText}
id={key}
/>
)}
<div className={classnames({ BaseFieldInline: displayInline })}>{children}</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface BFDWidgetProps extends Partial<WidgetProps> {
hideLabel?: boolean;
transparentBorder?: boolean;
};
hideLabel?: boolean;
}

export interface SelectWidgetProps extends BFDWidgetProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SelectWidgetProps } from '../types';
import { WidgetLabel } from './WidgetLabel';

export const SelectWidget: React.FunctionComponent<SelectWidgetProps> = props => {
const { onChange, onFocus, onBlur, value, options, label, schema, id } = props;
const { onChange, onFocus, onBlur, value, options, label, schema, id, hideLabel } = props;
const { description } = schema;

const handleChange = (_, option?: IDropdownOption) => {
Expand All @@ -23,7 +23,7 @@ export const SelectWidget: React.FunctionComponent<SelectWidgetProps> = props =>

return (
<>
<WidgetLabel label={label} description={description} id={id} />
{!hideLabel && <WidgetLabel label={label} description={description} id={id} />}
<Dropdown
id={id}
onBlur={() => onBlur && onBlur(id, value)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ interface DescriptionCalloutProps {
title: string;
description?: string;
id?: string;
helpLink?: string;
helpLinkText?: string;
}

const DescriptionCallout: React.FC<DescriptionCalloutProps> = props => {
const { description, title, id } = props;
const { description, title, id, helpLink, helpLinkText } = props;

if (!description) {
return null;
Expand All @@ -27,7 +29,18 @@ const DescriptionCallout: React.FC<DescriptionCalloutProps> = props => {
onRenderContent: () => (
<div>
<h3 style={{ fontSize: '20px', margin: '0', marginBottom: '10px' }}>{title}</h3>
<p>{description}</p>
<p>
{description}
{helpLink && helpLinkText && (
<>
<br />
<br />
<a href={helpLink} target="_blank" rel="noopener noreferrer">
{helpLinkText}
</a>
</>
)}
</p>
</div>
),
}}
Expand Down Expand Up @@ -57,10 +70,12 @@ interface WidgetLabelProps {
label?: string;
description?: string;
inline?: boolean;
helpLink?: string;
helpLinkText?: string;
}

export const WidgetLabel: React.FC<WidgetLabelProps> = props => {
const { label, description, id, inline } = props;
const { label, description, id, inline, helpLink, helpLinkText } = props;

if (!label) {
return null;
Expand All @@ -79,7 +94,13 @@ export const WidgetLabel: React.FC<WidgetLabelProps> = props => {
}}
>
{label}
<DescriptionCallout description={description} title={label} id={id} />
<DescriptionCallout
description={description}
title={label}
id={id}
helpLink={helpLink}
helpLinkText={helpLinkText}
/>
</Label>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ export const uiSchema: { [key in SDKTypes]?: UiSchema } = {
},
},
},
entities: {
items: {
'ui:options': {
hideLabel: true,
hideDescription: true,
},
},
},
},
'ui:order': ['recognizer', 'triggers', '*'],
'ui:hidden': ['triggers', 'autoEndDialog', 'generator', ...globalHidden],
Expand Down