Skip to content

Commit

Permalink
removed analystate and got bogged down obsessing over typescript and …
Browse files Browse the repository at this point in the history
…the 'zip'
  • Loading branch information
bobular committed Sep 5, 2023
1 parent c326950 commit 23cbfe0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
34 changes: 18 additions & 16 deletions packages/libs/eda/src/lib/map/analysis/DraggableTimeFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import {
import { DateRangeFilter, NumberRangeFilter } from '../../core/types/filter';
import { Tooltip } from '@material-ui/core';
import { preorder } from '@veupathdb/wdk-client/lib/Utils/TreeUtils';
import { zip } from 'lodash';

interface Props {
studyId: string;
entities: StudyEntity[];
// to handle filters
analysisState: AnalysisState;
subsettingClient: SubsettingClient;
filters: Filter[] | undefined;
starredVariables: VariableDescriptor[];
Expand All @@ -42,7 +42,6 @@ interface Props {

export default function DraggableTimeFilter({
studyId,
analysisState,
entities,
subsettingClient,
filters,
Expand Down Expand Up @@ -169,13 +168,27 @@ export default function DraggableTimeFilter({
])
);

type Data = { x: number[]; y: number[] } | undefined;
const data: Data =
Math.random() < 0.5 ? { x: [1, 2, 3], y: [10, 20, 30] } : undefined;
const z =
data != null
? data.x.map((value, index) => {
value + data.y[index];
})
: [];

// converting data to visx format
const timeFilterData: EZTimeFilterDataProp[] = useMemo(
() =>
!getTimeSliderData.pending && getTimeSliderData.value != null
? getTimeSliderData?.value?.x.map((value: string, index: number) => {
return { x: value, y: getTimeSliderData.value!.y[index] };
})
? zip(getTimeSliderData.value.x, getTimeSliderData.value.y)
.map(([xValue, yValue]) => ({ x: xValue, y: yValue }))
// and a type guard filter to avoid any `!` assertions.
.filter(
(val): val is EZTimeFilterDataProp =>
val.x != null && val.y != null
)
: [],
[getTimeSliderData]
);
Expand Down Expand Up @@ -206,17 +219,6 @@ export default function DraggableTimeFilter({
setTimeSliderVariable(selection.overlayVariable);
}

// set filter function
const { setFilters } = analysisState;

const filter = filters?.find(
(f): f is NumberRangeFilter | DateRangeFilter =>
timeSliderVariable != null &&
f.variableId === timeSliderVariable.variableId &&
f.entityId === timeSliderVariable.entityId &&
(f.type === 'dateRange' || f.type === 'numberRange')
);

// change selectedRange considering async data request
useEffect(() => {
if (!getTimeSliderData.pending && getTimeSliderData.value != null) {
Expand Down
1 change: 0 additions & 1 deletion packages/libs/eda/src/lib/map/analysis/MapAnalysis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,6 @@ function MapAnalysisImpl(props: ImplProps) {
entities={studyEntities}
subsettingClient={subsettingClient}
filters={filters}
analysisState={analysisState}
starredVariables={
analysisState.analysis?.descriptor.starredVariables ?? []
}
Expand Down

0 comments on commit 23cbfe0

Please sign in to comment.