Skip to content

Commit

Permalink
Merge branch 'main' into fix-exception-autopopulate-comment
Browse files Browse the repository at this point in the history
  • Loading branch information
WafaaNasr authored Jul 3, 2023
2 parents 233dbbb + 6a9e8d4 commit cc54eba
Show file tree
Hide file tree
Showing 79 changed files with 1,315 additions and 1,862 deletions.
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"home",
"taskManager",
"usageCollection",
"spaces"
"spaces",
"serverless",
],
"requiredBundles": [],
"extraPublicDirs": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '../kibana_react.mock';

export const KibanaServices = {
get: jest.fn(),
get: jest.fn(() => ({})),
getKibanaVersion: jest.fn(() => '8.0.0'),
getConfig: jest.fn(() => null),
};
Expand Down
7 changes: 5 additions & 2 deletions x-pack/plugins/cases/public/common/lib/kibana/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

import type { CoreStart } from '@kbn/core/public';
import type { CasesUiConfigType } from '../../../../common/ui/types';
import type { CasesPluginStart } from '../../../types';

type GlobalServices = Pick<CoreStart, 'application' | 'http' | 'theme'>;
type GlobalServices = Pick<CoreStart, 'application' | 'http' | 'theme'> &
Pick<CasesPluginStart, 'serverless'>;

export class KibanaServices {
private static kibanaVersion?: string;
Expand All @@ -19,13 +21,14 @@ export class KibanaServices {
application,
config,
http,
serverless,
kibanaVersion,
theme,
}: GlobalServices & {
kibanaVersion: string;
config: CasesUiConfigType;
}) {
this.services = { application, http, theme };
this.services = { application, http, theme, serverless };
this.kibanaVersion = kibanaVersion;
this.config = config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useGetCurrentUserProfile } from '../../containers/user_profiles/use_get
import { userProfiles, userProfilesMap } from '../../containers/user_profiles/api.mock';
import { useBulkGetUserProfiles } from '../../containers/user_profiles/use_bulk_get_user_profiles';

jest.mock('../../common/lib/kibana');
jest.mock('../../containers/use_get_tags');
jest.mock('../../containers/use_get_action_license', () => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { CreateCase } from '.';
import { useGetSupportedActionConnectors } from '../../containers/configure/use_get_supported_action_connectors';
import { useGetTags } from '../../containers/use_get_tags';

jest.mock('../../common/lib/kibana');
jest.mock('../../containers/api');
jest.mock('../../containers/user_profiles/api');
jest.mock('../../containers/use_get_tags');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ import { CasesDeepLinkId } from '../../common/navigation';

const mockSetBreadcrumbs = jest.fn();
const mockSetTitle = jest.fn();
const mockSetServerlessBreadcrumbs = jest.fn();
const mockGetKibanaServices = jest.fn((): unknown => ({
serverless: { setBreadcrumbs: mockSetServerlessBreadcrumbs },
}));

jest.mock('../../common/lib/kibana', () => {
const originalModule = jest.requireActual('../../common/lib/kibana');
return {
...originalModule,
KibanaServices: {
...originalModule.KibanaServices,
get: () => mockGetKibanaServices(),
},
useNavigation: jest.fn().mockReturnValue({
getAppUrl: jest.fn((params?: { deepLinkId: string }) => params?.deepLinkId ?? '/test'),
}),
Expand Down Expand Up @@ -50,12 +58,19 @@ describe('useCasesBreadcrumbs', () => {
{ href: '/test', onClick: expect.any(Function), text: 'Test' },
{ text: 'Cases' },
]);
expect(mockSetServerlessBreadcrumbs).toHaveBeenCalledWith([]);
});

it('should sets the cases title', () => {
renderHook(() => useCasesBreadcrumbs(CasesDeepLinkId.cases), { wrapper });
expect(mockSetTitle).toHaveBeenCalledWith(['Cases', 'Test']);
});

it('should not set serverless breadcrumbs in ess', () => {
mockGetKibanaServices.mockReturnValueOnce({ serverless: undefined });
renderHook(() => useCasesBreadcrumbs(CasesDeepLinkId.cases), { wrapper });
expect(mockSetServerlessBreadcrumbs).not.toHaveBeenCalled();
});
});

describe('set create_case breadcrumbs', () => {
Expand All @@ -66,12 +81,19 @@ describe('useCasesBreadcrumbs', () => {
{ href: CasesDeepLinkId.cases, onClick: expect.any(Function), text: 'Cases' },
{ text: 'Create' },
]);
expect(mockSetServerlessBreadcrumbs).toHaveBeenCalledWith([]);
});

it('should sets the cases title', () => {
renderHook(() => useCasesBreadcrumbs(CasesDeepLinkId.casesCreate), { wrapper });
expect(mockSetTitle).toHaveBeenCalledWith(['Create', 'Cases', 'Test']);
});

