diff --git a/frontend/app/components/Dashboard/components/AddCardSection/AddCardSection.tsx b/frontend/app/components/Dashboard/components/AddCardSection/AddCardSection.tsx index bcf214eac..aac378cf1 100644 --- a/frontend/app/components/Dashboard/components/AddCardSection/AddCardSection.tsx +++ b/frontend/app/components/Dashboard/components/AddCardSection/AddCardSection.tsx @@ -27,6 +27,7 @@ import { TABLE, TIMESERIES, USER_PATH, + CATEGORIES, } from 'App/constants/card'; import { useHistory } from 'react-router-dom'; import { dashboardMetricCreate, withSiteId, metricCreate } from 'App/routes'; @@ -40,8 +41,8 @@ interface TabItem { description: string; type: string; } -const tabItems: Record = { - product_analytics: [ +export const tabItems: Record = { + [CATEGORIES.product_analytics]: [ { icon: , title: 'Trends', @@ -75,7 +76,7 @@ const tabItems: Record = { description: 'Visualize user interaction patterns on your pages.', }, ], - monitors: [ + [CATEGORIES.monitors]: [ { icon: ( @@ -103,7 +104,7 @@ const tabItems: Record = { description: 'Pinpoint the slowest network requests causing delays.', }, ], - web_analytics: [ + [CATEGORIES.web_analytics]: [ { icon: , title: 'Top Pages', @@ -168,6 +169,7 @@ function CategoryTab({ tab, inCards }: { tab: string; inCards?: boolean }) { cardData.series.filter = []; } + metricStore.setCardCategory(tab); metricStore.merge(cardData); metricStore.instance.resetDefaults(); diff --git a/frontend/app/components/Dashboard/components/DashboardWidgetGrid/DashboardWidgetGrid.tsx b/frontend/app/components/Dashboard/components/DashboardWidgetGrid/DashboardWidgetGrid.tsx index 085d0cf41..33908ee7f 100644 --- a/frontend/app/components/Dashboard/components/DashboardWidgetGrid/DashboardWidgetGrid.tsx +++ b/frontend/app/components/Dashboard/components/DashboardWidgetGrid/DashboardWidgetGrid.tsx @@ -33,13 +33,13 @@ function DashboardWidgetGrid(props: Props) { ) : (
{list?.map((item: any, index: any) => (
, - value: TIMESERIES, - }, - { - icon: , - value: FUNNEL, - }, - { - icon: , - value: USER_PATH, - }, - { - icon: , - value: HEATMAP, - }, - { - icon: , - value: RETENTION, - }, -]; +import { tabItems } from 'Components/Dashboard/components/AddCardSection/AddCardSection' function MetricTypeSelector() { const { metricStore } = useStore(); const metric = metricStore.instance; - + const cardCategory = metricStore.cardCategory; + if (!cardCategory) { + return null; + } + const options = tabItems[cardCategory].map(opt => ({ + value: opt.type, + icon: opt.icon, + })) const onChange = (type: string) => { metricStore.changeType(type); }; - const selected = types.find((i) => i.value === metric.metricType) || types[0]; + const selected = options.find((i) => i.value === metric.metricType) || options[0]; return ( - + ); } diff --git a/frontend/app/components/Dashboard/components/WidgetWrapper/WidgetWrapperNew.tsx b/frontend/app/components/Dashboard/components/WidgetWrapper/WidgetWrapperNew.tsx index 095bd1559..14163e86b 100644 --- a/frontend/app/components/Dashboard/components/WidgetWrapper/WidgetWrapperNew.tsx +++ b/frontend/app/components/Dashboard/components/WidgetWrapper/WidgetWrapperNew.tsx @@ -97,8 +97,7 @@ function WidgetWrapperNew(props: Props & RouteComponentProps) { return ( { + switch (cardType) { + case TIMESERIES: + case FUNNEL: + case USER_PATH: + case HEATMAP: + return CATEGORIES.product_analytics; + case FilterKey.ERRORS: + case FilterKey.FETCH: + case TIMESERIES + '_4xx_requests': + case TIMESERIES + '_slow_network_requests': + return CATEGORIES.monitors; + case FilterKey.LOCATION: + case FilterKey.USER_BROWSER: + case FilterKey.REFERRER: + case FilterKey.USERID: + return CATEGORIES.web_analytics; + default: + return CATEGORIES.product_analytics; + } +} interface MetricFilter { query?: string; @@ -44,6 +68,8 @@ export default class MetricStore { clickMapSearch = ''; clickMapLabel = ''; + cardCategory: string | null = null; + constructor() { makeAutoObservable(this); } @@ -79,6 +105,10 @@ export default class MetricStore { this.instance.update(metric || new Widget()); } + setCardCategory(category: string) { + this.cardCategory = category; + } + updateKey(key: string, value: any) { // @ts-ignore this[key] = value; @@ -283,7 +313,12 @@ export default class MetricStore { return metricService .getMetric(id) .then((metric: any) => { - return (this.instance = new Widget().fromJson(metric, period)); + const inst = new Widget().fromJson(metric, period) + runInAction(() => { + this.instance = inst; + this.cardCategory = cardToCategory(inst.metricType); + }) + return inst; }) .finally(() => { this.setLoading(false);