Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/editor_frame_plugin/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class EditorFramePlugin {
// on it's own because we are loosing type information here.
// So it's basically explicitly saying "I'm dropping the information about type T here
// because this information isn't useful to me." but without using any which can leak
this.datasources[name] = datasource as Datasource<unknown>;
this.datasources[name] = datasource as Datasource<unknown, unknown>;
},
registerVisualization: (name, visualization) => {
this.visualizations[name] = visualization as Visualization<unknown>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { indexPatternDatasource } from './indexpattern';
import { indexPatternDatasource, PersistableIndexPatternPrivateState } from './indexpattern';
import { DatasourcePublicAPI, Operation } from '../types';

describe('IndexPattern Data Source', () => {
let persistedState: object;
let persistedState: PersistableIndexPatternPrivateState;

beforeEach(() => {
persistedState = {
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('IndexPattern Data Source', () => {
it('should persist from saved state', async () => {
const state = await indexPatternDatasource.initialize(persistedState);

expect(indexPatternDatasource.getPersistedState(state)).toEqual(persistedState);
expect(indexPatternDatasource.getPersistableState(state)).toEqual(persistedState);
});
});

Expand Down
10 changes: 7 additions & 3 deletions x-pack/plugins/lens/public/indexpattern_plugin/indexpattern.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ export interface IndexPatternPrivateState {
indexPatterns: { [id: string]: IndexPattern };
}

type PersistedKeys = 'currentIndexPattern' | 'columns' | 'columnOrder';

export type PersistableIndexPatternPrivateState = Pick<IndexPatternPrivateState, PersistedKeys>;

// Not stateful. State is persisted to the frame
export const indexPatternDatasource: Datasource<IndexPatternPrivateState> = {
async initialize(state?: IndexPatternPrivateState | any) {
export const indexPatternDatasource: Datasource<IndexPatternPrivateState, PersistableIndexPatternPrivateState> = {
async initialize(state?: PersistableIndexPatternPrivateState) {
// TODO: Make fetch request to load indexPatterns from saved objects
if (state) {
return {
Expand All @@ -67,7 +71,7 @@ export const indexPatternDatasource: Datasource<IndexPatternPrivateState> = {
};
},

getPersistedState({ currentIndexPattern, columns, columnOrder }: IndexPatternPrivateState) {
getPersistableState({ currentIndexPattern, columns, columnOrder }: IndexPatternPrivateState) {
return { currentIndexPattern, columns, columnOrder };
},

Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/lens/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export interface EditorFrameSetup {
render: (domElement: Element) => void;
// generic type on the API functions to pull the "unknown vs. specific type" error into the implementation
registerDatasource: <T>(name: string, datasource: Datasource<T>) => void;
registerDatasource: <T, P>(name: string, datasource: Datasource<T, P>) => void;
registerVisualization: <T>(name: string, visualization: Visualization<T>) => void;
}

Expand Down Expand Up @@ -37,12 +37,12 @@ export interface DatasourceSuggestion<T = unknown> {
/**
* Interface for the datasource registry
*/
export interface Datasource<T = unknown> {
export interface Datasource<T = unknown, P = unknown> {
// For initializing, either from an empty state or from persisted state
initialize: (state?: T | any) => Promise<T>;
initialize: (state?: P) => Promise<T>;

// Given the current state, which parts should be saved?
getPersistedState: (state: T) => object;
// Return the subset of the state which should be persisted in a saved object
getPersistableState: (state: T) => P;

renderDataPanel: (domElement: Element, props: DatasourceDataPanelProps<T>) => void;

Expand Down