Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Localize/lang/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5039,6 +5039,7 @@
"_rxMXmZ.comment": "Time zone value ",
"_s+4LEa.comment": "Open folder label",
"_s0Qaot.comment": "Workflow Parameters Panel",
"_s2XJ/T.comment": "Error message when the workflow name contains a space.",
"_s2f0XK.comment": "Content for the toaster after creating a group in add files panel",
"_s2ydQX.comment": "Error validation message for invalid JSON object. Do not remove the double single quotes around the display name, as it is needed to wrap the placeholder text.",
"_s5AOpV.comment": "Label for the title for panel header card",
Expand Down Expand Up @@ -6479,6 +6480,7 @@
"rxMXmZ": "(UTC+04:00) Port Louis",
"s+4LEa": "Open folder",
"s0Qaot": "Workflow Parameters Panel",
"s2XJ/T": "Workflow name cannot contain spaces. Use letters, numbers, dashes ('-') and underscores ('_') instead.",
"s2f0XK": "Group {name} has been created and selected.",
"s2ydQX": "''Value'' must be a valid JSON object",
"s5AOpV": "Card title",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,22 @@ describe('Template Validation Tests', () => {
id: 'zMKxg9',
description: 'Error message when the workflow name is invalid regex.',
});
expect(checkWorkflowNameWithRegex(intl, 'workflow name')).toBe(nameDoesNotMath);
expect(checkWorkflowNameWithRegex(intl, '1workflowName')).toBe(nameDoesNotMath);
expect(checkWorkflowNameWithRegex(intl, '1_workflowName_1')).toBe(nameDoesNotMath);
expect(checkWorkflowNameWithRegex(intl, 'workflow_Name space')).toBe(nameDoesNotMath);
expect(checkWorkflowNameWithRegex(intl, 'workflow_%7')).toBe(nameDoesNotMath);
});

test('Names with a space get a message that says spaces are not allowed', async () => {
const nameHasSpace = intl.formatMessage({
defaultMessage: "Workflow name cannot contain spaces. Use letters, numbers, dashes ('-') and underscores ('_') instead.",
id: 's2XJ/T',
description: 'Error message when the workflow name contains a space.',
});
expect(checkWorkflowNameWithRegex(intl, 'workflow name')).toBe(nameHasSpace);
expect(checkWorkflowNameWithRegex(intl, 'My Workflow')).toBe(nameHasSpace);
expect(checkWorkflowNameWithRegex(intl, 'workflow_Name space')).toBe(nameHasSpace);
expect(checkWorkflowNameWithRegex(intl, ' workflow')).toBe(nameHasSpace);
});
});

describe('validateWorkflowData', () => {
Expand Down
7 changes: 7 additions & 0 deletions libs/designer-v2/src/lib/core/templates/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ export const validateConnectionsValue = (
export const checkWorkflowNameWithRegex = (intl: IntlShape, workflowName: string) => {
const regex = /^[A-Za-z][A-Za-z0-9]*(?:[_-][A-Za-z0-9]+)*$/;
if (!regex.test(workflowName)) {
if (/\s/.test(workflowName)) {
return intl.formatMessage({
defaultMessage: "Workflow name cannot contain spaces. Use letters, numbers, dashes ('-') and underscores ('_') instead.",
id: 's2XJ/T',
description: 'Error message when the workflow name contains a space.',
});
}
return intl.formatMessage({
defaultMessage: "Name can only contain letters, numbers, and '-', '(', ')', '_' or '.",
id: 'TwBRcg',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,22 @@ describe('Template Validation Tests', () => {
id: 'zMKxg9',
description: 'Error message when the workflow name is invalid regex.',
});
expect(checkWorkflowNameWithRegex(intl, 'workflow name')).toBe(nameDoesNotMath);
expect(checkWorkflowNameWithRegex(intl, '1workflowName')).toBe(nameDoesNotMath);
expect(checkWorkflowNameWithRegex(intl, '1_workflowName_1')).toBe(nameDoesNotMath);
expect(checkWorkflowNameWithRegex(intl, 'workflow_Name space')).toBe(nameDoesNotMath);
expect(checkWorkflowNameWithRegex(intl, 'workflow_%7')).toBe(nameDoesNotMath);
});

test('Names with a space get a message that says spaces are not allowed', async () => {
const nameHasSpace = intl.formatMessage({
defaultMessage: "Workflow name cannot contain spaces. Use letters, numbers, dashes ('-') and underscores ('_') instead.",
id: 's2XJ/T',
description: 'Error message when the workflow name contains a space.',
});
expect(checkWorkflowNameWithRegex(intl, 'workflow name')).toBe(nameHasSpace);
expect(checkWorkflowNameWithRegex(intl, 'My Workflow')).toBe(nameHasSpace);
expect(checkWorkflowNameWithRegex(intl, 'workflow_Name space')).toBe(nameHasSpace);
expect(checkWorkflowNameWithRegex(intl, ' workflow')).toBe(nameHasSpace);
});
});

describe('validateWorkflowData', () => {
Expand Down
7 changes: 7 additions & 0 deletions libs/designer/src/lib/core/templates/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ export const validateConnectionsValue = (
export const checkWorkflowNameWithRegex = (intl: IntlShape, workflowName: string) => {
const regex = /^[A-Za-z][A-Za-z0-9]*(?:[_-][A-Za-z0-9]+)*$/;
if (!regex.test(workflowName)) {
if (/\s/.test(workflowName)) {
return intl.formatMessage({
defaultMessage: "Workflow name cannot contain spaces. Use letters, numbers, dashes ('-') and underscores ('_') instead.",
id: 's2XJ/T',
description: 'Error message when the workflow name contains a space.',
});
}
return intl.formatMessage({
defaultMessage: "Workflow name must start with a letter and can contain letters, numbers (0-9), dashes ('-'), and underscores ('_').",
id: '/21RuK',
Expand Down
Loading