From 098cabe0e08d1f040fb589d141c82a56dbdbc70e Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Wed, 4 Aug 2021 11:36:26 +0300 Subject: [PATCH] Add defaultAction prop to AddButton items Signed-off-by: Alex Andreev --- src/common/catalog/catalog-entity.ts | 1 + src/renderer/components/+catalog/catalog-add-button.tsx | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/common/catalog/catalog-entity.ts b/src/common/catalog/catalog-entity.ts index e74fd238e3..5647f5b0d3 100644 --- a/src/common/catalog/catalog-entity.ts +++ b/src/common/catalog/catalog-entity.ts @@ -124,6 +124,7 @@ export interface CatalogEntityContextMenu { export interface CatalogEntityAddMenu extends CatalogEntityContextMenu { icon: string | React.ComponentType; + defaultAction?: boolean; } export interface CatalogEntitySettingsMenu { diff --git a/src/renderer/components/+catalog/catalog-add-button.tsx b/src/renderer/components/+catalog/catalog-add-button.tsx index 636b03b2f7..7282c53f82 100644 --- a/src/renderer/components/+catalog/catalog-add-button.tsx +++ b/src/renderer/components/+catalog/catalog-add-button.tsx @@ -73,9 +73,10 @@ export class CatalogAddButton extends React.Component { @boundMethod onButtonClick() { - if (this.menuItems.length == 1) { - this.menuItems[0].onClick(); - } + const defaultAction = this.menuItems.find(item => item.defaultAction)?.onClick; + const clickAction = defaultAction || this.menuItems.length == 1 ? this.menuItems[0].onClick : null; + + clickAction?.(); } render() {