diff --git a/frontend/app/constants/card.ts b/frontend/app/constants/card.ts
index b1354b660..1cd764864 100644
--- a/frontend/app/constants/card.ts
+++ b/frontend/app/constants/card.ts
@@ -1,5 +1,6 @@
import { IconNames } from 'App/components/ui/SVG';
import { FilterKey } from 'Types/filter/filterType';
+import { MetricType } from 'App/components/Dashboard/components/MetricTypeItem/MetricTypeItem';
export interface CardType {
title: string;
@@ -23,6 +24,13 @@ export const RETENTION = 'retention';
export const FEATURE_ADOPTION = 'featureAdoption';
export const INSIGHTS = 'insights';
+export interface Option {
+ label: string;
+ icon: string;
+ value: string;
+ description: string;
+}
+
export const TYPES: CardType[] = [
{
title: 'Add from Library',
@@ -35,9 +43,7 @@ export const TYPES: CardType[] = [
icon: 'puzzle-piece',
description: 'Track the features that are being used the most.',
slug: CLICKMAP,
- subTypes: [
- { title: 'Visited URL', slug: FilterKey.CLICKMAP_URL, description: "" },
- ]
+ subTypes: [{ title: 'Visited URL', slug: FilterKey.CLICKMAP_URL, description: '' }],
},
{
title: 'Timeseries',
@@ -230,3 +236,12 @@ export const TYPES: CardType[] = [
slug: INSIGHTS,
},
];
+
+export const DROPDOWN_OPTIONS = TYPES.filter((i: MetricType) => i.slug !== LIBRARY).map(
+ (i: MetricType) => ({
+ label: i.title,
+ icon: i.icon,
+ value: i.slug,
+ description: i.description,
+ })
+);
diff --git a/frontend/app/mstore/metricStore.ts b/frontend/app/mstore/metricStore.ts
index 067fba38f..1a0d52697 100644
--- a/frontend/app/mstore/metricStore.ts
+++ b/frontend/app/mstore/metricStore.ts
@@ -15,7 +15,14 @@ import {
INSIGHTS,
} from 'App/constants/card';
import { clickmapFilter } from 'App/types/filter/newFilter';
+import { filterList, getRE } from 'App/utils';
+interface MetricFilter {
+ query?: string;
+ showMine?: boolean;
+ type?: string;
+ dashboard?: [];
+}
export default class MetricStore {
isLoading: boolean = false;
isSaving: boolean = false;
@@ -28,6 +35,8 @@ export default class MetricStore {
metricsSearch: string = '';
sort: any = { by: 'desc' };
+ filter: MetricFilter = { type: 'all', dashboard: [], query: '' };
+
sessionsPage: number = 1;
sessionsPageSize: number = 10;
listView?: boolean = true;
@@ -46,6 +55,22 @@ export default class MetricStore {
);
}
+ get filteredCards() {
+ const filterRE = this.filter.query ? getRE(this.filter.query, 'i') : null;
+ const dbIds = this.filter.dashboard ? this.filter.dashboard.map((i) => i.value) : [];
+ return this.metrics
+ .filter(
+ (card) =>
+ (this.filter.type === 'all' || card.metricType === this.filter.type) &&
+ (!dbIds.length ||
+ card.dashboards.map((i) => i.dashboardId).some((id) => dbIds.includes(id))) &&
+ (!filterRE || ['name', 'owner'].some((key) => filterRE.test(card[key])))
+ )
+ .sort((a, b) =>
+ this.sort.by === 'desc' ? b.lastModified - a.lastModified : a.lastModified - b.lastModified
+ );
+ }
+
// State Actions
init(metric?: Widget | null) {
this.instance.update(metric || new Widget());
@@ -80,14 +105,13 @@ export default class MetricStore {
}
}
-
Object.assign(this.instance, obj);
this.instance.updateKey('hasChanged', updateChangeFlag);
}
changeType(value: string) {
const obj: any = { metricType: value };
- obj.series = this.instance.series
+ obj.series = this.instance.series;
obj['metricValue'] = [];
@@ -117,7 +141,7 @@ export default class MetricStore {
}
if (value === CLICKMAP) {
- obj.series = obj.series.slice(0, 1)
+ obj.series = obj.series.slice(0, 1);
if (this.instance.metricType !== CLICKMAP) {
obj.series[0].filter.removeFilter(0);
}