Skip to content

Commit

Permalink
feat: 🎸 add legacy short URL locator
Browse files Browse the repository at this point in the history
  • Loading branch information
vadimkibana committed Aug 8, 2021
1 parent 395f6d8 commit bef580f
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { SerializableState } from 'src/plugins/kibana_utils/common';
import type { KibanaLocation, LocatorDefinition } from '../../../common/url_service';

export interface RelativePathLocatorParams extends SerializableState {
url: string;
}

export class RelativePathLocatorDefinition implements LocatorDefinition<RelativePathLocatorParams> {
public readonly id = 'RELATIVE_PATH_LOCATOR';

public async getLocation(params: RelativePathLocatorParams): Promise<KibanaLocation> {
const { url } = params;

const match = url.match(/^.*\/app\/([^\/#]+)(.+)$/);

if (!match) {
throw new Error('Unexpected URL path.');
}

const [, app, path] = match;

if (!app || !path) {
throw new Error('Could not parse URL path.');
}

return {
app,
path,
state: {},
};
}
}

0 comments on commit bef580f

Please sign in to comment.