Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
77d172f
add link attachment type
dominiqueclarke Jun 10, 2025
3bcb4d4
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Jun 10, 2025
bc5c03d
remove dashboard dependency from triggers actions ui
dominiqueclarke Jun 11, 2025
192116f
Merge branch 'feat/cases-link-attachment' of github.com:dominiqueclar…
dominiqueclarke Jun 11, 2025
8f3782f
Merge branch 'main' of https://github.com/elastic/kibana into feat/ca…
dominiqueclarke Jun 13, 2025
0aeebda
integrate screenshot
benakansara Jun 13, 2025
6037685
merge upstream
dominiqueclarke Jun 13, 2025
5266320
adjust types
dominiqueclarke Jun 16, 2025
14e8f82
[CI] Auto-commit changed files from 'node scripts/styled_components_m…
kibanamachine Jun 16, 2025
ac2ef57
quick checks
dominiqueclarke Jun 16, 2025
22cc56a
Merge branch 'feat/cases-link-attachment' of github.com:dominiqueclar…
dominiqueclarke Jun 16, 2025
9d0d253
remove unnecessary dashboard dependency
dominiqueclarke Jun 16, 2025
b45cdba
[CI] Auto-commit changed files from 'node scripts/styled_components_m…
kibanamachine Jun 16, 2025
6d1c98b
split and merge screenshot images
benakansara Jun 17, 2025
5bd0383
add actions
dominiqueclarke Jun 17, 2025
d28a975
merge upstream
dominiqueclarke Jun 17, 2025
e9818ad
remove screenshot functionality
dominiqueclarke Jun 17, 2025
b988b67
adjust rendered component
dominiqueclarke Jun 17, 2025
6565e1b
adjust types and linting
dominiqueclarke Jun 17, 2025
711442b
adjust types
dominiqueclarke Jun 17, 2025
ad3b528
adjust test
dominiqueclarke Jun 17, 2025
beb55d4
Merge branch 'main' of https://github.com/elastic/kibana into feat/ca…
dominiqueclarke Jun 17, 2025
f612f90
Merge branch 'main' into feat/cases-page-attachment
dominiqueclarke Jun 18, 2025
072a087
adjust types
dominiqueclarke Jun 18, 2025
da1e7a7
Merge branch 'feat/cases-page-attachment' of github.com:dominiqueclar…
dominiqueclarke Jun 18, 2025
d81aec3
adjust tests
dominiqueclarke Jun 18, 2025
c7166c5
adjust types
dominiqueclarke Jun 18, 2025
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
5 changes: 3 additions & 2 deletions src/platform/plugins/shared/dashboard/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"uiActions",
"urlForwarding",
"presentationUtil",
"unifiedSearch"
"unifiedSearch",
],
"optionalPlugins": [
"home",
Expand All @@ -39,7 +39,8 @@
"serverless",
"noDataPage",
"observabilityAIAssistant",
"lens"
"lens",
"cases"
],
"requiredBundles": [
"kibanaReact",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ export const topNavStrings = {
defaultMessage: 'Create a copy of your dashboard',
}),
},
addToCase: {
label: i18n.translate('dashboard.topNave.addToCaseButtonAriaLabel', {
defaultMessage: 'add to case',
}),
description: i18n.translate('dashboard.topNave.addToCaseConfigDescription', {
defaultMessage: 'Add this dashboard to a case',
}),
},
};

