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

Make navigateIframe and prepareInternalData functions be async #1799

Merged
merged 3 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 7 additions & 17 deletions core/src/App.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,12 @@
export let searchResult;
let featureToggleList;

const prepareInternalData = config => {
const prepareInternalData = async config => {
const iframeConf = config.iframe.luigi;
featureToggleList = LuigiFeatureToggles.getActiveFeatureToggleList();
const userSettingsGroupName = iframeConf.currentNode && iframeConf.currentNode.userSettingsGroup;
const userSettingGroups = await LuigiConfig.readUserSettings();
const hasUserSettings = (userSettingsGroupName && typeof userSettingGroups === 'object' && userSettingGroups !== null);
const internalData = {
isNavigateBack,
viewStackSize: preservedViews.length,
Expand All @@ -229,7 +232,8 @@
currentTheme: LuigiTheming.getCurrentTheme(),
clientPermissions: iframeConf.nextViewUrl
? iframeConf.nextClientPermissions
: iframeConf.clientPermissions
: iframeConf.clientPermissions,
userSettings: hasUserSettings ? userSettingGroups[userSettingsGroupName] : null
};

IframeHelpers.specialIframeTypes
Expand All @@ -247,20 +251,6 @@
return;
}

let internal = prepareInternalData(config);
const userSettingsGroupName =
config.iframe.luigi.currentNode.userSettingsGroup;
const userSettingGroups = await LuigiConfig.readUserSettings();

if (
userSettingsGroupName &&
typeof userSettingGroups === 'object' &&
userSettingGroups !== null
) {
const userSettings = userSettingGroups[userSettingsGroupName];
internal = { ...internal, userSettings };
}

const message = {
msg: 'luigi.init',
context: JSON.stringify(
Expand All @@ -272,7 +262,7 @@
pathParams: JSON.stringify(
Object.assign({}, config.pathParams || pathParams)
),
internal: JSON.stringify(internal),
internal: JSON.stringify(await prepareInternalData(config)),
authData: AuthHelpers.getStoredAuthData()
};

Expand Down
6 changes: 4 additions & 2 deletions core/src/services/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class IframeClass {
return !config.iframe.luigi.initOk;
}

navigateIframe(config, component, node) {
async navigateIframe(config, component, node) {
stanleychh marked this conversation as resolved.
Show resolved Hide resolved
clearTimeout(this.timeoutHandle);
const componentData = component.get();
let viewUrl = componentData.viewUrl;
Expand Down Expand Up @@ -347,6 +347,8 @@ class IframeClass {
config.iframe['vg'] = this.canCache(componentData.viewGroup)
? componentData.viewGroup
: undefined;
config.iframe.luigi.currentNode = componentData.currentNode;
const internalData = await component.prepareInternalData(config);
stanleychh marked this conversation as resolved.
Show resolved Hide resolved
const message = {
msg: 'luigi.navigate',
viewUrl: viewUrl,
Expand All @@ -355,7 +357,7 @@ class IframeClass {
),
nodeParams: JSON.stringify(Object.assign({}, componentData.nodeParams)),
pathParams: JSON.stringify(Object.assign({}, componentData.pathParams)),
internal: JSON.stringify(component.prepareInternalData(config))
internal: JSON.stringify(internalData)
};

const withSync = componentData.isNavigationSyncEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
NodeParams,
uxManager,
getActiveFeatureToggles,
getUserSettings
getUserSettings,
addContextUpdateListener
} from '@luigi-project/client';
import { Subscription } from 'rxjs';

Expand Down Expand Up @@ -61,6 +62,10 @@ export class SettingsComponent implements OnInit {
}
});

addContextUpdateListener(context => {
this.userSettings = getUserSettings();
});

// We suggest to use a centralized approach of LuigiClient.addContextUpdateListener
// Take a look at ngOnInit in this component and app.component.ts where we set the listeners.
this.lcSubscription = this.luigiService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export const projectDetailNavStructure = projectId => [
label: 'User Settings',
viewUrl: '/sampleapp.html#/projects/' + projectId + '/settings',
icon: 'settings',
isolateView: true,
userSettingsGroup: 'userAccount',
testId: 'myTestId'
},
Expand Down