From 97d2f64fa4d3f199404276542ac0d45211df070f Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Tue, 28 May 2024 09:37:23 +0200 Subject: [PATCH] feat: support `placeholder` on `String` and `Text` properties Related to https://github.com/bpmn-io/bpmn-js-element-templates/issues/92 --- .../CHANGELOG.md | 4 ++ .../src/defs/base-properties.json | 40 +++++++++++ .../fixtures/placeholder-invalid-property.js | 72 +++++++++++++++++++ .../test/fixtures/placeholder-invalid-type.js | 49 +++++++++++++ .../test/fixtures/placeholder.js | 37 ++++++++++ .../test/spec/validationSpec.js | 9 +++ .../CHANGELOG.md | 4 ++ .../fixtures/placeholder-invalid-property.js | 72 +++++++++++++++++++ .../test/fixtures/placeholder-invalid-type.js | 49 +++++++++++++ .../test/fixtures/placeholder.js | 37 ++++++++++ .../test/spec/validationSpec.js | 10 +++ 11 files changed, 383 insertions(+) create mode 100644 packages/element-templates-json-schema/test/fixtures/placeholder-invalid-property.js create mode 100644 packages/element-templates-json-schema/test/fixtures/placeholder-invalid-type.js create mode 100644 packages/element-templates-json-schema/test/fixtures/placeholder.js create mode 100644 packages/zeebe-element-templates-json-schema/test/fixtures/placeholder-invalid-property.js create mode 100644 packages/zeebe-element-templates-json-schema/test/fixtures/placeholder-invalid-type.js create mode 100644 packages/zeebe-element-templates-json-schema/test/fixtures/placeholder.js diff --git a/packages/element-templates-json-schema-shared/CHANGELOG.md b/packages/element-templates-json-schema-shared/CHANGELOG.md index b75701a..6b378d3 100644 --- a/packages/element-templates-json-schema-shared/CHANGELOG.md +++ b/packages/element-templates-json-schema-shared/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to [@camunda/element-templates-json-schema-shared](https://g ___Note:__ Yet to be released changes appear here._ +## 0.11.0 + +* `FEAT`: support `placeholder` property + ## 0.10.2 * `FIX`: allow number values for `Number` properties ([#138](https://github.com/camunda/element-templates-json-schema/issues/138)) diff --git a/packages/element-templates-json-schema-shared/src/defs/base-properties.json b/packages/element-templates-json-schema-shared/src/defs/base-properties.json index 1a0ff0e..47646f5 100644 --- a/packages/element-templates-json-schema-shared/src/defs/base-properties.json +++ b/packages/element-templates-json-schema-shared/src/defs/base-properties.json @@ -51,6 +51,46 @@ } } } + }, + { + "if": { + "oneOf": [ + { + "properties": { + "type": { + "enum": [ + "String", + "Text" + ] + } + }, + "required": [ + "type" + ] + }, + { + "not": { + "required": [ + "type" + ] + } + } + ] + }, + "then": { + "properties": { + "placeholder": { + "type": "string" + } + } + }, + "else": { + "not": { + "required": [ + "placeholder" + ] + } + } } ], "properties": { diff --git a/packages/element-templates-json-schema/test/fixtures/placeholder-invalid-property.js b/packages/element-templates-json-schema/test/fixtures/placeholder-invalid-property.js new file mode 100644 index 0000000..c5a9106 --- /dev/null +++ b/packages/element-templates-json-schema/test/fixtures/placeholder-invalid-property.js @@ -0,0 +1,72 @@ +export const template = { + name: 'Tooltip', + id: 'example.com.tooltip', + appliesTo: [ + 'bpmn:ServiceTask' + ], + properties: [ + { + label: 'Input with placeholder', + type: 'Boolean', + binding: { + type: 'property', + name: 'prop' + }, + placeholder: 'Invalid input type' + }, + { + label: 'Input with placeholder', + type: 'Hidden', + binding: { + type: 'property', + name: 'prop' + }, + placeholder: 'Invalid input type' + } + ] +}; + +export const errors = [ + { + 'dataPath': '/properties/0', + 'keyword': 'not', + 'message': 'should NOT be valid', + 'params': {}, + 'schemaPath': '#/allOf/0/items/allOf/3/else/not', + }, + { + 'dataPath': '/properties/0', + 'keyword': 'if', + 'message': 'should match "else" schema', + params: { failingKeyword: 'else' }, + schemaPath: '#/allOf/0/items/allOf/3/if' + }, + { + 'dataPath': '/properties/1', + 'keyword': 'not', + 'message': 'should NOT be valid', + 'params': {}, + 'schemaPath': '#/allOf/0/items/allOf/3/else/not', + }, + { + 'dataPath': '/properties/1', + 'keyword': 'if', + 'message': 'should match "else" schema', + params: { failingKeyword: 'else' }, + schemaPath: '#/allOf/0/items/allOf/3/if' + }, + { + keyword: 'type', + dataPath: '', + schemaPath: '#/oneOf/1/type', + params: { type: 'array' }, + message: 'should be array' + }, + { + keyword: 'oneOf', + dataPath: '', + schemaPath: '#/oneOf', + params: { passingSchemas: null }, + message: 'should match exactly one schema in oneOf' + } +]; \ No newline at end of file diff --git a/packages/element-templates-json-schema/test/fixtures/placeholder-invalid-type.js b/packages/element-templates-json-schema/test/fixtures/placeholder-invalid-type.js new file mode 100644 index 0000000..4034adc --- /dev/null +++ b/packages/element-templates-json-schema/test/fixtures/placeholder-invalid-type.js @@ -0,0 +1,49 @@ +export const template = { + name: 'Tooltip', + id: 'example.com.tooltip', + appliesTo: [ + 'bpmn:ServiceTask' + ], + properties: [ + { + label: 'Input with placeholder', + type: 'String', + binding: { + type: 'property', + name: 'prop' + }, + placeholder: [ 'invalid placeholder type' ] + } + ] +}; + +export const errors = [ + { + keyword: 'type', + dataPath: '/properties/0/placeholder', + schemaPath: '#/allOf/0/items/allOf/3/then/properties/placeholder/type', + params: { type: 'string' }, + message: 'should be string' + }, + { + dataPath: '/properties/0', + keyword: 'if', + message: 'should match "then" schema', + params: { failingKeyword: 'then' }, + schemaPath: '#/allOf/0/items/allOf/3/if' + }, + { + keyword: 'type', + dataPath: '', + schemaPath: '#/oneOf/1/type', + params: { type: 'array' }, + message: 'should be array' + }, + { + keyword: 'oneOf', + dataPath: '', + schemaPath: '#/oneOf', + params: { passingSchemas: null }, + message: 'should match exactly one schema in oneOf' + } +]; \ No newline at end of file diff --git a/packages/element-templates-json-schema/test/fixtures/placeholder.js b/packages/element-templates-json-schema/test/fixtures/placeholder.js new file mode 100644 index 0000000..f93f889 --- /dev/null +++ b/packages/element-templates-json-schema/test/fixtures/placeholder.js @@ -0,0 +1,37 @@ +export const template = { + name: 'Tooltip', + id: 'example.com.tooltip', + appliesTo: [ + 'bpmn:ServiceTask' + ], + properties: [ + { + label: 'Input with placeholder', + type: 'String', + binding: { + type: 'property', + name: 'prop' + }, + placeholder: 'This field has a placeholder' + }, + { + label: 'Input with placeholder', + type: 'Text', + binding: { + type: 'property', + name: 'prop' + }, + placeholder: 'This field has a placeholder' + }, + { + label: 'Input with placeholder', + binding: { + type: 'property', + name: 'prop' + }, + placeholder: 'This field has a placeholder' + } + ] +}; + +export const errors = null; \ No newline at end of file diff --git a/packages/element-templates-json-schema/test/spec/validationSpec.js b/packages/element-templates-json-schema/test/spec/validationSpec.js index 55673e1..4c86e46 100644 --- a/packages/element-templates-json-schema/test/spec/validationSpec.js +++ b/packages/element-templates-json-schema/test/spec/validationSpec.js @@ -328,6 +328,15 @@ describe('validation', function() { }); + + describe('placeholder', function() { + + testTemplate('placeholder'); + + testTemplate('placeholder-invalid-property'); + + testTemplate('placeholder-invalid-type'); + }); }); diff --git a/packages/zeebe-element-templates-json-schema/CHANGELOG.md b/packages/zeebe-element-templates-json-schema/CHANGELOG.md index ec17e10..5dcf895 100644 --- a/packages/zeebe-element-templates-json-schema/CHANGELOG.md +++ b/packages/zeebe-element-templates-json-schema/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to [@camunda/zeebe-element-templates-json-schema](https://gi ___Note:__ Yet to be released changes appear here._ +## 0.20.0 + +* `FEAT`: support `placeholder` property + ## 0.19.2 * `FIX`: allow number values for `Number` properties ([#138](https://github.com/camunda/element-templates-json-schema/issues/138)) diff --git a/packages/zeebe-element-templates-json-schema/test/fixtures/placeholder-invalid-property.js b/packages/zeebe-element-templates-json-schema/test/fixtures/placeholder-invalid-property.js new file mode 100644 index 0000000..356f67a --- /dev/null +++ b/packages/zeebe-element-templates-json-schema/test/fixtures/placeholder-invalid-property.js @@ -0,0 +1,72 @@ +export const template = { + name: 'Tooltip', + id: 'example.com.tooltip', + appliesTo: [ + 'bpmn:ServiceTask' + ], + properties: [ + { + label: 'Input with placeholder', + type: 'Boolean', + binding: { + type: 'property', + name: 'prop' + }, + placeholder: 'Invalid input type' + }, + { + label: 'Input with placeholder', + type: 'Number', + binding: { + type: 'property', + name: 'prop' + }, + placeholder: 'Invalid input type' + } + ] +}; + +export const errors = [ + { + 'dataPath': '/properties/0', + 'keyword': 'not', + 'message': 'should NOT be valid', + 'params': {}, + 'schemaPath': '#/allOf/0/items/allOf/3/else/not', + }, + { + 'dataPath': '/properties/0', + 'keyword': 'if', + 'message': 'should match "else" schema', + params: { failingKeyword: 'else' }, + schemaPath: '#/allOf/0/items/allOf/3/if' + }, + { + 'dataPath': '/properties/1', + 'keyword': 'not', + 'message': 'should NOT be valid', + 'params': {}, + 'schemaPath': '#/allOf/0/items/allOf/3/else/not', + }, + { + 'dataPath': '/properties/1', + 'keyword': 'if', + 'message': 'should match "else" schema', + params: { failingKeyword: 'else' }, + schemaPath: '#/allOf/0/items/allOf/3/if' + }, + { + keyword: 'type', + dataPath: '', + schemaPath: '#/oneOf/1/type', + params: { type: 'array' }, + message: 'should be array' + }, + { + keyword: 'oneOf', + dataPath: '', + schemaPath: '#/oneOf', + params: { passingSchemas: null }, + message: 'should match exactly one schema in oneOf' + } +]; \ No newline at end of file diff --git a/packages/zeebe-element-templates-json-schema/test/fixtures/placeholder-invalid-type.js b/packages/zeebe-element-templates-json-schema/test/fixtures/placeholder-invalid-type.js new file mode 100644 index 0000000..4034adc --- /dev/null +++ b/packages/zeebe-element-templates-json-schema/test/fixtures/placeholder-invalid-type.js @@ -0,0 +1,49 @@ +export const template = { + name: 'Tooltip', + id: 'example.com.tooltip', + appliesTo: [ + 'bpmn:ServiceTask' + ], + properties: [ + { + label: 'Input with placeholder', + type: 'String', + binding: { + type: 'property', + name: 'prop' + }, + placeholder: [ 'invalid placeholder type' ] + } + ] +}; + +export const errors = [ + { + keyword: 'type', + dataPath: '/properties/0/placeholder', + schemaPath: '#/allOf/0/items/allOf/3/then/properties/placeholder/type', + params: { type: 'string' }, + message: 'should be string' + }, + { + dataPath: '/properties/0', + keyword: 'if', + message: 'should match "then" schema', + params: { failingKeyword: 'then' }, + schemaPath: '#/allOf/0/items/allOf/3/if' + }, + { + keyword: 'type', + dataPath: '', + schemaPath: '#/oneOf/1/type', + params: { type: 'array' }, + message: 'should be array' + }, + { + keyword: 'oneOf', + dataPath: '', + schemaPath: '#/oneOf', + params: { passingSchemas: null }, + message: 'should match exactly one schema in oneOf' + } +]; \ No newline at end of file diff --git a/packages/zeebe-element-templates-json-schema/test/fixtures/placeholder.js b/packages/zeebe-element-templates-json-schema/test/fixtures/placeholder.js new file mode 100644 index 0000000..f93f889 --- /dev/null +++ b/packages/zeebe-element-templates-json-schema/test/fixtures/placeholder.js @@ -0,0 +1,37 @@ +export const template = { + name: 'Tooltip', + id: 'example.com.tooltip', + appliesTo: [ + 'bpmn:ServiceTask' + ], + properties: [ + { + label: 'Input with placeholder', + type: 'String', + binding: { + type: 'property', + name: 'prop' + }, + placeholder: 'This field has a placeholder' + }, + { + label: 'Input with placeholder', + type: 'Text', + binding: { + type: 'property', + name: 'prop' + }, + placeholder: 'This field has a placeholder' + }, + { + label: 'Input with placeholder', + binding: { + type: 'property', + name: 'prop' + }, + placeholder: 'This field has a placeholder' + } + ] +}; + +export const errors = null; \ No newline at end of file diff --git a/packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js b/packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js index 641f724..22f7ce1 100644 --- a/packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js +++ b/packages/zeebe-element-templates-json-schema/test/spec/validationSpec.js @@ -379,6 +379,16 @@ describe('validation', function() { testTemplate('called-element-missing-property'); }); + + + describe('placeholder', function() { + + testTemplate('placeholder'); + + testTemplate('placeholder-invalid-property'); + + testTemplate('placeholder-invalid-type'); + }); }); });