Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const simpleActionSpec: ActionItemInsertSpec = {
itemType: ToolbarItemType.ActionButton,
itemId: "simple-test-action-tool",
execute: (): void => {
// tslint:disable-next-line: no-console
console.log("Got Here!");
},
icon: "icon-developer",
label: "simple-test-action-tool",
};
const childActionSpec: ActionItemInsertSpec = {
itemType: ToolbarItemType.ActionButton,
itemId: "child-test-action-tool",
condition: {
type: ConditionalDisplayType.Visibility,
testFunc: (): boolean => SampleAppIModelApp.getTestProperty() !== "HIDE",
syncEventIds: [SampleAppUiActionId.setTestProperty],
},
execute: (): void => {
// tslint:disable-next-line: no-console
console.log("Got Here!");
},
icon: "icon-developer",
label: "child-test-action-tool",
};
const nestedActionSpec: ActionItemInsertSpec = {
itemType: ToolbarItemType.ActionButton,
parentToolGroupId: "tool-formatting-setting",
itemId: "nested-test-action-tool",
execute: (): void => {
});
itemDef = new GroupItemDef({
groupId: groupSpec.itemId,
iconSpec: groupSpec.icon,
label: groupSpec.label,
badgeType: groupSpec.badge,
items: childItems,
});
}
// If conditional display options are defined set up item def with necessary stateFunc and stateSyncIds
// istanbul ignore else
if (itemDef) {
// istanbul ignore else
if (spec.condition && spec.condition.testFunc && spec.condition.syncEventIds.length > 0) {
if (spec.condition.type === ConditionalDisplayType.Visibility) {
itemDef.stateFunc = (state: Readonly): BaseItemState => {
return spec.condition!.testFunc() ? { ...state, isVisible: true } : { ...state, isVisible: false };
};
} else {
itemDef.stateFunc = (state: Readonly): BaseItemState => {
return spec.condition!.testFunc() ? { ...state, isEnabled: true } : { ...state, isEnabled: false };
};
}
itemDef.stateSyncIds = spec.condition.syncEventIds;
}
}
return itemDef;
}