mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-22 00:13:12 +09:00
Merge pull request #930 from bbassie/feature/table-url-state
Persist table sort/filter state in the URL
This commit is contained in:
14 files changed
+644
-89
No files matched your search
@@ -6,7 +6,6 @@ import {
|
||||
import {
|
||||
ImportOutlined, PlusOutlined, SearchOutlined, DownloadOutlined,
|
||||
} from "@ant-design/icons";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
|
||||
import { useAccount } from "../model/account";
|
||||
@@ -18,6 +17,8 @@ import PageHeader from "./PageHeader";
|
||||
import PageLayout from "./PageLayout";
|
||||
import PluginExtra from "./PluginExtra";
|
||||
import SectionHeader from "./SectionHeader";
|
||||
import useTableQueryState from "../util/useTableQueryState";
|
||||
import useColumnSearch from "../util/useColumnSearch";
|
||||
import useRowNavigation from "../util/useRowNavigation";
|
||||
import Link from "./Link";
|
||||
import ModDetails from "./ModDetails";
|
||||
@@ -514,6 +515,16 @@ export default function ModsPage() {
|
||||
let control = useContext(ControlContext);
|
||||
let [mods] = useMods();
|
||||
let [modPacks] = useModPacks();
|
||||
const modPackTable = useTableQueryState<lib.ModPack>({
|
||||
namespace: "modPack", defaultSortKey: "name",
|
||||
});
|
||||
const modTable = useTableQueryState<lib.ModInfo>({
|
||||
namespace: "mod", defaultSortKey: "title",
|
||||
});
|
||||
const modPackNameSearch = useColumnSearch<lib.ModPack>(
|
||||
modPackTable, "name", modPack => modPack.name, "Search mod packs"
|
||||
);
|
||||
const modNameSearch = useColumnSearch<lib.ModInfo>(modTable, "title", mod => mod.title, "Search mods");
|
||||
const rowNav = useRowNavigation();
|
||||
|
||||
function actions(mod: lib.ModInfo) {
|
||||
@@ -580,8 +591,9 @@ export default function ModsPage() {
|
||||
{
|
||||
title: "Name",
|
||||
dataIndex: "name",
|
||||
defaultSortOrder: "ascend",
|
||||
sorter: (a, b) => strcmp(a.name, b.name),
|
||||
sortOrder: modPackTable.sortOrder("name"),
|
||||
filteredValue: modPackTable.filteredValue("name"),
|
||||
className: "table-link-cell",
|
||||
render: (_, modPack) => <Link
|
||||
to={`/mods/mod-packs/${modPack.id}/view`}
|
||||
@@ -589,11 +601,13 @@ export default function ModsPage() {
|
||||
>
|
||||
{modPack.name}
|
||||
</Link>,
|
||||
...modPackNameSearch,
|
||||
},
|
||||
{
|
||||
title: "Factorio Version",
|
||||
dataIndex: "factorioVersion",
|
||||
sorter: (a, b) => a.integerFactorioVersion - b.integerFactorioVersion,
|
||||
sortOrder: modPackTable.sortOrder("factorioVersion"),
|
||||
},
|
||||
{
|
||||
title: "Mods",
|
||||
@@ -602,7 +616,8 @@ export default function ModsPage() {
|
||||
},
|
||||
]}
|
||||
dataSource={[...modPacks.values()]}
|
||||
pagination={false}
|
||||
pagination={modPackTable.pagination}
|
||||
onChange={modPackTable.onChange}
|
||||
rowKey={modPack => Number(modPack.id)}
|
||||
onRow={modPack => rowNav(`/mods/mod-packs/${modPack.id}/view`)}
|
||||
/>
|
||||
@@ -629,10 +644,12 @@ export default function ModsPage() {
|
||||
{
|
||||
title: "Name",
|
||||
dataIndex: "title",
|
||||
defaultSortOrder: "ascend",
|
||||
sorter: (a, b) => (
|
||||
strcmp(a.name, b.name) || a.integerVersion - b.integerVersion
|
||||
),
|
||||
sortOrder: modTable.sortOrder("title"),
|
||||
filteredValue: modTable.filteredValue("title"),
|
||||
...modNameSearch,
|
||||
},
|
||||
{
|
||||
title: "Version",
|
||||
@@ -648,6 +665,7 @@ export default function ModsPage() {
|
||||
dataIndex: "filename",
|
||||
responsive: ["xl"],
|
||||
sorter: (a, b) => strcmp(a.filename, b.filename),
|
||||
sortOrder: modTable.sortOrder("filename"),
|
||||
},
|
||||
{
|
||||
title: "Size",
|
||||
@@ -656,6 +674,7 @@ export default function ModsPage() {
|
||||
render: (_, mod) => lib.formatBytes(mod.size),
|
||||
align: "right",
|
||||
sorter: (a, b) => a.size - b.size,
|
||||
sortOrder: modTable.sortOrder("size"),
|
||||
},
|
||||
{
|
||||
title: "Action",
|
||||
@@ -669,7 +688,8 @@ export default function ModsPage() {
|
||||
expandedRowClassName: () => "no-expanded-padding",
|
||||
}}
|
||||
dataSource={[...mods.values()]}
|
||||
pagination={false}
|
||||
pagination={modTable.pagination}
|
||||
onChange={modTable.onChange}
|
||||
rowKey={mod => mod.id}
|
||||
/>
|
||||
</Upload.Dragger>
|
||||
|
||||
Reference in new issue
Block a user