Skip to content

Commit

Permalink
NEXT-37264 - add changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsKemper committed Jul 25, 2024
1 parent 1ea91f7 commit f6064a5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: refactor & convert flowBuilderService to typescript
issue: NEXT-37264
author: Lars Kemper
author_email: [email protected]
author_github: @LarsKemper
---
# Administration

### `flow-builder.service.ts` Implementation Update

* Changed `flowBuilderService` to TypeScript and renamed file to `flow-builder.service.ts` located at `src/Administration/Resources/app/administration/src/module/sw-flow/service/flow-builder.service.ts`.
* Changed `flowBuilderService` function into a class `FlowBuilderService`.
* Changed all functions to class methods and applied type annotations.

### Additional Methods Added to `FlowBuilderService`

* Added `isKeyOfActionName()`
* Checks if the given key is a valid action name.
* Added `isKeyOfActionLabel()`
* Checks if the given key is a valid action label.
* Added `isKeyOfActionDescription()`
* Checks if the given key is a valid action description.
* Added `isKeyOfEntityIcon()`
* Checks if the given key is a valid entity icon.
* Added `configValuesToString()`
* Converts config values of an app action to a string in a type-safe manner.

### `flowBuilderService` Action Description Enhancement

* Added `$descriptionCallbacks`, a registry object for flow action description callback functions.
* Added `addDescriptionCallbacks()` method to register action description functions.
* Added `getDescriptionCallbacks()` method to retrieve all registered action description functions.
* Changed `getActionDescriptions()` method to execute registered action description callback functions, if available.
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @package services-settings
*/

import FlowBuilderService from 'src/module/sw-flow/service/flow-builder.service';
import { ACTION } from 'src/module/sw-flow/constant/flow.constant';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ type SequenceConfigValues = {
[key: string]: Primitive | Primitive[] | { [key: string]: Primitive | Primitive[] }
};

type AppAction = {
name: string,
label: string,
swIcon: string,
requirements: string[],
type AppAction = Entity<'app_flow_action'> & {
config: Array<{
name: string,
type: string,
Expand Down Expand Up @@ -65,18 +61,8 @@ type ActionTranslator = {
getInlineSnippet(value: { [key: string]: string }): string,
}

type ActionSequence = {
id: string,
actionName: string,
apiAlias: string,
appFlowActionId?: string,
children: Node[],
flowId: string,
group: string,
icon: string,
parentId: string,
value: string | number,
config: {
type ActionSequence = Entity<'flow_sequence'> & {
config: SequenceConfigValues & {
value?: boolean,
entity?: string,
active?: boolean,
Expand Down Expand Up @@ -104,7 +90,11 @@ type ActionSequence = {
},
}

type ActionContext = {
/**
* @private
* @package services-settings
*/
export type ActionContext = {
data: ActionData,
sequence: ActionSequence,
translator: ActionTranslator
Expand Down Expand Up @@ -353,7 +343,7 @@ export default class FlowBuilderService {
}

public getAppFlowActionDescription(context: ActionContext) {
const { config } = context.sequence;
const { sequence: { config } } = context;

const cloneConfig = { ...config } as SequenceConfigValues;
let descriptions = '';
Expand Down Expand Up @@ -383,8 +373,7 @@ export default class FlowBuilderService {
fieldName: string,
val: SequenceConfigValues[keyof SequenceConfigValues],
) {
const { appActions } = context.data;
const { actionName } = context.sequence;
const { data: { appActions }, sequence: { actionName } } = context;

const value: string = this.configValuesToString(val);
const selectedAppAction = appActions.find(item => item.name === actionName);
Expand Down Expand Up @@ -424,8 +413,8 @@ export default class FlowBuilderService {
}

public convertLabelPreview(context: ActionContext, fieldName: string) {
const { appActions } = context.data;
const { actionName } = context.sequence;
const { data: { appActions }, sequence: { actionName } } = context;

const selectedAppAction = appActions.find(item => item.name === actionName);

if (selectedAppAction === undefined) {
Expand Down Expand Up @@ -470,9 +459,9 @@ export default class FlowBuilderService {
}

public getCustomerStatusDescription(context: ActionContext) {
const { sequence, translator } = context;
const { sequence: { config }, translator } = context;

return sequence.config.active
return config.active
? translator.$tc('sw-flow.modals.customerStatus.active')
: translator.$tc('sw-flow.modals.customerStatus.inactive');
}
Expand Down Expand Up @@ -500,9 +489,9 @@ export default class FlowBuilderService {
}

public getCustomerGroupDescription(context: ActionContext) {
const { data, sequence } = context;
const { data, sequence: { config } } = context;

const customerGroup = data.customerGroups.find(item => item.id === sequence.config.customerGroupId);
const customerGroup = data.customerGroups.find(item => item.id === config.customerGroupId);
return customerGroup?.translated?.name;
}

Expand Down Expand Up @@ -606,9 +595,9 @@ export default class FlowBuilderService {
}

public getMailSendDescription(context: ActionContext) {
const { data, sequence, translator } = context;
const { data, sequence: { config }, translator } = context;

const mailTemplateData = data.mailTemplates.find(item => item.id === sequence.config.mailTemplateId);
const mailTemplateData = data.mailTemplates.find(item => item.id === config.mailTemplateId);

let mailSendDescription = translator.$tc('sw-flow.actions.labelTemplate', 0, {
template: mailTemplateData?.mailTemplateType?.name,
Expand All @@ -631,9 +620,9 @@ export default class FlowBuilderService {
}

public getDownloadAccessDescription(context: ActionContext) {
const { sequence, translator } = context;
const { sequence: { config }, translator } = context;

return sequence.config.value
return config.value
? translator.$tc('sw-flow.actions.downloadAccessLabel.granted')
: translator.$tc('sw-flow.actions.downloadAccessLabel.revoked');
}
Expand Down Expand Up @@ -716,7 +705,6 @@ export default class FlowBuilderService {
});
}


public configValuesToString(val: SequenceConfigValues[keyof SequenceConfigValues]): string {
if (val === null) {
return 'null';
Expand Down

0 comments on commit f6064a5

Please sign in to comment.