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

#2256 Add ability to display text description next to heading label #2263

Merged
merged 33 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6932f32
#2256 Add ability to display text description next to heading label
srikant-ch5 Dec 4, 2024
2666aea
Merge branch 'main' into Action-Image-Align
srikant-ch5 Dec 4, 2024
c3379c6
Merge branch 'main' into Action-Image-Align
srikant-ch5 Dec 6, 2024
54294aa
Include classname change
srikant-ch5 Dec 6, 2024
a0c3e38
Include changes in paramDef
srikant-ch5 Dec 6, 2024
0aebd18
Merge branch 'main' into Action-Image-Align
srikant-ch5 Dec 6, 2024
d97e731
Include description in Form
srikant-ch5 Dec 10, 2024
06f9714
Include description object
srikant-ch5 Dec 18, 2024
e53c03a
Merge branch 'main' into Action-Image-Align
srikant-ch5 Dec 18, 2024
c7beac5
Merge branch 'main' into Action-Image-Align
srikant-ch5 Jan 3, 2025
62cc2e9
Include renderTooltip function to show tooltip with link based on des…
srikant-ch5 Jan 6, 2025
9fc9962
Merge branch 'main' into Action-Image-Align
srikant-ch5 Jan 6, 2025
8214c5f
Merge branch 'main' into Action-Image-Align
srikant-ch5 Jan 7, 2025
a82ebe1
Change renderTootlip as per conditions
srikant-ch5 Jan 8, 2025
e532200
Merge branch 'main' into Action-Image-Align
srikant-ch5 Jan 8, 2025
cff31e2
Refactor title-editor code and include tests and include showHeadingD…
srikant-ch5 Jan 8, 2025
697784a
Update description text in Form
srikant-ch5 Jan 8, 2025
30b7f47
Fix test cases
srikant-ch5 Jan 8, 2025
be033c1
uncomment test cases
srikant-ch5 Jan 8, 2025
762748b
fix test case 2
srikant-ch5 Jan 8, 2025
cc18701
Merge branch 'main' into Action-Image-Align
srikant-ch5 Jan 13, 2025
ef729d2
Fix ui issues
srikant-ch5 Jan 13, 2025
a2b0edb
Update Help button label
srikant-ch5 Jan 13, 2025
c87918d
Merge branch 'main' into Action-Image-Align
srikant-ch5 Jan 15, 2025
51aaefd
Merge branch 'main' into Action-Image-Align
srikant-ch5 Jan 17, 2025
340e4b0
Merge branch 'main' into Action-Image-Align
matthoward366 Jan 17, 2025
25854af
Replace button with a link in title editor description
srikant-ch5 Jan 20, 2025
3ac2293
Include readonly desc with details
srikant-ch5 Jan 20, 2025
e64edb6
Merge branch 'main' into Action-Image-Align
srikant-ch5 Jan 22, 2025
2adf75e
Merge branch 'main' into Action-Image-Align
srikant-ch5 Jan 28, 2025
1347b86
Merge branch 'main' into Action-Image-Align
matthoward366 Jan 28, 2025
c376bdc
Remove span and include translated button label
srikant-ch5 Jan 29, 2025
7e45c1f
Include pointer title-editor desc help tooltip link
srikant-ch5 Jan 29, 2025
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 @@ -39,6 +39,7 @@ controller.setAppData(appData);

const helpClickHandler = sinon.spy();
const help = { data: "test-data" };
const description = "test description";

