Skip to content

Commit 928667b

Browse files
committed
StatsHouse UI: update zustand + eslint rules
1 parent 0c74df0 commit 928667b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+514
-404
lines changed

statshouse-ui/eslint.config.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,21 @@ export default tseslint.config({
2828
...react.configs.recommended.rules,
2929
...react.configs['jsx-runtime'].rules,
3030
'react-refresh/only-export-components': ['warn', { allowConstantExport: true }],
31-
// 'react-hooks/rules-of-hooks': 'warn',
3231
'react-hooks/exhaustive-deps': [
3332
'error',
3433
{
3534
enableDangerousAutofixThisMayCauseInfiniteLoops: true,
3635
},
3736
],
38-
// indent: 'off',
3937
'prettier/prettier': 'warn',
4038
'arrow-body-style': ['warn', 'as-needed'],
41-
// 'prefer-arrow-callback': 'off',
4239
'react/no-unescaped-entities': 'off',
4340
'no-console': 'warn',
4441
'no-empty': ['error', { allowEmptyCatch: true }],
4542
'@typescript-eslint/no-unused-vars': [
4643
'error',
4744
{
48-
args: 'after-used',
45+
args: 'all',
4946
argsIgnorePattern: '^_',
5047
caughtErrors: 'all',
5148
caughtErrorsIgnorePattern: '^_',

statshouse-ui/package-lock.json

Lines changed: 19 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

statshouse-ui/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"vite": "^6.0.7",
5959
"vite-plugin-ejs": "^1.7.0",
6060
"vite-plugin-eslint": "^1.8.1",
61-
"zustand": "^4.5.6"
61+
"zustand": "^5.0.3"
6262
},
6363
"devDependencies": {
6464
"@types/jest": "^29.5.14",
@@ -78,7 +78,8 @@
7878
"test:watch": "jest --watch",
7979
"genPromQlGrammar": "cd src/lib/lezer && bash build.sh",
8080
"lint": "eslint .",
81-
"lint:fix": "eslint --fix ."
81+
"lint:fix": "eslint --fix .",
82+
"tsc": "tsc"
8283
},
8384
"browserslist": {
8485
"production": [

statshouse-ui/src/admin/AdminDashControl/AdminDashControl.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
import React, { useCallback, useEffect, useMemo, useState } from 'react';
88
import { useStatsHouse } from '@/store2';
99
import { useMutation, useQueryClient } from '@tanstack/react-query';
10-
import { selectApiDashboardList, useApiDashboardList } from '../../api/dashboardsList';
11-
import { apiDashboardSave, DashboardInfo, useApiDashboard } from '../../api/dashboard';
10+
import { selectApiDashboardList, useApiDashboardList } from '@/api/dashboardsList';
11+
import { apiDashboardSave, DashboardInfo, useApiDashboard } from '@/api/dashboard';
1212
import cn from 'classnames';
13-
import { useIntersectionObserver } from '../../hooks';
14-
import { isObject, SearchFabric, toNumber } from '../../common/helpers';
15-
import { isUrlSearchArray } from '../../store2/urlStore/normalizeDashboard';
16-
import { arrToObj, getDefaultParams, toTreeObj, treeParamsObjectValueSymbol } from '../../url2';
17-
import { GET_PARAMS } from '../../api/enum';
18-
import { loadDashboard } from '../../store2/urlStore/loadDashboard';
13+
import { useIntersectionObserver } from '@/hooks';
14+
import { isObject, SearchFabric, toNumber } from '@/common/helpers';
15+
import { isUrlSearchArray } from '@/store2/urlStore/normalizeDashboard';
16+
import { arrToObj, toTreeObj, treeParamsObjectValueSymbol } from '@/url2';
17+
import { GET_PARAMS } from '@/api/enum';
18+
import { loadDashboard } from '@/store2/urlStore/loadDashboard';
1919
import { Link, useSearchParams } from 'react-router-dom';
20-
import { Button } from '../../components/UI';
20+
import { Button } from '@/components/UI';
2121
import { ReactComponent as SVGFloppy } from 'bootstrap-icons/icons/floppy.svg';
2222
import { produce } from 'immer';
23-
import { fmtInputDateTime } from '../../view/utils2';
23+
import { fmtInputDateTime } from '@/view/utils2';
2424

2525
const versionsList = [0, 1, 2, 3];
2626
const actualVersion = 3;
@@ -31,7 +31,6 @@ function useUpdateDashboard() {
3131
retry: false,
3232
mutationFn: async (id: number) => {
3333
const { params: saveParams, error: errorLoad } = await loadDashboard(
34-
{ ...getDefaultParams() },
3534
toTreeObj({ [GET_PARAMS.dashboardID]: [id.toString()] })
3635
);
3736
if (errorLoad) {

statshouse-ui/src/common/stackData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function stackData(data: uPlot.AlignedData): { data: uPlot.AlignedData; b
1818
}
1919
for (let i = 1; i < data.length; i++) {
2020
bands.push({
21-
series: [data.findIndex((s, j) => j > i), i],
21+
series: [data.findIndex((_s, j) => j > i), i],
2222
});
2323
}
2424
bands = bands.filter((b) => b.series[0] > -1);

statshouse-ui/src/components/DashboardSettings/VariablePlotLinkSelect.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
66

77
import React, { useCallback } from 'react';
8-
import { MetricMetaValue } from '../../api/metric';
9-
import { toTagKey } from '../../url/queryParams';
10-
import { TAG_KEY, TagKey } from '../../api/enum';
11-
import { getTagDescription, isTagEnabled } from '../../view/utils2';
8+
import { MetricMetaValue } from '@/api/metric';
9+
import { toTagKey } from '@/url/queryParams';
10+
import { TAG_KEY, TagKey } from '@/api/enum';
11+
import { getTagDescription, isTagEnabled } from '@/view/utils2';
1212

1313
export type VariablePlotLinkSelectProps = {
1414
indexPlot: number;
@@ -27,7 +27,7 @@ export function VariablePlotLinkSelect({ indexPlot, selectTag, metricMeta, onCha
2727
return (
2828
<select className="form-select form-select-sm" value={selectTag?.toString() ?? 'null'} onChange={changeTag}>
2929
<option value="null">-</option>
30-
{metricMeta?.tags?.map((tag, indexTag) => {
30+
{metricMeta?.tags?.map((_tag, indexTag) => {
3131
const keyTag = toTagKey(indexTag);
3232
return (
3333
keyTag != null &&

statshouse-ui/src/components/DashboardSettings/VariableSource.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
// This Source Code Form is subject to the terms of the Mozilla Public
44
// License, v. 2.0. If a copy of the MPL was not distributed with this
55
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6-
import { FilterTag, toTagKey, type VariableParamsSource } from '../../url/queryParams';
6+
import { FilterTag, toTagKey, type VariableParamsSource } from '@/url/queryParams';
77
import React, { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
88
import { SelectMetric } from '../SelectMertic';
9-
import { isTagKey, TAG_KEY, TagKey } from '../../api/enum';
9+
import { isTagKey, TAG_KEY, TagKey } from '@/api/enum';
1010
import { Button, ToggleButton } from '../UI';
11-
import { setUpdatedSource, useStore, useVariableListStore, VariableItem } from '../../store';
11+
import { setUpdatedSource, useStore, useVariableListStore, VariableItem } from '@/store';
1212
import { ReactComponent as SVGTrash } from 'bootstrap-icons/icons/trash.svg';
1313
import { ReactComponent as SVGPencil } from 'bootstrap-icons/icons/pencil.svg';
1414
import { VariableControl } from '../VariableControl';
1515
import cn from 'classnames';
1616
import { produce } from 'immer';
1717
import { TagBadges } from './TagBadges';
1818
import { dequal } from 'dequal/lite';
19-
import { mergeLeft } from '../../common/helpers';
20-
import { getTagDescription, isTagEnabled } from '../../view/utils2';
19+
import { mergeLeft } from '@/common/helpers';
20+
import { getTagDescription, isTagEnabled } from '@/view/utils2';
2121

2222
export type VariableSourceProps = {
2323
value?: VariableParamsSource;
@@ -220,7 +220,7 @@ export function VariableSource({ value, indexValue = 0, onChange }: VariableSour
220220
<SelectMetric value={localMetric} onChange={onChangeMetric} placeholder={placeholder} />
221221
</div>
222222
<div>
223-
{(meta?.tags || []).map((t, indexTag) => {
223+
{(meta?.tags || []).map((_t, indexTag) => {
224224
const tagKey = toTagKey(indexTag, TAG_KEY._0);
225225
return !tagKey || !isTagEnabled(meta, tagKey) ? null : (
226226
<div key={indexTag} className="form-check">

statshouse-ui/src/components/UPlotWrapper/UPlotWrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function UPlotWrapperNoMemo<LV = Record<string, unknown>>({
142142
onSetSelect,
143143
children,
144144
}: UPlotWrapperProps<LV>) {
145-
const uRef = useRef<uPlot>();
145+
const uRef = useRef<uPlot>(undefined);
146146
const uRefDiv = useRef<HTMLDivElement>(null);
147147
const { width, height } = useResizeObserver(uRefDiv);
148148
const hooksEvent = useRef<UPlotWrapperPropsHooks>({});

statshouse-ui/src/components2/Dashboard/Dashboard.tsx

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,26 @@ export const Dashboard = memo(function Dashboard({ className }: DashboardProps)
3838
isDashboard,
3939
saveDashboard,
4040
} = useStatsHouseShallow(
41-
({
42-
params: { tabNum, dashboardName, orderPlot, orderVariables, dashboardId },
43-
isEmbed,
44-
dashboardLayoutEdit,
45-
setDashboardLayoutEdit,
46-
saveDashboard,
47-
}) => ({
48-
tabNum,
49-
isEmbed,
50-
dashboardName,
51-
plotsLength: orderPlot.length,
52-
variablesLength: orderVariables.length,
53-
dashboardLayoutEdit,
54-
setDashboardLayoutEdit,
55-
isDashboard: dashboardId != null,
56-
saveDashboard,
57-
})
41+
useCallback(
42+
({
43+
params: { tabNum, dashboardName, orderPlot, orderVariables, dashboardId },
44+
isEmbed,
45+
dashboardLayoutEdit,
46+
setDashboardLayoutEdit,
47+
saveDashboard,
48+
}) => ({
49+
tabNum,
50+
isEmbed,
51+
dashboardName,
52+
plotsLength: orderPlot.length,
53+
variablesLength: orderVariables.length,
54+
dashboardLayoutEdit,
55+
setDashboardLayoutEdit,
56+
isDashboard: dashboardId != null,
57+
saveDashboard,
58+
}),
59+
[]
60+
)
5861
);
5962

6063
const onSaveDashboard = useCallback(() => {

statshouse-ui/src/components2/Dashboard/DashboardGroup.tsx

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,29 @@ export const DashboardGroup = memo(function DashboardGroup({ children, groupKey,
3737
removeDashboardGroup,
3838
moveDashboardGroup,
3939
} = useStatsHouseShallow(
40-
({
41-
params: { groups, orderGroup },
42-
dashboardLayoutEdit,
43-
isEmbed,
44-
setDashboardGroup,
45-
addDashboardGroup,
46-
removeDashboardGroup,
47-
moveDashboardGroup,
48-
}) => ({
49-
groups,
50-
isSingle: orderGroup.length === 1,
51-
isFirst: groupKey === orderGroup[0],
52-
isLast: groupKey === orderGroup[orderGroup.length - 1],
53-
dashboardLayoutEdit,
54-
isEmbed,
55-
setDashboardGroup,
56-
addDashboardGroup,
57-
removeDashboardGroup,
58-
moveDashboardGroup,
59-
})
40+
useCallback(
41+
({
42+
params: { groups, orderGroup },
43+
dashboardLayoutEdit,
44+
isEmbed,
45+
setDashboardGroup,
46+
addDashboardGroup,
47+
removeDashboardGroup,
48+
moveDashboardGroup,
49+
}) => ({
50+
groups,
51+
isSingle: orderGroup.length === 1,
52+
isFirst: groupKey === orderGroup[0],
53+
isLast: groupKey === orderGroup[orderGroup.length - 1],
54+
dashboardLayoutEdit,
55+
isEmbed,
56+
setDashboardGroup,
57+
addDashboardGroup,
58+
removeDashboardGroup,
59+
moveDashboardGroup,
60+
}),
61+
[groupKey]
62+
)
6063
);
6164
const onEditGroupName = useCallback(
6265
(e: React.ChangeEvent<HTMLInputElement>) => {

0 commit comments

Comments
 (0)