From 72be5088f9f3ed770df04627e8652b8a78d4e20b Mon Sep 17 00:00:00 2001 From: Prajwol Bhandari Date: Tue, 13 Feb 2024 11:23:24 -0700 Subject: [PATCH] feat(client): Ability to set a default history time to live via flags.json Related to https://github.com/camunda/camunda-modeler/issues/3869, https://github.com/camunda/camunda-modeler/issues/4062 Signed-off-by: Bhandari, Prajwol --- client/src/app/TabsProvider.js | 15 ++++++-- client/src/app/__tests__/TabsProviderSpec.js | 34 +++++++++++++++++-- .../app/tabs/bpmn/__tests__/DiagramSpec.js | 11 +----- client/src/app/tabs/bpmn/diagram.bpmn | 2 +- client/src/util/Flags.js | 2 ++ 5 files changed, 49 insertions(+), 15 deletions(-) diff --git a/client/src/app/TabsProvider.js b/client/src/app/TabsProvider.js index e1d509e48a..c494bc8119 100644 --- a/client/src/app/TabsProvider.js +++ b/client/src/app/TabsProvider.js @@ -53,7 +53,8 @@ import Flags, { DISABLE_ZEEBE, DISABLE_PLATFORM, DISABLE_CMMN, - DISABLE_HTTL_HINT + DISABLE_HTTL_HINT, + DEFAULT_HISTORY_TTL } from '../util/Flags'; import BPMNIcon from '../../resources/icons/file-types/BPMN-16x16.svg'; @@ -627,7 +628,7 @@ export default class TabsProvider { _getInitialFileContents(type) { const rawContents = this.getProvider(type).getInitialContents(); - return rawContents && replaceExporter(replaceVersions(replaceIds(rawContents, generateId))); + return rawContents && replaceHistoryTimeToLive(replaceExporter(replaceVersions(replaceIds(rawContents, generateId)))); } _getTabType(file) { @@ -750,3 +751,13 @@ function DisableHTTLHintPlugin() { } }; } + +function replaceHistoryTimeToLive(contents) { + if (!Flags.get(DEFAULT_HISTORY_TTL)) { + return contents.replace('camunda:historyTimeToLive="{{ DEFAULT_HISTORY_TTL }}"', ''); + } + return ( + contents + .replace('{{ DEFAULT_HISTORY_TTL }}', Flags.get(DEFAULT_HISTORY_TTL)) + ); +} diff --git a/client/src/app/__tests__/TabsProviderSpec.js b/client/src/app/__tests__/TabsProviderSpec.js index 82b64d4c79..348b4d78ad 100644 --- a/client/src/app/__tests__/TabsProviderSpec.js +++ b/client/src/app/__tests__/TabsProviderSpec.js @@ -17,7 +17,8 @@ import Flags, { DISABLE_CMMN, CLOUD_ENGINE_VERSION, PLATFORM_ENGINE_VERSION, - DISABLE_HTTL_HINT + DISABLE_HTTL_HINT, + DEFAULT_HISTORY_TTL } from '../../util/Flags'; import { @@ -1134,7 +1135,6 @@ describe('TabsProvider', function() { expect(tabsProvider.hasProvider('cmmn')).to.be.true; }); - it('should disable HTTL hint', async function() { // given @@ -1160,6 +1160,36 @@ describe('TabsProvider', function() { expect(customLinter.getPlugins()).to.have.length(1); }); + it('should return default history ttl', function() { + + // given + Flags.init({}); + const tabsProvider = new TabsProvider(); + + // when + const { file: { contents } } = tabsProvider.createTab('bpmn'); + + // then + expect(contents).to.not.include('historyTimeToLive'); + + }); + + it('should replace history ttl placeholder with version from flag (BPMN)', function() { + + // given + Flags.init({ + [DEFAULT_HISTORY_TTL]: '30' + }); + const tabsProvider = new TabsProvider(); + + // when + const { file: { contents } } = tabsProvider.createTab('bpmn'); + + // then + expect(contents).to.include('historyTimeToLive="30"'); + }); + + }); diff --git a/client/src/app/tabs/bpmn/__tests__/DiagramSpec.js b/client/src/app/tabs/bpmn/__tests__/DiagramSpec.js index 452f0a3ab5..5700b46789 100644 --- a/client/src/app/tabs/bpmn/__tests__/DiagramSpec.js +++ b/client/src/app/tabs/bpmn/__tests__/DiagramSpec.js @@ -20,16 +20,7 @@ describe('tabs/bpmn', function() { // then expect(contents).to.contain('id="Definitions_{{ ID }}"'); expect(contents).to.contain('id="Process_{{ ID:process }}"'); - }); - - - it('should contain defaults', function() { - - // when - const contents = require('../diagram.bpmn'); - - // then - expect(contents).not.to.contain('camunda:historyTimeToLive="180"'); + expect(contents).to.contain('historyTimeToLive="{{ DEFAULT_HISTORY_TTL }}'); }); }); diff --git a/client/src/app/tabs/bpmn/diagram.bpmn b/client/src/app/tabs/bpmn/diagram.bpmn index cfee010d09..ee949232a8 100644 --- a/client/src/app/tabs/bpmn/diagram.bpmn +++ b/client/src/app/tabs/bpmn/diagram.bpmn @@ -1,6 +1,6 @@ - + diff --git a/client/src/util/Flags.js b/client/src/util/Flags.js index a6626e3a83..8760905e2a 100644 --- a/client/src/util/Flags.js +++ b/client/src/util/Flags.js @@ -49,3 +49,5 @@ export const DISPLAY_VERSION = 'display-version'; export const CLOUD_ENGINE_VERSION = 'c8-engine-version'; export const PLATFORM_ENGINE_VERSION = 'c7-engine-version'; export const DISABLE_HTTL_HINT = 'disable-httl-hint'; +export const DEFAULT_HISTORY_TTL = 'default-history-ttl'; +