From 25bd7ce297f22bedaf99aefaabf2cbbc7da310aa Mon Sep 17 00:00:00 2001 From: Delirium Date: Wed, 17 Apr 2024 13:40:28 +0200 Subject: [PATCH] feat ui: add options to metric list (#2101) --- .../MetricListItem/MetricListItem.tsx | 143 ++++++++++++++---- .../components/MetricsList/ListView.tsx | 5 +- 2 files changed, 115 insertions(+), 33 deletions(-) diff --git a/frontend/app/components/Dashboard/components/MetricListItem/MetricListItem.tsx b/frontend/app/components/Dashboard/components/MetricListItem/MetricListItem.tsx index 795337cb9..816e31c2e 100644 --- a/frontend/app/components/Dashboard/components/MetricListItem/MetricListItem.tsx +++ b/frontend/app/components/Dashboard/components/MetricListItem/MetricListItem.tsx @@ -1,10 +1,14 @@ import React, { useEffect, useState } from 'react'; -import { Icon, Checkbox, Tooltip } from 'UI'; +import { Icon, Checkbox, Tooltip, confirm, Modal } from 'UI'; +import { Dropdown, Button, Input } from 'antd'; import { checkForRecent } from 'App/date'; import { withRouter, 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'; interface Props extends RouteComponentProps { metric: any; @@ -39,6 +43,9 @@ function MetricListItem(props: Props) { toggleSelection = () => {}, disableSelection = false, } = props; + const { metricStore } = useStore(); + const [isEdit, setIsEdit] = useState(false); + const [newName, setNewName] = useState(metric.name); const onItemClick = (e: React.MouseEvent) => { if (!disableSelection) { @@ -48,39 +55,113 @@ function MetricListItem(props: Props) { history.push(path); }; - return ( -
-
- {!disableSelection && ( - - )} + const onMenuClick = async ({ key }: { key: string }) => { + if (key === 'delete') { + if (await confirm({ + header: 'Confirm', + confirmButton: 'Yes, delete', + confirmation: `Are you sure you want to permanently delete this card?` + })) { + await metricStore.delete(metric) + toast.success('Card deleted'); + } + } + if (key === 'rename') { + setIsEdit(true); + } + } + const onRename = async () => { + try { + metric.updateKey('name', newName); + await metricStore.save(metric); + void metricStore.fetchList() + setIsEdit(false) + } catch (e) { + console.log(e) + toast.error('Failed to rename card'); + }} -
- -
{metric.name}
+ return ( + <> + setIsEdit(false)}> + Rename Card + + setNewName(e.target.value)} + /> + + + + + + + +
+
+ {!disableSelection && ( + + )} + +
+ +
{metric.name}
+
+
+
{metric.owner}
+
+
+ + {metric.isPublic ? 'Team' : 'Private'} +
+
+
+ {metric.lastModified && checkForRecent(metric.lastModified, 'LLL dd, yyyy, hh:mm a')} +
+
e.stopPropagation()}> + , + }, + { + label: "Delete", + key: "delete", + icon: + } + ], + onClick: onMenuClick, + }}> +
+ +
+
-
{metric.owner}
-
-
- - {metric.isPublic ? 'Team' : 'Private'} -
-
-
- {metric.lastModified && checkForRecent(metric.lastModified, 'LLL dd, yyyy, hh:mm a')} -
-
+ ); } -export default withRouter(MetricListItem); +export default withRouter(observer(MetricListItem)); diff --git a/frontend/app/components/Dashboard/components/MetricsList/ListView.tsx b/frontend/app/components/Dashboard/components/MetricsList/ListView.tsx index 446ffa431..1cb35a25d 100644 --- a/frontend/app/components/Dashboard/components/MetricsList/ListView.tsx +++ b/frontend/app/components/Dashboard/components/MetricsList/ListView.tsx @@ -31,9 +31,10 @@ function ListView(props: Props) { Title
-
Owner
+
Owner
Visibility
-
Last Modified
+
Last Modified
+
Options
{list.map((metric: any) => (