it('should not set serverless breadcrumbs in ess', () => {
mockGetKibanaServices.mockReturnValueOnce({ serverless: undefined });
renderHook(() => useCasesBreadcrumbs(CasesDeepLinkId.casesCreate), { wrapper });
expect(mockSetServerlessBreadcrumbs).not.toHaveBeenCalled();
});
});

describe('set case_view breadcrumbs', () => {
Expand All @@ -83,11 +105,18 @@ describe('useCasesBreadcrumbs', () => {
{ href: CasesDeepLinkId.cases, onClick: expect.any(Function), text: 'Cases' },
{ text: title },
]);
expect(mockSetServerlessBreadcrumbs).toHaveBeenCalledWith([{ text: title }]);
});

it('should sets the cases title', () => {
renderHook(() => useCasesTitleBreadcrumbs(title), { wrapper });
expect(mockSetTitle).toHaveBeenCalledWith([title, 'Cases', 'Test']);
});

it('should not set serverless breadcrumbs in ess', () => {
mockGetKibanaServices.mockReturnValueOnce({ serverless: undefined });
renderHook(() => useCasesTitleBreadcrumbs(title), { wrapper });
expect(mockSetServerlessBreadcrumbs).not.toHaveBeenCalled();
});
});
});
11 changes: 7 additions & 4 deletions x-pack/plugins/cases/public/components/use_breadcrumbs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { i18n } from '@kbn/i18n';
import type { ChromeBreadcrumb } from '@kbn/core/public';
import { useCallback, useEffect } from 'react';
import { useKibana, useNavigation } from '../../common/lib/kibana';
import { KibanaServices, useKibana, useNavigation } from '../../common/lib/kibana';
import type { ICasesDeepLinkId } from '../../common/navigation';
import { CasesDeepLinkId } from '../../common/navigation';
import { useCasesContext } from '../cases_context/use_cases_context';
Expand Down Expand Up @@ -84,6 +84,7 @@ export const useCasesBreadcrumbs = (pageDeepLink: ICasesDeepLinkId) => {
]
: []),
]);
KibanaServices.get().serverless?.setBreadcrumbs([]);
}, [pageDeepLink, appTitle, getAppUrl, applyBreadcrumbs]);
};

Expand All @@ -93,16 +94,18 @@ export const useCasesTitleBreadcrumbs = (caseTitle: string) => {
const applyBreadcrumbs = useApplyBreadcrumbs();

useEffect(() => {
const titleBreadcrumb: ChromeBreadcrumb = {
text: caseTitle,
};
const casesBreadcrumbs: ChromeBreadcrumb[] = [
{ text: appTitle, href: getAppUrl() },
{
text: casesBreadcrumbTitle[CasesDeepLinkId.cases],
href: getAppUrl({ deepLinkId: CasesDeepLinkId.cases }),
},
{
text: caseTitle,
},
titleBreadcrumb,
];
applyBreadcrumbs(casesBreadcrumbs);
KibanaServices.get().serverless?.setBreadcrumbs([titleBreadcrumb]);
}, [caseTitle, appTitle, getAppUrl, applyBreadcrumbs]);
};
3 changes: 3 additions & 0 deletions x-pack/plugins/cases/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type { LicensingPluginStart } from '@kbn/licensing-plugin/public';
import type { FilesSetup, FilesStart } from '@kbn/files-plugin/public';
import type { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public';
import type { UiActionsStart } from '@kbn/ui-actions-plugin/public';
import type { ServerlessPluginSetup, ServerlessPluginStart } from '@kbn/serverless/public';

import type {
CasesBulkGetRequest,
Expand Down Expand Up @@ -58,6 +59,7 @@ import type { PersistableStateAttachmentTypeRegistry } from './client/attachment
export interface CasesPluginSetup {
files: FilesSetup;
security: SecurityPluginSetup;
serverless?: ServerlessPluginSetup;
management: ManagementSetup;
home?: HomePublicPluginSetup;
}
Expand All @@ -72,6 +74,7 @@ export interface CasesPluginStart {
licensing?: LicensingPluginStart;
savedObjectsManagement: SavedObjectsManagementPluginStart;
security: SecurityPluginStart;
serverless?: ServerlessPluginStart;
spaces?: SpacesPluginStart;
storage: Storage;
triggersActionsUi: TriggersActionsStart;
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/cases/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"@kbn/core-lifecycle-browser",
"@kbn/core-saved-objects-api-server-mocks",
"@kbn/core-theme-browser",
"@kbn/serverless",
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function cronToFrequency(cron: string): Frequency {
if (fields.length < 4) {
return 'YEAR';
}
if (fields[1] === '*' || fields[1].startsWith('*/')) {
if (fields[1] === '*' || fields[1].includes(',')) {
return 'MINUTE';
}
if (fields[2] === '*') {
Expand Down
Loading

0 comments on commit cc54eba

Please sign in to comment.