Skip to content

Commit

Permalink
feat: add custom property to Action
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtek-krysiak committed Oct 17, 2020
1 parent ed190af commit 9d9f0cc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/backend/actions/action.interface.ts
Expand Up @@ -624,12 +624,21 @@ export interface Action <T extends ActionResponse> {

/**
* Defines the variant of the action. based on that it will receive given color.
* @new in version v3.3
*/
variant?: VariantType;

/**
* Action can be nested. If you give here another action name - it will be nested under it.
* If parent action doesn't exists - it will be nested under name in the parent.
* @deprecated in version v3.3
*/
parent?: string;

/**
* Any custom properties you want to pass down to {@link ActionJSON}. They have to
* be stringified.
* @new in version v3.3
*/
custom?: Record<string, any>;
}
5 changes: 5 additions & 0 deletions src/backend/decorators/action/action-decorator.ts
Expand Up @@ -318,6 +318,10 @@ class ActionDecorator {
return this.action.parent || null
}

custom(): Record<string, any> {
return this.action.custom || {}
}

hasHandler(): boolean {
return !!this.action.handler
}
Expand Down Expand Up @@ -347,6 +351,7 @@ class ActionDecorator {
variant: this.variant(),
parent: this.parent(),
hasHandler: this.hasHandler(),
custom: this.custom(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/frontend/components/spec/action-json.factory.ts
Expand Up @@ -14,4 +14,5 @@ factory.define<ActionJSON>('ActionJSON', Object, {
variant: 'default',
parent: null,
hasHandler: true,
custom: {},
})
6 changes: 6 additions & 0 deletions src/frontend/interfaces/action/action-json.interface.ts
Expand Up @@ -75,4 +75,10 @@ export interface ActionJSON {
* @new in version 3.3
*/
hasHandler: boolean;

/**
* Any custom options passed from the {@link Action} configuration.
* @new in version 3.3
*/
custom: Record<string, any>;
}

0 comments on commit 9d9f0cc

Please sign in to comment.