fix(editor): Format action names properly when action is not defined (#11030)

This commit is contained in:
Ricardo Espinoza
2024-10-02 08:16:33 -04:00
committed by GitHub
parent 74fa259b37
commit 9c43fb301d
6 changed files with 197 additions and 118 deletions

View File

@@ -1,5 +1,5 @@
import type { SectionCreateElement } from '@/Interface';
import { groupItemsInSections, sortNodeCreateElements } from '../utils';
import { formatTriggerActionName, groupItemsInSections, sortNodeCreateElements } from '../utils';
import { mockActionCreateElement, mockNodeCreateElement, mockSectionCreateElement } from './utils';
describe('NodeCreator - utils', () => {
@@ -62,4 +62,15 @@ describe('NodeCreator - utils', () => {
expect(sortNodeCreateElements([node1, node2, node3])).toEqual([node1, node2, node3]);
});
});
describe('formatTriggerActionName', () => {
test.each([
['project.created', 'project created'],
['Project Created', 'project created'],
['field.value.created', 'field value created'],
['attendee.checked_in', 'attendee checked in'],
])('Action name %i should become as %i', (actionName, expected) => {
expect(formatTriggerActionName(actionName)).toEqual(expected);
});
});
});

View File

@@ -12,6 +12,7 @@ import type {
import { i18n } from '@/plugins/i18n';
import { getCredentialOnlyNodeType } from '@/utils/credentialOnlyNodes';
import { formatTriggerActionName } from '../utils';
const PLACEHOLDER_RECOMMENDED_ACTION_KEY = 'placeholder_recommended';
@@ -168,7 +169,7 @@ function triggersCategory(nodeTypeDescription: INodeTypeDescription): ActionType
displayName:
categoryItem.action ??
cachedBaseText('nodeCreator.actionsCategory.onEvent', {
interpolate: { event: startCase(categoryItem.name) },
interpolate: { event: formatTriggerActionName(categoryItem.name) },
}),
description: categoryItem.description ?? '',
displayOptions: matchedProperty.displayOptions,

View File

@@ -19,6 +19,7 @@ import { sublimeSearch } from '@/utils/sortUtils';
import type { NodeViewItemSection } from './viewsData';
import { i18n } from '@/plugins/i18n';
import { sortBy } from 'lodash-es';
import * as changeCase from 'change-case';
import { usePostHog } from '@/stores/posthog.store';
@@ -177,3 +178,11 @@ export function groupItemsInSections(
return result;
}
export const formatTriggerActionName = (actionPropertyName: string) => {
let name = actionPropertyName;
if (actionPropertyName.includes('.')) {
name = actionPropertyName.split('.').join(' ');
}
return changeCase.noCase(name);
};