Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

feat(zeebe-plugin): persist endpoints and deployment config separately #197

Merged
merged 1 commit into from
Apr 6, 2020
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
Expand Up @@ -23,7 +23,8 @@ import DeploymentPluginValidator from './DeploymentPluginValidator';

import KeyboardInteractionTrap from './ui/KeyboardInteractionTrap';

const DEPLOYMENT_CONFIG_KEY = 'DEPLOYMENT_CONFIG';
const DEPLOYMENT_CONFIG_KEY = 'deployment-tool';
const ZEEBE_ENDPOINTS_CONFIG_KEY = 'zeebeEndpoints';

export default class DeploymentPlugin extends PureComponent {

Expand Down Expand Up @@ -64,13 +65,70 @@ export default class DeploymentPlugin extends PureComponent {
this.props.unsubscribeFromMessaging('deploymentPlugin');
}

getConfig = async () => {
const storedConfig = await this.props.config.get(DEPLOYMENT_CONFIG_KEY);
return storedConfig || {};
saveConfiguration = async (configuration) => {

const {
endpoint,
deployment
} = configuration;

await this.saveEndpoint(endpoint);

const tabConfiguration = {
deployment,
endpointId: endpoint.id
};

await this.setTabConfiguration(this.activeTab, tabConfiguration);

return configuration;
}

setConfig = (config) => {
this.props.config.set(DEPLOYMENT_CONFIG_KEY, config);
getSavedConfiguration = async () => {

const tabConfig = await this.getTabConfiguration(this.activeTab);

if (!tabConfig) {
return {};
}

const {
deployment,
endpointId
} = tabConfig;

const endpoints = await this.getEndpoints();

return {
deployment,
endpoint: endpoints.find(endpoint => endpoint.id === endpointId)
};
}

async saveEndpoint(endpoint) {
const existingEndpoints = await this.getEndpoints();

const updatedEndpoints = addOrUpdateById(existingEndpoints, endpoint);

await this.setEndpoints(updatedEndpoints);

return endpoint;
}

getEndpoints() {
return this.props.config.get(ZEEBE_ENDPOINTS_CONFIG_KEY, []);
}

setEndpoints(endpoints) {
return this.props.config.set(ZEEBE_ENDPOINTS_CONFIG_KEY, endpoints);
}

getTabConfiguration(tab) {
return this.props.config.getForFile(tab.file, DEPLOYMENT_CONFIG_KEY);
}

setTabConfiguration(tab, configuration) {
return this.props.config.setForFile(tab.file, DEPLOYMENT_CONFIG_KEY, configuration);
}

onDeploymentSuccess = (response) => {
Expand Down Expand Up @@ -173,8 +231,8 @@ export default class DeploymentPlugin extends PureComponent {
onClose={ this.closeModal }
validator={ this.validator }
onDeploy={ this.onDeploy }
getConfig={ this.getConfig }
setConfig={ this.setConfig }
getConfig={ this.getSavedConfiguration }
setConfig={ this.saveConfiguration }
tabName={ withoutExtension(this.activeTab.name) }
isStart={ isStart }
/>
Expand All @@ -189,3 +247,21 @@ export default class DeploymentPlugin extends PureComponent {
function withoutExtension(name) {
return name.replace(/\.[^.]+$/, '');
}

function addOrUpdateById(collection, element) {

const index = collection.findIndex(el => el.id === element.id);

if (index !== -1) {
return [
...collection.slice(0, index),
element,
...collection.slice(index + 1)
];
}

return [
...collection,
element
];
}
Loading