From 95b1bc0c66d9237535c3eeb9139b52e72ae5d0fb Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Tue, 25 Oct 2022 16:06:02 +0200 Subject: [PATCH] change(ui) - dashboard updates - wip --- .../components/AddCardModal/AddCardModal.tsx | 16 + .../components/AddCardModal/index.ts | 1 + .../DashboardHeader/DashboardHeader.tsx | 9 +- .../DashboardList/DashboardsView.tsx | 44 +-- .../components/DashboardList/Header.tsx | 49 +++ .../DashboardView/DashboardView.tsx | 4 +- .../MetricListItem/MetricListItem.tsx | 102 ++++--- .../MetricTypeItem/MetricTypeItem.tsx | 7 +- .../MetricTypeList/MetricTypeList.tsx | 10 +- .../MetricViewHeader/MetricViewHeader.tsx | 45 +++ .../components/MetricViewHeader/index.ts | 1 + .../MetricsLibraryModal.tsx | 13 + .../components/MetricsLibraryModal/index.ts | 1 + .../components/MetricsList/MetricsList.tsx | 35 ++- .../components/MetricsView/MetricsView.tsx | 42 +-- frontend/app/components/Modal/Modal.tsx | 35 ++- frontend/app/components/Modal/index.tsx | 99 +++--- frontend/app/components/Modal/withModal.tsx | 10 +- frontend/app/mstore/dashboardStore.ts | 2 +- frontend/app/mstore/metricStore.ts | 283 +++++++++--------- 20 files changed, 484 insertions(+), 324 deletions(-) create mode 100644 frontend/app/components/Dashboard/components/AddCardModal/AddCardModal.tsx create mode 100644 frontend/app/components/Dashboard/components/AddCardModal/index.ts create mode 100644 frontend/app/components/Dashboard/components/DashboardList/Header.tsx create mode 100644 frontend/app/components/Dashboard/components/MetricViewHeader/MetricViewHeader.tsx create mode 100644 frontend/app/components/Dashboard/components/MetricViewHeader/index.ts create mode 100644 frontend/app/components/Dashboard/components/MetricsLibraryModal/MetricsLibraryModal.tsx create mode 100644 frontend/app/components/Dashboard/components/MetricsLibraryModal/index.ts diff --git a/frontend/app/components/Dashboard/components/AddCardModal/AddCardModal.tsx b/frontend/app/components/Dashboard/components/AddCardModal/AddCardModal.tsx new file mode 100644 index 000000000..582e5b2f3 --- /dev/null +++ b/frontend/app/components/Dashboard/components/AddCardModal/AddCardModal.tsx @@ -0,0 +1,16 @@ +import Modal from 'App/components/Modal/Modal'; +import React from 'react'; +import MetricTypeList from '../MetricTypeList'; + +function AddCardModal() { + return ( + <> + + + + + + ); +} + +export default AddCardModal; diff --git a/frontend/app/components/Dashboard/components/AddCardModal/index.ts b/frontend/app/components/Dashboard/components/AddCardModal/index.ts new file mode 100644 index 000000000..c7864e849 --- /dev/null +++ b/frontend/app/components/Dashboard/components/AddCardModal/index.ts @@ -0,0 +1 @@ +export { default } from './AddCardModal'; diff --git a/frontend/app/components/Dashboard/components/DashboardHeader/DashboardHeader.tsx b/frontend/app/components/Dashboard/components/DashboardHeader/DashboardHeader.tsx index 89d2ed4d0..0ce2103eb 100644 --- a/frontend/app/components/Dashboard/components/DashboardHeader/DashboardHeader.tsx +++ b/frontend/app/components/Dashboard/components/DashboardHeader/DashboardHeader.tsx @@ -11,6 +11,7 @@ import DashboardOptions from '../DashboardOptions'; import withModal from 'App/components/Modal/withModal'; import { observer } from 'mobx-react-lite'; import DashboardEditModal from '../DashboardEditModal'; +import AddCardModal from '../AddCardModal'; interface IProps { siteId: string; @@ -23,7 +24,7 @@ function DashboardHeader(props: Props) { const { siteId } = props; const { dashboardStore } = useStore(); const { showModal } = useModal(); - const [showTooltip, setShowTooltip] = React.useState(false); + // const [showTooltip, setShowTooltip] = React.useState(false); const [focusTitle, setFocusedInput] = React.useState(true); const [showEditModal, setShowEditModal] = React.useState(false); const period = dashboardStore.period; @@ -79,7 +80,11 @@ function DashboardHeader(props: Props) { />
-
diff --git a/frontend/app/components/Dashboard/components/DashboardList/DashboardsView.tsx b/frontend/app/components/Dashboard/components/DashboardList/DashboardsView.tsx index 66d379e6f..f0c8b46ff 100644 --- a/frontend/app/components/Dashboard/components/DashboardList/DashboardsView.tsx +++ b/frontend/app/components/Dashboard/components/DashboardList/DashboardsView.tsx @@ -1,52 +1,12 @@ import React from 'react'; -import { Button, PageTitle, Icon } from 'UI'; import withPageTitle from 'HOCs/withPageTitle'; -import { useStore } from 'App/mstore'; -import { withSiteId } from 'App/routes'; -import Select from 'Shared/Select'; import DashboardList from './DashboardList'; -import DashboardSearch from './DashboardSearch'; -import { sort } from 'App/duck/sessions'; -import { useObserver } from 'mobx-react-lite'; +import Header from './Header'; function DashboardsView({ history, siteId }: { history: any; siteId: string }) { - const { dashboardStore } = useStore(); - const sort = useObserver(() => dashboardStore.sort); - - const onAddDashboardClick = () => { - dashboardStore.initDashboard(); - dashboardStore.save(dashboardStore.dashboardInstance).then(async (syncedDashboard) => { - dashboardStore.selectDashboardById(syncedDashboard.dashboardId); - history.push(withSiteId(`/dashboard/${syncedDashboard.dashboardId}`, siteId)); - }); - }; - return (
-
-
- -
-
- -
- dashboardStore.updateKey('sort', { by: value.value })} + /> +
+
+ +
+
+
+ ); +} + +export default Header; diff --git a/frontend/app/components/Dashboard/components/DashboardView/DashboardView.tsx b/frontend/app/components/Dashboard/components/DashboardView/DashboardView.tsx index bf02d1f8e..5ac13ef9f 100644 --- a/frontend/app/components/Dashboard/components/DashboardView/DashboardView.tsx +++ b/frontend/app/components/Dashboard/components/DashboardView/DashboardView.tsx @@ -76,8 +76,8 @@ function DashboardView(props: Props) { return (
- {/* @ts-ignore */} - + {/* @ts-ignore */} + { - switch (type) { - case 'funnel': - return 'filter'; - case 'table': - return 'list-alt'; - case 'timeseries': - return 'bar-chart-line'; - } + const getIcon = () => { + switch (type) { + case 'funnel': + return 'filter'; + case 'table': + return 'list-alt'; + case 'timeseries': + return 'bar-chart-line'; } + }; - return ( - {type}
} - > -
- -
- - ) + return ( + {type}
} > +
+ +
+ + ); } - - function MetricListItem(props: Props) { - const { metric, history, siteId } = props; + const { metric, history, siteId, selected, toggleSelection = () => {} } = props; - const onItemClick = () => { - const path = withSiteId(`/metrics/${metric.metricId}`, siteId); - history.push(path); - }; - return ( -
-
-
- -
- {metric.name} -
-
-
-
{metric.owner}
-
-
- - {metric.isPublic ? 'Team' : 'Private'} -
-
-
{metric.lastModified && checkForRecent(metric.lastModified, 'LLL dd, yyyy, hh:mm a')}
+ const onItemClick = () => { + const path = withSiteId(`/metrics/${metric.metricId}`, siteId); + history.push(path); + }; + return ( +
+
+ +
+ +
{metric.name}
- ); +
+
{metric.owner}
+
+
+ + {metric.isPublic ? 'Team' : 'Private'} +
+
+
+ {metric.lastModified && checkForRecent(metric.lastModified, 'LLL dd, yyyy, hh:mm a')} +
+
+ ); } export default withRouter(MetricListItem); diff --git a/frontend/app/components/Dashboard/components/MetricTypeItem/MetricTypeItem.tsx b/frontend/app/components/Dashboard/components/MetricTypeItem/MetricTypeItem.tsx index 7e4039721..380472bde 100644 --- a/frontend/app/components/Dashboard/components/MetricTypeItem/MetricTypeItem.tsx +++ b/frontend/app/components/Dashboard/components/MetricTypeItem/MetricTypeItem.tsx @@ -11,14 +11,19 @@ export interface MetricType { interface Props { metric: MetricType; + onClick?: any; } function MetricTypeItem(props: Props) { const { metric: { title, icon, description, slug }, + onClick = () => {}, } = props; return ( -
+
diff --git a/frontend/app/components/Dashboard/components/MetricTypeList/MetricTypeList.tsx b/frontend/app/components/Dashboard/components/MetricTypeList/MetricTypeList.tsx index d31bc5596..d5cea3be5 100644 --- a/frontend/app/components/Dashboard/components/MetricTypeList/MetricTypeList.tsx +++ b/frontend/app/components/Dashboard/components/MetricTypeList/MetricTypeList.tsx @@ -1,4 +1,6 @@ +import { useModal } from 'App/components/Modal'; import React from 'react'; +import MetricsLibraryModal from '../MetricsLibraryModal'; import MetricTypeItem, { MetricType } from '../MetricTypeItem/MetricTypeItem'; const METRIC_TYPES: MetricType[] = [ @@ -71,10 +73,16 @@ const METRIC_TYPES: MetricType[] = [ ]; function MetricTypeList() { + const { showModal } = useModal(); + const onClick = ({ slug }: MetricType) => { + if (slug === 'library') { + showModal(, { right: true, width: 700 }); + } + }; return ( <> {METRIC_TYPES.map((metric: MetricType) => ( - + onClick(metric)} /> ))} ); diff --git a/frontend/app/components/Dashboard/components/MetricViewHeader/MetricViewHeader.tsx b/frontend/app/components/Dashboard/components/MetricViewHeader/MetricViewHeader.tsx new file mode 100644 index 000000000..2c7790d73 --- /dev/null +++ b/frontend/app/components/Dashboard/components/MetricViewHeader/MetricViewHeader.tsx @@ -0,0 +1,45 @@ +import React from 'react'; +import { Icon, PageTitle, Button, Link } from 'UI'; +import MetricsSearch from '../MetricsSearch'; +import Select from 'Shared/Select'; +import { useStore } from 'App/mstore'; +import { useObserver } from 'mobx-react-lite'; + +function MetricViewHeader() { + const { metricStore } = useStore(); + const sort = useObserver(() => metricStore.sort); + return ( +
+
+
+ +
+
+ + + +
+