Skip to content

Commit 3d6d88e

Browse files
committed
StatsHouse UI: grid dash
1 parent d005bd1 commit 3d6d88e

24 files changed

+327
-48
lines changed

statshouse-ui/package-lock.json

Lines changed: 139 additions & 0 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@
4646
"react": "^19.1.0",
4747
"react-data-grid": "^7.0.0-beta.51",
4848
"react-dom": "^19.1.0",
49+
"react-grid-layout": "^1.5.1",
4950
"react-markdown": "^10.1.0",
5051
"react-router-dom": "^7.5.0",
5152
"react-window": "^1.8.11",
5253
"remark-gfm": "^4.0.1",
54+
"reselect": "^5.1.1",
5355
"rollup": "^4.39.0",
5456
"sass": "^1.69.7",
5557
"typescript": "^5.8.3",
@@ -66,6 +68,7 @@
6668
"@types/node": "^20.17.12",
6769
"@types/react": "^19.1.0",
6870
"@types/react-dom": "^19.1.2",
71+
"@types/react-grid-layout": "^1.3.5",
6972
"@typescript-eslint/eslint-plugin": "^8.29.1",
7073
"@typescript-eslint/parser": "^8.29.1",
7174
"prettier": "^3.5.3"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,9 @@ export function EditForm(props: { isReadonly: boolean; adminMode: boolean; isHis
428428
</label>
429429
<div className="col">
430430
<div id="tagsDraft" className="form-text"></div>
431-
{values.tags_draft.map((tag_draft_info, index) => (
431+
{values.tags_draft.map((tag_draft_info) => (
432432
<TagDraft
433-
key={index}
433+
key={tag_draft_info.name}
434434
tag_key={tag_draft_info.name}
435435
tag={tag_draft_info}
436436
free_tags={free_tags}

statshouse-ui/src/api/enum.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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/.
66

7-
import { invertObj, isEnum, toEnum, toNumber } from '../common/helpers';
7+
import { invertObj, isEnum, toEnum, toNumber } from '@/common/helpers';
88

99
export type Enum<T> = T[keyof T];
1010

@@ -36,6 +36,8 @@ export const GET_PARAMS = {
3636
metricMaxHost: 'mh',
3737
metricAgg: 'g',
3838
metricPromQL: 'q',
39+
metricGroupKey: 'dg',
40+
metricLayout: 'dl',
3941
/**
4042
* widget type
4143
*/
@@ -447,3 +449,20 @@ export const TIME_RANGE_ABBREV_DESCRIPTION: Record<TimeRangeAbbrev, string> = {
447449
[TIME_RANGE_ABBREV.last1y]: 'Last year',
448450
[TIME_RANGE_ABBREV.last2y]: 'Last 2 years',
449451
};
452+
453+
export const LAYOUT_WIDGET_SIZE = Object.freeze({
454+
[PLOT_TYPE.Metric]: {
455+
minW: 2,
456+
minH: 2,
457+
maxW: 12,
458+
maxH: 10,
459+
},
460+
[PLOT_TYPE.Event]: {
461+
minW: 2,
462+
minH: 2,
463+
maxW: 12,
464+
maxH: 10,
465+
},
466+
} as const);
467+
468+
export const LAYOUT_COLUMNS = 12;

statshouse-ui/src/api/table.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,30 @@ export function useApiTable<T = ApiTable>(
174174
});
175175
}
176176

177+
export function useApiTableNoLive<T = ApiTable>(
178+
plot: PlotParams,
179+
timeRange: TimeRange,
180+
variables: Partial<Record<VariableKey, VariableParams>>,
181+
key?: string,
182+
fromEnd: boolean = false,
183+
limit: number = 1000,
184+
select?: (response?: ApiTable) => T,
185+
enabled: boolean = true
186+
) {
187+
const queryClient = useQueryClient();
188+
189+
const options = useMemo(
190+
() => getTableOptions<ApiTable>(queryClient, plot, timeRange, variables, undefined, key, fromEnd, limit),
191+
[queryClient, plot, timeRange, variables, key, fromEnd, limit]
192+
);
193+
194+
return useQuery({
195+
...options,
196+
select,
197+
enabled,
198+
});
199+
}
200+
177201
type QueryFnTableInfinitePageParam = {
178202
fromEnd: boolean;
179203
key: string;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ export const Select: FC<SelectProps> = ({
659659
}, [filterOptions, updatePositionClass, multiple, meOpen, listOnlyOpen]);
660660

661661
const labelWidth = useMemo(() => {
662-
const labelsLength = options.map((o) => (o.title || o.value).length).sort((a, b) => b - a);
662+
const labelsLength = options.map((o) => (o.name || o.title || o.value).length).sort((a, b) => b - a);
663663
const k = multiple ? 30 : 0;
664664
const full = (labelsLength[0] ?? 0) * pxPerChar + k;
665665
const p75 = (labelsLength[Math.floor(labelsLength.length * 0.25)] ?? 0) * pxPerChar + k;

statshouse-ui/src/components2/Plot/PlotView/PlotEventOverlay/PlotEventOverlayTable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import cn from 'classnames';
1212
import css from './style.module.css';
1313
import { freeKeyPrefix, PlotParams, TimeRange } from '@/url2';
1414
import { useEventTagColumns2 } from '@/hooks/useEventTagColumns2';
15-
import { ApiTable, useApiTable } from '@/api/table';
15+
import { ApiTable, useApiTableNoLive } from '@/api/table';
1616
import { toNumber } from '@/common/helpers';
1717
import { StatsHouseStore, useStatsHouse } from '@/store2';
1818

@@ -69,7 +69,7 @@ export const PlotEventOverlayTable = memo(function PlotEventOverlayTable({
6969
[plot]
7070
);
7171

72-
const queryTable = useApiTable(
72+
const queryTable = useApiTableNoLive(
7373
{ ...plot, customAgg: toNumber(agg, 1) },
7474
range,
7575
variables,

statshouse-ui/src/store2/urlStore/updateParamsPlotStruct.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import {
1616
VariableKey,
1717
VariableParams,
1818
} from '@/url2';
19-
import type { StatsHouseStore } from '../statsHouseStore';
19+
import type { StatsHouseStore } from '@/store2';
2020
import type { TagKey } from '@/api/enum';
2121
import { isNotNil, toNumberM } from '@/common/helpers';
22-
import { clonePlot } from '../../url2/clonePlot';
23-
import { cloneGroup } from '../../url2/cloneGroup';
24-
import { cloneVariable } from '../../url2/cloneVariable';
22+
import { clonePlot } from '@/url2/clonePlot';
23+
import { cloneGroup } from '@/url2/cloneGroup';
24+
import { cloneVariable } from '@/url2/cloneVariable';
2525

2626
export type VariableLinks = { variableKey: VariableKey; tag: TagKey };
2727

statshouse-ui/src/store2/urlStore/updatePlotType.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
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/.
66

7-
import { StatsHouseStore } from '../statsHouseStore';
7+
import { StatsHouseStore } from '@/store2';
88
import type { PlotKey } from '@/url2';
99
import { PLOT_TYPE, type PlotType, QUERY_WHAT, TAG_KEY } from '@/api/enum';
1010
import { ProduceUpdate } from '../helpers';
@@ -41,7 +41,7 @@ export function updatePlotType(plotKey: PlotKey, nextType: PlotType): ProduceUpd
4141
}
4242

4343
if (plot.type === PLOT_TYPE.Metric) {
44-
store.params.orderPlot.forEach((pK) => {
44+
Object.keys(store.params.plots).forEach((pK) => {
4545
const pl = store.params.plots[pK];
4646
if (pl?.events.indexOf(plotKey)) {
4747
pl.events = pl.events.filter((epK) => epK !== plotKey);

statshouse-ui/src/url2/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
export const filterInSep = '-';
88
export const filterNotInSep = '~';
9+
export const layoutPlotSplitter = '.';
910
export const orderPlotSplitter = '.';
1011
export const orderGroupSplitter = '.';
1112
export const orderVariableSplitter = '.';

0 commit comments

Comments
 (0)