Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.13.1. #38

Merged
merged 1 commit into from
Jun 27, 2024
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.13.1

This version adds missing translations for the `variableNameValidator` function [#37](https://github.com/nocode-js/sequential-workflow-editor/issues/37).

## 0.13.0

This version introduces several internal changes that allowed for the creation of a new type of editor in the pro version: the hidden dependent value editor.
Expand Down
4 changes: 2 additions & 2 deletions demos/webpack-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"sequential-workflow-model": "^0.2.0",
"sequential-workflow-designer": "^0.21.2",
"sequential-workflow-machine": "^0.4.0",
"sequential-workflow-editor-model": "^0.13.0",
"sequential-workflow-editor": "^0.13.0"
"sequential-workflow-editor-model": "^0.13.1",
"sequential-workflow-editor": "^0.13.1"
},
"devDependencies": {
"ts-loader": "^9.4.2",
Expand Down
5 changes: 4 additions & 1 deletion docs/I18N-KEYS.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ This document lists all the I18N keys used in the Sequential Workflow Editor.
"variableDefinitions.delete": "Delete",
"variableDefinitions.namePlaceholder": "Variable name",
"variableDefinitions.valueTypeIsNotAllowed": "Value type is not allowed",
"variableDefinitions.variableNameIsDuplicated": "Variable name is already used"
"variableDefinitions.variableNameIsDuplicated": "Variable name is already used",
"variableName.invalidCharacters": "Variable name contains invalid characters",
"variableName.maxLength": "Variable name must be :n characters or less",
"variableName.required": "Variable name is required"
}
```
6 changes: 3 additions & 3 deletions editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sequential-workflow-editor",
"version": "0.13.0",
"version": "0.13.1",
"type": "module",
"main": "./lib/esm/index.js",
"types": "./lib/index.d.ts",
Expand Down Expand Up @@ -46,11 +46,11 @@
"prettier:fix": "prettier --write ./src ./css"
},
"dependencies": {
"sequential-workflow-editor-model": "^0.13.0",
"sequential-workflow-editor-model": "^0.13.1",
"sequential-workflow-model": "^0.2.0"
},
"peerDependencies": {
"sequential-workflow-editor-model": "^0.13.0",
"sequential-workflow-editor-model": "^0.13.1",
"sequential-workflow-model": "^0.2.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion model/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sequential-workflow-editor-model",
"version": "0.13.0",
"version": "0.13.1",
"homepage": "https://nocode-js.com/",
"author": {
"name": "NoCode JS",
Expand Down
31 changes: 17 additions & 14 deletions model/src/validator/variable-name-validator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { defaultI18n } from '../i18n';
import { variableNameValidator } from './variable-name-validator';

describe('VariableNameValidator', () => {
const i18n = defaultI18n;

it('creates correctly', () => {
expect(variableNameValidator('a')).toBeNull();
expect(variableNameValidator('ab')).toBeNull();
expect(variableNameValidator('a-b-c')).toBeNull();
expect(variableNameValidator('FooBar')).toBeNull();
expect(variableNameValidator('foo_bar')).toBeNull();
expect(variableNameValidator('item1')).toBeNull();
expect(variableNameValidator('item_1')).toBeNull();
expect(variableNameValidator('Item_1')).toBeNull();
expect(variableNameValidator('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_b')).toBeNull();
expect(variableNameValidator(i18n, 'a')).toBeNull();
expect(variableNameValidator(i18n, 'ab')).toBeNull();
expect(variableNameValidator(i18n, 'a-b-c')).toBeNull();
expect(variableNameValidator(i18n, 'FooBar')).toBeNull();
expect(variableNameValidator(i18n, 'foo_bar')).toBeNull();
expect(variableNameValidator(i18n, 'item1')).toBeNull();
expect(variableNameValidator(i18n, 'item_1')).toBeNull();
expect(variableNameValidator(i18n, 'Item_1')).toBeNull();
expect(variableNameValidator(i18n, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_b')).toBeNull();

expect(variableNameValidator('1')).toContain('invalid characters');
expect(variableNameValidator('fooBar&')).toContain('invalid characters');
expect(variableNameValidator('1_')).toContain('invalid characters');
expect(variableNameValidator('')).toContain('is required');
expect(variableNameValidator('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_bc')).toContain('32 characters or less');
expect(variableNameValidator(i18n, '1')).toContain('invalid characters');
expect(variableNameValidator(i18n, 'fooBar&')).toContain('invalid characters');
expect(variableNameValidator(i18n, '1_')).toContain('invalid characters');
expect(variableNameValidator(i18n, '')).toContain('is required');
expect(variableNameValidator(i18n, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa_bc')).toContain('32 characters or less');
});
});
12 changes: 8 additions & 4 deletions model/src/validator/variable-name-validator.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { I18n } from '../i18n';

const MAX_LENGTH = 32;

export function variableNameValidator(name: string): string | null {
export function variableNameValidator(i18n: I18n, name: string): string | null {
if (!name) {
return 'Variable name is required.';
return i18n('variableName.required', 'Variable name is required');
}
if (name.length > MAX_LENGTH) {
return `Variable name must be ${MAX_LENGTH} characters or less.`;
return i18n('variableName.maxLength', 'Variable name must be :n characters or less', {
n: String(MAX_LENGTH)
});
}
if (!/^[A-Za-z][a-zA-Z_0-9-]*$/.test(name)) {
return 'Variable name contains invalid characters.';
return i18n('variableName.invalidCharacters', 'Variable name contains invalid characters');
}
return null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const createNullableVariableDefinitionValueModel = (
);
}
if (value) {
const nameError = variableNameValidator(value.name);
const nameError = variableNameValidator(context.i18n, value.name);
if (nameError) {
return createValidationSingleError(nameError);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const createVariableDefinitionsValueModel = (
const value = context.getValue();

value.variables.forEach((variable, index) => {
const nameError = variableNameValidator(variable.name);
const nameError = variableNameValidator(context.i18n, variable.name);
if (nameError) {
errors[index] = nameError;
return;
Expand Down
Loading