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

Bugfix/preserve view contentarea #224

Merged
merged 15 commits into from
Nov 21, 2018
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
1 change: 0 additions & 1 deletion client/luigi-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
_callAllFns(_onInitFns, currentContext.context);
} else if ('luigi.navigate' === e.data.msg) {
setContext(e.data);

if (!currentContext.internal.isNavigateBack) {
var hashRoutingModeActive =
e.data.viewUrl.indexOf('#') !== -1 &&
Expand Down
6 changes: 3 additions & 3 deletions core/src/App.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,11 @@

if ('luigi.navigation.open' === e.data.msg) {
this.set({ isNavigateBack: false });
handleNavigation(this, e.data, config);
await handleNavigation(this, e.data, config);
}

if ('luigi.navigation.back' === e.data.msg) {
// go back: context from the view
this.set({ isNavigateBack: false });
const preservedViews = this.get().preservedViews;
if (preservedViews && preservedViews.length) {
// remove current active iframe and data
Expand All @@ -238,11 +237,12 @@
});

// TODO: check if handleNavigation or history pop to update hash / path
handleNavigation(
await handleNavigation(
this,
{ params: { link: previousActiveIframeData.path } },
config
);
this.set({ goBackContext: undefined, isNavigateBack: false });
} else {
console.error('goBack() not possible, no preserved views found.');
}
Expand Down
22 changes: 9 additions & 13 deletions core/src/services/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,6 @@ const navigateIframe = (config, component, node) => {
},
'*'
);
// clear goBackContext after sending it to the client
component.set({ goBackContext: undefined });

/**
* check if luigi responded
Expand Down Expand Up @@ -411,16 +409,14 @@ export const matchPath = async path => {
navigateTo used for navigation
@param route string absolute path of the new route
@param options object navi options, eg preserveView
@param windowElem object defaults to window
@param documentElem object defaults to document
*/
export const navigateTo = async (route, windowElem = window) => {
export const navigateTo = async route => {
if (LuigiConfig.getConfigValue('routing.useHashRouting')) {
windowElem.location.hash = route;
window.location.hash = route;
return;
}

windowElem.history.pushState(
window.history.pushState(
{
path: route
},
Expand All @@ -439,7 +435,7 @@ export const navigateTo = async (route, windowElem = window) => {
event = new CustomEvent('popstate');
}

windowElem.dispatchEvent(event);
window.dispatchEvent(event);
};

export const buildFromRelativePath = path => {
Expand All @@ -450,21 +446,21 @@ export const buildFromRelativePath = path => {
}
};

export const handleRouteClick = (node, windowElem = window) => {
export const handleRouteClick = node => {
if (node.externalLink && node.externalLink.url) {
node.externalLink.sameWindow
? (windowElem.location.href = node.externalLink.url)
: windowElem.open(node.externalLink.url).focus();
? (window.location.href = node.externalLink.url)
: window.open(node.externalLink.url).focus();
// externalLinkUrl property is provided so there's no need to trigger routing mechanizm
return;
} else if (node.link) {
const link = node.link.startsWith('/')
? node.link
: buildFromRelativePath(node.link);
navigateTo(link, windowElem);
navigateTo(link);
return;
} else {
const route = buildRoute(node, `/${node.pathSegment}`);
navigateTo(route, windowElem);
navigateTo(route);
}
};
13 changes: 6 additions & 7 deletions core/test/services/routing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ describe('Routing', () => {
LuigiConfig.getConfigValue.returns(true);

// when
routing.handleRouteClick(nodeWithParent, window, document);
routing.handleRouteClick(nodeWithParent);

// then
assert.equal(window.location.hash, expectedRoute);
Expand All @@ -528,7 +528,7 @@ describe('Routing', () => {
LuigiConfig.getConfigValue.returns(true);

// when
routing.handleRouteClick(nodeWithoutParent, window);
routing.handleRouteClick(nodeWithoutParent);

// then
assert.equal(window.location.hash, expectedRoute);
Expand All @@ -545,7 +545,7 @@ describe('Routing', () => {
LuigiConfig.getConfigValue.returns(false);

// when
routing.handleRouteClick(nodeWithParent, window);
routing.handleRouteClick(nodeWithParent);

// then
const pushStateArgs = window.history.pushState.args[0];
Expand All @@ -566,7 +566,7 @@ describe('Routing', () => {
LuigiConfig.getConfigValue.returns(false);

// when
routing.handleRouteClick(nodeWithoutParent, window, document);
routing.handleRouteClick(nodeWithoutParent);

// then
const pushStateArgs = window.history.pushState.args[0];
Expand All @@ -584,11 +584,10 @@ describe('Routing', () => {
window.history.pushState = sinon.spy();
window.dispatchEvent = sinon.spy();
const dispatchCallsNum = window.dispatchEvent.callCount;

// when
LuigiConfig.getConfigValue.returns(false);

routing.handleRouteClick(nodeWithoutParent, window, document);
// when
routing.handleRouteClick(nodeWithoutParent);

// then
const pushStateArgs = window.history.pushState.args[0];
Expand Down