Skip to content

Commit

Permalink
fix(dashboard): type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuhito committed Aug 15, 2024
1 parent af0affe commit 204750b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions dashboard/app/components/stats/Filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ const FILTER_OPTIONS: FilterOptions = {
label: 'Language',
placeholder: 'e.g. English',
},
property: {
label: 'Property',
placeholder: 'e.g. logged_in',
},
};

// Add this type guard function
Expand Down
13 changes: 13 additions & 0 deletions dashboard/app/components/stats/StatsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const LABEL_MAP: Record<Dataset, string> = {
devices: 'Devices',
countries: 'Countries',
languages: 'Languages',
properties: 'Properties',
} as const;

const ACCESSOR_MAP: Record<Dataset, keyof DataRow> = {
Expand All @@ -64,6 +65,7 @@ const ACCESSOR_MAP: Record<Dataset, keyof DataRow> = {
devices: 'device',
countries: 'country',
languages: 'language',
properties: 'property',
} as const;

const FILTER_MAP: Record<Dataset, Filter> = {
Expand All @@ -78,6 +80,7 @@ const FILTER_MAP: Record<Dataset, Filter> = {
devices: 'device',
countries: 'country',
languages: 'language',
properties: 'property',
} as const;

const PAGE_SIZES = [10, 25, 50, 100] as const;
Expand Down Expand Up @@ -415,6 +418,16 @@ const getColumnsForQuery = (
PRESET_COLUMNS.bounce_percentage,
PRESET_COLUMNS.duration,
];
case 'properties':
return [
{
accessor: ACCESSOR_MAP[query],
title: 'Property',
width: '100%',
render: (record) => record.property || 'Unknown',
},
PRESET_COLUMNS.visitors,
];
default:
throw new Error(`Invalid query: ${query}`);
}
Expand Down
1 change: 1 addition & 0 deletions dashboard/app/components/stats/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const FILTERS = [
'device',
'country',
'language',
'property',
] as const;

type Filter = (typeof FILTERS)[number];
Expand Down
2 changes: 1 addition & 1 deletion dashboard/app/utils/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { generateFilters } from './filters';

const DataSetWithSummary = [...DATASETS, 'summary'] as const;
type DatasetItem = (typeof DataSetWithSummary)[number];
type Datasets = readonly Dataset[];
type Datasets = readonly DatasetItem[];

interface FetchStatsOptions {
dataset?: Datasets;
Expand Down

0 comments on commit 204750b

Please sign in to comment.