Skip to content

Commit

Permalink
Set updated at field from advanced settings
Browse files Browse the repository at this point in the history
Signed-off-by: sitbubu <royi.sitbon@logz.io>
  • Loading branch information
RoyiSitbon committed Feb 14, 2022
1 parent c28c292 commit 7e81f6c
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export class DashboardListing extends React.Component {
}

getTableColumns() {
const [, dateFormat] = this.props.core.uiSettings.get('dateFormat:scaled')[3];
const tableColumns = [
{
field: 'title',
Expand Down Expand Up @@ -199,7 +200,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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export interface TableProps {
isSearching: boolean;
onShowRelationships: (object: SavedObjectWithMetadata) => void;
canGoInApp: (obj: SavedObjectWithMetadata) => boolean;
dateFormat: string;
}

interface TableState {
Expand Down Expand Up @@ -175,6 +176,7 @@ export class Table extends PureComponent<TableProps, TableState> {
basePath,
actionRegistry,
columnRegistry,
dateFormat,
} = this.props;

const pagination = {
Expand Down Expand Up @@ -266,7 +268,7 @@ export class Table extends PureComponent<TableProps, TableState> {
{ 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<SavedObjectWithMetadata<any>>,
...columnRegistry.getAll().map((column) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export interface SavedObjectsTableProps {
perPageConfig: number;
goInspectObject: (obj: SavedObjectWithMetadata) => void;
canGoInApp: (obj: SavedObjectWithMetadata) => boolean;
dateFormat: string;
}

export interface SavedObjectsTableState {
Expand Down Expand Up @@ -811,6 +812,7 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
isSearching={isSearching}
onShowRelationships={this.onShowRelationships}
canGoInApp={this.props.canGoInApp}
dateFormat={this.props.dateFormat}
/>
</RedirectAppLinks>
</EuiPageContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const SavedObjectsTablePage = ({
}) => {
const capabilities = coreStart.application.capabilities;
const itemsPerPage = coreStart.uiSettings.get<number>('savedObjects:perPage', 50);
const [, dateFormat] = coreStart.uiSettings.get<string>('dateFormat:scaled')[3];

useEffect(() => {
setBreadcrumbs([
Expand Down Expand Up @@ -95,6 +96,7 @@ const SavedObjectsTablePage = ({
);
}
}}
dateFormat={dateFormat}
canGoInApp={(savedObject) => {
const { inAppUrl } = savedObject.meta;
return inAppUrl ? Boolean(get(capabilities, inAppUrl.uiCapabilitiesPath)) : false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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') {
Expand Down Expand Up @@ -94,7 +95,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', {
Expand Down Expand Up @@ -158,7 +163,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]),
},
];

Expand Down

0 comments on commit 7e81f6c

Please sign in to comment.