({ page: 1, perPage: 20, orderBy: 'updated', orderHow: 'DESC' });
useEffect(() => {
initData();
- }, []);
+ }, [JSON.stringify(filterState)]);
+
+ const onPerPageSelect = (perPage: number) => {
+ setFilterState((prev) => ({ ...prev, perPage }));
+ };
+ const onSetPage = (page: number) => {
+ setFilterState((prev) => ({ ...prev, page }));
+ };
return (
-
+
+ {
+ console.log(index, direction);
+ setFilterState((prev) => ({
+ ...prev,
+ orderBy: (columnIds[index] as any) ?? 'updated',
+ orderHow: (direction.toUpperCase() as any) ?? 'DESC',
+ }));
+ }}
+ columns={cols}
+ />
);
};
diff --git a/src/inventoryPoc/api.ts b/src/inventoryPoc/api.ts
index ef7832d20..8608656bc 100644
--- a/src/inventoryPoc/api.ts
+++ b/src/inventoryPoc/api.ts
@@ -18,13 +18,15 @@ export type Host = {
};
};
-export const getHosts = async () => {
+export type HostApiOptions = { page?: number; perPage?: number; orderBy?: 'updated' | 'display_name' | 'id'; orderHow?: 'ASC' | 'DESC' };
+
+export const getHosts = async ({ orderBy = 'updated', orderHow = 'DESC', page = 1, perPage = 20 }: HostApiOptions) => {
const response = await axios.get<{ results: Host[] }>('/api/inventory/v1/hosts', {
params: {
- page: 1,
- per_page: 20,
- order_by: 'updated',
- order_how: 'DESC',
+ page,
+ per_page: perPage,
+ order_by: orderBy,
+ order_how: orderHow,
'fields[system_profile]': ['operating_system'],
},
});