Skip to content

Commit

Permalink
Improve timeline dataset types
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfdsilva committed Sep 7, 2023
1 parent 8d5c880 commit 4d341ed
Showing 1 changed file with 23 additions and 32 deletions.
55 changes: 23 additions & 32 deletions app/scripts/components/exploration/types.d.ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export type AnalysisTimeseriesEntry = Record<string, number | null> & {
date: Date;
};

interface AnalysisMeta {
loaded: number;
total: number;
}

// TimelineDatasetAnalysis type discriminants
export interface TimelineDatasetAnalysisIdle {
status: TimelineDatasetStatus.IDLE;
Expand All @@ -34,30 +39,21 @@ export interface TimelineDatasetAnalysisLoading {
status: TimelineDatasetStatus.LOADING;
data: null;
error: null;
meta: {
loaded?: number;
total?: number;
};
meta: Partial<AnalysisMeta>
}
export interface TimelineDatasetAnalysisError {
status: TimelineDatasetStatus.ERROR;
data: null;
error: unknown;
meta: {
loaded?: number;
total?: number;
};
meta: Partial<AnalysisMeta>
}
export interface TimelineDatasetAnalysisSuccess {
status: TimelineDatasetStatus.SUCCESS;
data: {
timeseries: AnalysisTimeseriesEntry[];
};
error: null;
meta: {
loaded: number;
total: number;
};
meta: AnalysisMeta;
}

export type TimelineDatasetAnalysis =
Expand All @@ -74,49 +70,44 @@ export interface TimelineDatasetData extends DatasetLayer {
domain: Date[];
}

export interface TimelineDatasetSettings {
// Whether or not the layer should be shown on the map.
isVisible?: boolean;
// Opacity of the layer on the map.
opacity?: number;
}

// TimelineDataset type discriminants
export interface TimelineDatasetIdle {
status: TimelineDatasetStatus.IDLE;
data: DatasetLayer;
error: null;
settings: {
// user defined settings like visibility, opacity
isVisible?: boolean;
opacity?: number;
};
// User controlled settings like visibility, opacity.
settings: TimelineDatasetSettings;
analysis: TimelineDatasetAnalysisIdle;
}
export interface TimelineDatasetLoading {
status: TimelineDatasetStatus.LOADING;
data: DatasetLayer;
error: null;
settings: {
// user defined settings like visibility, opacity
isVisible?: boolean;
opacity?: number;
};
// User controlled settings like visibility, opacity.
settings: TimelineDatasetSettings;
analysis: TimelineDatasetAnalysisIdle;
}
export interface TimelineDatasetError {
status: TimelineDatasetStatus.ERROR;
data: DatasetLayer;
error: unknown;
settings: {
// user defined settings like visibility, opacity
isVisible?: boolean;
opacity?: number;
};
// User controlled settings like visibility, opacity.
settings: TimelineDatasetSettings;
analysis: TimelineDatasetAnalysisIdle;
}
export interface TimelineDatasetSuccess {
status: TimelineDatasetStatus.SUCCESS;
data: TimelineDatasetData;
error: null;
settings: {
// user defined settings like visibility, opacity
isVisible?: boolean;
opacity?: number;
};
// User controlled settings like visibility, opacity.
settings: TimelineDatasetSettings;
analysis: TimelineDatasetAnalysis;
}

Expand Down

0 comments on commit 4d341ed

Please sign in to comment.