Skip to content

Commit

Permalink
Merge branch 'main' into fix-156249-unable-to-create-roles
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored May 2, 2023
2 parents 319680e + 41f0b75 commit b2344b2
Show file tree
Hide file tree
Showing 171 changed files with 5,487 additions and 2,557 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import useLocalStorage from 'react-use/lib/useLocalStorage';
import { css } from '@emotion/react';

import { i18n } from '@kbn/i18n';
import { EuiButtonIcon, EuiCollapsibleNav, EuiThemeProvider, useEuiTheme } from '@elastic/eui';
import { EuiButtonIcon, EuiCollapsibleNav } from '@elastic/eui';

const LOCAL_STORAGE_IS_OPEN_KEY = 'PROJECT_NAVIGATION_OPEN' as const;
const SIZE_OPEN = 248;
Expand All @@ -33,8 +33,6 @@ const closedAriaLabel = i18n.translate('core.ui.chrome.projectNav.collapsibleNav
});

export const ProjectNavigation: React.FC = ({ children }) => {
const { euiTheme, colorMode } = useEuiTheme();

const [isOpen, setIsOpen] = useLocalStorage(LOCAL_STORAGE_IS_OPEN_KEY, true);

const toggleOpen = useCallback(() => {
Expand All @@ -43,34 +41,31 @@ export const ProjectNavigation: React.FC = ({ children }) => {

const collabsibleNavCSS = css`
border-inline-end-width: 1,
background: ${euiTheme.colors.darkestShade},
display: flex,
flex-direction: row,
`;

return (
<EuiThemeProvider colorMode={colorMode === 'DARK' ? 'LIGHT' : 'DARK'}>
<EuiCollapsibleNav
css={collabsibleNavCSS}
isOpen={true}
showButtonIfDocked={true}
onClose={toggleOpen}
isDocked={true}
size={isOpen ? SIZE_OPEN : SIZE_CLOSED}
hideCloseButton={false}
button={
<span css={buttonCSS}>
<EuiButtonIcon
iconType={isOpen ? 'menuLeft' : 'menuRight'}
aria-label={isOpen ? openAriaLabel : closedAriaLabel}
color="text"
onClick={toggleOpen}
/>
</span>
}
>
{isOpen && children}
</EuiCollapsibleNav>
</EuiThemeProvider>
<EuiCollapsibleNav
css={collabsibleNavCSS}
isOpen={true}
showButtonIfDocked={true}
onClose={toggleOpen}
isDocked={true}
size={isOpen ? SIZE_OPEN : SIZE_CLOSED}
hideCloseButton={false}
button={
<span css={buttonCSS}>
<EuiButtonIcon
iconType={isOpen ? 'menuLeft' : 'menuRight'}
aria-label={isOpen ? openAriaLabel : closedAriaLabel}
color={isOpen ? 'ghost' : 'text'}
onClick={toggleOpen}
/>
</span>
}
>
{isOpen && children}
</EuiCollapsibleNav>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,32 @@ describe('useDataGridColumnsCellActions', () => {
expect(mockCloseCellPopover).toHaveBeenCalled();
});
});

it('should return empty array of actions when list of fields is empty', async () => {
const { result, waitForNextUpdate } = renderHook(useDataGridColumnsCellActions, {
initialProps: {
...useDataGridColumnsCellActionsProps,
fields: [],
},
});

await waitForNextUpdate();

expect(result.current).toBeInstanceOf(Array);
expect(result.current.length).toBe(0);
});

it('should return empty array of actions when list of fields is undefined', async () => {
const { result, waitForNextUpdate } = renderHook(useDataGridColumnsCellActions, {
initialProps: {
...useDataGridColumnsCellActionsProps,
fields: undefined,
},
});

await waitForNextUpdate();

expect(result.current).toBeInstanceOf(Array);
expect(result.current.length).toBe(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface BulkField extends Pick<CellActionField, 'name' | 'type'> {

export interface UseDataGridColumnsCellActionsProps
extends Pick<CellActionsProps, 'triggerId' | 'metadata' | 'disabledActionTypes'> {
fields: BulkField[];
fields?: BulkField[];
dataGridRef: MutableRefObject<EuiDataGridRefProps | null>;
}
export type UseDataGridColumnsCellActions<
Expand All @@ -46,11 +46,11 @@ export const useDataGridColumnsCellActions: UseDataGridColumnsCellActions = ({
}) => {
const bulkContexts: CellActionCompatibilityContext[] = useMemo(
() =>
fields.map(({ values, ...field }) => ({
fields?.map(({ values, ...field }) => ({
field, // we are getting the actions for the whole column field, so the compatibility check will be done without the value
trigger: { id: triggerId },
metadata,
})),
})) ?? [],
[fields, triggerId, metadata]
);

Expand All @@ -60,11 +60,13 @@ export const useDataGridColumnsCellActions: UseDataGridColumnsCellActions = ({

const columnsCellActions = useMemo<EuiDataGridColumnCellAction[][]>(() => {
if (loading) {
return fields.map(() => [
() => <EuiLoadingSpinner size="s" data-test-subj="dataGridColumnCellAction-loading" />,
]);
return (
fields?.map(() => [
() => <EuiLoadingSpinner size="s" data-test-subj="dataGridColumnCellAction-loading" />,
]) ?? []
);
}
if (!columnsActions) {
if (!columnsActions || !fields || fields.length === 0) {
return [];
}
return columnsActions.map((actions, columnIndex) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ kibana_vars=(
xpack.task_manager.version_conflict_threshold
xpack.task_manager.event_loop_delay.monitor
xpack.task_manager.event_loop_delay.warn_threshold
xpack.task_manager.worker_utilization_running_average_window
xpack.uptime.index
serverless
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ export const BUILT_IN_MODEL_TAG = 'prepackaged';
export const CURATED_MODEL_TAG = 'curated';

export const CURATED_MODEL_DEFINITIONS = {
'.elser_model_1_SNAPSHOT': {
'.elser_model_1': {
config: {
input: {
field_names: ['text_field'],
},
},
description: i18n.translate('xpack.ml.trainedModels.modelsList.elserDescription', {
defaultMessage: 'Elastic Learned Sparse EncodeR',
defaultMessage: 'Elastic Learned Sparse EncodeR v1 (Tech Preview)',
}),
},
} as const;
Expand Down
27 changes: 25 additions & 2 deletions x-pack/plugins/alerting/public/lib/test_utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { I18nProvider } from '@kbn/i18n-react';
import { KibanaContextProvider, KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import { render as reactRender, RenderOptions, RenderResult } from '@testing-library/react';
import { CoreStart } from '@kbn/core/public';
import { Capabilities, CoreStart } from '@kbn/core/public';
import { coreMock } from '@kbn/core/public/mocks';
import { euiDarkVars } from '@kbn/ui-theme';
import type { ILicense } from '@kbn/licensing-plugin/public';
Expand All @@ -22,6 +22,7 @@ import { licensingMock } from '@kbn/licensing-plugin/public/mocks';
type UiRender = (ui: React.ReactElement, options?: RenderOptions) => RenderResult;

interface AppMockRendererArgs {
capabilities?: Capabilities;
license?: ILicense | null;
}

Expand All @@ -30,9 +31,15 @@ export interface AppMockRenderer {
coreStart: CoreStart;
queryClient: QueryClient;
AppWrapper: React.FC<{ children: React.ReactElement }>;
mocked: {
setBadge: jest.Mock;
};
}

export const createAppMockRenderer = ({ license }: AppMockRendererArgs = {}): AppMockRenderer => {
export const createAppMockRenderer = ({
capabilities,
license,
}: AppMockRendererArgs = {}): AppMockRenderer => {
const theme$ = of({ eui: euiDarkVars, darkMode: true });

const licensingPluginMock = licensingMock.createStart();
Expand All @@ -53,13 +60,26 @@ export const createAppMockRenderer = ({ license }: AppMockRendererArgs = {}): Ap
error: () => {},
},
});

const mockedSetBadge = jest.fn();
const core = coreMock.createStart();
const services = {
...core,
application: {
...core.application,
capabilities: {
...core.application.capabilities,
...capabilities,
},
},
licensing:
license != null
? { ...licensingPluginMock, license$: new BehaviorSubject(license) }
: licensingPluginMock,
chrome: {
...core.chrome,
setBadge: mockedSetBadge,
},
};
const AppWrapper: React.FC<{ children: React.ReactElement }> = React.memo(({ children }) => (
<I18nProvider>
Expand All @@ -85,5 +105,8 @@ export const createAppMockRenderer = ({ license }: AppMockRendererArgs = {}): Ap
render,
queryClient,
AppWrapper,
mocked: {
setBadge: mockedSetBadge,
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ export const EmptyPrompt = React.memo<EmptyPromptProps>(
}, [showCreateButton, onClickCreate, docLinks]);

return (
<EuiPageTemplate.EmptyPrompt title={emptyTitle} body={emptyBody} actions={renderActions} />
<EuiPageTemplate.EmptyPrompt
data-test-subj="mw-empty-prompt"
title={emptyTitle}
body={emptyBody}
actions={renderActions}
/>
);
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const LicensePrompt = React.memo(() => {

return (
<EuiPageTemplate.EmptyPrompt
data-test-subj="mw-license-prompt"
title={title}
body={
<EuiFlexGroup direction="column">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ describe('MaintenanceWindowsList', () => {

test('it renders', () => {
const result = appMockRenderer.render(
<MaintenanceWindowsList refreshData={() => {}} loading={false} items={items} />
<MaintenanceWindowsList
refreshData={() => {}}
loading={false}
items={items}
readOnly={false}
/>
);

expect(result.getAllByTestId('list-item')).toHaveLength(items.length);
Expand All @@ -115,5 +120,24 @@ describe('MaintenanceWindowsList', () => {

// check the endDate formatting
expect(result.getAllByText('05/05/23 00:00 AM')).toHaveLength(4);

// check if action menu is there
expect(result.getAllByTestId('table-actions-icon-button')).toHaveLength(items.length);
});

test('it does NOT renders action column in readonly', () => {
const result = appMockRenderer.render(
<MaintenanceWindowsList
refreshData={() => {}}
loading={false}
items={items}
readOnly={true}
/>
);

expect(result.getAllByTestId('list-item')).toHaveLength(items.length);

// check if action menu is there
expect(result.queryByTestId('table-actions-icon-button')).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ import { useFinishAndArchiveMaintenanceWindow } from '../../../hooks/use_finish_
interface MaintenanceWindowsListProps {
loading: boolean;
items: MaintenanceWindowFindResponse[];
readOnly: boolean;
refreshData: () => void;
}

const columns: Array<EuiBasicTableColumn<MaintenanceWindowFindResponse>> = [
const COLUMNS: Array<EuiBasicTableColumn<MaintenanceWindowFindResponse>> = [
{
field: 'title',
name: i18n.NAME,
Expand Down Expand Up @@ -99,7 +100,7 @@ const search: { filters: SearchFilterConfig[] } = {
};

export const MaintenanceWindowsList = React.memo<MaintenanceWindowsListProps>(
({ loading, items, refreshData }) => {
({ loading, items, readOnly, refreshData }) => {
const { euiTheme } = useEuiTheme();
const { navigateToEditMaintenanceWindows } = useEditMaintenanceWindowsNavigation();
const onEdit = useCallback(
Expand Down Expand Up @@ -139,32 +140,41 @@ export const MaintenanceWindowsList = React.memo<MaintenanceWindowsListProps>(
`;
}, [euiTheme.colors.highlight]);

const actions: Array<EuiBasicTableColumn<MaintenanceWindowFindResponse>> = [
{
name: '',
render: ({ status, id }: { status: MaintenanceWindowStatus; id: string }) => {
return (
<TableActionsPopover
id={id}
status={status}
onEdit={onEdit}
onCancel={onCancel}
onArchive={onArchive}
onCancelAndArchive={onCancelAndArchive}
/>
);
const actions: Array<EuiBasicTableColumn<MaintenanceWindowFindResponse>> = useMemo(
() => [
{
name: '',
render: ({ status, id }: { status: MaintenanceWindowStatus; id: string }) => {
return (
<TableActionsPopover
id={id}
status={status}
onEdit={onEdit}
onCancel={onCancel}
onArchive={onArchive}
onCancelAndArchive={onCancelAndArchive}
/>
);
},
},
},
];
],
[onArchive, onCancel, onCancelAndArchive, onEdit]
);

const columns = useMemo(
() => (readOnly ? COLUMNS : COLUMNS.concat(actions)),
[actions, readOnly]
);

return (
<EuiInMemoryTable
data-test-subj="mw-table"
css={tableCss}
itemId="id"
loading={loading || isLoadingFinish || isLoadingArchive || isLoadingFinishAndArchive}
tableCaption="Maintenance Windows List"
items={items}
columns={columns.concat(actions)}
columns={columns}
pagination={true}
sorting={sorting}
rowProps={rowProps}
Expand Down
Loading

0 comments on commit b2344b2

Please sign in to comment.