Skip to content

Commit a0697d6

Browse files
authored
0.3.0. (#6)
1 parent 53c8656 commit a0697d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+359
-64
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 0.3.0
2+
3+
* Added new value model: nullable any variable (`nullableAnyVariableValueModel({ ... })`). This value model allows you to select any variable. Additionally, you can specify a variable type that can be selected by a user.
4+
* Added new optional property: `valueTypes` to `VariableDefinitionsValueModelConfiguration` interface. Now it's possible to force the types of variables during creation of variables by a user.
5+
6+
**Breaking changes:**
7+
8+
* Renamed the `variableType` property to `valueType` in the `NullableVariableValueModelConfiguration` interface.
9+
* Renamed the `variableType` property to `valueType` in the `NullableVariableDefinitionValueModelConfiguration` interface.
10+
111
## 0.2.1
212

313
Fixed bug with removing a message about an empty list.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ import { EditorProvider } from 'sequential-workflow-editor';
9696
import { Uid } from 'sequential-workflow-designer';
9797

9898
export const editorProvider = EditorProvider.create(definitionModel, {
99-
uidGenerator: Uid.next
99+
uidGenerator: Uid.next
100100
});
101101
```
102102

demos/webpack-app/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
"dependencies": {
1717
"xstate": "^4.37.2",
1818
"sequential-workflow-model": "^0.1.3",
19-
"sequential-workflow-designer": "^0.13.0",
19+
"sequential-workflow-designer": "^0.13.2",
2020
"sequential-workflow-machine": "^0.2.0",
21-
"sequential-workflow-editor-model": "^0.2.1",
22-
"sequential-workflow-editor": "^0.2.1"
21+
"sequential-workflow-editor-model": "^0.3.0",
22+
"sequential-workflow-editor": "^0.3.0"
2323
},
2424
"devDependencies": {
2525
"ts-loader": "^9.4.2",
@@ -33,4 +33,4 @@
3333
"@typescript-eslint/parser": "^5.47.0",
3434
"eslint": "^8.30.0"
3535
}
36-
}
36+
}

demos/webpack-app/public/assets/icon-calculate.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

demos/webpack-app/public/assets/icon-log.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

demos/webpack-app/public/assets/icon-setStringValue.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Loading

demos/webpack-app/src/playground/app.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export class App {
2828
root: editorProvider.createRootValidator()
2929
},
3030
steps: {
31-
iconUrlProvider: (_, type: string) => `./assets/icon-${type}.svg`
31+
iconUrlProvider: (componentType: string, type: string) => {
32+
return componentType === 'task' ? './assets/icon-task.svg' : `./assets/icon-${type}.svg`;
33+
}
3234
},
3335
toolbox: {
3436
groups: [
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { createAtomActivity } from 'sequential-workflow-machine';
2+
import { GlobalState } from '../global-state';
3+
import { ConvertValueStep } from '../../model/convert-value-step-model';
4+
5+
export const convertValueActivity = createAtomActivity<ConvertValueStep, GlobalState>({
6+
init: () => ({}),
7+
stepType: 'convertValue',
8+
handler: async (step: ConvertValueStep, { $variables }: GlobalState) => {
9+
if (!step.properties.source) {
10+
throw new Error('Source variable is required');
11+
}
12+
if (!step.properties.target) {
13+
throw new Error('Target variable is required');
14+
}
15+
16+
const value = $variables.read(step.properties.source.name);
17+
18+
let convertedValue: unknown;
19+
switch (step.properties.target.type) {
20+
case 'number':
21+
convertedValue = Number(value);
22+
break;
23+
case 'string':
24+
convertedValue = String(value);
25+
break;
26+
default:
27+
throw new Error(`Unsupported target type: ${step.properties.target.type}`);
28+
}
29+
30+
$variables.set(step.properties.target.name, convertedValue);
31+
}
32+
});

demos/webpack-app/src/playground/machine/activities/set-string-value-activity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createAtomActivity } from 'sequential-workflow-machine';
22
import { GlobalState } from '../global-state';
3-
import { SetStringValueStep } from '../../model/set-string-value-model';
3+
import { SetStringValueStep } from '../../model/set-string-value-step-model';
44

55
export const setStringValueActivity = createAtomActivity<SetStringValueStep, GlobalState>({
66
init: () => ({}),

demos/webpack-app/src/playground/machine/activity-set.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,13 @@ import { loopActivity } from './activities/loop-activity';
44
import { logActivity } from './activities/log-activity';
55
import { ifActivity } from './activities/if-activity';
66
import { calculateActivity } from './activities/calculate-activity';
7+
import { convertValueActivity } from './activities/convert-value-activity';
78

8-
export const activitySet = createActivitySet([calculateActivity, ifActivity, logActivity, loopActivity, setStringValueActivity]);
9+
export const activitySet = createActivitySet([
10+
calculateActivity,
11+
convertValueActivity,
12+
ifActivity,
13+
logActivity,
14+
loopActivity,
15+
setStringValueActivity
16+
]);

demos/webpack-app/src/playground/model/calculate-step-model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ export const calculateStepModel = createStepModel<CalculateStep>('calculate', 't
2727
numberValueModel({}),
2828
nullableVariableValueModel({
2929
isRequired: true,
30-
variableType: ValueKnownType.number
30+
valueType: ValueKnownType.number
3131
})
3232
]
3333
});
3434

3535
step.property('result').value(
3636
nullableVariableValueModel({
37-
variableType: ValueKnownType.number,
37+
valueType: ValueKnownType.number,
3838
isRequired: true
3939
})
4040
);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { NullableAnyVariable, createStepModel, nullableAnyVariableValueModel } from 'sequential-workflow-editor-model';
2+
import { Step } from 'sequential-workflow-model';
3+
4+
export interface ConvertValueStep extends Step {
5+
type: 'convertValue';
6+
componentType: 'task';
7+
properties: {
8+
source: NullableAnyVariable;
9+
target: NullableAnyVariable;
10+
};
11+
}
12+
13+
export const convertValueStepModel = createStepModel<ConvertValueStep>('convertValue', 'task', step => {
14+
step.property('source')
15+
.value(
16+
nullableAnyVariableValueModel({
17+
isRequired: true
18+
})
19+
)
20+
.label('Source variable');
21+
step.property('target')
22+
.value(
23+
nullableAnyVariableValueModel({
24+
isRequired: true
25+
})
26+
)
27+
.label('Target variable');
28+
});

demos/webpack-app/src/playground/model/definition-model.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { VariableDefinitions, createDefinitionModel } from 'sequential-workflow-
22
import { rootModel } from './root-model';
33
import { logStepModel } from './log-step-model';
44
import { loopStepModel } from './loop-step-model';
5-
import { setStringValueModel } from './set-string-value-model';
5+
import { setStringValueStepModel } from './set-string-value-step-model';
66
import { Definition } from 'sequential-workflow-model';
77
import { ifStepModel } from './if-step-model';
88
import { calculateStepModel } from './calculate-step-model';
9+
import { convertValueStepModel } from './convert-value-step-model';
910

1011
export interface MyDefinition extends Definition {
1112
properties: {
@@ -17,5 +18,5 @@ export interface MyDefinition extends Definition {
1718
export const definitionModel = createDefinitionModel<MyDefinition>(model => {
1819
model.valueTypes(['string', 'number']);
1920
model.root(rootModel);
20-
model.steps([calculateStepModel, ifStepModel, logStepModel, loopStepModel, setStringValueModel]);
21+
model.steps([calculateStepModel, convertValueStepModel, ifStepModel, logStepModel, loopStepModel, setStringValueStepModel]);
2122
});

demos/webpack-app/src/playground/model/if-step-model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const ifStepModel = createBranchedStepModel<IfStep>('if', 'switch', step
2727
numberValueModel({}),
2828
nullableVariableValueModel({
2929
isRequired: true,
30-
variableType: ValueKnownType.number
30+
valueType: ValueKnownType.number
3131
})
3232
]
3333
});

demos/webpack-app/src/playground/model/log-step-model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const logStepModel = createStepModel<LogStep>('log', 'task', step => {
3030
}),
3131
nullableVariableValueModel({
3232
isRequired: true,
33-
variableType: ValueKnownType.string
33+
valueType: ValueKnownType.string
3434
})
3535
]
3636
})

demos/webpack-app/src/playground/model/loop-step-model.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const loopStepModel = createSequentialStepModel('loop', 'container', step
3636
numberValueModel({}),
3737
nullableVariableValueModel({
3838
isRequired: true,
39-
variableType: ValueKnownType.number
39+
valueType: ValueKnownType.number
4040
})
4141
]
4242
})
@@ -58,7 +58,7 @@ export const loopStepModel = createSequentialStepModel('loop', 'container', step
5858
numberValueModel({}),
5959
nullableVariableValueModel({
6060
isRequired: true,
61-
variableType: ValueKnownType.number
61+
valueType: ValueKnownType.number
6262
})
6363
]
6464
})
@@ -74,7 +74,7 @@ export const loopStepModel = createSequentialStepModel('loop', 'container', step
7474
}),
7575
nullableVariableValueModel({
7676
isRequired: true,
77-
variableType: ValueKnownType.number
77+
valueType: ValueKnownType.number
7878
})
7979
]
8080
})
@@ -84,7 +84,7 @@ export const loopStepModel = createSequentialStepModel('loop', 'container', step
8484
.label('Index variable')
8585
.value(
8686
nullableVariableDefinitionValueModel({
87-
variableType: ValueKnownType.number,
87+
valueType: ValueKnownType.number,
8888
isRequired: true,
8989
defaultValue: {
9090
name: 'index',

demos/webpack-app/src/playground/model/root-model.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ export const rootModel = createRootModel<MyDefinition>(root => {
1111
return inputs.variables.length > 0 ? null : 'At least one input is required';
1212
}
1313
});
14-
root.property('outputs').value(
15-
variableDefinitionsValueModel({
16-
label: 'Outputs'
17-
})
18-
);
14+
root.property('outputs').value(variableDefinitionsValueModel({})).label('Outputs');
1915
root.sequence().value(
2016
sequenceValueModel({
2117
sequence: []

demos/webpack-app/src/playground/model/set-string-value-model.ts renamed to demos/webpack-app/src/playground/model/set-string-value-step-model.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export interface SetStringValueStep extends Step {
1818
};
1919
}
2020

21-
export const setStringValueModel = createStepModel<SetStringValueStep>('setStringValue', 'task', step => {
21+
export const setStringValueStepModel = createStepModel<SetStringValueStep>('setStringValue', 'task', step => {
2222
step.property('variable')
2323
.value(
2424
nullableVariableValueModel({
25-
variableType: ValueKnownType.string,
25+
valueType: ValueKnownType.string,
2626
isRequired: true
2727
})
2828
)
@@ -35,7 +35,7 @@ export const setStringValueModel = createStepModel<SetStringValueStep>('setStrin
3535
minLength: 1
3636
}),
3737
nullableVariableValueModel({
38-
variableType: ValueKnownType.string,
38+
valueType: ValueKnownType.string,
3939
isRequired: true
4040
})
4141
]

editor/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sequential-workflow-editor",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"type": "module",
55
"main": "./lib/esm/index.js",
66
"types": "./lib/index.d.ts",
@@ -46,11 +46,11 @@
4646
"prettier:fix": "prettier --write ./src ./css"
4747
},
4848
"dependencies": {
49-
"sequential-workflow-editor-model": "^0.2.1",
49+
"sequential-workflow-editor-model": "^0.3.0",
5050
"sequential-workflow-model": "^0.1.3"
5151
},
5252
"peerDependencies": {
53-
"sequential-workflow-editor-model": "^0.2.1",
53+
"sequential-workflow-editor-model": "^0.3.0",
5454
"sequential-workflow-model": "^0.1.3"
5555
},
5656
"devDependencies": {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { filterValueTypes } from './filter-value-types';
2+
3+
describe('filterValueTypes', () => {
4+
it('filters correctly if passed array', () => {
5+
const result = filterValueTypes(['number', 'string'], ['number']);
6+
expect(result.length).toBe(1);
7+
expect(result[0]).toBe('number');
8+
});
9+
10+
it('filters correctly if passed empty array', () => {
11+
const result = filterValueTypes(['number', 'string'], []);
12+
expect(result.length).toBe(0);
13+
});
14+
15+
it('does not filter if second argument is undefined', () => {
16+
const result = filterValueTypes(['number', 'string'], undefined);
17+
expect(result.length).toBe(2);
18+
expect(result[0]).toBe('number');
19+
expect(result[1]).toBe('string');
20+
});
21+
});

editor/src/core/filter-value-types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ValueType } from 'sequential-workflow-editor-model';
2+
3+
export function filterValueTypes(types: ValueType[], allowedTypes: ValueType[] | undefined): ValueType[] {
4+
if (!allowedTypes) {
5+
return types;
6+
}
7+
const result: ValueType[] = [];
8+
for (const type of types) {
9+
if (allowedTypes.includes(type)) {
10+
result.push(type);
11+
}
12+
}
13+
return result;
14+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { ContextVariable, Path } from 'sequential-workflow-editor-model';
2+
import { filterVariablesByType } from './filter-variables-by-type';
3+
4+
describe('filterVariablesByType', () => {
5+
const variables: ContextVariable[] = [
6+
{
7+
name: 'blue',
8+
stepId: '0x1',
9+
type: 'string',
10+
valueModelPath: Path.root()
11+
},
12+
{
13+
name: 'green',
14+
stepId: '0x2',
15+
type: 'number',
16+
valueModelPath: Path.root()
17+
},
18+
{
19+
name: 'pink',
20+
stepId: '0x3',
21+
type: 'boolean',
22+
valueModelPath: Path.root()
23+
}
24+
];
25+
26+
it('returns filtered list when passed string', () => {
27+
const result = filterVariablesByType(variables, 'string');
28+
expect(result.length).toBe(1);
29+
expect(result[0].name).toBe('blue');
30+
});
31+
32+
it('returns filtered list when passed array', () => {
33+
const result = filterVariablesByType(variables, ['number', 'boolean']);
34+
expect(result.length).toBe(2);
35+
expect(result[0].name).toBe('green');
36+
expect(result[1].name).toBe('pink');
37+
});
38+
39+
it('returns empty array if expected types are not found', () => {
40+
const result = filterVariablesByType(variables, ['date', 'time']);
41+
expect(result.length).toBe(0);
42+
});
43+
44+
it('returns source list if filter is not passed', () => {
45+
const result = filterVariablesByType(variables, undefined);
46+
expect(result.length).toBe(3);
47+
expect(result[0].name).toBe('blue');
48+
expect(result[1].name).toBe('green');
49+
expect(result[2].name).toBe('pink');
50+
});
51+
});

0 commit comments

Comments
 (0)