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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
cleanup continued...
  • Loading branch information
ThomThomson committed Jul 15, 2020
commit d1ab6837e739c31b374f3a90218802aac6cedfcb
10 changes: 6 additions & 4 deletions src/plugins/embeddable/public/lib/state_transfer/types.ts
Original file line number Diff line number Diff line change
@@ -21,26 +21,28 @@ import { Optional } from '@kbn/utility-types';
import { EmbeddableInput, SavedObjectEmbeddableInput } from '..';

/**
* Represents a state package that contains the last active app id.
* A state package that contains information an editor will need to create or edit an embeddable then redirect back.
* @public
*/
export interface EmbeddableEditorState {
originatingApp: string;
valueInput?: EmbeddableInput | 'createByValue';
embeddableId?: string;
valueInput?: EmbeddableInput;
byValueMode?: boolean;
ThomThomson marked this conversation as resolved.
Show resolved Hide resolved
}

export function isEmbeddableEditorState(state: unknown): state is EmbeddableEditorState {
return ensureFieldOfTypeExists('originatingApp', state, 'string');
}

/**
* Represents a state package that contains all fields necessary to create an embeddable by reference or by value in a container.
* A state package that contains all fields necessary to create or update an embeddable by reference or by value in a container.
* @public
*/
export interface EmbeddablePackageState {
id?: string;
type: string;
input: Optional<EmbeddableInput, 'id'> | Optional<SavedObjectEmbeddableInput, 'id'>;
embeddableId?: string;
}

