Skip to content

Commit

Permalink
chore: make process applications a plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Feb 3, 2025
1 parent 9cda129 commit 0e654fc
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 157 deletions.
2 changes: 1 addition & 1 deletion app/lib/menu/menu-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class MenuBuilder {
this.menu.append(new MenuItem({
label: 'New Process Application',
click: function() {
app.emit('menu:action', 'create-process-application');
app.emit('menu:action', 'emit-event', { type: 'create-process-application' });

Check warning on line 276 in app/lib/menu/menu-builder.js

View check run for this annotation

Codecov / codecov/patch

app/lib/menu/menu-builder.js#L276

Added line #L276 was not covered by tests
}
}));

Expand Down
94 changes: 11 additions & 83 deletions client/src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ import pSeries from 'p-series';

import History from './History';

import ProcessApplications from './process-applications';
import { ProcessApplicationsStatusBar } from './process-applications/components';

import { PluginsRoot } from './plugins';

import * as css from './App.less';
Expand Down Expand Up @@ -96,7 +93,6 @@ const INITIAL_STATE = {
dirtyTabs: {},
unsavedTabs: {},
recentTabs: [],
processApplication: null,
layout: {},
tabs: [],
tabState: {},
Expand Down Expand Up @@ -131,33 +127,6 @@ export class App extends PureComponent {
config: this.getGlobal('config')
});

const processApplications = this.processApplications = new ProcessApplications(this);

this.getGlobal('backend').on('file-context:changed', (_, items) => {
processApplications.emit('items-changed', items);
});

this.on('app.activeTabChanged', ({ activeTab }) => {
processApplications.emit('activeTab-changed', activeTab);
});

processApplications.on('changed', () => {
const hasOpenProcessApplication = processApplications.hasOpen();

if (!hasOpenProcessApplication) {
this.setState({
processApplication: null
});
} else {
this.setState({
processApplication: {
...processApplications.getOpen(),
items: processApplications.getItems()
}
});
}
});

this.tabRef = React.createRef();

const userPlugins = this.getPlugins('client');
Expand Down Expand Up @@ -1779,41 +1748,7 @@ export class App extends PureComponent {
return this.getGlobal('dialog').show(options);
}

async showCreateProcessApplicationDialog() {
const dialog = this.getGlobal('dialog');

const [ directoryPath ] = await dialog.showOpenFilesDialog({
properties: [ 'openDirectory' ],
title: 'Create Process Application'
});

return directoryPath;
}

/**
* Create and save new process application.
*/
async createProcessApplication() {
const directoryPath = await this.showCreateProcessApplicationDialog();

if (!directoryPath) {
return;
}

const file = {
name: '.process-application',
contents: JSON.stringify({}, null, 2),
path: null
};

const fileSystem = this.getGlobal('fileSystem');

await fileSystem.writeFile(`${directoryPath}/${file.name}`, file);

this.getGlobal('backend').send('file-context:file-opened', `${directoryPath}/${file.name}`, undefined);
}

triggerAction = failSafe((action, options) => {
triggerAction = failSafe((action, options = {}) => {

const {
activeTab
Expand All @@ -1822,10 +1757,6 @@ export class App extends PureComponent {

log('App#triggerAction %s %o', action, options);

if (action === 'create-process-application') {
return this.createProcessApplication();
}

if (action === 'lint-tab') {
const {
tab,
Expand Down Expand Up @@ -1884,6 +1815,12 @@ export class App extends PureComponent {
}

if (action === 'open-diagram') {
const { path } = options;

Check warning on line 1818 in client/src/app/App.js

View check run for this annotation

Codecov / codecov/patch

client/src/app/App.js#L1818

Added line #L1818 was not covered by tests

if (path) {
return this.readFileFromPath(path).then(file => this.openFiles([ file ]));

Check warning on line 1821 in client/src/app/App.js

View check run for this annotation

Codecov / codecov/patch

client/src/app/App.js#L1820-L1821

Added lines #L1820 - L1821 were not covered by tests
}

return this.showOpenFilesDialog();
}

Expand Down Expand Up @@ -2197,7 +2134,7 @@ export class App extends PureComponent {
title: 'Welcome Screen'
} }
draggable
processApplication={ this.state.processApplication }
processApplication={ null }
/>

<TabContainer className="main">
Expand Down Expand Up @@ -2247,17 +2184,6 @@ export class App extends PureComponent {

<StatusBar />

<ProcessApplicationsStatusBar
activeTab={ activeTab }
processApplication={ this.state.processApplication }
onOpen={ async (path) => {
const files = await this.readFileList([ path ]);

await this.openFiles(files);
} }
tabsProvider={ this.props.tabsProvider }
/>

<PluginsRoot
app={ this }
plugins={ this.plugins }
Expand All @@ -2283,11 +2209,13 @@ export class App extends PureComponent {

_getNewFileItems = () => {
let items = [

// TODO: make this configurable
{
text: 'Process application',
group: 'Camunda 8',
icon: ProcessApplicationIcon,
onClick: () => this.triggerAction('create-process-application')
onClick: () => this.triggerAction('emit-event', { type: 'create-process-application' })

Check warning on line 2218 in client/src/app/App.js

View check run for this annotation

Codecov / codecov/patch

client/src/app/App.js#L2218

Added line #L2218 was not covered by tests
}
];

Expand Down
12 changes: 5 additions & 7 deletions client/src/app/primitives/TabLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ export default class TabLinks extends PureComponent {
onContextMenu,
onClose,
placeholder,
processApplication,
className,
isDirty = () => false
} = this.props;
Expand All @@ -110,14 +109,11 @@ export default class TabLinks extends PureComponent {
const dirty = isDirty(tab);
const active = tab === activeTab;

const isProcessApplication = processApplication && processApplication.items.some(item => item.file.path === tab.file.path);

return (
<Tab
key={ tab.id }
tab={ tab }
active={ active }
processApplication={ isProcessApplication }
dirty={ dirty }
getTabIcon={ getTabIcon }
onClose={ onClose }
Expand Down Expand Up @@ -158,7 +154,6 @@ function Tab(props) {
onClose,
onContextMenu,
onSelect,
processApplication,
tab
} = props;

Expand All @@ -183,6 +178,10 @@ function Tab(props) {
return () => resizeObserver.disconnect();
}, [ tabNode ]);

const { group } = tab;

console.log('group', group);

return (
<div
tabIndex="0"
Expand All @@ -193,8 +192,7 @@ function Tab(props) {
'tab--active': active,
'tab--dirty': dirty,
'tab--small': small,
'tab--smaller': smaller,
'tab--process-application': processApplication
'tab--smaller': smaller
}) }
onClick={ (event) => onSelect(tab, event) }
onAuxClick={ (event) => {
Expand Down

This file was deleted.

11 changes: 0 additions & 11 deletions client/src/app/process-applications/components/index.js

This file was deleted.

2 changes: 2 additions & 0 deletions client/src/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import CreateNewAction from './create-new-action';
import ElementTemplatesModal from './element-templates-modal';
import ErrorTracking from './error-tracking';
import PrivacyPreferences from './privacy-preferences';
import ProcessApplications from './process-applications';
import ReportFeedback from './report-feedback';
import UpdateChecks from './update-checks';
import UserJourneyStatistics from './user-journey-statistics';
Expand All @@ -28,6 +29,7 @@ export default [
ElementTemplatesModal,
ErrorTracking,
PrivacyPreferences,
ProcessApplications,
ReportFeedback,
UpdateChecks,
VersionInfo,
Expand Down
File renamed without changes.
100 changes: 100 additions & 0 deletions client/src/plugins/process-applications/ProcessApplicationsPlugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership.
*
* Camunda licenses this file to you under the MIT; you may not use this file
* except in compliance with the MIT License.
*/

import React, { useEffect, useState } from 'react';

import ProcessApplications from './ProcessApplications';
import ProcessApplicationsStatusBar from './ProcessApplicationsStatusBar';

const processApplications = new ProcessApplications();

const DOCUMENTATION_URL = 'https://docs.camunda.io/docs/components/modeler/web-modeler/process-applications/';

export default function ProcessApplicationsPlugin(props) {
const {
_getFromApp: getFromApp,
_getGlobal: getGlobal,
subscribe,
triggerAction
} = props;

const [ activeTab, setActiveTab ] = useState(null);
const [ processApplication, setProcessApplication ] = useState(null);
const [ processApplicationItems, setProcessApplicationItems ] = useState([]);

useEffect(() => {
subscribe('app.activeTabChanged', (event) => {
const { activeTab } = event;

setActiveTab(activeTab);

processApplications.emit('activeTab-changed', activeTab);
});

subscribe('create-process-application', async () => {
const dialog = getGlobal('dialog');

Check warning on line 42 in client/src/plugins/process-applications/ProcessApplicationsPlugin.js

View check run for this annotation

Codecov / codecov/patch

client/src/plugins/process-applications/ProcessApplicationsPlugin.js#L42

Added line #L42 was not covered by tests

const [ directoryPath ] = await dialog.showOpenFilesDialog({

Check warning on line 44 in client/src/plugins/process-applications/ProcessApplicationsPlugin.js

View check run for this annotation

Codecov / codecov/patch

client/src/plugins/process-applications/ProcessApplicationsPlugin.js#L44

Added line #L44 was not covered by tests
properties: [ 'openDirectory' ],
title: 'Create Process Application'
});

if (!directoryPath) {
return;

Check warning on line 50 in client/src/plugins/process-applications/ProcessApplicationsPlugin.js

View check run for this annotation

Codecov / codecov/patch

client/src/plugins/process-applications/ProcessApplicationsPlugin.js#L49-L50

Added lines #L49 - L50 were not covered by tests
}

const file = createProcessApplicationFile();

Check warning on line 53 in client/src/plugins/process-applications/ProcessApplicationsPlugin.js

View check run for this annotation

Codecov / codecov/patch

client/src/plugins/process-applications/ProcessApplicationsPlugin.js#L53

Added line #L53 was not covered by tests

const fileSystem = getGlobal('fileSystem');

Check warning on line 55 in client/src/plugins/process-applications/ProcessApplicationsPlugin.js

View check run for this annotation

Codecov / codecov/patch

client/src/plugins/process-applications/ProcessApplicationsPlugin.js#L55

Added line #L55 was not covered by tests

await fileSystem.writeFile(`${directoryPath}/${file.name}`, file);

Check warning on line 57 in client/src/plugins/process-applications/ProcessApplicationsPlugin.js

View check run for this annotation

Codecov / codecov/patch

client/src/plugins/process-applications/ProcessApplicationsPlugin.js#L57

Added line #L57 was not covered by tests

getGlobal('backend').send('file-context:file-opened', `${directoryPath}/${file.name}`, undefined);

Check warning on line 59 in client/src/plugins/process-applications/ProcessApplicationsPlugin.js

View check run for this annotation

Codecov / codecov/patch

client/src/plugins/process-applications/ProcessApplicationsPlugin.js#L59

Added line #L59 was not covered by tests

triggerAction('display-notification', {

Check warning on line 61 in client/src/plugins/process-applications/ProcessApplicationsPlugin.js

View check run for this annotation

Codecov / codecov/patch

client/src/plugins/process-applications/ProcessApplicationsPlugin.js#L61

Added line #L61 was not covered by tests
type: 'success',
title: 'Process application created',
content: <a href={ DOCUMENTATION_URL }>Learn more about process applications</a>
});
});

getGlobal('backend').on('file-context:changed', (_, items) => {
processApplications.emit('items-changed', items);

Check warning on line 69 in client/src/plugins/process-applications/ProcessApplicationsPlugin.js

View check run for this annotation

Codecov / codecov/patch

client/src/plugins/process-applications/ProcessApplicationsPlugin.js#L69

Added line #L69 was not covered by tests
});

processApplications.on('changed', () => {
const hasOpen = processApplications.hasOpen();

Check warning on line 73 in client/src/plugins/process-applications/ProcessApplicationsPlugin.js

View check run for this annotation

Codecov / codecov/patch

client/src/plugins/process-applications/ProcessApplicationsPlugin.js#L73

Added line #L73 was not covered by tests

if (hasOpen) {
setProcessApplication(processApplications.getOpen());
setProcessApplicationItems(processApplications.getItems());

Check warning on line 77 in client/src/plugins/process-applications/ProcessApplicationsPlugin.js

View check run for this annotation

Codecov / codecov/patch

client/src/plugins/process-applications/ProcessApplicationsPlugin.js#L75-L77

Added lines #L75 - L77 were not covered by tests
} else {
setProcessApplication(null);
setProcessApplicationItems([]);

Check warning on line 80 in client/src/plugins/process-applications/ProcessApplicationsPlugin.js

View check run for this annotation

Codecov / codecov/patch

client/src/plugins/process-applications/ProcessApplicationsPlugin.js#L79-L80

Added lines #L79 - L80 were not covered by tests
}
});
}, []);

return <ProcessApplicationsStatusBar
activeTab={ activeTab }
processApplication={ processApplication }
processApplicationItems={ processApplicationItems }
onOpen={ (path) => triggerAction('open-diagram', { path }) }

Check warning on line 89 in client/src/plugins/process-applications/ProcessApplicationsPlugin.js

View check run for this annotation

Codecov / codecov/patch

client/src/plugins/process-applications/ProcessApplicationsPlugin.js#L89

Added line #L89 was not covered by tests
tabsProvider={ getFromApp('props').tabsProvider }
/>;
}

function createProcessApplicationFile(contents = {}) {
return {

Check warning on line 95 in client/src/plugins/process-applications/ProcessApplicationsPlugin.js

View check run for this annotation

Codecov / codecov/patch

client/src/plugins/process-applications/ProcessApplicationsPlugin.js#L95

Added line #L95 was not covered by tests
name: '.process-application',
contents: JSON.stringify(contents, null, 2),
path: null
};
}
Loading

0 comments on commit 0e654fc

Please sign in to comment.