export const getControlButtonTitle = () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { AppMountParameters, CoreStart } from '@kbn/core/public';
import { createKbnUrlStateStorage, withNotifyOnErrors } from '@kbn/kibana-utils-plugin/public';
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { Route, Routes } from '@kbn/shared-ux-router';
import { parse, ParsedQuery } from 'query-string';
import React from 'react';
Expand Down Expand Up @@ -144,25 +145,31 @@ export async function mountApp({

const app = (
<KibanaRenderContextProvider {...coreStart}>
<DashboardMountContext.Provider value={mountContext}>
<HashRouter>
<Routes>
<Route
path={[
CREATE_NEW_DASHBOARD_URL,
`${VIEW_DASHBOARD_URL}/:id/:expandedPanelId`,
`${VIEW_DASHBOARD_URL}/:id`,
]}
render={renderDashboard}
/>
<Route exact path={LANDING_PAGE_PATH} render={renderListingPage} />
<Route exact path="/">
<Redirect to={LANDING_PAGE_PATH} />
</Route>
<Route render={renderNoMatch} />
</Routes>
</HashRouter>
</DashboardMountContext.Provider>
<KibanaContextProvider
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Needed to render the Add to Case modal

services={{
...coreStart,
}}
>
<DashboardMountContext.Provider value={mountContext}>
<HashRouter>
<Routes>
<Route
path={[
CREATE_NEW_DASHBOARD_URL,
`${VIEW_DASHBOARD_URL}/:id/:expandedPanelId`,
`${VIEW_DASHBOARD_URL}/:id`,
]}
render={renderDashboard}
/>
<Route exact path={LANDING_PAGE_PATH} render={renderListingPage} />
<Route exact path="/">
<Redirect to={LANDING_PAGE_PATH} />
</Route>
<Route render={renderNoMatch} />
</Routes>
</HashRouter>
</DashboardMountContext.Provider>
</KibanaContextProvider>
</KibanaRenderContextProvider>
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
/*
* 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 React from 'react';
import { render } from '@testing-library/react';
import { AddToCaseModal } from './dashboard_add_to_case_modal';
import { coreServices, cases, shareService } from '../../../services/kibana_services';
import { DashboardContext } from '../../../dashboard_api/use_dashboard_api';
import { DashboardInternalContext } from '../../../dashboard_api/use_dashboard_internal_api';

import { buildMockDashboardApi } from '../../../mocks';

jest.mock('../../../services/kibana_services', () => ({
cases: {
ui: {
getCasesContext: jest.fn(() => ({ children }: any) => <>{children}</>),
},
helpers: {
canUseCases: jest.fn(() => ({
all: true,
create: true,
read: true,
update: true,
delete: true,
push: true,
connectors: true,
settings: true,
reopenCase: true,
createComment: true,
assign: true,
})),
},
hooks: {
useCasesAddToExistingCaseModal: jest.fn(() => ({
open: jest.fn(),
})),
},
},
shareService: {
url: {
locators: {
get: jest.fn(() => ({
getRedirectUrl: jest.fn().mockImplementation(({ timeRange }) => {
return `/mock-redirect-url?from=${encodeURIComponent(
timeRange.from
)}&to=${encodeURIComponent(timeRange.to)}`;
}),
})),
},
},
},
coreServices: {
notifications: {
toasts: {
addDanger: jest.fn(),
},
},
application: {
capabilities: {
dashboard_v2: {
save: true,
},
},
},
},
dataService: {
query: {
timefilter: {
timefilter: {
getTime: jest.fn(() => ({ from: 'now-15m', to: 'now' })),
getRefreshInterval: jest.fn(() => ({ pause: true, value: 0 })),
},
},
},
},
}));

describe('AddToCaseModal', () => {
const { api: mockDashboardApi, internalApi } = buildMockDashboardApi({
savedObjectId: 'mockSavedId',
overrides: {
timeRange: { from: 'now-15m', to: 'now' },
},
});

const mockDate = new Date('2025-06-17T15:37:53.937Z');
beforeAll(() => {
jest.useFakeTimers().setSystemTime(mockDate);
});

afterAll(() => {
jest.useRealTimers();
});

beforeEach(() => {
jest.clearAllMocks();
// @ts-ignore next line
shareService.url.locators.get = jest.fn(() => ({
getRedirectUrl: jest.fn().mockImplementation(({ timeRange }) => {
return `/mock-redirect-url?from=${encodeURIComponent(
timeRange.from
)}&to=${encodeURIComponent(timeRange.to)}`;
}),
}));
});

it('renders null if cases is not available', () => {
jest.mock('../../../services/kibana_services', () => ({ cases: null }));

const { container } = render(
<DashboardContext.Provider value={mockDashboardApi}>
<DashboardInternalContext.Provider value={internalApi}>
<AddToCaseModal isOpen={true} />
</DashboardInternalContext.Provider>
</DashboardContext.Provider>
);

expect(container.firstChild).toBeNull();
});

it('renders the modal when isOpen is true and required props are provided', () => {
const open = jest.fn();
const casesMock = cases!;
jest.spyOn(casesMock.hooks, 'useCasesAddToExistingCaseModal').mockReturnValue({
close: jest.fn(),
open,
});
render(
<DashboardContext.Provider value={mockDashboardApi}>
<DashboardInternalContext.Provider value={internalApi}>
<AddToCaseModal isOpen={true} />
</DashboardInternalContext.Provider>
</DashboardContext.Provider>
);

expect(open).toBeCalledWith(
expect.objectContaining({
getAttachments: expect.any(Function),
})
);

// Optionally, you can invoke the function and test its return value
const callArgs = open.mock.calls[0][0];
expect(callArgs.getAttachments()).toEqual([
{
persistableStateAttachmentTypeId: '.page',
type: 'persistableState',
persistableStateAttachmentState: {
type: 'dashboard',
url: {
iconType: 'dashboardApp',
pathAndQuery:
'/mock-redirect-url?from=2025-06-17T15%3A22%3A53.937Z&to=2025-06-17T15%3A37%3A53.937Z',
label: 'My Dashboard',
actionLabel: 'Go to dashboard',
},
screenContext: null,
},
},
]);
});

it('does not render the modal when isOpen is false', () => {
const { container } = render(
<DashboardContext.Provider value={mockDashboardApi}>
<DashboardInternalContext.Provider value={internalApi}>
<AddToCaseModal isOpen={false} />
</DashboardInternalContext.Provider>
</DashboardContext.Provider>
);

expect(container.firstChild).toBeNull();
});

it('shows a danger toast when the dashboard locator is not defined', () => {
shareService.url.locators.get = jest.fn(() => undefined);

render(
<DashboardContext.Provider value={mockDashboardApi}>
<DashboardInternalContext.Provider value={internalApi}>
<AddToCaseModal isOpen={true} />
</DashboardInternalContext.Provider>
</DashboardContext.Provider>
);

expect(coreServices.notifications.toasts.addDanger).toHaveBeenCalledWith({
title: expect.any(String),
'data-test-subj': 'dashboardAddToCaseError',
});
});

it('saves the time range in the URL as absolute time', () => {
const open = jest.fn();
const casesMock = cases!;
jest.spyOn(casesMock.hooks, 'useCasesAddToExistingCaseModal').mockReturnValue({
close: jest.fn(),
open,
});

render(
<DashboardContext.Provider value={mockDashboardApi}>
<DashboardInternalContext.Provider value={internalApi}>
<AddToCaseModal isOpen={true} />
</DashboardInternalContext.Provider>
</DashboardContext.Provider>
);

expect(open).toBeCalledWith(
expect.objectContaining({
getAttachments: expect.any(Function),
})
);

const callArgs = open.mock.calls[0][0];
const attachmentState = callArgs.getAttachments()[0].persistableStateAttachmentState;

expect(attachmentState.url.pathAndQuery).toContain(
'/mock-redirect-url?from=2025-06-17T15%3A22%3A53.937Z&to=2025-06-17T15%3A37%3A53.937Z'
);
});
});
Loading