Skip to content

Commit

Permalink
[Feat] Replaced filter enlarged with view: side | enlarged | minified…
Browse files Browse the repository at this point in the history
… - part 2 (#2537)

- Replaced filter enlarged with view: onToggleMinify

Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
  • Loading branch information
igorDykhta authored Oct 16, 2024
1 parent 1c0ef9a commit 97df4c9
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 36 deletions.
14 changes: 13 additions & 1 deletion src/components/src/bottom-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ export default function BottomWidgetFactory(
[visStateActions, enlargedFilterIdx]
);

const onToggleMinify = useCallback(
() =>
visStateActions.setFilterView(
enlargedFilterIdx,
filter.view === FILTER_VIEW_TYPES.enlarged
? FILTER_VIEW_TYPES.minified
: FILTER_VIEW_TYPES.enlarged
),
[enlargedFilterIdx, visStateActions, filter]
);

return (
<BottomWidgetContainer
width={Math.min(maxWidth, enlargedFilterWidth)}
Expand Down Expand Up @@ -174,8 +185,9 @@ export default function BottomWidgetFactory(
updateAnimationSpeed={visStateActions.updateFilterAnimationSpeed}
resetAnimation={resetAnimation}
isAnimatable={!animationConfig || !animationConfig.isAnimating}
onClose={onClose}
timeline={timeline}
onClose={onClose}
onToggleMinify={onToggleMinify}
/>
) : null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,17 @@ function TimeRangeFilterPanelFactory(
removeFilter,
toggleAnimation
}) => {
const onSetFilterValue = useCallback(value => setFilter(idx, 'value', value), [
idx,
setFilter
]);
const onSetFilterValue = useCallback(
value => setFilter(idx, 'value', value),
[idx, setFilter]
);

const totalDatasetsNum = useMemo(() => Object.keys(datasets).length, [datasets]);
const datasetsWithTime = useMemo(() => getDatasetsWithTimeField(datasets), [datasets]);
const datasetsWithTimeNum = useMemo(() => Object.keys(datasetsWithTime).length, [
datasetsWithTime
]);
const datasetsWithTimeNum = useMemo(
() => Object.keys(datasetsWithTime).length,
[datasetsWithTime]
);
const filterDatasetsNum = useMemo(() => filter.dataId.length, [filter]);
const onSetFilterPlot = useCallback(
(newProp, valueIndex) => setFilterPlot(idx, newProp, valueIndex),
Expand Down Expand Up @@ -118,10 +119,10 @@ function TimeRangeFilterPanelFactory(

const onFieldSelector = (field, valueIndex) => setFilter(idx, 'name', field.name, valueIndex);

const onSourceDataSelector = useCallback(value => setFilter(idx, 'dataId', value, 0), [
idx,
setFilter
]);
const onSourceDataSelector = useCallback(
value => setFilter(idx, 'dataId', value, 0),
[idx, setFilter]
);

const dataset = datasets[filter.dataId[0]];
const supportedFields = useMemo(
Expand All @@ -147,17 +148,16 @@ function TimeRangeFilterPanelFactory(
erasable={false}
onSelect={field => onFieldSelector(field, 0)}
/>
{panelActions &&
panelActions.map(panelAction => (
<PanelHeaderAction
id={panelAction.id}
key={panelAction.id}
onClick={panelAction.onClick}
tooltip={panelAction.tooltip}
IconComponent={panelAction.iconComponent}
active={panelAction.active}
/>
))}
{panelActions.map(panelAction => (
<PanelHeaderAction
id={panelAction.id}
key={panelAction.id}
onClick={panelAction.onClick}
tooltip={panelAction.tooltip}
IconComponent={panelAction.iconComponent}
active={panelAction.active}
/>
))}
</FilterPanelHeader>
<StyledFilterContent className="filter-panel__content">
{totalDatasetsNum > 1 && (
Expand Down
3 changes: 1 addition & 2 deletions src/components/src/filters/range-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ RangeFilterFactory.deps = [RangeSliderFactory];

export default function RangeFilterFactory(RangeSlider: ReturnType<typeof RangeSliderFactory>) {
const RangeFilter: React.FC<RangeFilterProps> = ({filter, setFilter, setFilterPlot}) => {
const isEnlarged = filter.view === FILTER_VIEW_TYPES.enlarged;
return (
<div>
<RangeSlider
Expand All @@ -19,7 +18,7 @@ export default function RangeFilterFactory(RangeSlider: ReturnType<typeof RangeS
value1={filter.value[1]}
step={filter.step}
bins={filter.bins}
isEnlarged={isEnlarged}
isEnlarged={filter.view === FILTER_VIEW_TYPES.enlarged}
onChange={setFilter}
setFilterPlot={setFilterPlot}
inputTheme="secondary"
Expand Down
10 changes: 5 additions & 5 deletions src/components/src/filters/time-widget.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project

import React, {useCallback, useState} from 'react';
import React, {useCallback, useMemo} from 'react';
import styled from 'styled-components';
import {FILTER_VIEW_TYPES} from '@kepler.gl/constants';
import {BottomWidgetInner} from '../common/styled-components';
import TimeRangeSliderFactory from '../common/time-range-slider';
import FloatingTimeDisplayFactory from '../common/animation-control/floating-time-display';
Expand All @@ -29,6 +30,7 @@ function TimeWidgetFactory(
showTimeDisplay,
setFilterAnimationTime,
onClose,
onToggleMinify,
resetAnimation,
isAnimatable,
updateAnimationSpeed,
Expand All @@ -37,16 +39,14 @@ function TimeWidgetFactory(
setFilterAnimationWindow,
timeline
}: TimeWidgetProps) => {
const [isMinified, setMinified] = useState(false);

const _updateAnimationSpeed = useCallback(
speed => updateAnimationSpeed(index, speed),
[updateAnimationSpeed, index]
);

const _toggleAnimation = useCallback(() => toggleAnimation(index), [toggleAnimation, index]);

const _onToggleMinify = useCallback(() => setMinified(!isMinified), [setMinified, isMinified]);
const isMinified = useMemo(() => filter.view === FILTER_VIEW_TYPES.minified, [filter]);

const _setFilterAnimationWindow = useCallback(
animationWindow => setFilterAnimationWindow({id: filter.id, animationWindow}),
Expand All @@ -72,7 +72,7 @@ function TimeWidgetFactory(
setFilterPlot={_setFilterPlot}
index={index}
onClose={onClose}
onToggleMinify={_onToggleMinify}
onToggleMinify={onToggleMinify}
isMinified={isMinified}
/>
{/* Once AnimationControl is able to display large timeline*/}
Expand Down
1 change: 1 addition & 0 deletions src/components/src/filters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export type TimeWidgetProps = {
isAnimatable: boolean;
resetAnimation: () => void;
onClose: () => void;
onToggleMinify: () => void;
setFilterAnimationTime: ActionHandler<typeof setFilterAnimationTime>;
updateAnimationSpeed: ActionHandler<typeof updateFilterAnimationSpeed>;
toggleAnimation: ActionHandler<typeof toggleFilterAnimation>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ interface FilterPanelPropsImpl extends Omit<FilterPanelProps, 'allAvailableField
filters: Filter[];
layers: ReadonlyArray<Layer>;
isAnyFilterAnimating: boolean;
enlargeFilter: () => void;
toggleAnimation: () => void;
enlargeFilter: () => void;
toggleFilterFeature: () => void;
}

Expand Down
1 change: 1 addition & 0 deletions src/table/src/kepler-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export type StringFieldFilterProps = MultiSelectFieldDomain & {
};
export type TimeFieldFilterProps = TimeRangeFieldDomain & {
type: string;
view: Filter['view'];
fixedDomain: boolean;
value: number[];
gpu: boolean;
Expand Down
7 changes: 2 additions & 5 deletions test/node/utils/timeline-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ test('#timeline -> getTimelineFromFilter', t => {
gpuChannel: [0]
};

const timeline = getTimelineFromFilter(filter);
t.deepEqual(
Object.keys(timeline),
Object.keys(getTimelineFromFilter(filter)),
[
'value',
'enableInteraction',
Expand Down Expand Up @@ -82,10 +81,8 @@ test('#timeline -> getTimelineFromAnimationConfig', t => {
duration: null
};

const timeline = getTimelineFromAnimationConfig(animationConfig);

t.deepEqual(
Object.keys(timeline),
Object.keys(getTimelineFromAnimationConfig(animationConfig)),
[
'value',
'enableInteraction',
Expand Down

0 comments on commit 97df4c9

Please sign in to comment.