Skip to content

Commit df03f51

Browse files
authored
added "rightIcon" property to the JSON and ability to select an icon on the editor (#19)
* feat: custom-component auto expanding of menus & actions * refactor: custom-component-revert revert configuration * test: custom-component removed logging * fix: custom-component added 'rightIcon' property to the json & functionality to edit it * test: custom-component removing log function * doc: custom-component adding some documentation points * refactor: custom-component removing unnecessary code
1 parent 3e736a8 commit df03f51

File tree

5 files changed

+1295
-2
lines changed

5 files changed

+1295
-2
lines changed

src/x-759224-menu-builder-uic/components/menu-item.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ import "@servicenow/now-collapse";
66
import "@servicenow/now-dropdown";
77
import "@servicenow/now-input";
88
import "./menu-editor";
9+
import iconlist from "../icons";
910

1011
// File description: This is where to configure all the details about a menu item, such as its name, link, or delete
1112

1213
const view = (
1314
{
14-
properties: { id, choice, label, type, page, sysId, href, expandParent },
15+
properties: { id, choice, label, type, page, sysId, href, expandParent, rightIcon },
1516
labelInput,
1617
typeInput,
1718
pageInput,
1819
sysIdInput,
1920
hrefInput,
2021
editMode,
22+
iconInput
2123
},
2224
{ dispatch }
2325
) => {
@@ -31,6 +33,7 @@ const view = (
3133
const pageValue = pageInput || page;
3234
const sysIdValue = sysIdInput || sysId;
3335
const hrefValue = hrefInput || href;
36+
const iconValue = iconInput || rightIcon;
3437

3538
// This is constructing the JSON output that the chrome_menu UX Page Property expects for this specific menu item
3639

@@ -54,6 +57,11 @@ const view = (
5457
},
5558
};
5659

60+
// adding rightIcon property to JSON
61+
if(iconValue){
62+
actionJSON.value.rightIcon = iconValue
63+
}
64+
5765
if (typeValue) {
5866
actionJSON.value.type = typeValue;
5967
actionJSON.value.value = typeValue === "route" ? routeJSON : externalJSON;
@@ -88,6 +96,32 @@ const view = (
8896
name="labelInput"
8997
readonly={!editMode}
9098
></now-input>
99+
{
100+
iconValue && <now-button
101+
variant="primary"
102+
size="md"
103+
icon={iconValue}
104+
></now-button>
105+
}
106+
<now-dropdown
107+
// mapping iconlist for required data in now-dropdown
108+
// adding no-icon as a no selection
109+
items={[{ id: null, label: "no-icon" }, ...iconlist.map(e => ({ id: e, label: e }))]}
110+
selectedItems={[iconValue]}
111+
name="iconInput"
112+
select="single"
113+
placeholder=""
114+
icon=""
115+
variant="secondary"
116+
size="md"
117+
bare={true}
118+
tooltip-content="Select right icon"
119+
panel-fit-props={{}}
120+
show-padding={true}
121+
config-aria={{}}
122+
disabled={!editMode}
123+
search="true"
124+
></now-dropdown>
91125
<now-dropdown
92126
items={[
93127
{ id: "external", label: "External Link" },
@@ -203,6 +237,9 @@ createCustomElement("menu-item", {
203237
},
204238
expandParent: {
205239
default: undefined
240+
},
241+
rightIcon: {
242+
default: null
206243
}
207244
},
208245
// Keeps track of any changes made during editing
@@ -212,6 +249,7 @@ createCustomElement("menu-item", {
212249
pageInput: undefined,
213250
sysIdInput: undefined,
214251
hrefInput: undefined,
252+
iconInput: undefined,
215253
editMode: false,
216254
},
217255
actionHandlers: {
@@ -229,6 +267,7 @@ createCustomElement("menu-item", {
229267
updateState({ typeInput: payload.item.id });
230268
break;
231269
default:
270+
updateState({ iconInput: payload.item.id }); // action on icon selection
232271
}
233272
},
234273
// Text input field has changed (someone typed in the field or cleared value for example)

src/x-759224-menu-builder-uic/components/menu-tree.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import "./menu-item";
99

1010

1111
const view = ({ properties: { tree }, expanded }, { updateState }) => {
12-
const { id, children, parent, choice, label, type, page, sys_id, href } =
12+
const { id, children, parent, choice, label, type, page, sys_id, href, rightIcon } =
1313
tree;
1414

1515
const hasChildren = children && children.length > 0;
@@ -40,6 +40,7 @@ const view = ({ properties: { tree }, expanded }, { updateState }) => {
4040
page={page}
4141
sysId={sys_id}
4242
href={href}
43+
rightIcon={rightIcon}
4344
className="menu-item"
4445
expandParent={EXPAND_PARENT}
4546
></menu-item>

0 commit comments

Comments
 (0)