Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dashboard First] Lens By Value #70272

Closed
wants to merge 70 commits into from
Closed
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
297dba0
Made lens work with the attribute service copied from #68719
ThomThomson Jun 25, 2020
168825a
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jun 25, 2020
0039a97
Editing lens by value now works.
ThomThomson Jun 26, 2020
8ec8020
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jun 26, 2020
681625f
Allow by value lens embeddable to be made by reference via the save a…
ThomThomson Jun 26, 2020
473a052
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jun 29, 2020
3ee8263
fixed up some jest tests
ThomThomson Jun 29, 2020
a34d585
functional and jest test fixes
ThomThomson Jun 30, 2020
b7ff957
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jun 30, 2020
5d05ac9
fix for visualize by value
ThomThomson Jun 30, 2020
adc1298
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 7, 2020
a3d0adc
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 13, 2020
3ecb3d9
Restructured adding and editing to minimize deletion of embeddables a…
ThomThomson Jul 14, 2020
72a068a
eslint changes
ThomThomson Jul 14, 2020
d1ab683
cleanup continued...
ThomThomson Jul 15, 2020
9cb9a7c
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 15, 2020
a0fffd0
Finished cleanup - separated embeddableId and savedObjectId in lens t…
ThomThomson Jul 17, 2020
4d64d5e
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 17, 2020
9e5f7a9
Test fixes
ThomThomson Jul 17, 2020
580fbba
More test fixes, started on feature flag creation
ThomThomson Jul 17, 2020
df5fad0
Finished feature flag
ThomThomson Jul 17, 2020
c6d87c7
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 20, 2020
cd61dfc
Updated jest test - because the newly created prop is now set correctly.
ThomThomson Jul 20, 2020
7f86d23
remove byValueMode from editorState in favor of using the embeddableI…
ThomThomson Jul 22, 2020
43657f9
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 22, 2020
888ca49
rename edit mode for clarity. Update ternary
ThomThomson Jul 22, 2020
b9d9c5c
Type fixes
ThomThomson Jul 23, 2020
c823217
Jest fix
ThomThomson Jul 23, 2020
87a780c
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 23, 2020
d3d2cfd
merge fix
ThomThomson Jul 23, 2020
b793ca3
Merge branch 'master' into feature/lensByValue
elasticmachine Jul 27, 2020
ef65220
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 29, 2020
ee625ec
merge fix
ThomThomson Jul 29, 2020
4e39564
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 30, 2020
ed461d3
cleaned up visualize state transfer package, set new lens flow defaul…
ThomThomson Jul 30, 2020
c9878c5
cleaned up visualize state transfer package, set new lens flow defaul…
ThomThomson Jul 30, 2020
cb72a3e
Merge branch 'feature/lensByValue' of github.com:ThomThomson/kibana i…
ThomThomson Jul 30, 2020
a5910f2
Added an interface for all by value or by reference embeddables to in…
ThomThomson Jul 31, 2020
ac5c91a
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Jul 31, 2020
068ebaf
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 4, 2020
c1435e0
Removed lens by value config in favor of the dashboard-wide config fr…
ThomThomson Aug 4, 2020
ac94aec
removed unused config related code from lens
ThomThomson Aug 5, 2020
642eea8
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 6, 2020
9af2c06
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 12, 2020
8b43747
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 17, 2020
df876af
Merge continued...
ThomThomson Aug 17, 2020
aeb25ee
Merge continued...
ThomThomson Aug 17, 2020
6fc1f00
Maps Update
ThomThomson Aug 17, 2020
9598011
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 18, 2020
10d98e3
Finished merge with visualize editor
ThomThomson Aug 18, 2020
e85caeb
Merge branch 'master' into feature/lensByValue
elasticmachine Aug 20, 2020
2ef26c6
Merge branch 'feature/lensByValue' of github.com:ThomThomson/kibana i…
ThomThomson Aug 20, 2020
ff13e40
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 20, 2020
3411c36
Added custom save method to attribute service to allow lens specific …
ThomThomson Aug 20, 2020
1d5b123
Small fix for lens embeddables on canvas, made cancel button show up …
ThomThomson Aug 20, 2020
f497244
Test fix
ThomThomson Aug 20, 2020
5b6d397
Removed accidental duplication of ref_or_val_embeddable. Added tests …
ThomThomson Aug 21, 2020
d345571
M o n s t e r M e r g e branch 'master' of github.com:elastic/kibana…
ThomThomson Aug 21, 2020
0dee8a7
Made attribute service unwrap references as well
ThomThomson Aug 22, 2020
12b9aa4
type and jest fix
ThomThomson Aug 22, 2020
e3dc91a
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 24, 2020
29ae393
Simplified and separated redirectTo method, made dashboard merge inco…
ThomThomson Aug 24, 2020
719d67c
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 24, 2020
3470c63
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 25, 2020
566500c
changed feature flag config to match dashboard
ThomThomson Aug 25, 2020
8796ab0
cleaned up types after 75560
ThomThomson Aug 25, 2020
216fd7f
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 25, 2020
d0e3fd8
Type cleanup continued
ThomThomson Aug 25, 2020
6f28a7f
Merge branch 'master' of github.com:elastic/kibana into feature/lensB…
ThomThomson Aug 31, 2020
cf74955
update eslint
ThomThomson Aug 31, 2020
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 src/plugins/dashboard/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
allowByValueEmbeddables: schema.boolean({ defaultValue: false }),
allowByValueEmbeddables: schema.boolean({ defaultValue: true }),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import {
ViewMode,
ContainerOutput,
EmbeddableInput,
SavedObjectEmbeddableInput,
} from '../../../embeddable/public';
import { NavAction, SavedDashboardPanel } from '../types';

