diff --git a/frontend/app/components/Dashboard/components/MetricListItem/MetricListItem.tsx b/frontend/app/components/Dashboard/components/MetricListItem/MetricListItem.tsx index bc0f5b2e0..31286dc01 100644 --- a/frontend/app/components/Dashboard/components/MetricListItem/MetricListItem.tsx +++ b/frontend/app/components/Dashboard/components/MetricListItem/MetricListItem.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useState } from 'react'; -import { Icon } from 'UI'; -import { Tooltip, Modal, Input, Button, Dropdown, Menu, Tag } from 'antd'; -import { UserOutlined, UserAddOutlined, TeamOutlined, LockOutlined, EditOutlined, DeleteOutlined, MoreOutlined } from '@ant-design/icons'; +import { Icon, Modal } from 'UI'; +import { Tooltip, Input, Button, Dropdown, Menu, Tag } from 'antd'; +import { TeamOutlined, LockOutlined, EditOutlined, DeleteOutlined, MoreOutlined } from '@ant-design/icons'; import { withRouter, RouteComponentProps } from 'react-router-dom'; import { withSiteId } from 'App/routes'; import { TYPES } from 'App/constants/card'; @@ -9,6 +9,7 @@ import cn from 'classnames'; import { useStore } from 'App/mstore'; import { observer } from 'mobx-react-lite'; import { toast } from 'react-toastify'; +import moment from 'moment'; // Import moment interface Props extends RouteComponentProps { metric: any; @@ -29,7 +30,7 @@ function MetricTypeIcon({ type }: any) { return ( {card.title}}>
- {card.icon && } + {card.icon && }
); @@ -48,6 +49,10 @@ const MetricListItem: React.FC = ({ const [isEdit, setIsEdit] = useState(false); const [newName, setNewName] = useState(metric.name); + useEffect(() => { + setNewName(metric.name); + }, [metric]); + const onItemClick = (e: React.MouseEvent) => { if (!disableSelection) { return toggleSelection(e); @@ -65,6 +70,7 @@ const MetricListItem: React.FC = ({ cancelText: 'No', onOk: async () => { await metricStore.delete(metric); + toast.success('Card deleted'); }, }); } @@ -75,8 +81,27 @@ const MetricListItem: React.FC = ({ const onRename = async () => { try { - metric.updateKey('name', newName); - await metricStore.save(metric); + console.log('Renaming metric:', metric); + console.log('New name:', newName); + metric.name = newName; // Directly update the name property + + // Add a toJson method if it doesn't exist + if (typeof metric.toJson !== 'function') { + metric.toJson = function () { + return { + metricId: this.metricId, + widgetId: this.widgetId, + category: this.category, + name: this.name, + metricType: this.metricType, + // Add other relevant properties here + }; + }; + } + + await metricStore.save(metric.toJson()); + + console.log('Metric saved:', metric); metricStore.fetchList(); setIsEdit(false); } catch (e) { @@ -86,27 +111,42 @@ const MetricListItem: React.FC = ({ }; const renderModal = () => ( - setIsEdit(false)} - footer={[ - , - , - ]} - > - setNewName(e.target.value)} - /> + + + ); + const parseDate = (dateString: string) => { + // Try to parse as ISO 8601 string first + let date = moment(dateString, moment.ISO_8601); + if (!date.isValid()) { + // Try to parse as a number (timestamp) + date = moment(Number(dateString)); + } + return date; + }; + switch (renderColumn) { case 'title': return ( @@ -130,10 +170,11 @@ const MetricListItem: React.FC = ({ ); case 'lastModified': - return new Date(metric.lastModified).toLocaleString(); + return parseDate(metric.lastModified).calendar(); // Use moment to return relative time case 'options': return ( <> +
@@ -147,8 +188,9 @@ const MetricListItem: React.FC = ({ } trigger={['click']} > -
{renderModal()} ); diff --git a/frontend/app/components/Dashboard/components/MetricsList/ListView.tsx b/frontend/app/components/Dashboard/components/MetricsList/ListView.tsx index c783b8972..22d189e6e 100644 --- a/frontend/app/components/Dashboard/components/MetricsList/ListView.tsx +++ b/frontend/app/components/Dashboard/components/MetricsList/ListView.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { Checkbox, Table } from 'antd'; import MetricListItem from '../MetricListItem'; +import classNames from 'classnames'; interface Props { list: any; @@ -33,7 +34,9 @@ const ListView: React.FC = (props: Props) => { ), dataIndex: 'name', key: 'title', + className: 'cap-first', sorter: (a: any, b: any) => a.name.localeCompare(b.name), + width: '40%', render: (text: any, metric: any) => ( = (props: Props) => { title: 'Owner', dataIndex: 'owner', key: 'owner', + className: 'capitalize', sorter: (a: any, b: any) => a.owner.localeCompare(b.owner), + width: '25%', render: (text: any, metric: any) => ( = (props: Props) => { /> ), }, - { - title: 'Visibility', - dataIndex: 'visibility', - key: 'visibility', - render: (text: any, metric: any) => ( - - ), - }, { title: 'Last Modified', dataIndex: 'lastModified', key: 'lastModified', sorter: (a: any, b: any) => new Date(a.lastModified).getTime() - new Date(b.lastModified).getTime(), + width: '20%', render: (text: any, metric: any) => ( = (props: Props) => { ), }, { - title: 'Options', + title: 'Visibility', + dataIndex: 'visibility', + key: 'visibility', + width: '10%', + render: (text: any, metric: any) => ( + + ), + }, + + { + title: '', key: 'options', + className: 'text-right', + width: '5%', + align: 'right', render: (text: any, metric: any) => (