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

[Navigation embeddable] Add content management #160896

Merged
merged 25 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0c7c839
Initialize content management
nickpeihl Jun 29, 2023
b426814
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jun 29, 2023
38340ab
Merge branch 'navigation-embeddable' of https://github.com/elastic/ki…
nickpeihl Jul 10, 2023
78b0bf2
Rename linkListJSON to linksJSON
nickpeihl Jul 10, 2023
9e8e10f
Merge branch 'navEmbeddable-cm' of https://github.com/nickpeihl/kiban…
nickpeihl Jul 10, 2023
81b3bb8
Start wiring content management to UI
nickpeihl Jul 12, 2023
8b5ec43
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Jul 12, 2023
719c046
Wire saved objects and attribute service
nickpeihl Jul 19, 2023
82da138
Merge branch 'navEmbeddable-cm' of https://github.com/nickpeihl/kiban…
nickpeihl Jul 19, 2023
88df8f2
Merge remote-tracking branch 'upstream/navigation-embeddable' into na…
nickpeihl Jul 19, 2023
cef9efb
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jul 19, 2023
9879a34
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine Jul 19, 2023
6046fde
Wires content management to UI. Mostly complete.
nickpeihl Jul 25, 2023
c024f9c
Change links mapping from object to array of links
nickpeihl Jul 28, 2023
e4d8327
Link panels must have a minimum of one link
nickpeihl Jul 28, 2023
f0bd9a9
Do not return anything from canceled flyout
nickpeihl Jul 31, 2023
78dd9ce
Create by-value or by-ref embeddable
nickpeihl Aug 7, 2023
c4d0dbc
Fix test failures
nickpeihl Aug 7, 2023
e352936
Replace embeddable + panel changes
Heenawter Aug 7, 2023
2b463fc
Clean up
Heenawter Aug 7, 2023
ff28220
Unify NAVIGATION_EMBEDDABLE_TYPE and CONTENT_ID constants
nickpeihl Aug 8, 2023
8fb0ed5
Merge pull request #2 from Heenawter/suggested-replace-changes_2023-0…
nickpeihl Aug 8, 2023
2729cfc
Review feedback
nickpeihl Aug 10, 2023
6b254f7
Merge remote-tracking branch 'origin/navEmbeddable-cm' into navEmbedd…
nickpeihl Aug 10, 2023
ce38804
Catch promise rejection when canceling edit panel
nickpeihl Aug 10, 2023
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 @@ -77,6 +77,7 @@ export const DEFAULT_INDEX_TYPES_MAP: IndexTypesMap = {
'ml-module',
'ml-trained-model',
'monitoring-telemetry',
'navigation_embeddable',
'osquery-manager-usage-metric',
'osquery-pack',
'osquery-pack-asset',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,23 @@ export const INDEX_MAP_BEFORE_SPLIT: IndexMap = {
},
},
},
navigation_embeddable: {
properties: {
id: {
type: 'text',
},
title: {
type: 'text',
},
description: {
type: 'text',
},
links: {
dynamic: false,
properties: {},
},
},
},
'cases-comments': {
dynamic: false,
properties: {
Expand Down
17 changes: 17 additions & 0 deletions packages/kbn-check-mappings-update-cli/current_mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,23 @@
}
}
},
"navigation_embeddable": {
"properties": {
"id": {
"type": "text"
},
"title": {
"type": "text"
},
"description": {
"type": "text"
},
"links": {
"dynamic": false,
"properties": {}
}
}
},
"lens": {
"properties": {
"title": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"ml-module": "2225cbb4bd508ea5f69db4b848be9d8a74b60198",
"ml-trained-model": "482195cefd6b04920e539d34d7356d22cb68e4f3",
"monitoring-telemetry": "5d91bf75787d9d4dd2fae954d0b3f76d33d2e559",
"navigation_embeddable": "de71a127ed325261ca6bc926d93c4cd676d17a05",
"observability-onboarding-state": "55b112d6a33fedb7c1e4fec4da768d2bcc5fadc2",
"osquery-manager-usage-metric": "983bcbc3b7dda0aad29b20907db233abba709bcc",
"osquery-pack": "6ab4358ca4304a12dcfc1777c8135b75cffb4397",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ describe('split .kibana index into multiple system indices', () => {
"ml-module",
"ml-trained-model",
"monitoring-telemetry",
"navigation_embeddable",
"observability-onboarding-state",
"osquery-manager-usage-metric",
"osquery-pack",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
EmbeddableStateTransfer,
EmbeddableInput,
Container,
isReferenceOrValueEmbeddable,
} from '../..';

export const ACTION_EDIT_PANEL = 'editPanel';
Expand Down Expand Up @@ -94,6 +95,12 @@ export class EditPanelAction implements Action<ActionContext> {
const oldExplicitInput = embeddable.getExplicitInput();
const newExplicitInput = await factory.getExplicitInput(oldExplicitInput, embeddable.parent);
embeddable.parent?.replaceEmbeddable(embeddable.id, newExplicitInput);
if (
isReferenceOrValueEmbeddable(embeddable) &&
embeddable.inputIsRefType(embeddable.getInput())
) {
embeddable.reload();
}
Copy link
Member Author

Choose a reason for hiding this comment

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

We can make this better by making changes to the Container.replaceEmbeddable method to be functionally similar to the replacePanel function in dashboard/public/dashboard_container/embeddable/api/panel_management.ts.

Copy link
Contributor

@Heenawter Heenawter Aug 7, 2023

Choose a reason for hiding this comment

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

PR to address this: nickpeihl#2 @nickpeihl @ThomThomson

Figured it was easiest to make a PR against this PR, so that we can test the saved object stuff in its entirety - let me know if something else works better, though 👍

return;
}

Expand Down
21 changes: 21 additions & 0 deletions src/plugins/navigation_embeddable/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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 { i18n } from '@kbn/i18n';

export const LATEST_VERSION = 1;

export const CONTENT_ID = 'navigation_embeddable';

export const NAVIGATION_EMBEDDABLE_TYPE = 'navigation';

export const APP_ICON = 'link';

export const APP_NAME = i18n.translate('navigationEmbeddable.visTypeAlias.title', {
defaultMessage: 'Links',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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 {
ContentManagementServicesDefinition as ServicesDefinition,
Version,
} from '@kbn/object-versioning';

// We export the versioned service definition from this file and not the barrel to avoid adding
// the schemas in the "public" js bundle

import { serviceDefinition as v1 } from './v1/cm_services';

export const cmServicesDefinition: { [version: Version]: ServicesDefinition } = {
1: v1,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.
*/

export { LATEST_VERSION, CONTENT_ID } from '../constants';

export type { NavigationEmbeddableContentType } from '../types';

export type {
NavigationEmbeddableCrudTypes,
NavigationEmbeddableAttributes,
NavigationEmbeddableItem,
NavigationLinkType,
NavigationEmbeddableLink,
} from './latest';

export { DASHBOARD_LINK_TYPE, EXTERNAL_LINK_TYPE } from './latest';

export * as NavigationEmbeddableV1 from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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.
*/

export * from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* 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 { schema } from '@kbn/config-schema';
import type { ContentManagementServicesDefinition as ServicesDefinition } from '@kbn/object-versioning';
import {
savedObjectSchema,
objectTypeToGetResultSchema,
createOptionsSchemas,
updateOptionsSchema,
createResultSchema,
} from '@kbn/content-management-utils';
import { DASHBOARD_LINK_TYPE, EXTERNAL_LINK_TYPE } from '.';

const navigationEmbeddableLinkSchema = schema.object({
id: schema.string(),
type: schema.oneOf([schema.literal(DASHBOARD_LINK_TYPE), schema.literal(EXTERNAL_LINK_TYPE)]),
destination: schema.string(),
label: schema.maybe(schema.string()),
order: schema.number(),
});

const navigationEmbeddableAttributesSchema = schema.object(
{
title: schema.string(),
description: schema.maybe(schema.string()),
links: schema.maybe(schema.arrayOf(navigationEmbeddableLinkSchema)),
},
{ unknowns: 'forbid' }
);

const navigationEmbeddableSavedObjectSchema = savedObjectSchema(
navigationEmbeddableAttributesSchema
);

const searchOptionsSchema = schema.maybe(
schema.object(
{
onlyTitle: schema.maybe(schema.boolean()),
},
{ unknowns: 'forbid' }
)
);

const navigationEmbeddableCreateOptionsSchema = schema.object({
references: schema.maybe(createOptionsSchemas.references),
overwrite: createOptionsSchemas.overwrite,
});

const navigationEmbeddableUpdateOptionsSchema = schema.object({
references: updateOptionsSchema.references,
});

// Content management service definition.
// We need it for BWC support between different versions of the content
export const serviceDefinition: ServicesDefinition = {
get: {
out: {
result: {
schema: objectTypeToGetResultSchema(navigationEmbeddableSavedObjectSchema),
},
},
},
create: {
in: {
options: {
schema: navigationEmbeddableCreateOptionsSchema,
},
data: {
schema: navigationEmbeddableAttributesSchema,
},
},
out: {
result: {
schema: createResultSchema(navigationEmbeddableSavedObjectSchema),
},
},
},
update: {
in: {
options: {
schema: navigationEmbeddableUpdateOptionsSchema, // same schema as "create"
},
data: {
schema: navigationEmbeddableAttributesSchema,
},
},
},
search: {
in: {
options: {
schema: searchOptionsSchema,
},
},
},
mSearch: {
out: {
result: {
schema: navigationEmbeddableSavedObjectSchema,
},
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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.
*/

/**
* Dashboard to dashboard links
*/
export const DASHBOARD_LINK_TYPE = 'dashboardLink';

/**
* External URL links
*/
export const EXTERNAL_LINK_TYPE = 'externalLink';
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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 { NavigationEmbeddableCrudTypes } from './types';
export type {
NavigationEmbeddableCrudTypes,
NavigationEmbeddableAttributes,
NavigationEmbeddableLink,
NavigationLinkType,
} from './types';
export type NavigationEmbeddableItem = NavigationEmbeddableCrudTypes['Item'];
export { DASHBOARD_LINK_TYPE, EXTERNAL_LINK_TYPE } from './constants';
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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 {
ContentManagementCrudTypes,
SavedObjectCreateOptions,
SavedObjectUpdateOptions,
} from '@kbn/content-management-utils';
import { NavigationEmbeddableContentType } from '../../types';
import { DASHBOARD_LINK_TYPE, EXTERNAL_LINK_TYPE } from './constants';

export type NavigationEmbeddableCrudTypes = ContentManagementCrudTypes<
NavigationEmbeddableContentType,
NavigationEmbeddableAttributes,
Pick<SavedObjectCreateOptions, 'references'>,
Pick<SavedObjectUpdateOptions, 'references'>,
{
/** Flag to indicate to only search the text on the "title" field */
onlyTitle?: boolean;
}
>;

/**
* Navigation embeddable explicit input
*/
export type NavigationLinkType = typeof DASHBOARD_LINK_TYPE | typeof EXTERNAL_LINK_TYPE;

export interface NavigationEmbeddableLink {
id: string;
type: NavigationLinkType;
destination: string;
label?: string;
order: number;
}

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export type NavigationEmbeddableAttributes = {
title: string;
description?: string;
links?: NavigationEmbeddableLink[];
};
9 changes: 9 additions & 0 deletions src/plugins/navigation_embeddable/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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.
*/

export { CONTENT_ID, LATEST_VERSION } from './constants';
19 changes: 19 additions & 0 deletions src/plugins/navigation_embeddable/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 { SavedObjectsResolveResponse } from '@kbn/core-saved-objects-api-server';

export type NavigationEmbeddableContentType = 'navigation_embeddable';

// TODO does this type need to be versioned?
Copy link
Member Author

@nickpeihl nickpeihl Aug 7, 2023

Choose a reason for hiding this comment

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

👀

export interface SharingSavedObjectProps {
outcome: SavedObjectsResolveResponse['outcome'];
aliasTargetId?: SavedObjectsResolveResponse['alias_target_id'];
aliasPurpose?: SavedObjectsResolveResponse['alias_purpose'];
sourceId?: string;
}
Loading