import type UI5Element from 'sap/ui/core/Element'; import type { SimpleQuickAction } from '@sap-ux-private/control-property-editor-common'; import { SIMPLE_QUICK_ACTION_KIND } from '@sap-ux-private/control-property-editor-common'; import { getRelevantControlFromActivePage } from '../../cpe/quick-actions/utils.js'; import type { QuickActionContext } from '../../cpe/quick-actions/quick-action-definition.js'; import type { EnablementValidator } from './enablement-validator.js'; import { QuickActionDefinitionBase } from './quick-action-base.js'; /** * Base class for all simple quick actions. */ export abstract class SimpleQuickActionDefinitionBase< T extends UI5Element = UI5Element > extends QuickActionDefinitionBase { public get isApplicable(): boolean { return this.control !== undefined; } protected control: T | undefined; constructor( public readonly type: string, protected readonly controlTypes: string[], protected readonly defaultTextKey: string, protected readonly context: QuickActionContext, protected readonly enablementValidators: EnablementValidator[] = [] ) { super(type, SIMPLE_QUICK_ACTION_KIND, defaultTextKey, context, enablementValidators); } initialize(): Promise { this.control = getRelevantControlFromActivePage( this.context.controlIndex, this.context.view, this.controlTypes )[0]; return Promise.resolve(); } getActionObject(): SimpleQuickAction { return { kind: SIMPLE_QUICK_ACTION_KIND, id: this.id, enabled: !this.isDisabled, tooltip: this.tooltip, title: this.context.resourceBundle.getText(this.textKey) }; } }