elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.59k stars 8.1k forks source link

[ShareURL] Absolute URL feature #153323

Closed dej611 closed 1 year ago

dej611 commented 1 year ago

Describe the feature:

At the moment it is not trivial to rebuild an absolute URL with the ShortURL service.

In Lens we've combined the ShortURL.create method with the application.getUrlForApp one:

const relativeUrl = await shortUrls.create({ locator, params });
const absoluteShortUrl = application.getUrlForApp('', {
  path: `/r/s/${relativeUrl.data.slug}`,
  absolute: true,
});

In the Share service a legacy service is used, which I think should be replaced:

...
const locator = this.dependencies.locators.get<LegacyShortUrlLocatorParams>(
    LEGACY_SHORT_URL_LOCATOR_ID
);

if (!locator) {
    throw new Error(`Locator "${LEGACY_SHORT_URL_LOCATOR_ID}" not found`);
}

const result = await this.createWithLocator({
      locator,
      params: {
        url: relativeUrl,
      },
});
const shortUrl = await result.locator.getUrl(result.params, { absolute: true });

In the first case that is not too bad, but I was think to propose a convenience absolute param for the ShortURL.create to make it one-liner:

const absoluteURL = await shortUrls.create({ locator, params, absolute: true });
elasticmachine commented 1 year ago

Pinging @elastic/appex-sharedux (Team:SharedUX)

lukasolson commented 1 year ago

Adding my +1 to this, we have a need in Discover as well.

vadimkibana commented 1 year ago

It is possible using the .crateWithLocator method. Like this:

const shortUrl = await shortUrls.createWithLocator({ locator, params });
const absoluteShortUrl = shortUrl.locator.getUrl(shortUrl.params, { absolute: true });
lukasolson commented 1 year ago

I still don't think this covers my use case: I'd like to generate a URL with getRedirectUrl that is absolute. Right now I think I have to manually convert to the absolute URL myself using relativeToAbsolute. Am I missing something?