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

#1604 Added property config to hide Alerts tab and message count on tab names #1605

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -18,6 +18,7 @@ import propertyUtils from "../../_utils_/property-utils";
import { expect } from "chai";
import numberfieldParamDef from "../../test_resources/paramDefs/numberfield_paramDef.json";
import structuretableParamDef from "../../test_resources/paramDefs/structuretable_paramDef.json";
import actionParamDef from "../../test_resources/paramDefs/action_paramDef.json";
import tableUtils from "./../../_utils_/table-utils";

describe("condition messages should add alerts tab", () => {
Expand Down Expand Up @@ -275,3 +276,55 @@ describe("condition messages should add alerts tab for tables", () => {
});

});

describe("Show/hide Alerts tab based on showAlertsTab boolean in propertiesConfig", () => {

it("Hide Alerts tab when showAlertsTab=false in propertiesConfig", () => {
// No "Alerts" tab. Also no messageCount next to Summary Panel Actions.
const categoryLabels = ["Actions", "Conditions", "Summary Panel Actions"];

const renderedObject = propertyUtils.flyoutEditorForm(actionParamDef, { showAlertsTab: false });
const wrapper = renderedObject.wrapper;

const allCategories = wrapper.find("div.properties-category-container");
expect(allCategories).to.have.length(3);

allCategories.forEach((category, idx) => {
const categoryTitle = category.find("button.properties-category-title").text();
expect(categoryTitle).to.equal(categoryLabels[idx]);
});
});

it("Show Alerts tab when showAlertsTab=true in propertiesConfig", () => {
// Shows "Alerts" tab and messageCount next to Summary Panel Actions.
const categoryLabels = ["Alerts (1)", "Actions", "Conditions", "Summary Panel Actions (1)"];

const renderedObject = propertyUtils.flyoutEditorForm(actionParamDef, { showAlertsTab: true });
const wrapper = renderedObject.wrapper;

const allCategories = wrapper.find("div.properties-category-container");
expect(allCategories).to.have.length(4);

allCategories.forEach((category, idx) => {
const categoryTitle = category.find("button.properties-category-title").text();
expect(categoryTitle).to.equal(categoryLabels[idx]);
});
});

it("Show Alerts tab when showAlertsTab is not set in propertiesConfig", () => {
// Shows "Alerts" tab and messageCount next to Summary Panel Actions.
const categoryLabels = ["Alerts (1)", "Actions", "Conditions", "Summary Panel Actions (1)"];

const renderedObject = propertyUtils.flyoutEditorForm(actionParamDef);
const wrapper = renderedObject.wrapper;

const allCategories = wrapper.find("div.properties-category-container");
expect(allCategories).to.have.length(4);

allCategories.forEach((category, idx) => {
const categoryTitle = category.find("button.properties-category-title").text();
expect(categoryTitle).to.equal(categoryLabels[idx]);
});
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ CommonProperties.propTypes = {
maxLengthForSingleLineControls: PropTypes.number,
convertValueDataTypes: PropTypes.bool,
showRequiredIndicator: PropTypes.bool,
showAlertsTab: PropTypes.bool,
locale: PropTypes.string
}),
callbacks: PropTypes.shape({
Expand Down Expand Up @@ -290,6 +291,7 @@ CommonProperties.defaultProps = {
maxLengthForSingleLineControls: 128,
convertValueDataTypes: false,
showRequiredIndicator: true,
showAlertsTab: true,
locale: DEFAULT_LOCALE
},
callbacks: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class EditorForm extends React.Component {
}

_getMessageCountForCategory(tab) {
if (!this.props.showAlertsTab) {
return null;
}
if (tab.group === ALERT_TAB_GROUP) {
return " (" + this.messages.length + ")";
}
Expand Down Expand Up @@ -609,7 +612,7 @@ class EditorForm extends React.Component {

render() {
let uiItems = this.props.controller.getUiItems();
if (!isEmpty(this.messages) && uiItems[0].itemType === "primaryTabs" && uiItems[0].tabs && uiItems[0].tabs.length > 1) {
if (this.props.showAlertsTab && !isEmpty(this.messages) && uiItems[0].itemType === "primaryTabs" && uiItems[0].tabs && uiItems[0].tabs.length > 1) {
// create a new copy for uiItems object so that alerts are not added multiple times
uiItems = cloneDeep(uiItems);
uiItems[0].tabs.unshift(this.genAlertsTab(this.messages)); // add alerts tab to the beginning of the tabs array
Expand Down Expand Up @@ -668,6 +671,7 @@ EditorForm.propTypes = {
customPanels: PropTypes.array,
rightFlyout: PropTypes.bool,
categoryView: PropTypes.oneOf([CATEGORY_VIEW.ACCORDIONS, CATEGORY_VIEW.TABS]),
showAlertsTab: PropTypes.bool,
activeTab: PropTypes.string, // set by redux
setActiveTab: PropTypes.func, // set by redux
messages: PropTypes.array // set by redux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ class PropertiesMain extends React.Component {
customPanels={this.props.customPanels}
rightFlyout={this.props.propertiesConfig.rightFlyout}
categoryView={this.props.propertiesConfig.categoryView}
showAlertsTab={(typeof this.props.propertiesConfig.showAlertsTab !== "undefined") ? this.props.propertiesConfig.showAlertsTab : true}
Copy link
Member

Choose a reason for hiding this comment

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

Instead of doing this check couldn't we do

showAlertsTab={ this.props.propertiesConfig.showAlertsTab !== false }

The in all cases besides false this would be true.

/>);

if (this.props.propertiesConfig.containerType === "Editing") {
Expand Down Expand Up @@ -630,6 +631,7 @@ PropertiesMain.propTypes = {
maxLengthForSingleLineControls: PropTypes.number,
convertValueDataTypes: PropTypes.bool,
showRequiredIndicator: PropTypes.bool,
showAlertsTab: PropTypes.bool,
locale: PropTypes.string
}),
callbacks: PropTypes.shape({
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 @@ -257,6 +257,7 @@ class App extends React.Component {
heading: false,
light: true,
showRequiredIndicator: true,
showAlertsTab: true,
enableResize: true,
initialEditorSize: "small",
conditionHiddenPropertyHandling: "null",
Expand Down Expand Up @@ -1997,6 +1998,7 @@ class App extends React.Component {
trimSpaces: this.state.trimSpaces,
heading: this.state.heading,
showRequiredIndicator: this.state.showRequiredIndicator,
showAlertsTab: this.state.showAlertsTab,
enableResize: this.state.enableResize,
conditionHiddenPropertyHandling: this.state.conditionHiddenPropertyHandling,
conditionDisabledPropertyHandling: this.state.conditionDisabledPropertyHandling,
Expand Down Expand Up @@ -2644,6 +2646,7 @@ class App extends React.Component {
heading: this.state.heading,
light: this.state.light,
showRequiredIndicator: this.state.showRequiredIndicator,
showAlertsTab: this.state.showAlertsTab,
enableResize: this.state.enableResize,
returnValueFiltering: this.state.returnValueFiltering,
initialEditorSize: this.state.initialEditorSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export default class FlowsProperties extends React.Component {
trimSpaces: true,
heading: true,
showRequiredIndicator: true,
showAlertsTab: true,
returnValueFiltering: [],
maxLengthForMultiLineControls: 1024,
maxLengthForSingleLineControls: 128,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"heading": false,
"light": true,
"showRequiredIndicator": true,
"showAlertsTab": true,
"enableResize": true,
"initialEditorSize": "small",
"conditionHiddenPropertyHandling": "null",
Expand Down Expand Up @@ -112,6 +113,11 @@
"default": true,
"type": "boolean"
},
{
"id": "showAlertsTab",
"default": true,
"type": "boolean"
},
{
"id": "enableResize",
"default": true,
Expand Down Expand Up @@ -343,6 +349,16 @@
},
"control": "toggle"
},
{
"parameter_ref": "showAlertsTab",
"label": {
"default": "showAlertsTab"
},
"description": {
"default": "Show 'Alerts' tab"
},
"control": "toggle"
},
{
"parameter_ref": "enableResize",
"label": {
Expand Down Expand Up @@ -650,6 +666,7 @@
"trimSpaces",
"heading",
"showRequiredIndicator",
"showAlertsTab",
"enableResize",
"conditionHiddenPropertyHandling",
"conditionDisabledPropertyHandling",
Expand Down Expand Up @@ -803,6 +820,8 @@
"tableButtonEnabled.toggle.on.label": "enable",
"tableButtonEnabled.toggle.off.label": "disable",
"showRequiredIndicator.toggle.on.label": "required",
"showRequiredIndicator.toggle.off.label": "optional"
"showRequiredIndicator.toggle.off.label": "optional",
"showAlertsTab.toggle.on.label": "show",
"showAlertsTab.toggle.off.label": "hide"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default class SidePanelProperties extends React.Component {
"heading": this.props.propertiesConfig.heading,
"light": this.props.propertiesConfig.light,
"showRequiredIndicator": this.props.propertiesConfig.showRequiredIndicator,
"showAlertsTab": this.props.propertiesConfig.showAlertsTab,
"enableResize": this.props.propertiesConfig.enableResize,
"initialEditorSize": this.props.propertiesConfig.initialEditorSize,
"conditionHiddenPropertyHandling": this.props.propertiesConfig.conditionHiddenPropertyHandling,
Expand Down Expand Up @@ -343,6 +344,7 @@ SidePanelProperties.propTypes = {
heading: PropTypes.bool,
light: PropTypes.bool,
showRequiredIndicator: PropTypes.bool,
showAlertsTab: PropTypes.bool,
enableResize: PropTypes.bool,
returnValueFiltering: PropTypes.string,
initialEditorSize: PropTypes.string,
Expand Down