/*
* 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 React from 'react';
import { History } from 'history';
import { EuiBetaBadge, EuiButton, EuiEmptyPrompt, EuiIcon, EuiLink, EuiBadge } from '@elastic/eui';
import { i18n } from '@osd/i18n';
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 'src/core/public';
const getBadge = (item: VisualizationListItem) => {
if (item.stage === 'beta') {
return (
);
} else if (item.stage === 'experimental') {
return (
);
}
};
const renderItemTypeIcon = (item: VisualizationListItem) => {
let icon;
if (item.image) {
icon = (
);
} else {
icon = (
);
}
return icon;
};
export const getTableColumns = (
application: ApplicationStart,
history: History,
uiSettings: IUiSettingsClient
) => [
{
field: 'title',
name: i18n.translate('visualize.listing.table.titleColumnName', {
defaultMessage: 'Title',
}),
sortable: true,
render: (field: string, { editApp, editUrl, title, error }: VisualizationListItem) =>
// In case an error occurs i.e. the vis has wrong type, we render the vis but without the link
!error ? (
{field}
) : (
field
),
},
{
field: 'typeTitle',
name: i18n.translate('visualize.listing.table.typeColumnName', {
defaultMessage: 'Type',
}),
sortable: true,
render: (field: string, record: VisualizationListItem) =>
!record.error ? (
{renderItemTypeIcon(record)}
{record.typeTitle}
{getBadge(record)}
) : (
{record.error}
),
},
{
field: 'description',
name: i18n.translate('visualize.listing.table.descriptionColumnName', {
defaultMessage: 'Description',
}),
sortable: true,
render: (field: string, record: VisualizationListItem) => {record.description},
},
{
field: `updated_at`,
name: i18n.translate('visualize.listing.table.columnUpdatedAtName', {
defaultMessage: 'Last updated',
}),
dataType: 'date',
sortable: true,
description: i18n.translate('visualize.listing.table.columnUpdatedAtDescription', {
defaultMessage: 'Last update of the saved object',
}),
['data-test-subj']: 'updated-at',
render: (updatedAt: string) =>
updatedAt && moment(updatedAt).format(uiSettings.get('dateFormat')),
},
];
export const getNoItemsMessage = (createItem: () => void) => (
}
body={
}
actions={
}
/>
);