kibana/examples/locator_examples/public/locator.ts
Tyler Smalley 4681a80317
[DX] Upgrade prettier to v2.4.0 (#112359)
Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
2021-09-19 22:34:30 -07:00

55 lines
1.6 KiB
TypeScript

/*
* 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 { SerializableRecord } from '@kbn/utility-types';
import { MigrateFunction } from 'src/plugins/kibana_utils/common';
import { LocatorDefinition, LocatorPublic } from '../../../src/plugins/share/public';
export const HELLO_LOCATOR = 'HELLO_LOCATOR';
export interface HelloLocatorV1Params extends SerializableRecord {
name: string;
}
export interface HelloLocatorV2Params extends SerializableRecord {
firstName: string;
lastName: string;
}
export type HelloLocatorParams = HelloLocatorV2Params;
const migrateV1ToV2: MigrateFunction<HelloLocatorV1Params, HelloLocatorV2Params> = (
v1: HelloLocatorV1Params
) => {
const v2: HelloLocatorV2Params = {
firstName: v1.name,
lastName: '',
};
return v2;
};
export type HelloLocator = LocatorPublic<HelloLocatorParams>;
export class HelloLocatorDefinition implements LocatorDefinition<HelloLocatorParams> {
public readonly id = HELLO_LOCATOR;
public readonly getLocation = async ({ firstName, lastName }: HelloLocatorParams) => {
return {
app: 'locatorExamples',
path: `/hello?firstName=${encodeURIComponent(firstName)}&lastName=${encodeURIComponent(
lastName
)}`,
state: {},
};
};
public readonly migrations = {
'0.0.2': migrateV1ToV2 as unknown as MigrateFunction,
};
}