Skip to content

Commit 862bf43

Browse files
authored
StatsHouse UI: fix visible preview icon by hover (#2090)
* StatsHouse UI: fix visible preview icon by hover * StatsHouse UI: refactor
1 parent 8e4467d commit 862bf43

File tree

6 files changed

+57
-41
lines changed

6 files changed

+57
-41
lines changed

statshouse-ui/src/admin/pages/FormPage.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import { Dispatch, useCallback, useContext, useEffect, useMemo, useState } from 'react';
88
import { useNavigate, useParams } from 'react-router-dom';
99
import { IKind, IMetric, ITagAlias } from '../models/metric';
10-
import { MetricFormValuesContext, MetricFormValuesStorage } from '../storages/MetricFormValues';
1110
import { ReactComponent as SVGTrash } from 'bootstrap-icons/icons/trash.svg';
1211
import { IActions } from '../storages/MetricFormValues/reducer';
1312
import {
@@ -32,12 +31,12 @@ import { produce } from 'immer';
3231
import { TagDraft } from './TagDraft';
3332
import { formatInputDate } from '@/view/utils2';
3433
import { Select } from '@/components/Select';
35-
3634
import { mapEditToMetric, mapMetricToEdit, resetMetricFlood } from '../api/saveMetric';
3735
import { ConfirmButton } from '@/components/UI/ConfirmButton';
3836
import { useStateBoolean } from '@/hooks';
3937
import { useApiMetric, useMutationMetricMeta } from '@/api/metric';
4038
import { useHistoricalMetricVersion } from '@/hooks/useHistoricalMetricVersion';
39+
import { MetricFormValuesContext, MetricFormValuesStorage } from '@/admin/storages/MetricFormValues';
4140

4241
const METRIC_TYPE_KEYS: MetricType[] = Object.values(METRIC_TYPE);
4342
const METRIC_META_TAG_RAW_KIND_KEYS: MetricMetaTagRawKind[] = Object.values(METRIC_META_TAG_RAW_KIND);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2025 V Kontakte LLC
2+
//
3+
// This Source Code Form is subject to the terms of the Mozilla Public
4+
// License, v. 2.0. If a copy of the MPL was not distributed with this
5+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
7+
import { IMetric } from '@/admin/models/metric';
8+
import { createContext, Dispatch, ReactNode } from 'react';
9+
import { IActions, initialValues } from '@/admin/storages/MetricFormValues/reducer';
10+
11+
export interface IMetricFormValuesProps {
12+
initialMetric?: Partial<IMetric>;
13+
children?: ReactNode;
14+
}
15+
16+
export interface IMetricFormValuesContext {
17+
values: IMetric;
18+
dispatch: Dispatch<IActions>;
19+
}
20+
21+
export const MetricFormValuesContext = createContext<IMetricFormValuesContext>({
22+
values: initialValues,
23+
dispatch: () => {},
24+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2025 V Kontakte LLC
2+
//
3+
// This Source Code Form is subject to the terms of the Mozilla Public
4+
// License, v. 2.0. If a copy of the MPL was not distributed with this
5+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
7+
import { initialValues, reducer } from './reducer';
8+
import { FC, useEffect, useMemo, useReducer } from 'react';
9+
import { IMetricFormValuesProps, MetricFormValuesContext } from './MetricFormValuesContext';
10+
11+
export const MetricFormValuesStorage: FC<IMetricFormValuesProps> = (props) => {
12+
const { initialMetric, children } = props;
13+
14+
const initValues = useMemo(() => ({ ...initialValues, ...initialMetric }), [initialMetric]);
15+
16+
const [values, dispatch] = useReducer(reducer, initValues);
17+
18+
useEffect(() => {
19+
dispatch({ type: 'reset', newState: initValues });
20+
}, [initValues, initialMetric]);
21+
22+
return <MetricFormValuesContext value={{ values, dispatch }}>{children}</MetricFormValuesContext>;
23+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright 2025 V Kontakte LLC
2+
//
3+
// This Source Code Form is subject to the terms of the Mozilla Public
4+
// License, v. 2.0. If a copy of the MPL was not distributed with this
5+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
7+
export * from './MetricFormValuesContext';
8+
export * from './MetricFormValuesStorage';

statshouse-ui/src/admin/storages/MetricFormValues/index.tsx

Lines changed: 0 additions & 38 deletions
This file was deleted.

statshouse-ui/src/components2/LeftMenu/LeftMenuPlotItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const LeftMenuPlotItem = memo(function LeftMenuPlotItem({ active }: LeftM
5656
[openRef, setOpen]
5757
);
5858
const visible = useIntersectionObserver(visibleRef, 0, undefined, 0);
59-
const visibleBool = visible > 0;
59+
const visibleBool = visible > 0 || open;
6060
const plotPreviewUrl = usePlotPreviewStore(useCallback((s) => s.plotPreviewUrlList[plotKey], [plotKey]));
6161

6262
const plotType = useStatsHouse(useCallback(({ params: { plots } }) => plots[plotKey]?.type, [plotKey]));

0 commit comments

Comments
 (0)