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 all 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
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class BookEmbeddable

getInputAsRefType = async (): Promise<BookByReferenceInput> => {
const input = this.attributeService.getExplicitInputFromEmbeddable(this);
return this.attributeService.getInputAsRefType(input, { showSaveModal: true });
return this.attributeService.getInputAsRefType(input, this, { showSaveModal: true });
ThomThomson marked this conversation as resolved.
Show resolved Hide resolved
};

public render(node: HTMLElement) {
Expand Down
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,22 @@ 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: {
...originalPanelState.explicitInput,
...incomingEmbeddable.input,
id: incomingEmbeddable.embeddableId,
},
};
incomingEmbeddable = undefined;
}

let expandedPanelId;
if (dashboardContainer && !isErrorEmbeddable(dashboardContainer)) {
expandedPanelId = dashboardContainer.getInput().expandedPanelId;
Expand Down Expand Up @@ -454,32 +469,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;
// @ts-expect-error
delete input.id;
const explicitInput = {
savedVis: input,
};
const embeddableId =
'embeddableId' in incomingEmbeddable
? incomingEmbeddable.embeddableId
: undefined;
container.addOrUpdateEmbeddable<EmbeddableInput>(
incomingEmbeddable.type,
// This ugly solution is temporary - https://github.com/elastic/kibana/pull/70272 fixes this whole section
(explicitInput as unknown) as EmbeddableInput,
embeddableId
);
}
// 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,10 @@ import {
SavedObjectEmbeddableInput,
isSavedObjectEmbeddableInput,
IEmbeddable,
Container,
EmbeddableStart,
EmbeddableFactory,
EmbeddableFactoryNotFoundError,
} from '../embeddable_plugin';
import {
SavedObjectsClientContract,
Expand All @@ -39,47 +43,53 @@ import {
SaveResult,
checkForDuplicateTitle,
} from '../../../saved_objects/public';
import {
EmbeddableStart,
EmbeddableFactory,
EmbeddableFactoryNotFoundError,
Container,
} from '../../../embeddable/public';

/**
* The attribute service is a shared, generic service that embeddables can use to provide the functionality
* required to fulfill the requirements of the ReferenceOrValueEmbeddable interface. The attribute_service
* can also be used as a higher level wrapper to transform an embeddable input shape that references a saved object
* into an embeddable input shape that contains that saved object's attributes by value.
*/
export interface AttributeServiceOptions<A extends { title: string }> {
customSaveMethod?: (attributes: A, savedObjectId?: string) => Promise<{ id: string }>;
customUnwrapMethod?: (savedObject: SimpleSavedObject<A>) => A;
}

export class AttributeService<
SavedObjectAttributes extends { title: string },
ValType extends EmbeddableInput & { attributes: SavedObjectAttributes },
ValType extends EmbeddableInput & {
attributes: SavedObjectAttributes;
},
RefType extends SavedObjectEmbeddableInput
> {
private embeddableFactory: EmbeddableFactory;
private embeddableFactory?: EmbeddableFactory;

constructor(
private type: string,
private savedObjectsClient: SavedObjectsClientContract,
private overlays: OverlayStart,
private i18nContext: I18nStart['Context'],
private toasts: NotificationsStart['toasts'],
getEmbeddableFactory: EmbeddableStart['getEmbeddableFactory']
getEmbeddableFactory?: EmbeddableStart['getEmbeddableFactory'],
private options?: AttributeServiceOptions<SavedObjectAttributes>
) {
const factory = getEmbeddableFactory(this.type);
if (!factory) {
throw new EmbeddableFactoryNotFoundError(this.type);
if (getEmbeddableFactory) {
const factory = getEmbeddableFactory(this.type);
if (!factory) {
throw new EmbeddableFactoryNotFoundError(this.type);
}
this.embeddableFactory = factory;
}
this.embeddableFactory = factory;
}

public async unwrapAttributes(input: RefType | ValType): Promise<SavedObjectAttributes> {
if (this.inputIsRefType(input)) {
const savedObject: SimpleSavedObject<SavedObjectAttributes> = await this.savedObjectsClient.get<
SavedObjectAttributes
>(this.type, input.savedObjectId);
return savedObject.attributes;
return this.options?.customUnwrapMethod
? this.options?.customUnwrapMethod(savedObject)
: { ...savedObject.attributes };
}
return input.attributes;
}
Expand All @@ -98,10 +108,13 @@ export class AttributeService<
} else {
try {
if (savedObjectId) {
await this.savedObjectsClient.update(this.type, savedObjectId, newAttributes);
if (this.options?.customSaveMethod) await this.options.customSaveMethod(newAttributes);
else await this.savedObjectsClient.update(this.type, savedObjectId, newAttributes);
return { savedObjectId } as RefType;
} else {
const savedItem = await this.savedObjectsClient.create(this.type, newAttributes);
const savedItem = this.options?.customSaveMethod
? await this.options.customSaveMethod(newAttributes, savedObjectId)
: await this.savedObjectsClient.create(this.type, newAttributes);
return { savedObjectId: savedItem.id } as RefType;
}
} catch (error) {
Expand Down Expand Up @@ -146,6 +159,7 @@ export class AttributeService<

getInputAsRefType = async (
input: ValType | RefType,
embeddable: IEmbeddable,
saveOptions?: { showSaveModal: boolean } | { title: string }
): Promise<RefType> => {
if (this.inputIsRefType(input)) {
Expand All @@ -159,7 +173,7 @@ export class AttributeService<
copyOnSave: false,
lastSavedTitle: '',
getEsType: () => this.type,
getDisplayName: this.embeddableFactory.getDisplayName,
getDisplayName: this.embeddableFactory?.getDisplayName || (() => this.type),
},
props.isTitleDuplicateConfirmed,
props.onTitleDuplicate,
Expand All @@ -185,7 +199,7 @@ export class AttributeService<
<SavedObjectSaveModal
onSave={onSave}
onClose={() => reject()}
title={input.attributes.title}
title={embeddable.getTitle() || input.attributes.title}
showCopyOnSave={false}
objectType={this.type}
showDescription={false}
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
11 changes: 7 additions & 4 deletions src/plugins/dashboard/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import {
ACTION_ADD_TO_LIBRARY,
AddToLibraryActionContext,
} from './application/actions/add_to_library_action';
import { AttributeServiceOptions } from './attribute_service/attribute_service';

declare module '../../share/public' {
export interface UrlGeneratorStateMapping {
Expand All @@ -109,7 +110,7 @@ declare module '../../share/public' {

export type DashboardUrlGenerator = UrlGeneratorContract<typeof DASHBOARD_APP_URL_GENERATOR>;

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

Expand Down Expand Up @@ -151,7 +152,8 @@ export interface DashboardStart {
V extends EmbeddableInput & { attributes: A },
R extends SavedObjectEmbeddableInput
>(
type: string
type: string,
options?: AttributeServiceOptions<A>
) => AttributeService<A, V, R>;
}

Expand Down Expand Up @@ -458,14 +460,15 @@ export class DashboardPlugin
DashboardContainerByValueRenderer: createDashboardContainerByValueRenderer({
factory: dashboardContainerFactory,
}),
getAttributeService: (type: string) =>
getAttributeService: (type, options) =>
new AttributeService(
type,
core.savedObjects.client,
core.overlays,
core.i18n.Context,
core.notifications.toasts,
embeddable.getEmbeddableFactory
embeddable.getEmbeddableFactory,
options
),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { EditPanelAction } from './edit_panel_action';
import { Embeddable, EmbeddableInput } from '../embeddables';
import { Embeddable, EmbeddableInput, SavedObjectEmbeddableInput } from '../embeddables';
import { ViewMode } from '../types';
import { ContactCardEmbeddable } from '../test_samples';
import { embeddablePluginMock } from '../../mocks';
Expand Down Expand Up @@ -53,20 +53,50 @@ 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 input = { id: '123', viewMode: ViewMode.EDIT };
const embeddable = new EditableEmbeddable(input, true);
const embeddable = new EditableEmbeddable(
({
id: '123',
viewMode: ViewMode.EDIT,
coolInput1: 1,
coolInput2: 2,
} as unknown) as EmbeddableInput,
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: {
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' } as SavedObjectEmbeddableInput,
true
);
embeddable.getOutput = jest.fn(() => ({ editApp: 'ultraVisualize', editPath: '/123' }));
await action.execute({ embeddable });
expect(stateTransferMock.navigateToEditor).toHaveBeenCalledWith('ultraVisualize', {
path: '/123',
state: {
originatingApp: 'superCoolCurrentApp',
byValueMode: true,
embeddableId: '123',
valueInput: input,
valueInput: undefined,
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export class EditPanelAction implements Action<ActionContext> {
const byValueMode = !(embeddable.getInput() as SavedObjectEmbeddableInput).savedObjectId;
const state: EmbeddableEditorState = {
originatingApp: this.currentAppId,
byValueMode,
valueInput: byValueMode ? embeddable.getInput() : undefined,
embeddableId: embeddable.id,
};
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 @@ -199,8 +199,8 @@ export abstract class Container<
return {
type: factory.type,
explicitInput: {
id: embeddableId,
...explicitInput,
id: embeddableId,
} as TEmbeddableInput,
};
}
Expand Down
Loading