export function isEmbeddablePackageState(state: unknown): state is EmbeddablePackageState {
2 changes: 1 addition & 1 deletion src/plugins/visualizations/public/wizard/new_vis_modal.tsx
Original file line number Diff line number Diff line change
@@ -177,7 +177,7 @@ class NewVisModal extends React.Component<TypeSelectionProps, TypeSelectionState
path: params,
state: {
originatingApp: this.props.originatingApp,
valueInput: this.props.createByValue ? 'createByValue' : undefined,
byValueMode: this.props.createByValue,
},
});
} else {
5 changes: 3 additions & 2 deletions x-pack/plugins/lens/kibana.json
Original file line number Diff line number Diff line change
@@ -11,9 +11,10 @@
"kibanaLegacy",
"visualizations",
"dashboard",
"charts"
"charts",
"embeddable"
],
"optionalPlugins": ["embeddable", "usageCollection", "taskManager", "uiActions"],
"optionalPlugins": ["usageCollection", "taskManager", "uiActions"],
"configPath": ["xpack", "lens"],
"extraPublicDirs": ["common/constants"],
"requiredBundles": ["savedObjects", "kibanaUtils", "kibanaReact", "embeddable"]
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
@@ -463,7 +463,7 @@ describe('Lens App', () => {
act(() =>
onChange({
filterableIndexPatterns: [],
doc: { id: initialDocId, ...lastKnownDoc } as Document,
doc: { savedObjectId: initialDocId, ...lastKnownDoc } as Document,
})
);

38 changes: 16 additions & 22 deletions x-pack/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
@@ -227,9 +227,8 @@ export function App({

useEffect(() => {
if (
!embeddableEditorIncomingState?.valueInput &&
savedObjectId &&
(!state.persistedDoc || state.persistedDoc.id !== savedObjectId)
(!state.persistedDoc || state.persistedDoc.savedObjectId !== savedObjectId)
) {
setState((s) => ({ ...s, isLoading: true }));
docStorage
@@ -246,13 +245,9 @@ export function App({

redirectTo();
});
} else if (
!!embeddableEditorIncomingState?.valueInput &&
embeddableEditorIncomingState?.valueInput !== 'createByValue'
) {
const doc = {
} else if (!!embeddableEditorIncomingState?.valueInput) {
const doc: Document = {
...(embeddableEditorIncomingState?.valueInput as LensByValueInput).attributes,
id: embeddableEditorIncomingState?.valueInput.id,
};
updateDoc(doc);
redirectTo();
@@ -298,8 +293,7 @@ export function App({
returnToOrigin: boolean;
onTitleDuplicate?: OnSaveProps['onTitleDuplicate'];
newDescription?: string;
},
saveToLibrary: boolean = false
}
) => {
if (!lastKnownDoc) {
return;
@@ -319,17 +313,17 @@ export function App({
}
: lastKnownDoc;

const doc = {
const doc: Document = {
...lastDocWithoutPinned,
description: saveProps.newDescription,
id: saveProps.newCopyOnSave ? undefined : lastKnownDoc.id,
savedObjectId: saveProps.newCopyOnSave ? undefined : lastKnownDoc.savedObjectId,
title: saveProps.newTitle,
};

const newlyCreated = saveProps.newCopyOnSave || !lastKnownDoc?.id || saveToLibrary;
const newlyCreated = saveProps.newCopyOnSave || !lastKnownDoc?.savedObjectId;

if (!!embeddableEditorIncomingState?.valueInput && !saveToLibrary) {
redirectTo(doc.id, doc, saveProps.returnToOrigin, newlyCreated);
if (!!embeddableEditorIncomingState?.valueInput && !saveProps.newCopyOnSave) {
redirectTo(doc.savedObjectId, doc, saveProps.returnToOrigin, newlyCreated);
} else {
await checkForDuplicateTitle(
{
@@ -349,14 +343,11 @@ export function App({
overlays: core.overlays,
}
);
if (saveToLibrary && embeddableEditorIncomingState?.valueInput) {
delete doc.id;
}
docStorage
.save(doc)
.then(({ id }) => {
// Prevents unnecessary network request and disables save button
const newDoc = { ...doc, id };
const newDoc: Document = { ...doc, savedObjectId: id };
setState((s) => ({
...s,
isSaveModalVisible: false,
@@ -405,7 +396,8 @@ export function App({
<div className="lnsApp__header">
<TopNavMenu
config={[
...((!!embeddableEditorIncomingState?.originatingApp && lastKnownDoc?.id) ||
...((!!embeddableEditorIncomingState?.originatingApp &&
lastKnownDoc?.savedObjectId) ||
embeddableEditorIncomingState?.valueInput
? [
{
@@ -431,7 +423,7 @@ export function App({
: []),
{
label:
lastKnownDoc?.id ||
lastKnownDoc?.savedObjectId ||
(embeddableEditorIncomingState?.valueInput &&
!!embeddableEditorIncomingState?.originatingApp)
? i18n.translate('xpack.lens.app.saveAs', {
@@ -567,7 +559,9 @@ export function App({
onSave={(props) => runSave(props, true)}
onClose={() => setState((s) => ({ ...s, isSaveModalVisible: false }))}
documentInfo={{
id: embeddableEditorIncomingState?.valueInput ? undefined : lastKnownDoc.id,
id: embeddableEditorIncomingState?.valueInput
? undefined
: lastKnownDoc.savedObjectId,
title: lastKnownDoc.title || '',
description: lastKnownDoc.description || '',
}}
19 changes: 5 additions & 14 deletions x-pack/plugins/lens/public/app_plugin/mounter.tsx
Original file line number Diff line number Diff line change
@@ -39,9 +39,7 @@ export async function mountApp(
);

const stateTransfer = embeddable?.getStateTransfer(params.history);
const embeddableEditorIncomingState = stateTransfer?.getIncomingEditorState({
keysToRemoveAfterFetch: ['originatingApp'],
});
const embeddableEditorIncomingState = stateTransfer?.getIncomingEditorState();

const instance = await createEditorFrame();

@@ -54,7 +52,7 @@ export async function mountApp(
const redirectTo = (
routeProps: RouteComponentProps<{ id?: string }>,
savedObjectId?: string,
documentByValue?: Document,
document?: Document,
returnToOrigin?: boolean,
newlyCreated?: boolean
) => {
@@ -65,21 +63,13 @@ export async function mountApp(
} else if (!!embeddableEditorIncomingState?.originatingApp && returnToOrigin) {
routeProps.history.push(`/edit/${savedObjectId}`);
if (newlyCreated && savedObjectId) {
stateTransfer.navigateToWithEmbeddablePackage(
embeddableEditorIncomingState?.originatingApp,
{
state: { type: LENS_EMBEDDABLE_TYPE, input: { savedObjectId } },
}
);
} else if (documentByValue) {
const { type, id, ...rest } = documentByValue;
stateTransfer.navigateToWithEmbeddablePackage(
embeddableEditorIncomingState?.originatingApp,
{
state: {
id,
embeddableId: embeddableEditorIncomingState.embeddableId,
type: LENS_EMBEDDABLE_TYPE,
input: { attributes: rest },
input: { savedObjectId },
},
}
);
@@ -121,6 +111,7 @@ export async function mountApp(
<HashRouter>
<Switch>
<Route exact path="/edit/:id" render={renderEditor} />
<Route exact path="/by_value" render={renderEditor} />
<Route exact path="/" render={renderEditor} />
<Route path="/" component={NotFound} />
</Switch>
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ export function getSavedObjectFormat({
});

return {
id: state.persistedId,
savedObjectId: state.persistedId,
title: state.title,
description: state.description,
type: 'lens',
Original file line number Diff line number Diff line change
@@ -379,7 +379,7 @@ describe('editor_frame state management', () => {
{
type: 'VISUALIZATION_LOADED',
doc: {
id: 'b',
savedObjectId: 'b',
expression: '',
state: {
datasourceMetaData: { filterableIndexPatterns: [] },
Original file line number Diff line number Diff line change
@@ -156,7 +156,7 @@ export const reducer = (state: EditorFrameState, action: Action): EditorFrameSta
case 'VISUALIZATION_LOADED':
return {
...state,
persistedId: action.doc.id,
persistedId: action.doc.savedObjectId,
title: action.doc.title,
description: action.doc.description,
datasourceStates: Object.entries(action.doc.state.datasourceStates).reduce(

This file was deleted.

Original file line number Diff line number Diff line change
@@ -29,12 +29,13 @@ import {
EmbeddableOutput,
IContainer,
SavedObjectEmbeddableInput,
AttributeService,
} from '../../../../../../src/plugins/embeddable/public';
import { DOC_TYPE, Document } from '../../persistence';
import { ExpressionWrapper } from './expression_wrapper';
import { UiActionsStart } from '../../../../../../src/plugins/ui_actions/public';
import { isLensBrushEvent, isLensFilterEvent } from '../../types';
import { AttributeService } from './attribute_service';

import { IndexPatternsContract } from '../../../../../../src/plugins/data/public';
import { getEditPath } from '../../../common';
import { IBasePath } from '../../../../../../src/core/public';
@@ -133,7 +134,7 @@ export class Embeddable extends AbstractEmbeddable<LensEmbeddableInput, LensEmbe
this.savedVis = {
...attributes,
type: this.type,
id: input.id,
savedObjectId: (input as LensByReferenceInput)?.savedObjectId,
};
this.initializeOutput();
if (this.domNode) {
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ import { ReactExpressionRendererType } from '../../../../../../src/plugins/expre
import {
EmbeddableFactoryDefinition,
IContainer,
AttributeService,
EmbeddableStart,
} from '../../../../../../src/plugins/embeddable/public';
import {
Embeddable,
@@ -25,7 +27,6 @@ import {
} from './embeddable';
import { DOC_TYPE } from '../../persistence';
import { UiActionsStart } from '../../../../../../src/plugins/ui_actions/public';
import { AttributeService } from './attribute_service';

interface StartServices {
timefilter: TimefilterContract;
@@ -34,6 +35,7 @@ interface StartServices {
savedObjectsClient: SavedObjectsClientContract;
expressionRenderer: ReactExpressionRendererType;
indexPatternService: IndexPatternsContract;
embeddable: EmbeddableStart;
uiActions?: UiActionsStart;
}

@@ -47,12 +49,6 @@ export class EmbeddableFactory implements EmbeddableFactoryDefinition {
getIconForSavedObject: () => 'lensApp',
};

private attributeService?: AttributeService<
LensSavedObjectAttributes,
LensByValueInput,
LensByReferenceInput
>;

constructor(private getStartServices: () => Promise<StartServices>) {}

public isEditable = async () => {
@@ -85,10 +81,15 @@ export class EmbeddableFactory implements EmbeddableFactoryDefinition {
uiActions,
coreHttp,
indexPatternService,
embeddable,
} = await this.getStartServices();
return new Embeddable(
{
attributeService: await this.getAttributeService(),
attributeService: embeddable.getAttributeService<
LensSavedObjectAttributes,
LensByValueInput,
LensByReferenceInput
>(this.type),
indexPatternService,
timefilter,
expressionRenderer,
@@ -100,16 +101,4 @@ export class EmbeddableFactory implements EmbeddableFactoryDefinition {
parent
);
}

private async getAttributeService() {
const savedObjectsService = (await this.getStartServices()).savedObjectsClient;
if (!this.attributeService) {
this.attributeService = new AttributeService<
LensSavedObjectAttributes,
LensByValueInput,
LensByReferenceInput
>(this.type, savedObjectsService);
}
return this.attributeService;
}
}
Loading