Skip to content

Commit

Permalink
Merge branch 'main' into ml-package-storage
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Jan 3, 2023
2 parents 834f71f + 9111a2e commit 64a4aa0
Show file tree
Hide file tree
Showing 68 changed files with 1,844 additions and 919 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"endpoint:user-artifact": "f94c250a52b30d0a2d32635f8b4c5bdabd1e25c0",
"endpoint:user-artifact-manifest": "8c14d49a385d5d1307d956aa743ec78de0b2be88",
"enterprise_search_telemetry": "fafcc8318528d34f721c42d1270787c52565bad5",
"epm-packages": "2915aee4302d4b00472ed05c21f59b7d498b5206",
"epm-packages": "7d80ba3f1fcd80316aa0b112657272034b66d5a8",
"epm-packages-assets": "9fd3d6726ac77369249e9a973902c2cd615fc771",
"event_loop_delays_daily": "d2ed39cf669577d90921c176499908b4943fb7bd",
"exception-list": "fe8cc004fd2742177cdb9300f4a67689463faf9c",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ async function createRoot({ logFileName }: CreateRootConfig) {
// suite is very long, the 10mins default can cause timeouts
jest.setTimeout(15 * 60 * 1000);

describe('migration v2', () => {
// FLAKY: https://github.com/elastic/kibana/issues/148263
describe.skip('migration v2', () => {
let esServer: TestElasticsearchUtils;
let rootA: Root;
let rootB: Root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function useDataState<T extends DataMsg>(data$: BehaviorSubject<T>) {
useEffect(() => {
const subscription = data$.subscribe((next) => {
if (next.fetchStatus !== fetchState.fetchStatus) {
setFetchState({ ...fetchState, ...next });
setFetchState({ ...fetchState, ...next, ...(next.error ? {} : { error: undefined }) });
}
});
return () => subscription.unsubscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,27 @@ import {
EuiDescriptionListDescription,
} from '@elastic/eui';
import { Interpolation, Theme, css } from '@emotion/react';
import { css as classNameCss } from '@emotion/css';

import type { MonacoError } from './helpers';

const isMac = navigator.platform.toLowerCase().indexOf('mac') >= 0;
const COMMAND_KEY = isMac ? '⌘' : '^';

interface EditorFooterProps {
lines: number;
containerCSS: Interpolation<Theme>;
errors?: Array<{ startLineNumber: number; message: string }>;
errors?: MonacoError[];
onErrorClick: (error: MonacoError) => void;
refreshErrors: () => void;
}

export const EditorFooter = memo(function EditorFooter({
lines,
containerCSS,
errors,
onErrorClick,
refreshErrors,
}: EditorFooterProps) {
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
return (
Expand Down Expand Up @@ -75,7 +82,10 @@ export const EditorFooter = memo(function EditorFooter({
text-decoration: underline;
}
`}
onClick={() => setIsPopoverOpen(!isPopoverOpen)}
onClick={() => {
refreshErrors();
setIsPopoverOpen(!isPopoverOpen);
}}
>
<p>
{i18n.translate(
Expand Down Expand Up @@ -104,7 +114,15 @@ export const EditorFooter = memo(function EditorFooter({
<EuiDescriptionList>
{errors.map((error, index) => {
return (
<EuiDescriptionListDescription key={index}>
<EuiDescriptionListDescription
key={index}
className={classNameCss`
&:hover {
cursor: pointer;
}
`}
onClick={() => onErrorClick(error)}
>
<EuiFlexGroup gutterSize="xl" alignItems="flexStart">
<EuiFlexItem grow={false}>
<EuiFlexGroup gutterSize="s" alignItems="center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ import useDebounce from 'react-use/lib/useDebounce';
import { monaco } from '@kbn/monaco';
import { i18n } from '@kbn/i18n';

export interface MonacoError {
message: string;
startColumn: number;
startLineNumber: number;
endColumn: number;
endLineNumber: number;
severity: monaco.MarkerSeverity;
}

export const useDebounceWithOptions = (
fn: Function,
{ skipFirstRender }: { skipFirstRender: boolean } = { skipFirstRender: false },
Expand All @@ -33,7 +42,7 @@ export const useDebounceWithOptions = (
);
};

export const parseErrors = (errors: Error[], code: string) => {
export const parseErrors = (errors: Error[], code: string): MonacoError[] => {
return errors.map((error) => {
if (error.message.includes('line')) {
const text = error.message.split('line')[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
parseErrors,
getInlineEditorText,
getDocumentationSections,
MonacoError,
} from './helpers';
import { EditorFooter } from './editor_footer';
import { ResizableButton } from './resizable_button';
Expand Down Expand Up @@ -103,9 +104,7 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({
const [isCompactFocused, setIsCompactFocused] = useState(isCodeEditorExpanded);
const [isCodeEditorExpandedFocused, setIsCodeEditorExpandedFocused] = useState(false);
const [isWordWrapped, setIsWordWrapped] = useState(true);
const [editorErrors, setEditorErrors] = useState<
Array<{ startLineNumber: number; message: string }>
>([]);
const [editorErrors, setEditorErrors] = useState<MonacoError[]>([]);
const [documentationSections, setDocumentationSections] =
useState<LanguageDocumentationSections>();
const kibana = useKibana<IUnifiedSearchPluginServices>();
Expand Down Expand Up @@ -241,6 +240,19 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({
[errors]
);

const onErrorClick = useCallback(({ startLineNumber, startColumn }: MonacoError) => {
if (!editor1.current) {
return;
}

editor1.current.focus();
editor1.current.setPosition({
lineNumber: startLineNumber,
column: startColumn,
});
editor1.current.revealLine(startLineNumber);
}, []);

// Clean up the monaco editor and DOM on unmount
useEffect(() => {
const model = editorModel;
Expand Down Expand Up @@ -456,7 +468,12 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({
</EuiFlexItem>
</EuiFlexGroup>
)}
<EuiFlexGroup gutterSize="none" responsive={false} css={{ margin: 0 }} ref={containerRef}>
<EuiFlexGroup
gutterSize="none"
responsive={false}
css={{ margin: '0 0 1px 0' }}
ref={containerRef}
>
<EuiResizeObserver onResize={onResize}>
{(resizeRef) => (
<EuiOutsideClickDetector
Expand Down Expand Up @@ -512,6 +529,8 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({
lines={lines}
containerCSS={styles.bottomContainer}
errors={editorErrors}
onErrorClick={onErrorClick}
refreshErrors={onTextLangQuerySubmit}
/>
)}
</div>
Expand Down Expand Up @@ -577,7 +596,13 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({
)}
</EuiFlexGroup>
{isCodeEditorExpanded && (
<EditorFooter lines={lines} containerCSS={styles.bottomContainer} errors={editorErrors} />
<EditorFooter
lines={lines}
containerCSS={styles.bottomContainer}
errors={editorErrors}
onErrorClick={onErrorClick}
refreshErrors={onTextLangQuerySubmit}
/>
)}
{isCodeEditorExpanded && (
<ResizableButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import React, {
} from 'react';
import { type DataViewField } from '@kbn/data-views-plugin/public';
import { startWith } from 'rxjs';
import useMount from 'react-use/lib/useMount';
import type { Query, Filter } from '@kbn/es-query';
import { usePageUrlState } from '@kbn/ml-url-state';
import {
Expand Down Expand Up @@ -129,7 +128,7 @@ export const ChangePointDetectionContextProvider: FC = ({ children }) => {

const timeRange = useTimeRangeUpdates();

useMount(function updateIntervalOnTimeBoundsChange() {
useEffect(function updateIntervalOnTimeBoundsChange() {
const timeUpdateSubscription = timefilter
.getTimeUpdate$()
.pipe(startWith(timefilter.getTime()))
Expand All @@ -145,7 +144,8 @@ export const ChangePointDetectionContextProvider: FC = ({ children }) => {
return () => {
timeUpdateSubscription.unsubscribe();
};
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const metricFieldOptions = useMemo<DataViewField[]>(() => {
return dataView.fields.filter(({ aggregatable, type }) => aggregatable && type === 'number');
Expand Down Expand Up @@ -195,15 +195,16 @@ export const ChangePointDetectionContextProvider: FC = ({ children }) => {
[filterManager]
);

useMount(() => {
useEffect(() => {
setResultFilter(filterManager.getFilters());
const sub = filterManager.getUpdates$().subscribe(() => {
setResultFilter(filterManager.getFilters());
});
return () => {
sub.unsubscribe();
};
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(
function syncFilters() {
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/cases/common/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ export type SingleCaseMetricsFeature =
| 'lifespan';

export enum SortFieldCase {
createdAt = 'createdAt',
closedAt = 'closedAt',
createdAt = 'createdAt',
severity = 'severity',
status = 'status',
title = 'title',
}

export type ElasticUser = SnakeToCamelCase<User>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React from 'react';
import { mount } from 'enzyme';
import moment from 'moment-timezone';
import { render, waitFor, screen, act } from '@testing-library/react';
import { render, waitFor, screen, act, within } from '@testing-library/react';
import { renderHook } from '@testing-library/react-hooks';
import userEvent from '@testing-library/user-event';
import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl';
Expand Down Expand Up @@ -257,23 +257,28 @@ describe('AllCasesListGeneric', () => {
expect.objectContaining({
queryParams: {
...DEFAULT_QUERY_PARAMS,
sortOrder: 'asc',
},
})
);
});
});

it('renders the title column', async () => {
const res = appMockRenderer.render(<AllCasesList />);

expect(res.getByTestId('tableHeaderCell_title_0')).toBeInTheDocument();
});

it('renders the status column', async () => {
const res = appMockRenderer.render(<AllCasesList />);

expect(res.getByTestId('tableHeaderCell_Status_6')).toBeInTheDocument();
expect(res.getByTestId('tableHeaderCell_status_6')).toBeInTheDocument();
});

it('renders the severity column', async () => {
const res = appMockRenderer.render(<AllCasesList />);

expect(res.getByTestId('tableHeaderCell_Severity_7')).toBeInTheDocument();
expect(res.getByTestId('tableHeaderCell_severity_7')).toBeInTheDocument();
});

it('should render the case stats', () => {
Expand Down Expand Up @@ -393,6 +398,66 @@ describe('AllCasesListGeneric', () => {
});
});

it('should sort by status', async () => {
const result = appMockRenderer.render(<AllCasesList isSelectorView={false} />);

userEvent.click(
within(result.getByTestId('tableHeaderCell_status_6')).getByTestId('tableHeaderSortButton')
);

await waitFor(() => {
expect(useGetCasesMock).toHaveBeenLastCalledWith(
expect.objectContaining({
queryParams: {
...DEFAULT_QUERY_PARAMS,
sortField: SortFieldCase.status,
sortOrder: 'asc',
},
})
);
});
});

it('should sort by severity', async () => {
const result = appMockRenderer.render(<AllCasesList isSelectorView={false} />);

userEvent.click(
within(result.getByTestId('tableHeaderCell_severity_7')).getByTestId('tableHeaderSortButton')
);

await waitFor(() => {
expect(useGetCasesMock).toHaveBeenLastCalledWith(
expect.objectContaining({
queryParams: {
...DEFAULT_QUERY_PARAMS,
sortField: SortFieldCase.severity,
sortOrder: 'asc',
},
})
);
});
});

it('should sort by title', async () => {
const result = appMockRenderer.render(<AllCasesList isSelectorView={false} />);

userEvent.click(
within(result.getByTestId('tableHeaderCell_title_0')).getByTestId('tableHeaderSortButton')
);

await waitFor(() => {
expect(useGetCasesMock).toHaveBeenLastCalledWith(
expect.objectContaining({
queryParams: {
...DEFAULT_QUERY_PARAMS,
sortField: SortFieldCase.title,
sortOrder: 'asc',
},
})
);
});
});

it('should filter by status: closed', async () => {
const result = appMockRenderer.render(<AllCasesList isSelectorView={false} />);
userEvent.click(result.getByTestId('case-status-filter'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const ProgressLoader = styled(EuiProgress)`
`;

const getSortField = (field: string): SortFieldCase =>
field === SortFieldCase.closedAt ? SortFieldCase.closedAt : SortFieldCase.createdAt;
// @ts-ignore
SortFieldCase[field] ?? SortFieldCase.title;

export interface AllCasesListProps {
hiddenStatuses?: CaseStatusWithAllStatus[];
Expand Down
Loading

0 comments on commit 64a4aa0

Please sign in to comment.