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

Enable connector templates per default #4474

Merged
merged 7 commits into from
Aug 26, 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
Expand Up @@ -17,10 +17,11 @@ const { Agent, MockAgent, setGlobalDispatcher } = require('undici');

const { isString } = require('min-dash');

const { updateConnectorTemplates } = require('../updateConnectorTemplates');
const { updateConnectorTemplates } = require('..');

const userPath = path.resolve(__dirname, 'tmp');


describe('updateConnectorTemplates', function() {

let mockAgent;
Expand Down Expand Up @@ -297,7 +298,7 @@ describe('updateConnectorTemplates', function() {

// then
expect(sendSpy).to.have.been.calledWith('client:connector-templates-update-success', true, [
'Unable to fetch Camunda connector template Foo'
'Unable to fetch template Foo'
]);

expectConnectorTemplates(userPath, [
Expand Down Expand Up @@ -372,7 +373,7 @@ describe('updateConnectorTemplates', function() {

// then
expect(sendSpy).to.have.been.calledWith('client:connector-templates-update-success', true, [
'Unable to fetch Camunda connector template Foo'
'Unable to fetch template Foo'
]);

expectConnectorTemplates(userPath, [
Expand Down Expand Up @@ -447,7 +448,7 @@ describe('updateConnectorTemplates', function() {

// then
expect(sendSpy).to.have.been.calledWith('client:connector-templates-update-success', true, [
'Unable to fetch Camunda connector template Foo'
'Unable to fetch template Foo'
]);

expectConnectorTemplates(userPath, [
Expand Down Expand Up @@ -500,4 +501,4 @@ async function expectNoConnectorTemplates(userPath) {
const connectorTemplatesFilePath = getConnectorTemplatesFilePath(userPath);

expect(fs.existsSync(connectorTemplatesFilePath)).to.be.false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ function getConnectorTemplatesPath(userPath) {
module.exports.getConnectorTemplatesPath = getConnectorTemplatesPath;

async function updateConnectorTemplates(renderer, userPath) {

const t = Date.now();

log.info('Starting update');

try {
const connectorTemplatesPath = getConnectorTemplatesPath(userPath);

Expand Down Expand Up @@ -65,6 +70,8 @@ async function updateConnectorTemplates(renderer, userPath) {
} catch (error) {
renderer.send('client:connector-templates-update-error', error.message);
}

log.info('Update done in %sms', Date.now() - t);
}

module.exports.updateConnectorTemplates = updateConnectorTemplates;
Expand All @@ -76,12 +83,14 @@ module.exports.updateConnectorTemplates = updateConnectorTemplates;
* @returns {Promise<Template[]>}
*/
async function fetchLatestConnectorTemplates() {
log.info('Fetching Camunda connector templates');
log.info('Fetching latest templates');

let response = await fetch(`${ MARKET_PLACE_API_URL }/connectors?creatorType=camunda`);

if (!response.ok) {
throw new Error('Failed to fetch Camunda connector templates');
log.warn('Failed to fetch templates (HTTP %s)', response.status);

throw new Error('Failed to fetch templates');
}

const { items } = await response.json();
Expand All @@ -93,9 +102,9 @@ async function fetchLatestConnectorTemplates() {
response = await fetch(`${ MARKET_PLACE_API_URL }/connectors/${ item.id }`);

if (!response.ok) {
log.warn('Failed to fetch Camunda connector template', item.name);
log.warn('Failed to fetch template', item.name);

warnings.push(`Unable to fetch Camunda connector template ${ item.name }`);
warnings.push(`Unable to fetch template ${ item.name }`);

continue;
}
Expand All @@ -106,9 +115,9 @@ async function fetchLatestConnectorTemplates() {
response = await fetch(template.url);

if (!response.ok) {
log.warn('Failed to fetch Camunda connector template', item.name);
log.warn('Failed to fetch template', item.name);

warnings.push(`Unable to fetch Camunda connector template ${ item.name }`);
warnings.push(`Unable to fetch template ${ item.name }`);

continue;
}
Expand All @@ -120,17 +129,19 @@ async function fetchLatestConnectorTemplates() {

latestConnectorTemplates.push(templateJson);

log.info('Fetched Camunda connector template', templateJson.id);
log.info('Fetched template', templateJson.id);
} catch (error) {
log.warn('Failed to fetch Camunda connector template', item.name);
log.warn('Failed to fetch template', item.name);

warnings.push(`Unable to fetch Camunda connector template ${ item.name }`);
warnings.push(`Unable to fetch template ${ item.name }`);

continue;
}
}
}

log.info('Fetched latest templates');

return { latestConnectorTemplates, warnings };
}

Expand Down Expand Up @@ -161,13 +172,13 @@ function mergeConnectorTemplates(connectorTemplates, latestConnectorTemplates) {

replaced++;

log.info('Replaced Camunda connector template', latestConnectorTemplate.id);
log.info('Replaced template', latestConnectorTemplate.id);
} else {
mergedConnectorTemplates.push(latestConnectorTemplate);

added++;

log.info('Added Camunda connector template', latestConnectorTemplate.id);
log.info('Added template', latestConnectorTemplate.id);
}
}

Expand All @@ -176,4 +187,32 @@ function mergeConnectorTemplates(connectorTemplates, latestConnectorTemplates) {
added,
replaced
};
}
}

const ONE_DAY_MS = 1000 * 60 * 60 * 24;

/**
* @param {import('../util/renderer') } renderer
* @param {string} userPath
*/
function registerConnectorTemplateUpdater(renderer, userPath) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 👏🏻


let shouldUpdate = true;

setInterval(() => {
shouldUpdate = true;
}, ONE_DAY_MS);

const handleTabChange = (newActive) => {

if (newActive?.type === 'cloud-bpmn' && shouldUpdate) {
shouldUpdate = false;

updateConnectorTemplates(renderer, userPath);
}
};

renderer.on('activeTab:change', handleTabChange);
}

module.exports.registerConnectorTemplateUpdater = registerConnectorTemplateUpdater;
12 changes: 5 additions & 7 deletions app/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const Workspace = require('./workspace');
const ZeebeAPI = require('./zeebe-api');
const {
getConnectorTemplatesPath,
updateConnectorTemplates
} = require('./connector-templates/updateConnectorTemplates');
registerConnectorTemplateUpdater
} = require('./connector-templates');

const {
readFile,
Expand Down Expand Up @@ -630,7 +630,7 @@ function bootstrap() {
// (3) config
const ignoredPaths = [];

if (!flags.get('enable-connector-templates', false)) {
if (!flags.get('enable-connector-templates', true)) {
ignoredPaths.push(getConnectorTemplatesPath(userPath));
}

Expand Down Expand Up @@ -693,10 +693,8 @@ function bootstrap() {
const zeebeAPI = new ZeebeAPI({ readFile }, ZeebeNode, flags);

// (10) connector templates
if (flags.get('enable-connector-templates', false)) {
app.on('app:client-ready', function() {
updateConnectorTemplates(renderer, userPath);
});
if (flags.get('enable-connector-templates', true)) {
registerConnectorTemplateUpdater(renderer, userPath);
}

return {
Expand Down
13 changes: 7 additions & 6 deletions app/lib/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const allowedEvents = [
'file:read',
'file:read-stats',
'file:write',
'activeTab:change',
'menu:register',
'menu:update',
'system-clipboard:write-text',
Expand Down Expand Up @@ -116,12 +117,12 @@ function createBackend(ipcRenderer, platform) {
}

/**
* Subscribe to event.
*
* @param {string} event
* @param {Function} callback
* @returns {{ cancel: () => void }}
*/
* Subscribe to event.
*
* @param {string} event
* @param {Function} callback
* @returns {{ cancel: () => void }}
*/
function on(event, callback) {
ipcRenderer.on(event, callback);

Expand Down
8 changes: 8 additions & 0 deletions app/lib/util/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const {
} = require('min-dash');


const log = require('../log')('app:renderer');

function on(event, callback, that) {

ipcMain.on(event, function(evt, id, args) {
Expand Down Expand Up @@ -65,6 +67,12 @@ module.exports.onSync = onSync;
function send() {
var args = Array.prototype.slice.call(arguments);

if (!app.mainWindow) {
log.warn('trying to send to non-existing client window', args[0]);

return;
}

app.mainWindow.webContents.send.apply(app.mainWindow.webContents, args);
}

Expand Down
12 changes: 11 additions & 1 deletion client/src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
isString,
map,
merge,
reduce
reduce,
pick
} from 'min-dash';

import EventEmitter from 'events';
Expand Down Expand Up @@ -351,6 +352,8 @@ export class App extends PureComponent {
return tabShown.promise;
}

this.handleActiveTabChange(tab, activeTab);

if (!this.isEmptyTab(tab)) {
const navigationHistory = this.navigationHistory;

Expand All @@ -361,6 +364,7 @@ export class App extends PureComponent {

const deferred = pDefer();


this.setState({
activeTab: tab,
Tab: this.getTabComponent(tab),
Expand Down Expand Up @@ -1942,6 +1946,12 @@ export class App extends PureComponent {
return tab.triggerAction(action, options);
}, this.handleError);

handleActiveTabChange(newActive, oldActive) {
const stripTab = (tab) => tab && pick(tab, [ 'id', 'type' ]);

this.getGlobal('backend').send('activeTab:change', stripTab(newActive), stripTab(oldActive));
}

openExternalUrl(options) {
this.getGlobal('backend').send('external:open-url', options);
}
Expand Down
31 changes: 31 additions & 0 deletions client/src/app/__tests__/AppSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,7 @@ describe('<App>', function() {

});


describe('tab errors', function() {

it('should propagate', async function() {
Expand Down Expand Up @@ -2757,6 +2758,36 @@ describe('<App>', function() {
});


it('#handleActiveTabChange', async function() {

// given
const sendSpy = spy();

const backend = new Backend({
send: sendSpy
});

const { app } = createApp({
globals: {
backend
}
});

// when
const {
id,
type
} = await app.createDiagram('cloud-bpmn');

// then
expect(sendSpy).to.have.been.calledWith(
'activeTab:change',
{ id, type },
EMPTY_TAB
);
});


describe('modal handling', function() {

let app;
Expand Down
2 changes: 2 additions & 0 deletions client/src/app/__tests__/mocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ export class Backend extends Mock {

sendReady() { }

send() { }

on(event, listener) {
this.listeners[event] = (this.listeners[event] || []).concat([ listener.bind(this) ]);

Expand Down
4 changes: 2 additions & 2 deletions client/src/plugins/version-info/ReleaseInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export function ReleaseInfo(props) {
<div className={ css.ReleaseInfo }>
<ul className="dashed">
<li>
<h4>Support for Camunda 8.6 features</h4>
This release adds support for upcoming Camunda 8.6 features, including execution listeners, the new binding type property, and converging inclusive gateways.
<h4>Camunda 8 Connector support</h4>
Use Camunda 8 Connectors to access a growing range of external services and communication protocols. You can now quickly and easily add pre-built Camunda connectors to your BPMN processes. To learn how to configure this feature, check out the <a href="https://docs.camunda.io/docs/components/modeler/desktop-modeler/use-connectors/">connector documentation</a>.
</li>
<li>
<h4>Adaptable input fields</h4>
Expand Down