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

feat: add version tag support #1243

Merged
merged 2 commits into from
Aug 23, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { get } from 'min-dash';

import { useService } from '../hooks';

import { TextFieldEntry, isTextFieldEntryEdited } from '@bpmn-io/properties-panel';

export function VersionTagEntry(props) {
const { editField, field } = props;

const entries = [];

entries.push({
id: 'versionTag',
component: VersionTag,
editField: editField,
field: field,
isEdited: isTextFieldEntryEdited,
isDefaultVisible: (field) => field.type === 'default',
});

return entries;
}

function VersionTag(props) {
const { editField, field, id } = props;

const debounce = useService('debounce');

const path = ['versionTag'];

const getValue = () => {
return get(field, path, '');
};

const setValue = (value, error) => {
if (error) {
return;
}

return editField(field, path, value);
};

const tooltip = <div>Version tag by which this form can be referenced.</div>;

return TextFieldEntry({
debounce,
element: field,
getValue,
id,
label: 'Version tag',
setValue,
tooltip,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ export { RowCountEntry } from './RowCountEntry';
export { HeadersSourceSelectEntry } from './HeadersSourceSelectEntry';
export { ColumnsExpressionEntry } from './ColumnsExpressionEntry';
export { StaticColumnsSourceEntry } from './StaticColumnsSourceEntry';
export { VersionTagEntry } from './VersionTagEntry';
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import {
TableDataSourceEntry,
PaginationEntry,
RowCountEntry,
VersionTagEntry,
} from '../entries';

export function GeneralGroup(field, editField, getService) {
const entries = [
...IdEntry({ field, editField }),
...VersionTagEntry({ field, editField }),
...LabelEntry({ field, editField }),
...DescriptionEntry({ field, editField }),
...KeyEntry({ field, editField, getService }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,75 @@ describe('GeneralGroup', function () {
});
});

describe('versionTag', function () {
it('should render for default', function () {
// given
const field = { type: 'default' };

// when
const { container } = renderGeneralGroup({ field });

// then
const versionTagInput = findInput('versionTag', container);

expect(versionTagInput).to.exist;
});

it('should NOT render for textfield', function () {
// given
const field = { type: 'textfield' };

// when
const { container } = renderGeneralGroup({ field });

// then
const versionTagInput = findInput('versionTag', container);

expect(versionTagInput).to.not.exist;
});

it('should read', function () {
// given
const field = {
type: 'default',
id: 'foobar',
versionTag: 'v1',
};

// when
const { container } = renderGeneralGroup({ field });

// when
const versionTagInput = findInput('versionTag', container);

// then
expect(versionTagInput).to.exist;
expect(versionTagInput.value).to.equal('v1');
});

it('should write', function () {
// given
const field = {
type: 'default',
id: 'foobar',
versionTag: 'v1',
};

const editFieldSpy = sinon.spy((field, path, value) => set(field, path, value));

const { container } = renderGeneralGroup({ field, editField: editFieldSpy });

const versionTagInput = findInput('versionTag', container);

// when
fireEvent.input(versionTagInput, { target: { value: 'newVal' } });

// then
expect(editFieldSpy).to.have.been.calledOnce;
expect(field.versionTag).to.equal('newVal');
});
});

describe('label', function () {
it('should NOT render for default', function () {
// given
Expand Down
5 changes: 5 additions & 0 deletions packages/form-json-schema/src/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
"description": "The target execution platform version of a form",
"type": "string"
},
"versionTag": {
"$id": "#/versionTag",
"description": "The version tag of a form",
"type": "string"
},
"exporter": {
"$id": "#/exporter",
"$ref": "src/defs/exporter.json"
Expand Down
Loading