Skip to content

Commit

Permalink
feat: 🎸 migrate locator params to the latest in redirect endp
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Jun 24, 2021
1 parent e2973ff commit 81c6521
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/plugins/kibana_utils/common/persistable_state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
*/

export * from './types';
export { migrateToLatest } from './migrate_to_latest';
2 changes: 1 addition & 1 deletion src/plugins/share/common/url_service/locators/locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface LocatorDependencies {
getUrl: (location: KibanaLocation, getUrlParams: LocatorGetUrlParams) => Promise<string>;
}

export class Locator<P extends SerializableState> implements PersistableState<P>, LocatorPublic<P> {
export class Locator<P extends SerializableState> implements LocatorPublic<P> {
public readonly migrations: PersistableState<P>['migrations'];

constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class LocatorClient implements ILocatorClient {
* @param id ID of a URL locator.
* @returns A public interface of a registered URL locator.
*/
public get<P>(id: string): undefined | LocatorPublic<P> {
public get<P extends SerializableState>(id: string): undefined | LocatorPublic<P> {
return this.locators.get(id);
}
}
4 changes: 2 additions & 2 deletions src/plugins/share/common/url_service/locators/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface ILocatorClient {
*
* @param id Unique ID of the locator.
*/
get<P>(id: string): undefined | LocatorPublic<P>;
get<P extends SerializableState>(id: string): undefined | LocatorPublic<P>;
}

/**
Expand All @@ -50,7 +50,7 @@ export interface LocatorDefinition<P extends SerializableState>
/**
* Public interface of a registered locator.
*/
export interface LocatorPublic<P> {
export interface LocatorPublic<P extends SerializableState> extends PersistableState<P> {
/**
* Returns a reference to a Kibana client-side location.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

import type { CoreSetup } from 'src/core/public';
import type { History } from 'history';
import { i18n } from '@kbn/i18n';
import type { SerializableState } from 'src/plugins/kibana_utils/common';
import { migrateToLatest } from 'src/plugins/kibana_utils/common';
import { i18n } from '@kbn/i18n';
import { BehaviorSubject } from 'rxjs';
import type { UrlService } from '../../../common/url_service';
import { render } from './render';
Expand Down Expand Up @@ -67,10 +68,10 @@ export class RedirectManager {
throw error;
}

// TODO: Perform migration to the latest version.
const [migratedParams] = migrateToLatest(locator.migrations, [options.params, options.version]);

locator
.navigate(options.params)
.navigate(migratedParams)
.then()
.catch((error) => {
// eslint-disable-next-line no-console
Expand Down

0 comments on commit 81c6521

Please sign in to comment.