Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TableListView] Refactor to function component #135807

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions packages/kbn-test-jest-helpers/src/testbed/testbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ const defaultConfig: TestBedConfig = {
});
```
*/
export function registerTestBed<T extends string = string>(
export function registerTestBed<T extends string = string, P extends object = any>(
Component: ComponentType<any>,
config: AsyncTestBedConfig
): AsyncSetupFunc<T>;
export function registerTestBed<T extends string = string>(
): AsyncSetupFunc<T, Partial<P>>;
export function registerTestBed<T extends string = string, P extends object = any>(
Component: ComponentType<any>,
config?: TestBedConfig
): SyncSetupFunc<T>;
export function registerTestBed<T extends string = string>(
): SyncSetupFunc<T, Partial<P>>;
export function registerTestBed<T extends string = string, P extends object = any>(
Component: ComponentType<any>,
config?: AsyncTestBedConfig | TestBedConfig
): SetupFunc<T> {
): SetupFunc<T, Partial<P>> {
const {
defaultProps = defaultConfig.defaultProps,
memoryRouter = defaultConfig.memoryRouter!,
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-test-jest-helpers/src/testbed/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { Store } from 'redux';
import { ReactWrapper as GenericReactWrapper } from 'enzyme';
import { LocationDescriptor } from 'history';

export type AsyncSetupFunc<T> = (props?: any) => Promise<TestBed<T>>;
export type SyncSetupFunc<T> = (props?: any) => TestBed<T>;
export type SetupFunc<T> = (props?: any) => TestBed<T> | Promise<TestBed<T>>;
export type AsyncSetupFunc<T, P extends object = any> = (props?: P) => Promise<TestBed<T>>;
export type SyncSetupFunc<T, P extends object = any> = (props?: P) => TestBed<T>;
export type SetupFunc<T, P extends object = any> = (props?: P) => TestBed<T> | Promise<TestBed<T>>;
export type ReactWrapper = GenericReactWrapper<any>;

export interface EuiTableMetaData {
Expand Down

This file was deleted.

62 changes: 62 additions & 0 deletions src/plugins/kibana_react/public/table_list_view/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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 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 or the Server
* Side Public License, v 1.
*/
import type { HttpFetchError } from '@kbn/core/public';
import type { CriteriaWithPagination } from '@elastic/eui';

export interface OnFetchItemsAction {
type: 'onFetchItems';
}

export interface OnFetchItemsSuccessAction<T> {
type: 'onFetchItemsSuccess';
data: {
response: {
total: number;
hits: T[];
};
listingLimit: number;
};
}

export interface OnFetchItemsErrorAction {
type: 'onFetchItemsError';
data: HttpFetchError;
}

export interface DeleteItemsActions {
type: 'onCancelDeleteItems' | 'onDeleteItems' | 'onItemsDeleted';
}

export interface OnSelectionChangeAction<T> {
type: 'onSelectionChange';
data: T[];
}

export interface OnTableChangeAction<T> {
type: 'onTableChange';
data: CriteriaWithPagination<T>;
}

export interface OnClickDeleteItemsAction {
type: 'onClickDeleteItems';
}

export interface OnFilterChangeAction {
type: 'onFilterChange';
data: string;
}

export type Action<T> =
| OnFetchItemsAction
| OnFetchItemsSuccessAction<T>
| OnFetchItemsErrorAction
| DeleteItemsActions
| OnSelectionChangeAction<T>
| OnTableChangeAction<T>
| OnClickDeleteItemsAction
| OnFilterChangeAction;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 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 or the Server
* Side Public License, v 1.
*/

export { UpdatedAtField } from './updated_at_field';
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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 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 or the Server
* Side Public License, v 1.
*/

import React, { FC } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiToolTip } from '@elastic/eui';
import { FormattedRelative } from '@kbn/i18n-react';
import moment from 'moment';

export const UpdatedAtField: FC<{ dateTime?: string }> = ({ dateTime }) => {
if (!dateTime) {
return (
<EuiToolTip
content={i18n.translate('kibana-react.tableListView.updatedDateUnknownLabel', {
defaultMessage: 'Last updated unknown',
})}
>
<span>-</span>
</EuiToolTip>
);
}
const updatedAt = moment(dateTime);

if (updatedAt.diff(moment(), 'days') > -7) {
return (
<FormattedRelative value={new Date(dateTime).getTime()}>
{(formattedDate: string) => (
<EuiToolTip content={updatedAt.format('LL LT')}>
<span>{formattedDate}</span>
</EuiToolTip>
)}
</FormattedRelative>
);
}
return (
<EuiToolTip content={updatedAt.format('LL LT')}>
<span>{updatedAt.format('LL')}</span>
</EuiToolTip>
);
};
4 changes: 3 additions & 1 deletion src/plugins/kibana_react/public/table_list_view/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
* Side Public License, v 1.
*/

export * from './table_list_view';
export { TableListView } from './table_list_view';

export type { Props as TableListViewProps, State as TableListViewState } from './table_list_view';
Loading