From 6879ca405496e63fa9fec5430e51804c7a4079aa Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Mon, 19 Jul 2021 14:37:09 -0600 Subject: [PATCH] ui(admin): cleanup table hooks, more... --- .../scripts/api/admin/databases/getDatabases.ts | 2 +- .../scripts/api/admin/{admin.ts => index.ts} | 0 .../scripts/api/admin/locations/getLocations.ts | 2 +- resources/scripts/api/admin/mounts/getMounts.ts | 2 +- resources/scripts/api/admin/nests/getEggs.ts | 2 +- resources/scripts/api/admin/nests/getNests.ts | 2 +- resources/scripts/api/admin/nodes/getNodes.ts | 2 +- resources/scripts/api/admin/roles/getRoles.ts | 2 +- .../scripts/api/admin/servers/getServers.ts | 2 +- resources/scripts/api/admin/users/getUsers.ts | 2 +- .../scripts/components/admin/AdminTable.tsx | 17 ++--------------- 11 files changed, 11 insertions(+), 24 deletions(-) rename resources/scripts/api/admin/{admin.ts => index.ts} (100%) diff --git a/resources/scripts/api/admin/databases/getDatabases.ts b/resources/scripts/api/admin/databases/getDatabases.ts index 75ee30e3f..4ad5f4a3d 100644 --- a/resources/scripts/api/admin/databases/getDatabases.ts +++ b/resources/scripts/api/admin/databases/getDatabases.ts @@ -1,7 +1,7 @@ import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http'; import { useContext } from 'react'; import useSWR from 'swr'; -import { createContext } from '@/api/admin/admin'; +import { createContext } from '@/api/admin'; export interface Database { id: number; diff --git a/resources/scripts/api/admin/admin.ts b/resources/scripts/api/admin/index.ts similarity index 100% rename from resources/scripts/api/admin/admin.ts rename to resources/scripts/api/admin/index.ts diff --git a/resources/scripts/api/admin/locations/getLocations.ts b/resources/scripts/api/admin/locations/getLocations.ts index dc2936fff..f43567e51 100644 --- a/resources/scripts/api/admin/locations/getLocations.ts +++ b/resources/scripts/api/admin/locations/getLocations.ts @@ -1,7 +1,7 @@ import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http'; import { useContext } from 'react'; import useSWR from 'swr'; -import { createContext } from '@/api/admin/admin'; +import { createContext } from '@/api/admin'; export interface Location { id: number; diff --git a/resources/scripts/api/admin/mounts/getMounts.ts b/resources/scripts/api/admin/mounts/getMounts.ts index 55b6346ea..449308119 100644 --- a/resources/scripts/api/admin/mounts/getMounts.ts +++ b/resources/scripts/api/admin/mounts/getMounts.ts @@ -1,7 +1,7 @@ import http, { FractalResponseData, FractalResponseList, getPaginationSet, PaginatedResult } from '@/api/http'; import { useContext } from 'react'; import useSWR from 'swr'; -import { createContext } from '@/api/admin/admin'; +import { createContext } from '@/api/admin'; import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg'; import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes'; import { Server, rawDataToServer } from '@/api/admin/servers/getServers'; diff --git a/resources/scripts/api/admin/nests/getEggs.ts b/resources/scripts/api/admin/nests/getEggs.ts index 038efd719..6a406dc96 100644 --- a/resources/scripts/api/admin/nests/getEggs.ts +++ b/resources/scripts/api/admin/nests/getEggs.ts @@ -1,7 +1,7 @@ import http, { getPaginationSet, PaginatedResult } from '@/api/http'; import { useContext } from 'react'; import useSWR from 'swr'; -import { createContext } from '@/api/admin/admin'; +import { createContext } from '@/api/admin'; import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg'; export interface Filters { diff --git a/resources/scripts/api/admin/nests/getNests.ts b/resources/scripts/api/admin/nests/getNests.ts index 82946c69e..712a2a29b 100644 --- a/resources/scripts/api/admin/nests/getNests.ts +++ b/resources/scripts/api/admin/nests/getNests.ts @@ -1,7 +1,7 @@ import http, { FractalResponseData, FractalResponseList, getPaginationSet, PaginatedResult } from '@/api/http'; import { useContext } from 'react'; import useSWR from 'swr'; -import { createContext } from '@/api/admin/admin'; +import { createContext } from '@/api/admin'; import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg'; export interface Nest { diff --git a/resources/scripts/api/admin/nodes/getNodes.ts b/resources/scripts/api/admin/nodes/getNodes.ts index 7db9612c5..59e87ceb4 100644 --- a/resources/scripts/api/admin/nodes/getNodes.ts +++ b/resources/scripts/api/admin/nodes/getNodes.ts @@ -1,7 +1,7 @@ import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http'; import { useContext } from 'react'; import useSWR from 'swr'; -import { createContext } from '@/api/admin/admin'; +import { createContext } from '@/api/admin'; import { Database, rawDataToDatabase } from '@/api/admin/databases/getDatabases'; import { Location, rawDataToLocation } from '@/api/admin/locations/getLocations'; diff --git a/resources/scripts/api/admin/roles/getRoles.ts b/resources/scripts/api/admin/roles/getRoles.ts index 60f61f017..c9ceb3def 100644 --- a/resources/scripts/api/admin/roles/getRoles.ts +++ b/resources/scripts/api/admin/roles/getRoles.ts @@ -1,7 +1,7 @@ import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http'; import { useContext } from 'react'; import useSWR from 'swr'; -import { createContext } from '@/api/admin/admin'; +import { createContext } from '@/api/admin'; export interface Role { id: number; diff --git a/resources/scripts/api/admin/servers/getServers.ts b/resources/scripts/api/admin/servers/getServers.ts index 2923c0c08..4ba207c77 100644 --- a/resources/scripts/api/admin/servers/getServers.ts +++ b/resources/scripts/api/admin/servers/getServers.ts @@ -2,7 +2,7 @@ import { Egg, rawDataToEgg } from '@/api/admin/eggs/getEgg'; import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http'; import { useContext } from 'react'; import useSWR from 'swr'; -import { createContext } from '@/api/admin/admin'; +import { createContext } from '@/api/admin'; import { Node, rawDataToNode } from '@/api/admin/nodes/getNodes'; import { User, rawDataToUser } from '@/api/admin/users/getUsers'; diff --git a/resources/scripts/api/admin/users/getUsers.ts b/resources/scripts/api/admin/users/getUsers.ts index 52b3fedd1..8876c6b09 100644 --- a/resources/scripts/api/admin/users/getUsers.ts +++ b/resources/scripts/api/admin/users/getUsers.ts @@ -1,7 +1,7 @@ import http, { FractalResponseData, getPaginationSet, PaginatedResult } from '@/api/http'; import { useContext } from 'react'; import useSWR from 'swr'; -import { createContext } from '@/api/admin/admin'; +import { createContext } from '@/api/admin'; export interface User { id: number; diff --git a/resources/scripts/components/admin/AdminTable.tsx b/resources/scripts/components/admin/AdminTable.tsx index a17f024c1..93856a4c5 100644 --- a/resources/scripts/components/admin/AdminTable.tsx +++ b/resources/scripts/components/admin/AdminTable.tsx @@ -7,22 +7,9 @@ import Spinner from '@/components/elements/Spinner'; import styled from 'styled-components/macro'; import tw from 'twin.macro'; import { PaginatedResult, PaginationDataSet } from '@/api/http'; +import { ListContext as TableHooks } from '@/api/admin'; -interface Hooks { - page: number; - setPage: (page: ((p: number) => number) | number) => void; - - filters: T | null; - setFilters: (filters: ((f: T | null) => T | null) | T | null) => void; - - sort: string | null; - setSort: (sort: string | null) => void; - - sortDirection: boolean; - setSortDirection: (direction: ((p: boolean) => boolean) | boolean) => void; -} - -export function useTableHooks (): Hooks { +export function useTableHooks (): TableHooks { const [ page, setPage ] = useState(1); const [ filters, setFilters ] = useState(null); const [ sort, setSortState ] = useState(null);