Expand Down Expand Up @@ -168,7 +167,7 @@ export class DashboardAppController {
chrome.docTitle.change(dash.title);
}

const incomingEmbeddable = embeddable
let incomingEmbeddable = embeddable
.getStateTransfer(scopedHistory())
.getIncomingEmbeddablePackage();

Expand Down Expand Up @@ -328,6 +327,21 @@ export class DashboardAppController {
dashboardStateManager.getPanels().forEach((panel: SavedDashboardPanel) => {
embeddablesMap[panel.panelIndex] = convertSavedDashboardPanelToPanelState(panel);
});

// If the incoming embeddable state's id already exists in the embeddables map, replace the input, retaining the existing gridData for that panel.
if (incomingEmbeddable?.embeddableId && embeddablesMap[incomingEmbeddable.embeddableId]) {
const originalPanelState = { ...embeddablesMap[incomingEmbeddable.embeddableId] };
ThomThomson marked this conversation as resolved.
Show resolved Hide resolved
embeddablesMap[incomingEmbeddable.embeddableId] = {
gridData: originalPanelState.gridData,
type: incomingEmbeddable.type,
explicitInput: {
...incomingEmbeddable.input,
id: incomingEmbeddable.embeddableId,
},
};
incomingEmbeddable = undefined;
}

let expandedPanelId;
if (dashboardContainer && !isErrorEmbeddable(dashboardContainer)) {
expandedPanelId = dashboardContainer.getInput().expandedPanelId;
Expand Down Expand Up @@ -454,25 +468,16 @@ export class DashboardAppController {
refreshDashboardContainer();
});

if (incomingEmbeddable) {
if ('id' in incomingEmbeddable) {
container.addOrUpdateEmbeddable<SavedObjectEmbeddableInput>(
incomingEmbeddable.type,
{
savedObjectId: incomingEmbeddable.id,
}
);
} else if ('input' in incomingEmbeddable) {
const input = incomingEmbeddable.input;
delete input.id;
const explicitInput = {
savedVis: input,
};
container.addOrUpdateEmbeddable<EmbeddableInput>(
incomingEmbeddable.type,
explicitInput
);
}
// If the incomingEmbeddable does not yet exist in the panels listing, create a new panel using the container's addEmbeddable method.
if (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already started making this change in implementing attribute service for visualize, so again - the question is who goes first with this 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping to sneak this one in before you started work on using attribute service. Seems like I was too slow on the draw!

incomingEmbeddable &&
(!incomingEmbeddable.embeddableId ||
!container.getInput().panels[incomingEmbeddable.embeddableId])
) {
container.addNewEmbeddable<EmbeddableInput>(
incomingEmbeddable.type,
incomingEmbeddable.input
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
SavedObjectEmbeddableInput,
isSavedObjectEmbeddableInput,
IEmbeddable,
Container,
} from '../embeddable_plugin';
import {
SavedObjectsClientContract,
Expand Down Expand Up @@ -105,6 +106,15 @@ export class AttributeService<
return isSavedObjectEmbeddableInput(input);
};

public getExplicitInputFromEmbeddable(embeddable: IEmbeddable): ValType | RefType {
return embeddable.getRoot() &&
(embeddable.getRoot() as Container).getInput().panels[embeddable.id].explicitInput
? ((embeddable.getRoot() as Container).getInput().panels[embeddable.id].explicitInput as
| ValType
| RefType)
: (embeddable.getInput() as ValType | RefType);
}

getInputAsValueType = async (input: ValType | RefType): Promise<ValType> => {
if (!this.inputIsRefType(input)) {
return input;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dashboard/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export {
} from './application';
export { DashboardConstants, createDashboardEditUrl } from './dashboard_constants';

export { DashboardStart, DashboardUrlGenerator } from './plugin';
export { DashboardStart, DashboardUrlGenerator, DashboardFeatureFlagConfig } from './plugin';
export {
DASHBOARD_APP_URL_GENERATOR,
createDashboardUrlGenerator,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/dashboard/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ declare module '../../share/public' {

export type DashboardUrlGenerator = UrlGeneratorContract<typeof DASHBOARD_APP_URL_GENERATOR>;

interface DashboardFeatureFlagConfig {
export interface DashboardFeatureFlagConfig {
allowByValueEmbeddables: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,46 @@ test('is compatible when edit url is available, in edit mode and editable', asyn
).toBe(true);
});

test('redirects to app using state transfer', async () => {
test('redirects to app using state transfer with by value mode', async () => {
applicationMock.currentAppId$ = of('superCoolCurrentApp');
const action = new EditPanelAction(getFactory, applicationMock, stateTransferMock);
const embeddable = new EditableEmbeddable({ id: '123', viewMode: ViewMode.EDIT }, true);
const embeddable = new EditableEmbeddable(
{ id: '123', viewMode: ViewMode.EDIT, coolInput1: 1, coolInput2: 2 },
true
);
embeddable.getOutput = jest.fn(() => ({ editApp: 'ultraVisualize', editPath: '/123' }));
await action.execute({ embeddable });
expect(stateTransferMock.navigateToEditor).toHaveBeenCalledWith('ultraVisualize', {
path: '/123',
state: { originatingApp: 'superCoolCurrentApp' },
state: {
originatingApp: 'superCoolCurrentApp',
embeddableId: '123',
valueInput: {
id: '123',
viewMode: ViewMode.EDIT,
coolInput1: 1,
coolInput2: 2,
},
},
});
});

test('redirects to app using state transfer without by value mode', async () => {
applicationMock.currentAppId$ = of('superCoolCurrentApp');
const action = new EditPanelAction(getFactory, applicationMock, stateTransferMock);
const embeddable = new EditableEmbeddable(
{ id: '123', viewMode: ViewMode.EDIT, savedObjectId: '1234' },
true
);
embeddable.getOutput = jest.fn(() => ({ editApp: 'ultraVisualize', editPath: '/123' }));
await action.execute({ embeddable });
expect(stateTransferMock.navigateToEditor).toHaveBeenCalledWith('ultraVisualize', {
path: '/123',
state: {
originatingApp: 'superCoolCurrentApp',
embeddableId: '123',
valueInput: undefined,
},
});
});

Expand Down
15 changes: 12 additions & 3 deletions src/plugins/embeddable/public/lib/actions/edit_panel_action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import { take } from 'rxjs/operators';
import { ViewMode } from '../types';
import { EmbeddableFactoryNotFoundError } from '../errors';
import { EmbeddableStart } from '../../plugin';
import { IEmbeddable, EmbeddableEditorState, EmbeddableStateTransfer } from '../..';
import { IEmbeddable, EmbeddableStateTransfer, EmbeddableEditorState } from '../..';
import { SavedObjectEmbeddableInput } from '..';

export const ACTION_EDIT_PANEL = 'editPanel';

Expand Down Expand Up @@ -109,8 +110,16 @@ export class EditPanelAction implements Action<ActionContext> {
const app = embeddable ? embeddable.getOutput().editApp : undefined;
const path = embeddable ? embeddable.getOutput().editPath : undefined;
if (app && path) {
const state = this.currentAppId ? { originatingApp: this.currentAppId } : undefined;
return { app, path, state };
if (this.currentAppId) {
ThomThomson marked this conversation as resolved.
Show resolved Hide resolved
const byValueMode = !(embeddable.getInput() as SavedObjectEmbeddableInput).savedObjectId;
const state: EmbeddableEditorState = {
originatingApp: this.currentAppId,
valueInput: byValueMode ? embeddable.getInput() : undefined,
embeddableId: embeddable.getInput().id,
};
return { app, path, state };
}
return { app, path };
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/embeddable/public/lib/containers/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ export abstract class Container<
return {
type: factory.type,
explicitInput: {
id: embeddableId,
...explicitInput,
id: embeddableId,
} as TEmbeddableInput,
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { ReferenceOrValueEmbeddable, isReferenceOrValueEmbeddable } from './types';
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { EmbeddableInput, SavedObjectEmbeddableInput } from '..';

export interface ReferenceOrValueEmbeddable<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this showing as a diff? how is this not in master already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good catch. Merge issue meant that this was in the wrong place. I've deleted this file.

ValTypeInput extends EmbeddableInput = EmbeddableInput,
RefTypeInput extends SavedObjectEmbeddableInput = SavedObjectEmbeddableInput
> {
inputIsRefType: (input: ValTypeInput | RefTypeInput) => input is RefTypeInput;
getInputAsValueType: () => Promise<ValTypeInput>;
getInputAsRefType: () => Promise<RefTypeInput>;
}

export function isReferenceOrValueEmbeddable(
incoming: unknown
): incoming is ReferenceOrValueEmbeddable {
return (
!!(incoming as ReferenceOrValueEmbeddable).inputIsRefType &&
!!(incoming as ReferenceOrValueEmbeddable).getInputAsValueType &&
!!(incoming as ReferenceOrValueEmbeddable).getInputAsRefType
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,27 @@ describe('embeddable state transfer', () => {

it('can send an outgoing embeddable package state', async () => {
await stateTransfer.navigateToWithEmbeddablePackage(destinationApp, {
state: { type: 'coolestType', id: '150' },
state: { type: 'coolestType', input: { savedObjectId: '150' } },
});
expect(application.navigateToApp).toHaveBeenCalledWith('superUltraVisualize', {
state: { type: 'coolestType', id: '150' },
state: { type: 'coolestType', input: { savedObjectId: '150' } },
});
});

it('can send an outgoing embeddable package state in append mode', async () => {
const historyMock = mockHistoryState({ kibanaIsNowForSports: 'extremeSportsKibana' });
stateTransfer = new EmbeddableStateTransfer(application.navigateToApp, historyMock);
await stateTransfer.navigateToWithEmbeddablePackage(destinationApp, {
state: { type: 'coolestType', id: '150' },
state: { type: 'coolestType', input: { savedObjectId: '150' } },
appendToExistingState: true,
});
expect(application.navigateToApp).toHaveBeenCalledWith('superUltraVisualize', {
path: undefined,
state: { kibanaIsNowForSports: 'extremeSportsKibana', type: 'coolestType', id: '150' },
state: {
kibanaIsNowForSports: 'extremeSportsKibana',
type: 'coolestType',
input: { savedObjectId: '150' },
},
});
});

Expand All @@ -97,10 +101,13 @@ describe('embeddable state transfer', () => {
});

it('can fetch an incoming embeddable package state', async () => {
const historyMock = mockHistoryState({ type: 'skisEmbeddable', id: '123' });
const historyMock = mockHistoryState({
type: 'skisEmbeddable',
input: { savedObjectId: '123' },
});
stateTransfer = new EmbeddableStateTransfer(application.navigateToApp, historyMock);
const fetchedState = stateTransfer.getIncomingEmbeddablePackage();
expect(fetchedState).toEqual({ type: 'skisEmbeddable', id: '123' });
expect(fetchedState).toEqual({ type: 'skisEmbeddable', input: { savedObjectId: '123' } });
});

it('returns undefined when embeddable package is not in the right shape', async () => {
Expand All @@ -113,12 +120,12 @@ describe('embeddable state transfer', () => {
it('removes all keys in the keysToRemoveAfterFetch array', async () => {
const historyMock = mockHistoryState({
type: 'skisEmbeddable',
id: '123',
input: { savedObjectId: '123' },
test1: 'test1',
test2: 'test2',
});
stateTransfer = new EmbeddableStateTransfer(application.navigateToApp, historyMock);
stateTransfer.getIncomingEmbeddablePackage({ keysToRemoveAfterFetch: ['type', 'id'] });
stateTransfer.getIncomingEmbeddablePackage({ keysToRemoveAfterFetch: ['type', 'input'] });
expect(historyMock.replace).toHaveBeenCalledWith(
expect.objectContaining({ state: { test1: 'test1', test2: 'test2' } })
);
Expand All @@ -127,15 +134,15 @@ describe('embeddable state transfer', () => {
it('leaves state as is when no keysToRemove are supplied', async () => {
const historyMock = mockHistoryState({
type: 'skisEmbeddable',
id: '123',
input: { savedObjectId: '123' },
test1: 'test1',
test2: 'test2',
});
stateTransfer = new EmbeddableStateTransfer(application.navigateToApp, historyMock);
stateTransfer.getIncomingEmbeddablePackage();
expect(historyMock.location.state).toEqual({
type: 'skisEmbeddable',
id: '123',
input: { savedObjectId: '123' },
test1: 'test1',
test2: 'test2',
});
Expand Down
Loading