Skip to content

Commit

Permalink
Merge branch 'main' into chore/resolve-191090
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Nov 18, 2024
2 parents 11cf71f + cc38d8d commit 88c3008
Show file tree
Hide file tree
Showing 387 changed files with 5,574 additions and 5,249 deletions.
118 changes: 101 additions & 17 deletions .github/CODEOWNERS

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const FinderApp = (props: {
<ContentClientProvider contentClient={props.contentClient}>
<I18nProvider>
<SavedObjectFinder
id="cmFinderApp"
showFilter={true}
services={{
savedObjectsTagging: props.savedObjectsTagging.getTaggingApi(),
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@
"@kbn/core-security-server-internal": "link:packages/core/security/core-security-server-internal",
"@kbn/core-security-server-mocks": "link:packages/core/security/core-security-server-mocks",
"@kbn/core-status-common": "link:packages/core/status/core-status-common",
"@kbn/core-status-common-internal": "link:packages/core/status/core-status-common-internal",
"@kbn/core-status-server": "link:packages/core/status/core-status-server",
"@kbn/core-status-server-internal": "link:packages/core/status/core-status-server-internal",
"@kbn/core-test-helpers-deprecations-getters": "link:packages/core/test-helpers/core-test-helpers-deprecations-getters",
Expand Down
20 changes: 20 additions & 0 deletions packages/content-management/table_list_view_table/src/mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import React from 'react';
import { from } from 'rxjs';
import type { IStorage } from '@kbn/kibana-utils-plugin/public';

import type { Services, TagListProps } from './services';

Expand Down Expand Up @@ -149,3 +150,22 @@ export const getStoryArgTypes = () => ({
defaultValue: false,
},
});

export const localStorageMock = (): IStorage => {
let store: Record<string, unknown> = {};

return {
getItem: (key: string) => {
return store[key] || null;
},
setItem: (key: string, value: unknown) => {
store[key] = value;
},
clear() {
store = {};
},
removeItem(key: string) {
delete store[key];
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { LocationDescriptor, History } from 'history';
import type { UserContentCommonSchema } from '@kbn/content-management-table-list-view-common';

import { WithServices } from './__jest__';
import { getTagList } from './mocks';
import { getTagList, localStorageMock } from './mocks';
import { TableListViewTable, type TableListViewTableProps } from './table_list_view_table';
import { getActions } from './table_list_view.test.helpers';
import type { Services } from './services';
Expand Down Expand Up @@ -335,6 +335,12 @@ describe('TableListView', () => {
const totalItems = 30;
const updatedAt = new Date().toISOString();

beforeEach(() => {
Object.defineProperty(window, 'localStorage', {
value: localStorageMock(),
});
});

const hits: UserContentCommonSchema[] = [...Array(totalItems)].map((_, i) => ({
id: `item${i}`,
type: 'dashboard',
Expand Down Expand Up @@ -429,6 +435,54 @@ describe('TableListView', () => {
expect(firstRowTitle).toBe('Item 20');
expect(lastRowTitle).toBe('Item 29');
});

test('should persist the number of rows in the table', async () => {
let testBed: TestBed;

const tableId = 'myTable';

await act(async () => {
testBed = await setup({
initialPageSize,
findItems: jest.fn().mockResolvedValue({ total: hits.length, hits: [...hits] }),
id: tableId,
});
});

{
const { component, table, find } = testBed!;
component.update();

const { tableCellsValues } = table.getMetaData('itemsInMemTable');
expect(tableCellsValues.length).toBe(20); // 20 by default

let storageValue = localStorage.getItem(`tablePersist:${tableId}`);
expect(storageValue).toBe(null);

find('tablePaginationPopoverButton').simulate('click');
find('tablePagination-10-rows').simulate('click');

storageValue = localStorage.getItem(`tablePersist:${tableId}`);
expect(storageValue).not.toBe(null);
expect(JSON.parse(storageValue!).pageSize).toBe(10);
}

// Mount a second table and verify that is shows only 10 rows
{
await act(async () => {
testBed = await setup({
initialPageSize,
findItems: jest.fn().mockResolvedValue({ total: hits.length, hits: [...hits] }),
id: tableId,
});
});

const { component, table } = testBed!;
component.update();
const { tableCellsValues } = table.getMetaData('itemsInMemTable');
expect(tableCellsValues.length).toBe(10); // 10 items this time
}
});
});

describe('column sorting', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
ContentInsightsProvider,
useContentInsightsServices,
} from '@kbn/content-management-content-insights-public';
import { useEuiTablePersist } from '@kbn/shared-ux-table-persist';

import {
Table,
Expand Down Expand Up @@ -443,7 +444,7 @@ function TableListViewTableComp<T extends UserContentCommonSchema>({
hasUpdatedAtMetadata,
hasCreatedByMetadata,
hasRecentlyAccessedMetadata,
pagination,
pagination: _pagination,
tableSort,
tableFilter,
} = state;
Expand Down Expand Up @@ -903,7 +904,7 @@ function TableListViewTableComp<T extends UserContentCommonSchema>({
[updateTableSortFilterAndPagination]
);

const onTableChange = useCallback(
const customOnTableChange = useCallback(
(criteria: CriteriaWithPagination<T>) => {
const data: {
sort?: State<T>['tableSort'];
Expand Down Expand Up @@ -1038,6 +1039,20 @@ function TableListViewTableComp<T extends UserContentCommonSchema>({
);
}, [entityName, fetchError]);

const { pageSize, onTableChange } = useEuiTablePersist({
tableId: listingId,
initialPageSize,
customOnTableChange,
pageSizeOptions: uniq([10, 20, 50, initialPageSize]).sort(),
});

const pagination = useMemo<Pagination>(() => {
return {
..._pagination,
pageSize,
};
}, [_pagination, pageSize]);

// ------------
// Effects
// ------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
"@kbn/content-management-user-profiles",
"@kbn/recently-accessed",
"@kbn/content-management-content-insights-public",
"@kbn/content-management-favorites-public"
"@kbn/content-management-favorites-public",
"@kbn/kibana-utils-plugin",
"@kbn/shared-ux-table-persist"
],
"exclude": [
"target/**/*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import React from 'react';
import { shallow } from 'enzyme';
import type { StatusInfoServiceStatus as ServiceStatus } from '@kbn/core-status-common-internal';
import type { StatusInfoServiceStatus as ServiceStatus } from '@kbn/core-status-common';
import { StatusTable } from './status_table';

const state = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import React from 'react';
import { mountWithIntl, findTestSubject } from '@kbn/test-jest-helpers';
import type { ServerVersion } from '@kbn/core-status-common-internal';
import type { ServerVersion } from '@kbn/core-status-common';
import { VersionHeader } from './version_header';

const buildServerVersion = (parts: Partial<ServerVersion> = {}): ServerVersion => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import React, { FC } from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiPanel, EuiText } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import type { ServerVersion } from '@kbn/core-status-common-internal';
import type { ServerVersion } from '@kbn/core-status-common';

interface VersionHeaderProps {
version: ServerVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { httpServiceMock } from '@kbn/core-http-browser-mocks';
import type { StatusResponse } from '@kbn/core-status-common-internal';
import type { StatusResponse } from '@kbn/core-status-common';
import { notificationServiceMock } from '@kbn/core-notifications-browser-mocks';
import { mocked } from '@kbn/core-metrics-collectors-server-mocks';
import { loadStatus } from './load_status';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import numeral from '@elastic/numeral';
import { i18n } from '@kbn/i18n';
import type { HttpSetup } from '@kbn/core-http-browser';
import type { NotificationsSetup } from '@kbn/core-notifications-browser';
import type { ServiceStatusLevelId } from '@kbn/core-status-common';
import type {
ServiceStatusLevelId,
StatusResponse,
StatusInfoServiceStatus as ServiceStatus,
} from '@kbn/core-status-common-internal';
} from '@kbn/core-status-common';
import type { DataType } from './format_number';

interface MetricMeta {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { StatusInfoServiceStatus as ServiceStatus } from '@kbn/core-status-common-internal';
import type { StatusInfoServiceStatus as ServiceStatus } from '@kbn/core-status-common';
import { getLevelSortValue, groupByLevel, getHighestStatus } from './status_level';
import { FormattedStatus, StatusState } from './load_status';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"@kbn/core-application-browser",
"@kbn/core-application-browser-internal",
"@kbn/core-mount-utils-browser-internal",
"@kbn/core-status-common-internal",
"@kbn/core-http-browser-internal",
"@kbn/core-application-browser-mocks",
"@kbn/core-notifications-browser-mocks",
Expand Down
35 changes: 35 additions & 0 deletions packages/core/base/core-base-common/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")

SRCS = glob(
[
"**/*.ts",
"**/*.tsx",
],
exclude = [
"**/test_helpers.ts",
"**/*.config.js",
"**/*.mock.*",
"**/*.test.*",
"**/*.stories.*",
"**/__snapshots__/**",
"**/integration_tests/**",
"**/mocks/**",
"**/scripts/**",
"**/storybook/**",
"**/test_fixtures/**",
"**/test_helpers/**",
],
)

DEPS = [
"@npm//react",
"@npm//tslib",
]

js_library(
name = "core-base-common",
package_name = "@kbn/core-base-common",
srcs = ["package.json"] + SRCS,
deps = DEPS,
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const createSetupContractMock = () => {
setupContract.getPlugins.mockReturnValue([]);
setupContract.getTheme.mockReturnValue({
darkMode: false,
name: 'amsterdam',
version: 'v8',
stylesheetPaths: {
default: ['light-1.css'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface InjectedMetadataExternalUrlPolicy {
/** @internal */
export interface InjectedMetadataTheme {
darkMode: DarkModeValue;
name: string;
version: ThemeVersion;
stylesheetPaths: {
default: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { last } from 'lodash';
import { LogRecord } from '@kbn/logging';
import { Conversion } from './types';

const dateRegExp = /%date({(?<format>[^}]+)})?({(?<timezone>[^}]+)})?/g;
const dateRegExp = /%date(?:\{(?<format>[^}]+)\})?(?:\{(?<timezone>[A-Za-z/_+-]+)\})?/g;

const formats = {
ISO8601: 'ISO8601',
Expand All @@ -29,7 +29,6 @@ function formatDate(
): string {
const momentDate = moment(date);
momentDate.tz(timezone ?? moment.tz.guess());

switch (dateFormat) {
case formats.ISO8601:
return momentDate.toISOString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,21 @@ describe('schema', () => {
`"Date format expected one of ISO8601, ISO8601_TZ, ABSOLUTE, UNIX, UNIX_MILLIS, but given: HH"`
);
});

it('fails on %date with schema too long', () => {
const generateLongFormat = () => {
const longFormat = [];
for (let i = 1; i < 1001; i++) {
longFormat.push(`${i}`);
}
return longFormat.join('');
};
expect(() =>
patternSchema.validate(`%date${generateLongFormat()}`)
).toThrowErrorMatchingInlineSnapshot(
`"value has length [2898] but it must have a maximum length of [1000]."`
);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
const DEFAULT_PATTERN = `[%date][%level][%logger] %message`;

export const patternSchema = schema.string({
maxLength: 1000,
validate: (string) => {
DateConversion.validate!(string);
},
Expand Down
Loading

0 comments on commit 88c3008

Please sign in to comment.