Skip to content

Commit

Permalink
Filter out current dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Heenawter committed Jun 21, 2023
1 parent e0c4bd2 commit 7a0ac38
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ export const NavigationEmbeddableDashboardPicker = ({ embeddable }: Props) => {
return await embeddable.getDashboardList();
}, []);

useEffect(() => {
console.log('dashboardList', dashboardList);
}, [dashboardList]);
// useEffect(() => {
// console.log('dashboardList', dashboardList);
// }, [dashboardList]);

return loadingDashboardList ? (
<EuiLoadingSpinner />
) : (
<EuiPanel>
{(dashboardList?.hits ?? []).map((hit) => (
{dashboardList?.currentDashboard && (
<li key={dashboardList.currentDashboard.id}>
<b>{dashboardList.currentDashboard.attributes.title}</b>
</li>
)}
{(dashboardList?.otherDashboards ?? []).map((hit) => (
<li key={hit.id}>{hit.attributes.title}</li>
))}
</EuiPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import ReactDOM from 'react-dom';

import { Embeddable } from '@kbn/embeddable-plugin/public';
import type { EmbeddableInput, IContainer } from '@kbn/embeddable-plugin/public';
import { NavigationEmbeddableDashboardPicker } from '../components/navigation_embeddable_dashboard_picker';
import { DashboardContainer } from '@kbn/dashboard-plugin/public/dashboard_container';

import { DashboardList } from '../types';
import { dashboardServices, untilPluginStartServicesReady } from '../services/services';
import { SearchDashboardsResponse } from '@kbn/dashboard-plugin/public/services/dashboard_content_management/lib/find_dashboards';
import { NavigationEmbeddableDashboardPicker } from '../components/navigation_embeddable_dashboard_picker';

export const NAVIGATION_EMBEDDABLE_TYPE = 'navigation';

Expand All @@ -35,17 +37,32 @@ export class NavigationEmbeddable extends Embeddable {
ReactDOM.render(<NavigationEmbeddableDashboardPicker embeddable={this} />, node);
}

public async getDashboardList(
search: string = '',
size: number = 10
): Promise<SearchDashboardsResponse> {
public async getDashboardList(search: string = '', size: number = 10): Promise<DashboardList> {
await untilPluginStartServicesReady();
const findDashboardsService = await dashboardServices.findDashboardsService();
const responses = await findDashboardsService.search({
search,
size,
});
return responses;

const parentDashboardId = (this.parent as DashboardContainer | undefined)?.getState()
.componentState.lastSavedId;

let currentDashboard: DashboardList['currentDashboard'];
const otherDashboards: DashboardList['otherDashboards'] = [];
responses.hits.forEach((hit) => {
if (hit.id === parentDashboardId) {
currentDashboard = hit;
} else {
otherDashboards.push(hit);
}
});

return {
otherDashboards,
currentDashboard,
total: responses.total,
};
}

public reload() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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 { DashboardItem } from '@kbn/dashboard-plugin/common/content_management';

export interface DashboardList {
total: number;
currentDashboard?: DashboardItem;
otherDashboards: DashboardItem[];
}

0 comments on commit 7a0ac38

Please sign in to comment.