From e5557a5e4bde5088e095279684df76f2fcaced64 Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Mon, 2 Jan 2023 13:51:50 +0100 Subject: [PATCH] feat(ui) - cards - metric selection --- .../MetricListItem/MetricListItem.tsx | 20 +++++++++++-------- .../components/MetricsList/ListView.tsx | 8 ++++++-- .../components/MetricsList/MetricsList.tsx | 10 ++++++++-- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/frontend/app/components/Dashboard/components/MetricListItem/MetricListItem.tsx b/frontend/app/components/Dashboard/components/MetricListItem/MetricListItem.tsx index b8c7a3115..097f18faf 100644 --- a/frontend/app/components/Dashboard/components/MetricListItem/MetricListItem.tsx +++ b/frontend/app/components/Dashboard/components/MetricListItem/MetricListItem.tsx @@ -9,6 +9,7 @@ interface Props extends RouteComponentProps { siteId: string; selected?: boolean; toggleSelection?: any; + disableSelection?: boolean } function MetricTypeIcon({ type }: any) { @@ -33,7 +34,7 @@ function MetricTypeIcon({ type }: any) { } function MetricListItem(props: Props) { - const { metric, history, siteId, selected, toggleSelection = () => {} } = props; + const { metric, history, siteId, selected, toggleSelection = () => {}, disableSelection = false } = props; const onItemClick = () => { const path = withSiteId(`/metrics/${metric.metricId}`, siteId); @@ -46,13 +47,16 @@ function MetricListItem(props: Props) { onClick={onItemClick} >
- + {!disableSelection && ( + + )} +
{metric.name}
diff --git a/frontend/app/components/Dashboard/components/MetricsList/ListView.tsx b/frontend/app/components/Dashboard/components/MetricsList/ListView.tsx index b31df78ac..838e7cbdc 100644 --- a/frontend/app/components/Dashboard/components/MetricsList/ListView.tsx +++ b/frontend/app/components/Dashboard/components/MetricsList/ListView.tsx @@ -8,13 +8,15 @@ interface Props { selectedList: any; toggleSelection?: (metricId: any) => void; toggleAll?: (e: any) => void; + disableSelection?: boolean } function ListView(props: Props) { - const { siteId, list, selectedList, toggleSelection } = props; + const { siteId, list, selectedList, toggleSelection, disableSelection = false } = props; return (
-
+ {!disableSelection && ( +
Title
+ )}
Owner
Visibility
Last Modified
{list.map((metric: any) => ( {}, + onSelectionChange, }: { siteId: string; onSelectionChange?: (selected: any[]) => void; @@ -26,6 +26,9 @@ function MetricsList({ }, []); useEffect(() => { + if (!onSelectionChange) { + return; + } onSelectionChange(selectedMetrics); }, [selectedMetrics]); @@ -65,11 +68,14 @@ function MetricsList({ > {listView ? ( setSelectedMetrics(checked ? list.map((i: any) => i.metricId) : [])} + toggleAll={({ target: { checked, name } }) => + setSelectedMetrics(checked ? list.map((i: any) => i.metricId) : []) + } /> ) : (