From 86d47b595dd36bbf5904c428870d002323c6b5f7 Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Tue, 27 Jun 2023 18:05:08 +0200 Subject: [PATCH] change(ui): new card with modal options --- .../components/AddCardModal/AddCardModal.tsx | 4 +- .../MetricTypeList/MetricTypeList.tsx | 24 ++++---- .../MetricViewHeader/MetricViewHeader.tsx | 55 ++++++++++--------- .../MetricsLibraryModal.tsx | 2 +- .../components/MetricsView/MetricsView.tsx | 2 +- 5 files changed, 47 insertions(+), 40 deletions(-) diff --git a/frontend/app/components/Dashboard/components/AddCardModal/AddCardModal.tsx b/frontend/app/components/Dashboard/components/AddCardModal/AddCardModal.tsx index 227b485f6..dc9022873 100644 --- a/frontend/app/components/Dashboard/components/AddCardModal/AddCardModal.tsx +++ b/frontend/app/components/Dashboard/components/AddCardModal/AddCardModal.tsx @@ -4,14 +4,14 @@ import MetricTypeList from '../MetricTypeList'; interface Props { siteId: string; - dashboardId: string; + dashboardId?: string; } function AddCardModal(props: Props) { return ( <> - + ); diff --git a/frontend/app/components/Dashboard/components/MetricTypeList/MetricTypeList.tsx b/frontend/app/components/Dashboard/components/MetricTypeList/MetricTypeList.tsx index 12d6e88d1..898ab416b 100644 --- a/frontend/app/components/Dashboard/components/MetricTypeList/MetricTypeList.tsx +++ b/frontend/app/components/Dashboard/components/MetricTypeList/MetricTypeList.tsx @@ -4,20 +4,21 @@ import MetricsLibraryModal from '../MetricsLibraryModal'; import MetricTypeItem, { MetricType } from '../MetricTypeItem/MetricTypeItem'; import { TYPES, LIBRARY, INSIGHTS } from 'App/constants/card'; import { withRouter, RouteComponentProps } from 'react-router-dom'; -import { dashboardMetricCreate, withSiteId } from 'App/routes'; +import { dashboardMetricCreate, metricCreate, withSiteId } from 'App/routes'; import { useStore } from 'App/mstore'; import { connect } from 'react-redux'; import { ENTERPRISE_REQUEIRED } from 'App/constants'; interface Props extends RouteComponentProps { - dashboardId: number; + dashboardId?: number; siteId: string; isEnterprise: boolean; } + function MetricTypeList(props: Props) { const { dashboardId, siteId, history, isEnterprise } = props; const { metricStore } = useStore(); - const { hideModal } = useModal(); + const { showModal, hideModal } = useModal(); const list = React.useMemo(() => { return TYPES.map((metric: MetricType) => { @@ -25,12 +26,15 @@ function MetricTypeList(props: Props) { return { ...metric, disabled: metric.slug === INSIGHTS && !isEnterprise, - tooltipTitle: disabled ? ENTERPRISE_REQUEIRED : '', + tooltipTitle: disabled ? ENTERPRISE_REQUEIRED : '' }; }); }, []); - const { showModal } = useModal(); + if (!dashboardId) { + list.shift(); + } + const onClick = ({ slug }: MetricType) => { hideModal(); if (slug === LIBRARY) { @@ -39,16 +43,16 @@ function MetricTypeList(props: Props) { width: 800, onClose: () => { metricStore.updateKey('metricsSearch', ''); - }, + } }); } - // TODO redirect to card builder with metricType query param - const path = withSiteId(dashboardMetricCreate(dashboardId + ''), siteId); + const path = dashboardId ? withSiteId(dashboardMetricCreate(dashboardId + ''), siteId) : + withSiteId(metricCreate(), siteId); const queryString = new URLSearchParams({ type: slug }).toString(); history.push({ pathname: path, - search: `?${queryString}`, + search: `?${queryString}` }); }; @@ -62,5 +66,5 @@ function MetricTypeList(props: Props) { } export default connect((state: any) => ({ - isEnterprise: state.getIn(['user', 'account', 'edition']) === 'ee', + isEnterprise: state.getIn(['user', 'account', 'edition']) === 'ee' }))(withRouter(MetricTypeList)); diff --git a/frontend/app/components/Dashboard/components/MetricViewHeader/MetricViewHeader.tsx b/frontend/app/components/Dashboard/components/MetricViewHeader/MetricViewHeader.tsx index 719677914..89fc066be 100644 --- a/frontend/app/components/Dashboard/components/MetricViewHeader/MetricViewHeader.tsx +++ b/frontend/app/components/Dashboard/components/MetricViewHeader/MetricViewHeader.tsx @@ -1,45 +1,48 @@ import React from 'react'; -import { Icon, PageTitle, Button, Link, Toggler } from 'UI'; +import { PageTitle, Button, Link, Toggler } from 'UI'; import MetricsSearch from '../MetricsSearch'; import Select from 'Shared/Select'; import { useStore } from 'App/mstore'; import { observer, useObserver } from 'mobx-react-lite'; import { DROPDOWN_OPTIONS } from 'App/constants/card'; +import AddCardModal from 'Components/Dashboard/components/AddCardModal'; +import { useModal } from 'Components/Modal'; -function MetricViewHeader() { +function MetricViewHeader({ siteId }: { siteId: string }) { const { metricStore } = useStore(); const filter = metricStore.filter; + const { showModal } = useModal(); return (
-
-
- +
+
+
-
- - - -
+
+ +
- -
-
+ +
+
metricStore.updateKey('filter', { ...filter, showMine: !filter.showMine }) } /> metricStore.updateKey('sort', { by: value.value })} plain={true} - className="ml-4" + className='ml-4' />
@@ -83,13 +86,13 @@ function DashboardDropdown({ onChange, plain = false }: { plain?: boolean; onCha const dashboardOptions = dashboardStore.dashboards.map((i: any) => ({ key: i.id, label: i.name, - value: i.dashboardId, + value: i.dashboardId })); return (