admin/logs: don't reset tabs switching

Massimo Melina committed Feb 10, 2024 at 09:40 UTC 37f1afc7d9fcdc75615cfb57f623d0c8d716ef55
2 files changed +7 -5
admin/src/DataTable.ts
+1 -1
@@ -91,7 +91,7 @@ export function DataTable({ columns, initialState={}, actions, actionsProps, ini
91 const o = Object.fromEntries(fields.map(x => [x, false]))
92 _.merge(initialState, { columns: { columnVisibilityModel: o } })
93 return fields
94 - }, [manipulatedColumns])
94 + }, [manipulatedColumns, width])
95 const [vis, setVis] = useState({})
96
97 const displayingDetails = useRef<any>({})
admin/src/LogsPage.ts
+6 -4
@@ -36,7 +36,8 @@ export default function LogsPage() {
36 h(IconBtn, { icon: Download, title: "Download as file", link: API_URL + `get_log_file?file=${file}` }),
37 h(IconBtn, { icon: Settings, title: "Options", onClick: showLogOptions })
38 ),
39 - h(LogFile, { file, key: tab }), // without key, some state is accidentally preserved across files
39 + files.map(f =>
40 + h(LogFile, { hidden: file !== f, file: f, key: f }) ),
41 )
42
43 function showLogOptions() {
@@ -79,7 +80,7 @@ export default function LogsPage() {
80 }
81 }
82
82 -function LogFile({ file, addToFooter }: { file: string, addToFooter?: ReactNode }) {
83 +function LogFile({ file, addToFooter, hidden }: { hidden?: boolean, file: string, addToFooter?: ReactNode }) {
84 const [showCountry, setShowCountry] = useState(false)
85 const [showAgent, setShowAgent] = useState(false)
86 const { pause, pauseButton } = usePauseButton()
@@ -138,10 +139,11 @@ function LogFile({ file, addToFooter }: { file: string, addToFooter?: ReactNode
139 valueGetter: ({ value }) => new Date(value as string),
140 renderCell: ({ value }) => h(Fragment, {}, value.toLocaleDateString(), h('br'), value.toLocaleTimeString())
141 }
141 - return h(DataTable, {
142 + const rows = useMemo(() => showApi || list?.[0]?.uri === undefined ? list : list.filter(x => !x.uri.startsWith(API_URL)), [list, showApi]) //TODO TypeError: l.uri is undefined
143 + return hidden ? null : h(DataTable, {
144 error,
145 loading: connecting,
144 - rows: useMemo(() => showApi || list?.[0]?.uri === undefined ? list : list.filter(x => !x.uri.startsWith(API_URL)), [list, showApi]), //TODO TypeError: l.uri is undefined
146 + rows,
147 compact: true,
148 componentsProps: {
149 pagination: {