admin/plugins: search online columns will now persist page change

Massimo Melina committed Jun 5, 2022 at 09:46 UTC 85e5050cb667381142a577b38760984e4aafb043
2 files changed +11 -3
admin/src/OnlinePlugins.ts
+5 -3
@@ -7,11 +7,13 @@ import { toast } from './dialog'
7 import { StringField } from '@hfs/mui-grid-form'
8 import { useDebounce } from 'use-debounce'
9 import { repoLink, showError } from './InstalledPlugins'
10 +import { state, useSnapState } from './state'
11
12 export default function OnlinePlugins() {
13 const [search, setSearch] = useState('')
14 const [debouncedSearch] = useDebounce(search, 1000)
15 const { list, error, initializing } = useApiList('search_online_plugins', { text: debouncedSearch })
16 + const snap = useSnapState()
17 if (error)
18 return showError(error)
19 return h(Fragment, {},
@@ -26,6 +28,8 @@ export default function OnlinePlugins() {
28 rows: list.length ? list : [], // workaround for DataGrid bug causing 'no rows' message to be not displayed after 'loading' was also used
29 localeText: { noRowsLabel: "No compatible plugins have been found" },
30 loading: initializing,
31 + columnVisibilityModel: snap.onlinePluginsColumns,
32 + onColumnVisibilityModelChange: newModel => Object.assign(state.onlinePluginsColumns, newModel),
33 columns: [
34 {
35 field: 'id',
@@ -35,18 +39,15 @@ export default function OnlinePlugins() {
39 {
40 field: 'version',
41 width: 70,
38 - hide: true,
42 },
43 {
44 field: 'pushed_at',
45 headerName: "last update",
43 - hide: true,
46 valueGetter: ({ value }) => new Date(value).toLocaleDateString(),
47 },
48 {
49 field: 'license',
50 width: 80,
49 - hide: true,
51 },
52 {
53 field: 'description',
@@ -64,6 +65,7 @@ export default function OnlinePlugins() {
65 align: 'center',
66 hideSortIcons: true,
67 disableColumnMenu: true,
68 + hideable: false,
69 renderCell({ row }) {
70 const { id, branch } = row
71 return h('div', {},
admin/src/state.ts
+6
@@ -12,6 +12,7 @@ export const state = proxy<{
12 selectedFiles: VfsNode[]
13 loginRequired: boolean
14 username: string
15 + onlinePluginsColumns: Dict<boolean>
16 }>({
17 title: '',
18 config: {},
@@ -20,6 +21,11 @@ export const state = proxy<{
21 vfs: undefined,
22 loginRequired: false,
23 username: '',
24 + onlinePluginsColumns: {
25 + version: false,
26 + pushed_at: false,
27 + license: false,
28 + }
29 })
30
31 export function useSnapState() {