Skip to content

Commit

Permalink
fix(gv-policy-studio): make dynamic properties backward compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaeyaert authored and gcusnieux committed Jul 30, 2021
1 parent b65304b commit 0e894f5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 33 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 35 additions & 31 deletions src/organisms/gv-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { empty } from '../styles/empty';
export class GvProperties extends KeyboardElement(LitElement) {
static get properties() {
return {
dynamicPropertySchema: { type: Object },
properties: { type: Array },
_properties: { type: Array, attribute: false },
provider: { type: Object },
Expand Down Expand Up @@ -208,44 +209,47 @@ export class GvProperties extends KeyboardElement(LitElement) {
}

_onConfigureDynamicProperties() {
const providersTitleMap = this.providers.reduce((map, provider) => {
map[provider.id] = provider.key;
return map;
}, {});

const providersEnum = Object.keys(providersTitleMap);
const defaultSchema = {
properties: {
enabled: {
type: 'boolean',
title: 'Enabled',
description: ' This service is requiring an API deployment. Do not forget to deploy API to start dynamic-properties service.',
},
schedule: {
type: 'string',
title: 'Schedule',
'x-schema-form': {
'cron-expression': true,
if (this.dynamicPropertySchema == null) {
// dynamicPropertySchema has been introduced to ensure backward compatibility with old versions. If no schema is provided a default schema will be used.
const providersTitleMap = this.providers.reduce((map, provider) => {
map[provider.id] = provider.key;
return map;
}, {});

const providersEnum = Object.keys(providersTitleMap);
this.dynamicPropertySchema = {
properties: {
enabled: {
type: 'boolean',
title: 'Enabled',
description: ' This service is requiring an API deployment. Do not forget to deploy API to start dynamic-properties service.',
},
},
provider: {
type: 'string',
title: 'Provider type',
enum: providersEnum,
default: providersEnum[0],
'x-schema-form': {
titleMap: providersTitleMap,
schedule: {
type: 'string',
title: 'Schedule',
'x-schema-form': {
'cron-expression': true,
},
},
provider: {
type: 'string',
title: 'Provider type',
enum: providersEnum,
default: providersEnum[0],
'x-schema-form': {
titleMap: providersTitleMap,
},
},
},
},
required: ['schedule', 'provider'],
};
required: ['schedule', 'provider'],
};
}

const defaultProvider = this.providers[0];

this._propertySchemaForm = {
properties: { ...defaultSchema.properties, configuration: defaultProvider.schema },
required: defaultSchema.required,
properties: { ...this.dynamicPropertySchema.properties, configuration: defaultProvider.schema },
required: this.dynamicPropertySchema.required,
};
this._providerDocumentation = defaultProvider.documentation;
this._maximizeBottomView();
Expand Down
3 changes: 3 additions & 0 deletions src/policy-studio/gv-policy-studio.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const FLOW_STEP_FORM_ID = 'flow-step-form';
* @attr {Array} services - Services available
* @attr {Array} resourceTypes - Resources types available
* @attr {Array} propertyProviders - Providers of properties
* @attr {Array} dynamicPropertySchema - Schema for the dynamic property form
* @attr {String} tabId - Current tabId to display (design, settings, properties or resources)
* @attr {Object} definition - The definition of flows
* @attr {Object} documentation - The documentation to display
Expand All @@ -70,6 +71,7 @@ export class GvPolicyStudio extends KeyboardElement(LitElement) {
services: { type: Object },
resourceTypes: { type: Array, attribute: 'resource-types' },
propertyProviders: { type: Array, attribute: 'property-providers' },
dynamicPropertySchema: { type: Object, attribute: 'dynamic-property-schema' },
tabId: { type: String, attribute: 'tab-id' },
_tabId: { type: String, attribute: false },
definition: { type: Object },
Expand Down Expand Up @@ -1704,6 +1706,7 @@ export class GvPolicyStudio extends KeyboardElement(LitElement) {
?readonly="${readonlyMode}"
.properties="${this.definedProperties}"
.providers="${this.propertyProviders}"
.dynamicPropertySchema="${this.dynamicPropertySchema}"
></gv-properties>
<gv-resources
id="resources"
Expand Down

0 comments on commit 0e894f5

Please sign in to comment.