const titleChangeHandlerFunction = function(title, callbackFunction) {
// If Title is valid. No need to send anything in callbackFunction
Expand Down Expand Up @@ -143,6 +144,52 @@ describe("title-editor renders correctly", () => {
const helpButton = container.querySelector(".properties-title-editor-btn[data-id='help']");
fireEvent.click(helpButton);
});
it("test description button callback", () => {
helpClickHandler.resetHistory();
const wrapper = renderWithIntl(
<TitleEditor
store={controller.getStore()}
controller={controller}
labelEditable
help={help}
description={description}
showHeadingDesc
/>
);
const { container } = wrapper;
const helpButton = container.querySelector(".properties-title-editor-desc-btn[data-id='desc-help']");
fireEvent.click(helpButton);
});
it("test description should not be visible if description is not present", () => {
helpClickHandler.resetHistory();
const wrapper = renderWithIntl(
<TitleEditor
store={controller.getStore()}
controller={controller}
labelEditable
help={help}
showHeadingDesc
/>
);
const { container } = wrapper;
expect(container.querySelector(".properties-title-desc-icon")).to.not.exist;
});
it("test description should not be visible if showHeadingDesc is not present", () => {
helpClickHandler.resetHistory();
const wrapper = renderWithIntl(
<TitleEditor
store={controller.getStore()}
controller={controller}
labelEditable
help={help}
description={description}
/>
);
const { container } = wrapper;
expect(container.querySelector(".properties-title-desc-icon")).to.not.exist;
const helpButton = container.querySelector(".properties-title-editor-btn[data-id='help']");
fireEvent.click(helpButton);
});
it("test edit link", () => {
helpClickHandler.resetHistory();
const wrapper = renderWithIntl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ describe("Correct form should be created", () => {
}
};
let help;
let description;
let pixelWidth; // Pass in an undefined pixelWidth to simulate it missing from ParamDefs.
let conditions;
let resources;
const expectedForm = new Form("TestOp", "TestOp", true, help, "small", pixelWidth, [primaryTabs], buttons, data, conditions, resources, "./test.svg");
const expectedForm = new Form("TestOp", "TestOp", true, help, description, "small", pixelWidth, [primaryTabs], buttons, data, conditions, resources, "./test.svg");

const paramSpec = {
"current_parameters": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
"componentId": "org.apache.spark.ml.ibm.transformers.Distinct",
"label": "Form placement test",
"labelEditable": true,
"description": "Remove rows to leave only rows with distinct combinations of rows",
"editorSize": "small",
"uiItems": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
"componentId": "sort",
"label": "Form structure2 test",
"labelEditable": false,
"description": "Sorts the data",
"editorSize": "large",
"uiItems": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"summary.longTable.placeholder": "More than ten fields...",
"alerts.tab.title": "Alerts",
"title.editor.label": "edit title",
"title.editor.helpButton.label": "help",
"title.editor.helpButton.label": "Help",
"title.editor.descButton.label": "Heading additional information",
"table.summary.error": "There are {errorMsgCount} error cells. ",
"table.summary.warning": "There are {warningMsgCount} warning cells. ",
"control.summary.error": "There are {errorMsgCount} parameters with errors. ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import { connect } from "react-redux";
import Isvg from "react-inlinesvg";
import { get } from "lodash";
import classNames from "classnames";
import { Help, Edit, Close } from "@carbon/react/icons";
import { TextInput, Button, Layer } from "@carbon/react";
import { Help, Edit, Close, Information } from "@carbon/react/icons";
import { TextInput, Button, Layer, Link } from "@carbon/react";
import { Toggletip, ToggletipButton, ToggletipContent, ToggletipActions } from "@carbon/react";

import { setTitle } from "./../../actions";
import { MESSAGE_KEYS, CONDITION_MESSAGE_TYPE } from "./../../constants/constants";
import * as PropertyUtils from "./../../util/property-utils";
import ActionFactory from "../../actions/action-factory.js";


class TitleEditor extends Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -118,6 +118,7 @@ class TitleEditor extends Component {
}
const propertiesTitleEditButtonLabel = PropertyUtils.formatMessage(this.props.controller.getReactIntl(), MESSAGE_KEYS.TITLE_EDITOR_LABEL);
const helpButtonLabel = PropertyUtils.formatMessage(this.props.controller.getReactIntl(), MESSAGE_KEYS.TITLE_EDITOR_HELPBUTTON_LABEL);
const descButtonLabel = PropertyUtils.formatMessage(this.props.controller.getReactIntl(), MESSAGE_KEYS.TITLE_EDITOR_DESCBUTTON_LABEL);
const closeButtonLabel = PropertyUtils.formatMessage(this.props.controller.getReactIntl(), MESSAGE_KEYS.PROPERTIESEDIT_CLOSEBUTTON_LABEL);
const titleValidationTypes = [CONDITION_MESSAGE_TYPE.ERROR, CONDITION_MESSAGE_TYPE.WARNING];
const titleWithWarning = get(this.state.titleValidation, "type", null) === CONDITION_MESSAGE_TYPE.WARNING;
Expand All @@ -137,19 +138,65 @@ class TitleEditor extends Component {
hasIconOnly
/>);

const helpButton = this.props.help
? (<Button
kind="ghost"
className="properties-title-editor-btn help"
data-id="help"
onClick={this.helpClickHandler}
tooltipPosition="bottom"
renderIcon={Help}
size="sm"
iconDescription={helpButtonLabel}
hasIconOnly
/>)
: null;
const renderTooltip = (isDescWithLink) => {
const { description } = this.props;
// If description is present and has a link, show help button
const tooltipButton = isDescWithLink ? (
<ToggletipActions>
<Link
className="properties-title-editor-desc-btn desc-help"
onClick={this.helpClickHandler}
data-id="desc-help"
Copy link
Member

Choose a reason for hiding this comment

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

What is data-id used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

data-id is used in test case just like existing help button.
const helpButton = container.querySelector(".properties-title-editor-desc-btn[data-id='desc-help']");

>
{helpButtonLabel}
</Link>
</ToggletipActions>
) : null;

return (
<Toggletip className="properties-title-desc-tooltip" align="bottom" autoAlign>
<ToggletipButton label={descButtonLabel}>
<Information />
</ToggletipButton>
<ToggletipContent>
<p className="properties-title-editor-desc">{description}</p>
{tooltipButton}
</ToggletipContent>
</Toggletip>
);
};

const renderHelpButton = () => {
const { help } = this.props;

return help ? (
<Button
kind="ghost"
className="properties-title-editor-btn help"
data-id="help"
onClick={this.helpClickHandler}
tooltipPosition="bottom"
renderIcon={Help}
size="sm"
iconDescription={helpButtonLabel}
hasIconOnly
/>
) : null;
};

const renderHelpOrTooltipButton = () => {
const { showHeadingDesc, description, help } = this.props;

// If showHeadingDesc is true and description is present, show tooltip
if (showHeadingDesc && description) {
return renderTooltip(help);
}

// If description is not present, show help button
return renderHelpButton();
};

const helpButton = renderHelpOrTooltipButton();

const closeButton = this.props.closeHandler
? (<div className="properties-close-button">
Expand Down Expand Up @@ -195,7 +242,8 @@ class TitleEditor extends Component {
<div className={classNames(
"properties-title-editor-input",
{
"properties-title-editor-with-help": this.props.help && !this.headingEnabled && !titleValidationTypes.includes(get(this.state.titleValidation, "type")),
"properties-title-editor-with-help": (this.props.help || this.props.description) &&
!this.headingEnabled && !titleValidationTypes.includes(get(this.state.titleValidation, "type")),
"properties-title-editor-with-warning": titleWithWarning,
"properties-title-editor-with-error": titleWithErrror
}
Expand Down Expand Up @@ -239,8 +287,10 @@ TitleEditor.propTypes = {
icon: PropTypes.string,
heading: PropTypes.string,
showHeading: PropTypes.bool,
showHeadingDesc: PropTypes.bool,
rightFlyoutTabsView: PropTypes.bool,
titleInfo: PropTypes.object,
description: PropTypes.object,
title: PropTypes.string, // set by redux
setTitle: PropTypes.func // set by redux
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@
}
}
}

.properties-title-desc-tooltip {
position: absolute;
margin: $spacing-03 0 0 $spacing-03; // spacing between desc tooltip and heading label

.properties-title-editor-desc-btn {
cursor: pointer;
}
}
}

// Action buttons within a small right flyout will take up 50% width and display 2 buttons per row
Expand Down Expand Up @@ -86,6 +95,10 @@
margin-left: $spacing-02; // spacing between heading label and help button
}
}
.properties-title-desc-tooltip {
position: relative;
margin: 0 0 0 $spacing-04; // spacing between desc tooltip and heading label
}
}
.properties-title-editor-input {
width: calc(100% - #{$spacing-03}); // subtract 8px to align with Close icon when applyOnBlur is set
Expand Down Expand Up @@ -152,3 +165,11 @@
justify-content: center;
padding: 0;
}


.properties-title-editor {
.tooltip-container {
height: $spacing-05;
cursor: pointer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const MESSAGE_KEYS = {
ALERTS_TAB_TITLE: "alerts.tab.title",
TITLE_EDITOR_LABEL: "title.editor.label",
TITLE_EDITOR_HELPBUTTON_LABEL: "title.editor.helpButton.label",
TITLE_EDITOR_DESCBUTTON_LABEL: "title.editor.descButton.label",
TABLE_SUMMARY_ERROR: "table.summary.error",
TABLE_SUMMARY_WARNING: "table.summary.warning",
CONTROL_SUMMARY_ERROR: "control.summary.error",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import { Size } from "../constants/form-constants";
import { CONTAINER_TYPE } from "../constants/constants";

export default class Form {
constructor(componentId, label, labelEditable, help, editorSize, pixelWidth, uiItems, buttons, data, conditions, resources, icon, heading, title, titleUiItems) {
constructor(componentId, label, labelEditable, help, description, editorSize, pixelWidth, uiItems, buttons, data, conditions, resources, icon, heading, title, titleUiItems) {
this.componentId = componentId;
this.label = label;
this.labelEditable = labelEditable;
this.help = help;
this.description = description;
this.editorSize = editorSize;
this.pixelWidth = pixelWidth;
this.uiItems = uiItems;
Expand Down Expand Up @@ -81,6 +82,7 @@ export default class Form {
propDef.label,
propDef.labelEditable,
propDef.help,
l10nProvider.l10nResource(propDef.description),
propDef.editorSizeHint(editorSizeDefault),
propDef.pixelWidth,
[UIItem.makePrimaryTabs(tabs)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,14 @@ class PropertiesMain extends React.Component {
propertiesTitle = (<TitleEditor
labelEditable={formData.labelEditable}
help={formData.help}
description={formData.description}
controller={this.propertiesController}
helpClickHandler={this.props.callbacks.helpClickHandler}
closeHandler={applyOnBlurEnabled ? this.applyPropertiesEditing.bind(this, true) : null}
icon={formData.icon}
heading={formData.heading}
showHeading={this.props.propertiesConfig.heading}
showHeadingDesc={this.props.propertiesConfig.showHeadingDesc}
titleInfo={formData.title}
rightFlyoutTabsView={this.props.propertiesConfig.categoryView === CATEGORY_VIEW.TABS}
/>);
Expand Down Expand Up @@ -668,6 +670,7 @@ PropertiesMain.propTypes = {
conditionReturnValueHandling: PropTypes.string,
returnValueFiltering: PropTypes.array,
heading: PropTypes.bool,
showHeadingDesc: PropTypes.bool,
buttonLabels: PropTypes.shape({
primary: PropTypes.string,
secondary: PropTypes.string
Expand Down
3 changes: 3 additions & 0 deletions canvas_modules/harness/src/client/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class App extends React.Component {
trimSpaces: true,
displayAdditionalComponents: false,
heading: false,
showHeadingDesc: false,
light: true,
lightTheme: false,
showRequiredIndicator: true,
Expand Down Expand Up @@ -2073,6 +2074,7 @@ class App extends React.Component {
disableSaveOnRequiredErrors: this.state.disableSaveOnRequiredErrors,
trimSpaces: this.state.trimSpaces,
heading: this.state.heading,
showHeadingDesc: this.state.showHeadingDesc,
showRequiredIndicator: this.state.showRequiredIndicator,
showAlertsTab: this.state.showAlertsTab,
enableResize: this.state.enableResize,
Expand Down Expand Up @@ -2513,6 +2515,7 @@ class App extends React.Component {
expressionBuilder: this.state.expressionBuilder,
displayAdditionalComponents: this.state.displayAdditionalComponents,
heading: this.state.heading,
showHeadingDesc: this.state.showHeadingDesc,
light: this.state.light,
showRequiredIndicator: this.state.showRequiredIndicator,
showAlertsTab: this.state.showAlertsTab,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"trimSpaces": true,
"displayAdditionalComponents": false,
"heading": false,
"showHeadingDesc": false,
"light": true,
"showRequiredIndicator": true,
"showAlertsTab": true,
Expand Down Expand Up @@ -105,6 +106,11 @@
"default": false,
"type": "boolean"
},
{
"id": "showHeadingDesc",
"default": false,
"type": "boolean"
},
{
"id": "light",
"default": false,
Expand Down Expand Up @@ -340,6 +346,16 @@
},
"control": "toggle"
},
{
"parameter_ref": "showHeadingDesc",
"label": {
"default": "showHeadingDesc"
},
"description": {
"default": "Show panel heading description"
},
"control": "toggle"
},
{
"parameter_ref": "light",
"label": {
Expand Down Expand Up @@ -713,6 +729,7 @@
"disableSaveOnRequiredErrors",
"trimSpaces",
"heading",
"showHeadingDesc",
"showRequiredIndicator",
"showAlertsTab",
"enableResize",
Expand Down
Loading