diff --git a/core/src/core-api/config.js b/core/src/core-api/config.js index 98914d5cf7..f81c50bf3c 100644 --- a/core/src/core-api/config.js +++ b/core/src/core-api/config.js @@ -1,6 +1,7 @@ import { AsyncHelpers, EventListenerHelpers, GenericHelpers, StateHelpers } from '../utilities/helpers'; import { LuigiAuth, LuigiElements } from '.'; import { AuthLayerSvc, LifecycleHooks } from '../services'; +import { NodeDataManagementStorage } from '../services/node-data-management.js'; /** * @name Configuration */ @@ -279,6 +280,32 @@ class LuigiConfig { this.unload(); this.setConfig(cfg); } + + /** + * Clear navigation node related caches. + * @memberof Configuration + * @example + * Luigi.clearNavigationCache(); + * @since NEXT_RELEASE + */ + clearNavigationCache() { + NodeDataManagementStorage.deleteCache(); + + const clearTitleResolverCache = nodes => { + if (nodes && nodes.forEach) { + nodes.forEach(node => { + if (node.titleResolver && node.titleResolver._cache) { + node.titleResolver._cache = undefined; + } + if (node.children) { + clearTitleResolverCache(node.children); + } + }); + } + }; + + clearTitleResolverCache(this.getConfig().navigation.nodes); + } } export const config = new LuigiConfig(); diff --git a/core/test/services/config.spec.js b/core/test/services/config.spec.js index ef3eab6e88..c58b3ccfee 100644 --- a/core/test/services/config.spec.js +++ b/core/test/services/config.spec.js @@ -39,10 +39,7 @@ describe('Config', () => { // then assert.equal(LuigiConfig.getConfigBooleanValue('whatever'), false); - assert.equal( - LuigiConfig.getConfigBooleanValue('whateverparent.whateverchild'), - false - ); + assert.equal(LuigiConfig.getConfigBooleanValue('whateverparent.whateverchild'), false); }); }); @@ -51,24 +48,13 @@ describe('Config', () => { //given LuigiConfig.config = { truthyFn: (param1, param2) => 'value' + param1 + param2, - truthyFnAsync: (param1, param2) => - Promise.resolve('value' + param1 + param2) + truthyFnAsync: (param1, param2) => Promise.resolve('value' + param1 + param2) }; - const resultTruthyFn = await LuigiConfig.executeConfigFnAsync( - 'truthyFn', - false, - 'foo', - 'bar' - ); + const resultTruthyFn = await LuigiConfig.executeConfigFnAsync('truthyFn', false, 'foo', 'bar'); assert.equal(resultTruthyFn, 'valuefoobar'); - const resultTruthyFnAsync = await LuigiConfig.executeConfigFnAsync( - 'truthyFnAsync', - false, - 'foo', - 'bar' - ); + const resultTruthyFnAsync = await LuigiConfig.executeConfigFnAsync('truthyFnAsync', false, 'foo', 'bar'); assert.equal(resultTruthyFnAsync, 'valuefoobar'); }); @@ -76,17 +62,14 @@ describe('Config', () => { //given LuigiConfig.config = {}; - const resultUndefined = await LuigiConfig.executeConfigFnAsync( - 'not.existing.value' - ); + const resultUndefined = await LuigiConfig.executeConfigFnAsync('not.existing.value'); assert.isUndefined(resultUndefined, 'async fn result is not undefined'); }); it('returns undefined on error/rejected promise', async () => { //given LuigiConfig.config = { - rejectFnAsync: (param1, param2) => - Promise.reject(new Error('rejected')), + rejectFnAsync: (param1, param2) => Promise.reject(new Error('rejected')), errFnAsync: (param1, param2) => { throw new Error({ name: 'someError', @@ -95,24 +78,18 @@ describe('Config', () => { } }; - const resultRejectFnAsync = await LuigiConfig.executeConfigFnAsync( - 'rejectFnAsync' - ); + const resultRejectFnAsync = await LuigiConfig.executeConfigFnAsync('rejectFnAsync'); assert.isUndefined(resultRejectFnAsync, 'rejection did not return'); - const resultErrFnAsync = await LuigiConfig.executeConfigFnAsync( - 'errFnAsync' - ); + const resultErrFnAsync = await LuigiConfig.executeConfigFnAsync('errFnAsync'); assert.isUndefined(resultErrFnAsync, 'error did not return'); }); it('throws an error if throwError flag is set', async () => { - sinon - .stub(AsyncHelpers, 'applyFunctionPromisified') - .returns(Promise.reject(new Error('rejected'))); + sinon.stub(AsyncHelpers, 'applyFunctionPromisified').returns(Promise.reject(new Error('rejected'))); //given LuigiConfig.config = { - rejectFnAsync: (param1, param2) => { } + rejectFnAsync: (param1, param2) => {} }; // second parameter throws an error and we want it to throw an error on failure @@ -179,4 +156,27 @@ describe('Config', () => { sinon.assert.calledOnce(console.log); }); }); + + describe('clearNavigationCache', () => { + it('should clean navigation titleResolver cache', () => { + LuigiConfig.config = { + navigation: { + nodes: { + titleResolver: { + url: 'http://localhost', + _cache: { + key: 'cacheKey', + value: 'cacheValue' + } + } + } + } + }; + LuigiConfig.clearNavigationCache(); + + const actual = LuigiConfig.getConfigValue('navigation.titleResolver._cache'); + const expected = undefined; + assert.equal(actual, expected); + }); + }); }); diff --git a/core/test/utilities/helpers/navigation-helpers.spec.js b/core/test/utilities/helpers/navigation-helpers.spec.js index 09508e340c..bf2fed26ef 100644 --- a/core/test/utilities/helpers/navigation-helpers.spec.js +++ b/core/test/utilities/helpers/navigation-helpers.spec.js @@ -3,7 +3,7 @@ const chai = require('chai'); const assert = chai.assert; const sinon = require('sinon'); -import { AuthHelpers, NavigationHelpers, GenericHelpers, RoutingHelpers } from '../../../src/utilities/helpers'; +import { AuthHelpers, NavigationHelpers, RoutingHelpers } from '../../../src/utilities/helpers'; import { LuigiAuth, LuigiConfig } from '../../../src/core-api'; import { Routing } from '../../../src/services/routing'; import { Navigation } from '../../../src/navigation/services/navigation'; @@ -490,7 +490,6 @@ describe('Navigation-helpers', () => { it('group nodes by category label', () => { nodes[1].category.collapsible = true; const result = NavigationHelpers.groupNodesBy(nodes, 'category', true); - console.log('result ', result.test['metaInfo']); assert.deepEqual(Object.keys(result), ['1', 'test', 'luigi']); assert.deepEqual(result.test['metaInfo'], { categoryUid: 'test', label: 'test', collapsible: true, order: 1 }); }); diff --git a/docs/luigi-client-api.md b/docs/luigi-client-api.md index e3d39b030c..8a6013a28b 100644 --- a/docs/luigi-client-api.md +++ b/docs/luigi-client-api.md @@ -453,11 +453,11 @@ LuigiClient.linkManager().newTab().navigate('/projects/xy/foobar'); #### preserveQueryParams -Keeps url's query parameters for a navigation request. +Keeps the URL's query parameters for a navigation request. ##### Parameters -- `preserve` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** By default, it is set to `false`. If it is set to `true` the url's query parameters will be kept after navigation. (optional, default `false`) +- `preserve` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** By default, it is set to `false`. If it is set to `true`, the URL's query parameters will be kept after navigation. (optional, default `false`) ##### Examples diff --git a/docs/luigi-core-api.md b/docs/luigi-core-api.md index f3abee487f..336d680c61 100644 --- a/docs/luigi-core-api.md +++ b/docs/luigi-core-api.md @@ -228,6 +228,20 @@ Luigi.reset(); - **since**: 1.14.0 +#### clearNavigationCache + +Clear navigation node related caches. + +##### Examples + +```javascript +Luigi.clearNavigationCache(); +``` + +**Meta** + +- **since**: NEXT_RELEASE + ## Luigi.elements()