Skip to content

Commit 052b03e

Browse files
philippfrommeSkaiir
authored andcommitted
feat(editor): support version tag
Co-authored-by: Vinicius Goulart <[email protected]> Related to camunda/camunda-modeler#4463
1 parent 65fb3de commit 052b03e

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { get } from 'min-dash';
2+
3+
import { useService } from '../hooks';
4+
5+
import { TextFieldEntry, isTextFieldEntryEdited } from '@bpmn-io/properties-panel';
6+
7+
export function VersionTagEntry(props) {
8+
const { editField, field } = props;
9+
10+
const entries = [];
11+
12+
entries.push({
13+
id: 'versionTag',
14+
component: VersionTag,
15+
editField: editField,
16+
field: field,
17+
isEdited: isTextFieldEntryEdited,
18+
isDefaultVisible: (field) => field.type === 'default',
19+
});
20+
21+
return entries;
22+
}
23+
24+
function VersionTag(props) {
25+
const { editField, field, id } = props;
26+
27+
const debounce = useService('debounce');
28+
29+
const path = ['versionTag'];
30+
31+
const getValue = () => {
32+
return get(field, path, '');
33+
};
34+
35+
const setValue = (value, error) => {
36+
if (error) {
37+
return;
38+
}
39+
40+
return editField(field, path, value);
41+
};
42+
43+
const tooltip = <div>Version tag by which this form can be referenced.</div>;
44+
45+
return TextFieldEntry({
46+
debounce,
47+
element: field,
48+
getValue,
49+
id,
50+
label: 'Version tag',
51+
setValue,
52+
tooltip,
53+
});
54+
}

packages/form-js-editor/src/features/properties-panel/entries/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ export { RowCountEntry } from './RowCountEntry';
3939
export { HeadersSourceSelectEntry } from './HeadersSourceSelectEntry';
4040
export { ColumnsExpressionEntry } from './ColumnsExpressionEntry';
4141
export { StaticColumnsSourceEntry } from './StaticColumnsSourceEntry';
42+
export { VersionTagEntry } from './VersionTagEntry';

packages/form-js-editor/src/features/properties-panel/groups/GeneralGroup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ import {
2323
TableDataSourceEntry,
2424
PaginationEntry,
2525
RowCountEntry,
26+
VersionTagEntry,
2627
} from '../entries';
2728

2829
export function GeneralGroup(field, editField, getService) {
2930
const entries = [
3031
...IdEntry({ field, editField }),
32+
...VersionTagEntry({ field, editField }),
3133
...LabelEntry({ field, editField }),
3234
...DescriptionEntry({ field, editField }),
3335
...KeyEntry({ field, editField, getService }),

packages/form-js-editor/test/spec/features/properties-panel/groups/GeneralGroup.spec.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,75 @@ describe('GeneralGroup', function () {
8181
});
8282
});
8383

84+
describe('versionTag', function () {
85+
it('should render for default', function () {
86+
// given
87+
const field = { type: 'default' };
88+
89+
// when
90+
const { container } = renderGeneralGroup({ field });
91+
92+
// then
93+
const versionTagInput = findInput('versionTag', container);
94+
95+
expect(versionTagInput).to.exist;
96+
});
97+
98+
it('should NOT render for textfield', function () {
99+
// given
100+
const field = { type: 'textfield' };
101+
102+
// when
103+
const { container } = renderGeneralGroup({ field });
104+
105+
// then
106+
const versionTagInput = findInput('versionTag', container);
107+
108+
expect(versionTagInput).to.not.exist;
109+
});
110+
111+
it('should read', function () {
112+
// given
113+
const field = {
114+
type: 'default',
115+
id: 'foobar',
116+
versionTag: 'v1',
117+
};
118+
119+
// when
120+
const { container } = renderGeneralGroup({ field });
121+
122+
// when
123+
const versionTagInput = findInput('versionTag', container);
124+
125+
// then
126+
expect(versionTagInput).to.exist;
127+
expect(versionTagInput.value).to.equal('v1');
128+
});
129+
130+
it('should write', function () {
131+
// given
132+
const field = {
133+
type: 'default',
134+
id: 'foobar',
135+
versionTag: 'v1',
136+
};
137+
138+
const editFieldSpy = sinon.spy((field, path, value) => set(field, path, value));
139+
140+
const { container } = renderGeneralGroup({ field, editField: editFieldSpy });
141+
142+
const versionTagInput = findInput('versionTag', container);
143+
144+
// when
145+
fireEvent.input(versionTagInput, { target: { value: 'newVal' } });
146+
147+
// then
148+
expect(editFieldSpy).to.have.been.calledOnce;
149+
expect(field.versionTag).to.equal('newVal');
150+
});
151+
});
152+
84153
describe('label', function () {
85154
it('should NOT render for default', function () {
86155
// given

0 commit comments

Comments
 (0)