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

Load Lens together with kibana app #50164

Merged
merged 18 commits into from Nov 20, 2019
Merged

Conversation

flash1293
Copy link
Contributor

@flash1293 flash1293 commented Nov 11, 2019

This PR hooks the lens routes into the angular routing of Kibana app and loads it in the same bundle to prevent the page load between the apps.
This changes the URL: app/lens becomes app/kibana#/lens.
Old urls are redirected to the new URL scheme.

As there is no page load in between, the local state of the data plugin can be leveraged to keep filters and time range when switching between Lens visualizations and others.

@flash1293 flash1293 changed the title Load lens together with kibana app Load Lens together with kibana app Nov 11, 2019
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💔 Build Failed

@flash1293
Copy link
Contributor Author

Making this ready for review even the build failed (error was a problem reaching github).

@flash1293 flash1293 marked this pull request as ready for review November 13, 2019 13:48
@flash1293 flash1293 added the Team:Visualizations Visualization editors, elastic-charts and infrastructure label Nov 13, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@wylieconlon wylieconlon added this to In progress in Lens Nov 14, 2019
window.location.hash.replace(/^#\//, '#/lens/');

// redirect
window.location.href = window.location.href.replace(
Copy link
Contributor

Choose a reason for hiding this comment

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

This code seems a bit brittle. Can we do something to avoid replacing the location in such a way?

Copy link
Contributor Author

@flash1293 flash1293 Nov 18, 2019

Choose a reason for hiding this comment

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

I see what you mean. This code is covering a very specific edge case - when a user bookmarks a Lens visualization in 7.5

As it's just here for BWC reasons I wanted to keep it as simple as possible. Do you have a suggestion for improvement?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with Maja. It'll still be hacky, but I'd be more OK with this if it was done inside a conditional, rather than 100% of the time that Lens loads up. (e.g. if we detect we're on a 7.5 URl, redirect to a 7.6 URL, etc).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, there might be a misconception. This isn't executed each time Lens loads - just if you navigate to app/lens (which can only happen if you have a bookmark stored because the Visualize dialog will point to app/kibana#/lens instead).

Copy link
Contributor

@majagrubic majagrubic left a comment

Choose a reason for hiding this comment

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

Works great

@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@chrisdavies chrisdavies left a comment

Choose a reason for hiding this comment

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

LGTM w/ tweaks

x-pack/legacy/plugins/lens/public/app_plugin/app.tsx Outdated Show resolved Hide resolved
window.location.hash.replace(/^#\//, '#/lens/');

// redirect
window.location.href = window.location.href.replace(
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with Maja. It'll still be hacky, but I'd be more OK with this if it was done inside a conditional, rather than 100% of the time that Lens loads up. (e.g. if we detect we're on a 7.5 URl, redirect to a 7.6 URL, etc).

@@ -26,10 +26,11 @@ export const lens: LegacyPluginInitializer = kibana => {
app: {
title: NOT_INTERNATIONALIZED_PRODUCT_NAME,
description: 'Explore and visualize data.',
main: `plugins/${PLUGIN_ID}/index`,
main: `plugins/${PLUGIN_ID}/redirect`,
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't look like we have a '/redirect' route in Lens at all. I'm assuming this is a standard Kibana app thing or something? Just wanted to double check that this was an intentional change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't a route, it's the entrypoint of the app/lens "app" which doesn't exist anymore. It points to the redirect.ts file which does the redirect to the actual app which is loaded as part of the kibana app.

All of this is an interim measure, with the new platform we can just use the application service directly.

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

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

Overall this change is working for me, and I like that Lens is now getting a bit better integration with the rest of Kibana. I have the same concerns as others about the URL issue, but I'm not even sure we need the redirect for backwards compatibility.

Either way, this probably needs a release note that the Lens URL is changing.

fromDate: timeDefaults.from,
toDate: timeDefaults.to,
fromDate: data.query.timefilter.timefilter.getTime().from,
toDate: data.query.timefilter.timefilter.getTime().to,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, I like this change!

@@ -204,6 +203,8 @@ export function App({
trackUiEvent('app_query_change');
}

data.query.timefilter.timefilter.setTime(dateRange);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what effect this has, but is it worth looking at whether the new date range differs from the old date range? There is already a condition above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This syncs the time range in the other direction (from within the app to the global state), but you are right, we can put it into that condition.

);
localApplicationService.register({
id: 'lens',
title: 'Lens',
Copy link
Contributor

Choose a reason for hiding this comment

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

Can or should this be i18n?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not really used right now, it's just there to have the same interface as the real application service. I will use the NOT_INTERNATIONALIZED_PRODUCT_NAME for now.

@flash1293
Copy link
Contributor Author

Improved the implementation of the redirect code to make it look less brittle.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

const prefixedHashRoute = window.location.hash.replace(/^#\//, '#/lens/');

// redirect to the new lens url `app/kibana#/lens/...`
window.location.href = npSetup.core.http.basePath.prepend('/app/kibana' + prefixedHashRoute);
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this a lot better.

@flash1293 flash1293 merged commit ff2a3ab into elastic:master Nov 20, 2019
Lens automation moved this from In progress to Done Nov 20, 2019
@flash1293 flash1293 deleted the lens/no-reload branch November 20, 2019 11:07
flash1293 added a commit to flash1293/kibana that referenced this pull request Nov 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants