From 0dd070a7cbd5c3f29d704aa2245e6e4788e0073c Mon Sep 17 00:00:00 2001 From: sitbubu Date: Mon, 7 Feb 2022 10:31:42 +0200 Subject: [PATCH 1/9] Add updated_at columnb to objects' tables Signed-off-by: sitbubu --- .../saved_objects/saved_objects_client.test.ts | 6 ++++-- .../saved_objects/simple_saved_object.test.ts | 7 +++++++ .../public/saved_objects/simple_saved_object.ts | 14 +++++++++++++- .../application/listing/dashboard_listing.js | 14 ++++++++++++++ .../public/saved_object/saved_object_loader.ts | 9 +++++++-- .../objects_table/components/table.tsx | 15 +++++++++++++++ .../application/utils/get_table_columns.tsx | 14 ++++++++++++++ 7 files changed, 74 insertions(+), 5 deletions(-) diff --git a/src/core/public/saved_objects/saved_objects_client.test.ts b/src/core/public/saved_objects/saved_objects_client.test.ts index 3218fc24e049..716b688ab423 100644 --- a/src/core/public/saved_objects/saved_objects_client.test.ts +++ b/src/core/public/saved_objects/saved_objects_client.test.ts @@ -33,11 +33,13 @@ import { SimpleSavedObject } from './simple_saved_object'; import { httpServiceMock } from '../http/http_service.mock'; describe('SavedObjectsClient', () => { + const updatedAt = new Date().toString(); const doc = { id: 'AVwSwFxtcMV38qjDZoQg', type: 'config', attributes: { title: 'Example title' }, version: 'foo', + updated_at: updatedAt, }; const http = httpServiceMock.createStartContract(); @@ -356,7 +358,7 @@ describe('SavedObjectsClient', () => { Array [ "/api/saved_objects/_bulk_create", Object { - "body": "[{\\"id\\":\\"AVwSwFxtcMV38qjDZoQg\\",\\"type\\":\\"config\\",\\"attributes\\":{\\"title\\":\\"Example title\\"},\\"version\\":\\"foo\\"}]", + "body": "[{\\"id\\":\\"AVwSwFxtcMV38qjDZoQg\\",\\"type\\":\\"config\\",\\"attributes\\":{\\"title\\":\\"Example title\\"},\\"version\\":\\"foo\\",\\"updated_at\\":\\"${updatedAt}\\"}]", "method": "POST", "query": Object { "overwrite": false, @@ -374,7 +376,7 @@ describe('SavedObjectsClient', () => { Array [ "/api/saved_objects/_bulk_create", Object { - "body": "[{\\"id\\":\\"AVwSwFxtcMV38qjDZoQg\\",\\"type\\":\\"config\\",\\"attributes\\":{\\"title\\":\\"Example title\\"},\\"version\\":\\"foo\\"}]", + "body": "[{\\"id\\":\\"AVwSwFxtcMV38qjDZoQg\\",\\"type\\":\\"config\\",\\"attributes\\":{\\"title\\":\\"Example title\\"},\\"version\\":\\"foo\\",\\"updated_at\\":\\"${updatedAt}\\"}]", "method": "POST", "query": Object { "overwrite": true, diff --git a/src/core/public/saved_objects/simple_saved_object.test.ts b/src/core/public/saved_objects/simple_saved_object.test.ts index 436b5c278e86..234adb3c6862 100644 --- a/src/core/public/saved_objects/simple_saved_object.test.ts +++ b/src/core/public/saved_objects/simple_saved_object.test.ts @@ -67,4 +67,11 @@ describe('SimpleSavedObject', () => { const savedObject = new SimpleSavedObject(client, { version } as SavedObject); expect(savedObject._version).toEqual(version); }); + + it('persists updated_at', () => { + const updatedAt = new Date().toString(); + + const savedObject = new SimpleSavedObject(client, { updated_at: updatedAt } as SavedObject); + expect(savedObject.updated_at).toEqual(updatedAt); + }); }); diff --git a/src/core/public/saved_objects/simple_saved_object.ts b/src/core/public/saved_objects/simple_saved_object.ts index fe0c66764008..7cbedf4b9bb9 100644 --- a/src/core/public/saved_objects/simple_saved_object.ts +++ b/src/core/public/saved_objects/simple_saved_object.ts @@ -51,10 +51,21 @@ export class SimpleSavedObject { public migrationVersion: SavedObjectType['migrationVersion']; public error: SavedObjectType['error']; public references: SavedObjectType['references']; + public updated_at: SavedObjectType['updated_at']; constructor( private client: SavedObjectsClientContract, - { id, type, version, attributes, error, references, migrationVersion }: SavedObjectType + { + id, + type, + version, + attributes, + error, + references, + migrationVersion, + // eslint-disable-next-line @typescript-eslint/naming-convention + updated_at, + }: SavedObjectType ) { this.id = id; this.type = type; @@ -62,6 +73,7 @@ export class SimpleSavedObject { this.references = references || []; this._version = version; this.migrationVersion = migrationVersion; + this.updated_at = updated_at; if (error) { this.error = error; } diff --git a/src/plugins/dashboard/public/application/listing/dashboard_listing.js b/src/plugins/dashboard/public/application/listing/dashboard_listing.js index dc778be046b2..8fadc47c7838 100644 --- a/src/plugins/dashboard/public/application/listing/dashboard_listing.js +++ b/src/plugins/dashboard/public/application/listing/dashboard_listing.js @@ -30,6 +30,7 @@ import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; +import moment from 'moment'; import { FormattedMessage, I18nProvider } from '@osd/i18n/react'; import { i18n } from '@osd/i18n'; @@ -185,6 +186,19 @@ export class DashboardListing extends React.Component { dataType: 'string', sortable: true, }, + { + field: `updated_at`, + name: i18n.translate('dashboard.listing.table.columnUpdatedAtName', { + defaultMessage: 'Updated at', + }), + dataType: 'date', + sortable: true, + description: i18n.translate('dashboard.listing.table.columnUpdatedAtDescription', { + defaultMessage: 'Updated at of the saved object', + }), + ['data-test-subj']: 'updated-at', + render: (updatedAt) => updatedAt && moment(updatedAt).format('MMM DD YYYY'), + }, ]; return tableColumns; } diff --git a/src/plugins/saved_objects/public/saved_object/saved_object_loader.ts b/src/plugins/saved_objects/public/saved_object/saved_object_loader.ts index 9184d467c247..65b0384e4a17 100644 --- a/src/plugins/saved_objects/public/saved_object/saved_object_loader.ts +++ b/src/plugins/saved_objects/public/saved_object/saved_object_loader.ts @@ -105,12 +105,17 @@ export class SavedObjectLoader { } /** - * Updates hit.attributes to contain an id and url field, and returns the updated + * Updates hit.attributes to contain an updated_at, id and url field, and returns the updated * attributes object. * @param hit * @returns {hit.attributes} The modified hit.attributes object, with an id and url field. */ - mapSavedObjectApiHits(hit: { attributes: Record; id: string }) { + mapSavedObjectApiHits(hit: { + attributes: Record; + id: string; + updated_at?: string; + }) { + hit.attributes.updated_at = hit.updated_at; return this.mapHitSource(hit.attributes, hit.id); } diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx index ba3b443354f8..f476ec6ad28e 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx @@ -30,6 +30,7 @@ import { IBasePath } from 'src/core/public'; import React, { PureComponent, Fragment } from 'react'; +import moment from 'moment'; import { EuiSearchBar, EuiBasicTable, @@ -251,6 +252,20 @@ export class Table extends PureComponent { ); }, } as EuiTableFieldDataColumnType>, + { + field: `updated_at`, + name: i18n.translate('savedObjectsManagement.objectsTable.table.columnUpdatedAtName', { + defaultMessage: 'Updated at', + }), + dataType: 'date', + sortable: true, + description: i18n.translate( + 'savedObjectsManagement.objectsTable.table.columnUpdatedAtDescription', + { defaultMessage: 'Updated at of the saved object' } + ), + 'data-test-subj': 'updated-at', + render: (updatedAt: string) => updatedAt && moment(updatedAt).format('MMM DD YYYY'), + } as EuiTableFieldDataColumnType>, ...columnRegistry.getAll().map((column) => { return { ...column.euiColumn, diff --git a/src/plugins/visualize/public/application/utils/get_table_columns.tsx b/src/plugins/visualize/public/application/utils/get_table_columns.tsx index 356d28989551..f3f81db7bbeb 100644 --- a/src/plugins/visualize/public/application/utils/get_table_columns.tsx +++ b/src/plugins/visualize/public/application/utils/get_table_columns.tsx @@ -36,6 +36,7 @@ import { FormattedMessage } from '@osd/i18n/react'; import { ApplicationStart } from 'opensearch-dashboards/public'; import { VisualizationListItem } from 'src/plugins/visualizations/public'; +import moment from 'moment'; const getBadge = (item: VisualizationListItem) => { if (item.stage === 'beta') { @@ -144,6 +145,19 @@ export const getTableColumns = (application: ApplicationStart, history: History) sortable: true, render: (field: string, record: VisualizationListItem) => {record.description}, }, + { + field: `updated_at`, + name: i18n.translate('visualize.listing.table.columnUpdatedAtName', { + defaultMessage: 'Updated at', + }), + dataType: 'date', + sortable: true, + description: i18n.translate('visualize.listing.table.columnUpdatedAtDescription', { + defaultMessage: 'Updated at of the saved object', + }), + ['data-test-subj']: 'updated-at', + render: (updatedAt: string) => updatedAt && moment(updatedAt).format('MMM DD YYYY'), + }, ]; export const getNoItemsMessage = (createItem: () => void) => ( From 1e14eaa481e309111fa03bf7222a7536c81fcbd4 Mon Sep 17 00:00:00 2001 From: sitbubu Date: Sun, 13 Feb 2022 11:19:26 +0200 Subject: [PATCH 2/9] Grammer and iso usage Signed-off-by: sitbubu --- src/core/public/saved_objects/saved_objects_client.test.ts | 2 +- .../dashboard/public/application/listing/dashboard_listing.js | 4 ++-- .../management_section/objects_table/components/table.tsx | 4 ++-- .../visualize/public/application/utils/get_table_columns.tsx | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/public/saved_objects/saved_objects_client.test.ts b/src/core/public/saved_objects/saved_objects_client.test.ts index 716b688ab423..19b140ad3a12 100644 --- a/src/core/public/saved_objects/saved_objects_client.test.ts +++ b/src/core/public/saved_objects/saved_objects_client.test.ts @@ -33,7 +33,7 @@ import { SimpleSavedObject } from './simple_saved_object'; import { httpServiceMock } from '../http/http_service.mock'; describe('SavedObjectsClient', () => { - const updatedAt = new Date().toString(); + const updatedAt = new Date().toISOString(); const doc = { id: 'AVwSwFxtcMV38qjDZoQg', type: 'config', diff --git a/src/plugins/dashboard/public/application/listing/dashboard_listing.js b/src/plugins/dashboard/public/application/listing/dashboard_listing.js index 8fadc47c7838..5780b152c041 100644 --- a/src/plugins/dashboard/public/application/listing/dashboard_listing.js +++ b/src/plugins/dashboard/public/application/listing/dashboard_listing.js @@ -189,12 +189,12 @@ export class DashboardListing extends React.Component { { field: `updated_at`, name: i18n.translate('dashboard.listing.table.columnUpdatedAtName', { - defaultMessage: 'Updated at', + defaultMessage: 'Last updated', }), dataType: 'date', sortable: true, description: i18n.translate('dashboard.listing.table.columnUpdatedAtDescription', { - defaultMessage: 'Updated at of the saved object', + defaultMessage: 'Last update of the saved object', }), ['data-test-subj']: 'updated-at', render: (updatedAt) => updatedAt && moment(updatedAt).format('MMM DD YYYY'), diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx index f476ec6ad28e..c17b8f929bad 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx @@ -255,13 +255,13 @@ export class Table extends PureComponent { { field: `updated_at`, name: i18n.translate('savedObjectsManagement.objectsTable.table.columnUpdatedAtName', { - defaultMessage: 'Updated at', + defaultMessage: 'Last updated', }), dataType: 'date', sortable: true, description: i18n.translate( 'savedObjectsManagement.objectsTable.table.columnUpdatedAtDescription', - { defaultMessage: 'Updated at of the saved object' } + { defaultMessage: 'Last update of the saved object' } ), 'data-test-subj': 'updated-at', render: (updatedAt: string) => updatedAt && moment(updatedAt).format('MMM DD YYYY'), diff --git a/src/plugins/visualize/public/application/utils/get_table_columns.tsx b/src/plugins/visualize/public/application/utils/get_table_columns.tsx index f3f81db7bbeb..f7c599e24172 100644 --- a/src/plugins/visualize/public/application/utils/get_table_columns.tsx +++ b/src/plugins/visualize/public/application/utils/get_table_columns.tsx @@ -148,12 +148,12 @@ export const getTableColumns = (application: ApplicationStart, history: History) { field: `updated_at`, name: i18n.translate('visualize.listing.table.columnUpdatedAtName', { - defaultMessage: 'Updated at', + defaultMessage: 'Last updated', }), dataType: 'date', sortable: true, description: i18n.translate('visualize.listing.table.columnUpdatedAtDescription', { - defaultMessage: 'Updated at of the saved object', + defaultMessage: 'Last update of the saved object', }), ['data-test-subj']: 'updated-at', render: (updatedAt: string) => updatedAt && moment(updatedAt).format('MMM DD YYYY'), From ea814905f90a0a0318548f9cb6b846aa34b80324 Mon Sep 17 00:00:00 2001 From: sitbubu Date: Mon, 14 Feb 2022 11:23:36 +0200 Subject: [PATCH 3/9] Set updated at field from advanced settings Signed-off-by: sitbubu --- .../public/application/listing/dashboard_listing.js | 3 ++- .../public/saved_object/saved_object_loader.ts | 2 +- .../objects_table/components/table.tsx | 4 +++- .../objects_table/saved_objects_table.tsx | 2 ++ .../management_section/saved_objects_table_page.tsx | 2 ++ .../application/components/visualize_listing.tsx | 6 +++++- .../public/application/utils/get_table_columns.tsx | 10 ++++++++-- 7 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/plugins/dashboard/public/application/listing/dashboard_listing.js b/src/plugins/dashboard/public/application/listing/dashboard_listing.js index 5780b152c041..e51e78c56fda 100644 --- a/src/plugins/dashboard/public/application/listing/dashboard_listing.js +++ b/src/plugins/dashboard/public/application/listing/dashboard_listing.js @@ -162,6 +162,7 @@ export class DashboardListing extends React.Component { } getTableColumns() { + const [, dateFormat] = this.props.core.uiSettings.get('dateFormat:scaled')[3]; const tableColumns = [ { field: 'title', @@ -197,7 +198,7 @@ export class DashboardListing extends React.Component { defaultMessage: 'Last update of the saved object', }), ['data-test-subj']: 'updated-at', - render: (updatedAt) => updatedAt && moment(updatedAt).format('MMM DD YYYY'), + render: (updatedAt) => updatedAt && moment(updatedAt).format(dateFormat), }, ]; return tableColumns; diff --git a/src/plugins/saved_objects/public/saved_object/saved_object_loader.ts b/src/plugins/saved_objects/public/saved_object/saved_object_loader.ts index 65b0384e4a17..26d7136e3737 100644 --- a/src/plugins/saved_objects/public/saved_object/saved_object_loader.ts +++ b/src/plugins/saved_objects/public/saved_object/saved_object_loader.ts @@ -115,7 +115,7 @@ export class SavedObjectLoader { id: string; updated_at?: string; }) { - hit.attributes.updated_at = hit.updated_at; + hit.attributes.updated_at = hit?.updated_at ?? hit.attributes._updatedAt; return this.mapHitSource(hit.attributes, hit.id); } diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx index c17b8f929bad..50ec838b9860 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/table.tsx @@ -81,6 +81,7 @@ export interface TableProps { isSearching: boolean; onShowRelationships: (object: SavedObjectWithMetadata) => void; canGoInApp: (obj: SavedObjectWithMetadata) => boolean; + dateFormat: string; } interface TableState { @@ -173,6 +174,7 @@ export class Table extends PureComponent { basePath, actionRegistry, columnRegistry, + dateFormat, } = this.props; const pagination = { @@ -264,7 +266,7 @@ export class Table extends PureComponent { { defaultMessage: 'Last update of the saved object' } ), 'data-test-subj': 'updated-at', - render: (updatedAt: string) => updatedAt && moment(updatedAt).format('MMM DD YYYY'), + render: (updatedAt: string) => updatedAt && moment(updatedAt).format(dateFormat), } as EuiTableFieldDataColumnType>, ...columnRegistry.getAll().map((column) => { return { diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx index 9561774d7e12..8d0d13d3334a 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/saved_objects_table.tsx @@ -109,6 +109,7 @@ export interface SavedObjectsTableProps { perPageConfig: number; goInspectObject: (obj: SavedObjectWithMetadata) => void; canGoInApp: (obj: SavedObjectWithMetadata) => boolean; + dateFormat: string; } export interface SavedObjectsTableState { @@ -811,6 +812,7 @@ export class SavedObjectsTable extends Component diff --git a/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx b/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx index fd15fd94494e..1942014ac6d5 100644 --- a/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx +++ b/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx @@ -59,6 +59,7 @@ const SavedObjectsTablePage = ({ }) => { const capabilities = coreStart.application.capabilities; const itemsPerPage = coreStart.uiSettings.get('savedObjects:perPage', 50); + const [, dateFormat] = coreStart.uiSettings.get('dateFormat:scaled')[3]; useEffect(() => { setBreadcrumbs([ @@ -93,6 +94,7 @@ const SavedObjectsTablePage = ({ ); } }} + dateFormat={dateFormat} canGoInApp={(savedObject) => { const { inAppUrl } = savedObject.meta; return inAppUrl ? Boolean(get(capabilities, inAppUrl.uiCapabilitiesPath)) : false; diff --git a/src/plugins/visualize/public/application/components/visualize_listing.tsx b/src/plugins/visualize/public/application/components/visualize_listing.tsx index 9c39150cc036..767793efa2d8 100644 --- a/src/plugins/visualize/public/application/components/visualize_listing.tsx +++ b/src/plugins/visualize/public/application/components/visualize_listing.tsx @@ -109,7 +109,11 @@ export const VisualizeListing = () => { ); const noItemsFragment = useMemo(() => getNoItemsMessage(createNewVis), [createNewVis]); - const tableColumns = useMemo(() => getTableColumns(application, history), [application, history]); + const tableColumns = useMemo(() => getTableColumns(application, history, uiSettings), [ + application, + history, + uiSettings, + ]); const fetchItems = useCallback( (filter) => { diff --git a/src/plugins/visualize/public/application/utils/get_table_columns.tsx b/src/plugins/visualize/public/application/utils/get_table_columns.tsx index f7c599e24172..d3b9f8c0773d 100644 --- a/src/plugins/visualize/public/application/utils/get_table_columns.tsx +++ b/src/plugins/visualize/public/application/utils/get_table_columns.tsx @@ -37,6 +37,7 @@ import { FormattedMessage } from '@osd/i18n/react'; import { ApplicationStart } from 'opensearch-dashboards/public'; import { VisualizationListItem } from 'src/plugins/visualizations/public'; import moment from 'moment'; +import { IUiSettingsClient } from '../../../../../core/public'; const getBadge = (item: VisualizationListItem) => { if (item.stage === 'beta') { @@ -92,7 +93,11 @@ const renderItemTypeIcon = (item: VisualizationListItem) => { return icon; }; -export const getTableColumns = (application: ApplicationStart, history: History) => [ +export const getTableColumns = ( + application: ApplicationStart, + history: History, + uiSettings: IUiSettingsClient +) => [ { field: 'title', name: i18n.translate('visualize.listing.table.titleColumnName', { @@ -156,7 +161,8 @@ export const getTableColumns = (application: ApplicationStart, history: History) defaultMessage: 'Last update of the saved object', }), ['data-test-subj']: 'updated-at', - render: (updatedAt: string) => updatedAt && moment(updatedAt).format('MMM DD YYYY'), + render: (updatedAt: string) => + updatedAt && moment(updatedAt).format(uiSettings.get('dateFormat:scaled')[3][1]), }, ]; From 49523a3959e62b61be630190ffed2abc84253746 Mon Sep 17 00:00:00 2001 From: sitbubu Date: Fri, 13 May 2022 14:32:35 +0300 Subject: [PATCH 4/9] Use dateFormat instead of dateFormat:scaled Signed-off-by: sitbubu --- .../dashboard/public/application/listing/dashboard_listing.js | 2 +- .../public/management_section/saved_objects_table_page.tsx | 2 +- .../visualize/public/application/utils/get_table_columns.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/dashboard/public/application/listing/dashboard_listing.js b/src/plugins/dashboard/public/application/listing/dashboard_listing.js index e51e78c56fda..1864c2852aeb 100644 --- a/src/plugins/dashboard/public/application/listing/dashboard_listing.js +++ b/src/plugins/dashboard/public/application/listing/dashboard_listing.js @@ -162,7 +162,7 @@ export class DashboardListing extends React.Component { } getTableColumns() { - const [, dateFormat] = this.props.core.uiSettings.get('dateFormat:scaled')[3]; + const dateFormat = this.props.core.uiSettings.get('dateFormat'); const tableColumns = [ { field: 'title', diff --git a/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx b/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx index 1942014ac6d5..1640e5e2dd36 100644 --- a/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx +++ b/src/plugins/saved_objects_management/public/management_section/saved_objects_table_page.tsx @@ -59,7 +59,7 @@ const SavedObjectsTablePage = ({ }) => { const capabilities = coreStart.application.capabilities; const itemsPerPage = coreStart.uiSettings.get('savedObjects:perPage', 50); - const [, dateFormat] = coreStart.uiSettings.get('dateFormat:scaled')[3]; + const dateFormat = coreStart.uiSettings.get('dateFormat'); useEffect(() => { setBreadcrumbs([ diff --git a/src/plugins/visualize/public/application/utils/get_table_columns.tsx b/src/plugins/visualize/public/application/utils/get_table_columns.tsx index d3b9f8c0773d..fbf51bba1958 100644 --- a/src/plugins/visualize/public/application/utils/get_table_columns.tsx +++ b/src/plugins/visualize/public/application/utils/get_table_columns.tsx @@ -162,7 +162,7 @@ export const getTableColumns = ( }), ['data-test-subj']: 'updated-at', render: (updatedAt: string) => - updatedAt && moment(updatedAt).format(uiSettings.get('dateFormat:scaled')[3][1]), + updatedAt && moment(updatedAt).format(uiSettings.get('dateFormat')), }, ]; From 3c54667f881524800a0e38a0290675db2c2463e6 Mon Sep 17 00:00:00 2001 From: sitbubu Date: Fri, 13 May 2022 15:31:15 +0300 Subject: [PATCH 5/9] snapshot Signed-off-by: sitbubu --- .../dashboard_listing.test.js.snap | 138 +++++++++++++++++- .../__snapshots__/table.test.tsx.snap | 18 +++ 2 files changed, 150 insertions(+), 6 deletions(-) diff --git a/src/plugins/dashboard/public/application/listing/__snapshots__/dashboard_listing.test.js.snap b/src/plugins/dashboard/public/application/listing/__snapshots__/dashboard_listing.test.js.snap index cfa5d1ce8aa5..fd45b2291f99 100644 --- a/src/plugins/dashboard/public/application/listing/__snapshots__/dashboard_listing.test.js.snap +++ b/src/plugins/dashboard/public/application/listing/__snapshots__/dashboard_listing.test.js.snap @@ -45,13 +45,34 @@ exports[`after fetch hideWriteControls 1`] = ` "name": "Description", "sortable": true, }, + Object { + "data-test-subj": "updated-at", + "dataType": "date", + "description": "Last update of the saved object", + "field": "updated_at", + "name": "Last updated", + "render": [Function], + "sortable": true, + }, ] } tableListTitle="Dashboards" toastNotifications={Object {}} uiSettings={ Object { - "get": [MockFunction], + "get": [MockFunction] { + "calls": Array [ + Array [ + "dateFormat", + ], + ], + "results": Array [ + Object { + "type": "return", + "value": 10, + }, + ], + }, } } /> @@ -147,13 +168,34 @@ exports[`after fetch initialFilter 1`] = ` "name": "Description", "sortable": true, }, + Object { + "data-test-subj": "updated-at", + "dataType": "date", + "description": "Last update of the saved object", + "field": "updated_at", + "name": "Last updated", + "render": [Function], + "sortable": true, + }, ] } tableListTitle="Dashboards" toastNotifications={Object {}} uiSettings={ Object { - "get": [MockFunction], + "get": [MockFunction] { + "calls": Array [ + Array [ + "dateFormat", + ], + ], + "results": Array [ + Object { + "type": "return", + "value": 10, + }, + ], + }, } } /> @@ -249,13 +291,34 @@ exports[`after fetch renders call to action when no dashboards exist 1`] = ` "name": "Description", "sortable": true, }, + Object { + "data-test-subj": "updated-at", + "dataType": "date", + "description": "Last update of the saved object", + "field": "updated_at", + "name": "Last updated", + "render": [Function], + "sortable": true, + }, ] } tableListTitle="Dashboards" toastNotifications={Object {}} uiSettings={ Object { - "get": [MockFunction], + "get": [MockFunction] { + "calls": Array [ + Array [ + "dateFormat", + ], + ], + "results": Array [ + Object { + "type": "return", + "value": 10, + }, + ], + }, } } /> @@ -351,13 +414,34 @@ exports[`after fetch renders table rows 1`] = ` "name": "Description", "sortable": true, }, + Object { + "data-test-subj": "updated-at", + "dataType": "date", + "description": "Last update of the saved object", + "field": "updated_at", + "name": "Last updated", + "render": [Function], + "sortable": true, + }, ] } tableListTitle="Dashboards" toastNotifications={Object {}} uiSettings={ Object { - "get": [MockFunction], + "get": [MockFunction] { + "calls": Array [ + Array [ + "dateFormat", + ], + ], + "results": Array [ + Object { + "type": "return", + "value": 10, + }, + ], + }, } } /> @@ -453,13 +537,34 @@ exports[`after fetch renders warning when listingLimit is exceeded 1`] = ` "name": "Description", "sortable": true, }, + Object { + "data-test-subj": "updated-at", + "dataType": "date", + "description": "Last update of the saved object", + "field": "updated_at", + "name": "Last updated", + "render": [Function], + "sortable": true, + }, ] } tableListTitle="Dashboards" toastNotifications={Object {}} uiSettings={ Object { - "get": [MockFunction], + "get": [MockFunction] { + "calls": Array [ + Array [ + "dateFormat", + ], + ], + "results": Array [ + Object { + "type": "return", + "value": 10, + }, + ], + }, } } /> @@ -554,13 +659,34 @@ exports[`renders empty page in before initial fetch to avoid flickering 1`] = ` "name": "Description", "sortable": true, }, + Object { + "data-test-subj": "updated-at", + "dataType": "date", + "description": "Last update of the saved object", + "field": "updated_at", + "name": "Last updated", + "render": [Function], + "sortable": true, + }, ] } tableListTitle="Dashboards" toastNotifications={Object {}} uiSettings={ Object { - "get": [MockFunction], + "get": [MockFunction] { + "calls": Array [ + Array [ + "dateFormat", + ], + ], + "results": Array [ + Object { + "type": "return", + "value": 10, + }, + ], + }, } } /> diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/table.test.tsx.snap b/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/table.test.tsx.snap index 65a6a98777cc..e22f7f3a0128 100644 --- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/table.test.tsx.snap +++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/table.test.tsx.snap @@ -143,6 +143,15 @@ exports[`Table prevents saved objects from being deleted 1`] = ` "render": [Function], "sortable": false, }, + Object { + "data-test-subj": "updated-at", + "dataType": "date", + "description": "Last update of the saved object", + "field": "updated_at", + "name": "Last updated", + "render": [Function], + "sortable": true, + }, Object { "actions": Array [ Object { @@ -359,6 +368,15 @@ exports[`Table should render normally 1`] = ` "render": [Function], "sortable": false, }, + Object { + "data-test-subj": "updated-at", + "dataType": "date", + "description": "Last update of the saved object", + "field": "updated_at", + "name": "Last updated", + "render": [Function], + "sortable": true, + }, Object { "actions": Array [ Object { From 0d182a38ed1df5cdbe99b7038410934483225a11 Mon Sep 17 00:00:00 2001 From: sitbubu Date: Thu, 9 Jun 2022 10:52:05 +0300 Subject: [PATCH 6/9] Add updated_at to additional comment Signed-off-by: sitbubu --- .../saved_objects/public/saved_object/saved_object_loader.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/saved_objects/public/saved_object/saved_object_loader.ts b/src/plugins/saved_objects/public/saved_object/saved_object_loader.ts index 26d7136e3737..fa329d9032b8 100644 --- a/src/plugins/saved_objects/public/saved_object/saved_object_loader.ts +++ b/src/plugins/saved_objects/public/saved_object/saved_object_loader.ts @@ -108,7 +108,7 @@ export class SavedObjectLoader { * Updates hit.attributes to contain an updated_at, id and url field, and returns the updated * attributes object. * @param hit - * @returns {hit.attributes} The modified hit.attributes object, with an id and url field. + * @returns {hit.attributes} The modified hit.attributes object, with an updated_at, id and url field. */ mapSavedObjectApiHits(hit: { attributes: Record; From 0641af37ca23f318cc3024469efc480b080bd742 Mon Sep 17 00:00:00 2001 From: sitbubu Date: Thu, 9 Jun 2022 16:53:22 +0300 Subject: [PATCH 7/9] Add unit-tests for updated_at as null undefined or unknown Signed-off-by: sitbubu --- .../saved_object/saved_object_loader.test.ts | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 src/plugins/saved_objects/public/saved_object/saved_object_loader.test.ts diff --git a/src/plugins/saved_objects/public/saved_object/saved_object_loader.test.ts b/src/plugins/saved_objects/public/saved_object/saved_object_loader.test.ts new file mode 100644 index 000000000000..645b495b5bf1 --- /dev/null +++ b/src/plugins/saved_objects/public/saved_object/saved_object_loader.test.ts @@ -0,0 +1,106 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Any modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { SavedObjectsClientContract } from 'opensearch-dashboards/public'; +import { SavedObjectLoader } from './saved_object_loader'; + +describe('SimpleSavedObjectLoader', () => { + const createLoader = (updatedAt?: any) => { + const id = 'logstash-*'; + const type = 'index-pattern'; + + const savedObject = { + attributes: {}, + id, + type, + updated_at: updatedAt as any, + }; + + client = { + ...client, + find: jest.fn(() => + Promise.resolve({ + total: 1, + savedObjects: [savedObject], + }) + ), + } as any; + + return new SavedObjectLoader(savedObject, client); + }; + + let client: SavedObjectsClientContract; + beforeEach(() => { + client = { + update: jest.fn(), + create: jest.fn(), + delete: jest.fn(), + } as any; + }); + + it('persists updated_at if undefined', async () => { + const loader = createLoader(undefined); + const savedObjects = await loader.findAll(); + + expect(savedObjects.hits).toEqual([ + { + id: 'logstash-*', + updated_at: undefined, + url: '#/index-pattern/logstash-*', + }, + ]); + }); + + it("persists updated_at as undefined if doesn't exist", async () => { + const loader = createLoader(); + const savedObjects = await loader.findAll(); + + expect(savedObjects.hits).toEqual([ + { + id: 'logstash-*', + updated_at: undefined, + url: '#/index-pattern/logstash-*', + }, + ]); + }); + + it('set updated_at as undefined if null', async () => { + const loader = createLoader(null); + const savedObjects = await loader.findAll(); + + expect(savedObjects.hits).toEqual([ + { + id: 'logstash-*', + updated_at: undefined, + url: '#/index-pattern/logstash-*', + }, + ]); + }); +}); From dce8b05b38df0d91184bbe35e4fa606959188115 Mon Sep 17 00:00:00 2001 From: sitbubu Date: Thu, 9 Jun 2022 17:16:47 +0300 Subject: [PATCH 8/9] Simplify test file Signed-off-by: sitbubu --- .../saved_object/saved_object_loader.test.ts | 38 +++++-------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/src/plugins/saved_objects/public/saved_object/saved_object_loader.test.ts b/src/plugins/saved_objects/public/saved_object/saved_object_loader.test.ts index 645b495b5bf1..95fdc94ff862 100644 --- a/src/plugins/saved_objects/public/saved_object/saved_object_loader.test.ts +++ b/src/plugins/saved_objects/public/saved_object/saved_object_loader.test.ts @@ -57,6 +57,7 @@ describe('SimpleSavedObjectLoader', () => { }; let client: SavedObjectsClientContract; + let loader: SavedObjectLoader; beforeEach(() => { client = { update: jest.fn(), @@ -65,42 +66,21 @@ describe('SimpleSavedObjectLoader', () => { } as any; }); - it('persists updated_at if undefined', async () => { - const loader = createLoader(undefined); + afterEach(async () => { const savedObjects = await loader.findAll(); - expect(savedObjects.hits).toEqual([ - { - id: 'logstash-*', - updated_at: undefined, - url: '#/index-pattern/logstash-*', - }, - ]); + expect(savedObjects.hits[0].updated_at).toEqual(undefined); }); - it("persists updated_at as undefined if doesn't exist", async () => { - const loader = createLoader(); - const savedObjects = await loader.findAll(); + it('set updated_at as undefined if undefined', async () => { + loader = createLoader(undefined); + }); - expect(savedObjects.hits).toEqual([ - { - id: 'logstash-*', - updated_at: undefined, - url: '#/index-pattern/logstash-*', - }, - ]); + it("set updated_at as undefined if doesn't exist", async () => { + loader = createLoader(); }); it('set updated_at as undefined if null', async () => { - const loader = createLoader(null); - const savedObjects = await loader.findAll(); - - expect(savedObjects.hits).toEqual([ - { - id: 'logstash-*', - updated_at: undefined, - url: '#/index-pattern/logstash-*', - }, - ]); + loader = createLoader(null); }); }); From 87e49eda613a37c1f6c64339f25f97cc7c8f7938 Mon Sep 17 00:00:00 2001 From: sitbubu Date: Mon, 20 Jun 2022 09:32:45 +0300 Subject: [PATCH 9/9] Simplified header and import from src Signed-off-by: sitbubu --- .../saved_object/saved_object_loader.test.ts | 27 +------------------ .../application/utils/get_table_columns.tsx | 2 +- 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/src/plugins/saved_objects/public/saved_object/saved_object_loader.test.ts b/src/plugins/saved_objects/public/saved_object/saved_object_loader.test.ts index 95fdc94ff862..bf0efbe50377 100644 --- a/src/plugins/saved_objects/public/saved_object/saved_object_loader.test.ts +++ b/src/plugins/saved_objects/public/saved_object/saved_object_loader.test.ts @@ -1,31 +1,6 @@ /* + * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - * - * Any modifications Copyright OpenSearch Contributors. See - * GitHub history for details. - */ - -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. */ import { SavedObjectsClientContract } from 'opensearch-dashboards/public'; diff --git a/src/plugins/visualize/public/application/utils/get_table_columns.tsx b/src/plugins/visualize/public/application/utils/get_table_columns.tsx index fbf51bba1958..a88714052d18 100644 --- a/src/plugins/visualize/public/application/utils/get_table_columns.tsx +++ b/src/plugins/visualize/public/application/utils/get_table_columns.tsx @@ -37,7 +37,7 @@ import { FormattedMessage } from '@osd/i18n/react'; import { ApplicationStart } from 'opensearch-dashboards/public'; import { VisualizationListItem } from 'src/plugins/visualizations/public'; import moment from 'moment'; -import { IUiSettingsClient } from '../../../../../core/public'; +import { IUiSettingsClient } from 'src/core/public'; const getBadge = (item: VisualizationListItem) => { if (item.stage === 'beta') {