Skip to content

Commit

Permalink
Fix tagging service
Browse files Browse the repository at this point in the history
  • Loading branch information
Heenawter committed Sep 25, 2024
1 parent 02caf41 commit 445ec58
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { apiCanExpandPanels, type CanExpandPanels } from '@kbn/presentation-containers';
import {
apiHasParentApi,
apiHasUniqueId,
type HasParentApi,
type HasUniqueId,
} from '@kbn/presentation-publishing';

export type ExpandPanelActionApi = HasUniqueId & HasParentApi<CanExpandPanels>;

export const compatibilityCheck = (api: unknown): api is ExpandPanelActionApi => {
return Boolean(apiHasUniqueId(api) && apiHasParentApi(api) && apiCanExpandPanels(api.parentApi));
};

export function isCompatible(api: unknown) {
if (!compatibilityCheck(api)) return false;
const { createNew: canCreateNew, showWriteControls: canEditExisting } =
dashboardCapabilitiesService.dashboardCapabilities;
return Boolean(canCreateNew || canEditExisting);
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ export const DashboardSettings = ({ onClose }: DashboardSettingsProps) => {
};

const renderTagSelector = () => {
if (!savedObjectsTaggingService) return;
const savedObjectsTaggingApi = savedObjectsTaggingService?.getTaggingApi();
if (!savedObjectsTaggingApi) return;

return (
<EuiFormRow
Expand All @@ -130,7 +131,7 @@ export const DashboardSettings = ({ onClose }: DashboardSettingsProps) => {
/>
}
>
<savedObjectsTaggingService.ui.components.TagSelector
<savedObjectsTaggingApi.ui.components.TagSelector
selected={localSettings.tags}
onTagsSelected={(selectedTags) => updateDashboardSetting({ tags: selectedTags })}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ export const DashboardSaveModal: React.FC<DashboardSaveModalProps> = ({
);

const renderDashboardSaveOptions = useCallback(() => {
const tagSelector = savedObjectsTaggingService ? (
<savedObjectsTaggingService.ui.components.SavedObjectSaveModalTagSelector
const savedObjectsTaggingApi = savedObjectsTaggingService?.getTaggingApi();
const tagSelector = savedObjectsTaggingApi ? (
<savedObjectsTaggingApi.ui.components.SavedObjectSaveModalTagSelector
initialSelection={selectedTags}
onTagsSelected={(selectedTagIds) => {
setSelectedTags(selectedTagIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const DashboardListing = ({
<TableListViewKibanaProvider
{...{
core: coreServices,
savedObjectsTagging: savedObjectsTaggingService,
savedObjectsTagging: savedObjectsTaggingService?.getTaggingApi(),
FormattedRelative,
favorites: dashboardFavoritesClient,
contentInsightsClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const DashboardListingTable = ({
<I18nProvider>
<TableListViewKibanaProvider
core={coreServices}
savedObjectsTagging={savedObjectsTaggingService}
savedObjectsTagging={savedObjectsTaggingService?.getTaggingApi()}
FormattedRelative={FormattedRelative}
contentInsightsClient={contentInsightsClient}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export const loadDashboardState = async ({
title,

viewMode: ViewMode.VIEW, // dashboards loaded from saved object default to view mode. If it was edited recently, the view mode from session storage will override this.
tags: savedObjectsTaggingService?.ui.getTagIdsFromReferences(references) ?? [],
tags: savedObjectsTaggingService?.getTaggingApi()?.ui.getTagIdsFromReferences(references) ?? [],

controlGroupInput: attributes.controlGroupInput,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ export const saveDashboardState = async ({
{ embeddablePersistableStateService: embeddableService }
);

const references = savedObjectsTaggingService?.ui.updateTagsReferences
? savedObjectsTaggingService?.ui.updateTagsReferences(dashboardReferences, tags)
const savedObjectsTaggingApi = savedObjectsTaggingService?.getTaggingApi();
const references = savedObjectsTaggingApi?.ui.updateTagsReferences
? savedObjectsTaggingApi?.ui.updateTagsReferences(dashboardReferences, tags)
: dashboardReferences;

const allReferences = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export const updateDashboardMeta = async ({
return;
}

const savedObjectsTaggingApi = savedObjectsTaggingService?.getTaggingApi();
const references =
savedObjectsTaggingService?.ui.updateTagsReferences && tags.length
? savedObjectsTaggingService.ui.updateTagsReferences(dashboard.references, tags)
savedObjectsTaggingApi?.ui.updateTagsReferences && tags.length
? savedObjectsTaggingApi.ui.updateTagsReferences(dashboard.references, tags)
: dashboard.references;

await contentManagementService.client.update<
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/dashboard/public/services/kibana_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { NavigationPublicPluginStart } from '@kbn/navigation-plugin/public'
import type { NoDataPagePluginStart } from '@kbn/no-data-page-plugin/public';
import type { ObservabilityAIAssistantPublicStart } from '@kbn/observability-ai-assistant-plugin/public';
import type { PresentationUtilPluginStart } from '@kbn/presentation-util-plugin/public';
import type { SavedObjectsTaggingApi } from '@kbn/saved-objects-tagging-oss-plugin/public';
import type { SavedObjectTaggingOssPluginStart } from '@kbn/saved-objects-tagging-oss-plugin/public';
import type { ScreenshotModePluginStart } from '@kbn/screenshot-mode-plugin/public';
import type { ServerlessPluginStart } from '@kbn/serverless/public';
import type { SharePluginStart } from '@kbn/share-plugin/public';
Expand All @@ -41,7 +41,7 @@ export let navigationService: NavigationPublicPluginStart;
export let noDataPageService: NoDataPagePluginStart | undefined;
export let observabilityAssistantService: ObservabilityAIAssistantPublicStart | undefined;
export let presentationUtilService: PresentationUtilPluginStart;
export let savedObjectsTaggingService: SavedObjectsTaggingApi | undefined;
export let savedObjectsTaggingService: SavedObjectTaggingOssPluginStart | undefined;
export let screenshotModeService: ScreenshotModePluginStart;
export let serverlessService: ServerlessPluginStart | undefined;
export let shareService: SharePluginStart | undefined;
Expand All @@ -64,7 +64,7 @@ export const setKibanaServices = (kibanaCore: CoreStart, deps: DashboardStartDep
noDataPageService = deps.noDataPage;
observabilityAssistantService = deps.observabilityAIAssistant;
presentationUtilService = deps.presentationUtil;
savedObjectsTaggingService = deps.savedObjectsTaggingOss?.getTaggingApi();
savedObjectsTaggingService = deps.savedObjectsTaggingOss;
serverlessService = deps.serverless;
screenshotModeService = deps.screenshotMode;
shareService = deps.share;
Expand Down

0 comments on commit 445ec58

Please sign in to comment.