From e1a788568e659c8b21e3e3e1310ee05e06f9af2f Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Fri, 5 Jul 2024 12:01:17 +0200 Subject: [PATCH] fix(ui): cards rename --- .../MetricListItem/MetricListItem.tsx | 93 +++++++------------ .../components/MetricsList/ListView.tsx | 17 ++-- 2 files changed, 41 insertions(+), 69 deletions(-) diff --git a/frontend/app/components/Dashboard/components/MetricListItem/MetricListItem.tsx b/frontend/app/components/Dashboard/components/MetricListItem/MetricListItem.tsx index a79dc1a78..edcb63a4f 100644 --- a/frontend/app/components/Dashboard/components/MetricListItem/MetricListItem.tsx +++ b/frontend/app/components/Dashboard/components/MetricListItem/MetricListItem.tsx @@ -1,14 +1,14 @@ import React, { useEffect, useState } from 'react'; import { Icon, Modal } from 'UI'; -import { Tooltip, Input, Button, Dropdown, Menu, Tag } from 'antd'; +import { Tooltip, Input, Button, Dropdown, Menu, Tag, Modal as AntdModal, Form, Avatar } from 'antd'; import { TeamOutlined, LockOutlined, EditOutlined, DeleteOutlined, MoreOutlined } from '@ant-design/icons'; -import { withRouter, RouteComponentProps } from 'react-router-dom'; +import { RouteComponentProps } from 'react-router-dom'; import { withSiteId } from 'App/routes'; import { TYPES } from 'App/constants/card'; -import cn from 'classnames'; import { useStore } from 'App/mstore'; import { observer } from 'mobx-react-lite'; import { toast } from 'react-toastify'; +import { useHistory } from 'react-router'; interface Props extends RouteComponentProps { metric: any; @@ -28,22 +28,20 @@ function MetricTypeIcon({ type }: any) { return ( {card.title}}> -
- {card.icon && } -
+ } className="bg-tealx-lightest mr-2" />
); } const MetricListItem: React.FC = ({ - metric, - siteId, - history, - selected, - toggleSelection = () => {}, - disableSelection = false, - renderColumn -}) => { + metric, + siteId, + toggleSelection = () => { + }, + disableSelection = false, + renderColumn + }) => { + const history = useHistory(); const { metricStore } = useStore(); const [isEdit, setIsEdit] = useState(false); const [newName, setNewName] = useState(metric.name); @@ -62,15 +60,14 @@ const MetricListItem: React.FC = ({ const onMenuClick = async ({ key }: { key: string }) => { if (key === 'delete') { - Modal.confirm({ + AntdModal.confirm({ title: 'Confirm', content: 'Are you sure you want to permanently delete this card?', okText: 'Yes, delete', cancelText: 'No', onOk: async () => { await metricStore.delete(metric); - toast.success('Card deleted'); - }, + } }); } if (key === 'rename') { @@ -80,56 +77,30 @@ const MetricListItem: React.FC = ({ const onRename = async () => { try { - metric.name = newName; - - // 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, - }; - }; - } - - await metricStore.save(metric.toJson()); - + metric.update({ name: newName }); + await metricStore.save(metric); metricStore.fetchList(); setIsEdit(false); } catch (e) { - console.log(e); toast.error('Failed to rename card'); } }; const renderModal = () => ( - setIsEdit(false)}> - Rename Card - - setNewName(e.target.value)} - /> - - - - - - + setIsEdit(false)} + > + setNewName(e.target.value)} + /> + ); const parseDate = (dateString: string) => { @@ -193,7 +164,7 @@ const MetricListItem: React.FC = ({ case 'visibility': return (
- + {metric.isPublic ? : } {metric.isPublic ? 'Team' : 'Private'} @@ -221,4 +192,4 @@ const MetricListItem: React.FC = ({ } }; -export default withRouter(observer(MetricListItem)); +export default observer(MetricListItem); diff --git a/frontend/app/components/Dashboard/components/MetricsList/ListView.tsx b/frontend/app/components/Dashboard/components/MetricsList/ListView.tsx index b1b520b8d..6cc12a7a3 100644 --- a/frontend/app/components/Dashboard/components/MetricsList/ListView.tsx +++ b/frontend/app/components/Dashboard/components/MetricsList/ListView.tsx @@ -2,19 +2,20 @@ import React, { useState, useMemo } from 'react'; import { Checkbox, Table, Typography } from 'antd'; import MetricListItem from '../MetricListItem'; import { TablePaginationConfig, SorterResult } from 'antd/lib/table/interface'; +import Widget from 'App/mstore/types/widget'; const { Text } = Typography; -interface Metric { - metricId: number; - name: string; - owner: string; - lastModified: string; - visibility: string; -} +// interface Metric { +// metricId: number; +// name: string; +// owner: string; +// lastModified: string; +// visibility: string; +// } interface Props { - list: Metric[]; + list: Widget[]; siteId: string; selectedList: number[]; toggleSelection?: (metricId: number) => void;