From 03474ccfcf8822c33108ead8fdc9149ff31964bc Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Fri, 1 Jan 2021 16:55:06 -0700 Subject: [PATCH] Add AdminTable.tsx component --- .../scripts/components/admin/AdminTable.tsx | 163 ++++++++++++++ .../components/admin/nests/NestsContainer.tsx | 203 ++++-------------- 2 files changed, 201 insertions(+), 165 deletions(-) create mode 100644 resources/scripts/components/admin/AdminTable.tsx diff --git a/resources/scripts/components/admin/AdminTable.tsx b/resources/scripts/components/admin/AdminTable.tsx new file mode 100644 index 000000000..c5fd5564c --- /dev/null +++ b/resources/scripts/components/admin/AdminTable.tsx @@ -0,0 +1,163 @@ +import React from 'react'; +import { TableCheckbox } from '@/components/admin/AdminCheckbox'; +import Spinner from '@/components/elements/Spinner'; +import tw from 'twin.macro'; + +export const TableHead = ({ children }: { children: React.ReactNode }) => { + return ( + + + + + {children} + + + ); +}; + +export const TableHeader = ({ name }: { name: string }) => { + return ( + + + {name} + +
+ + + + +
+
+ + ); +}; + +export const TableBody = ({ children }: { children: React.ReactNode }) => { + return ( + + {children} + + ); +}; + +export const TableRow = ({ children }: { children: React.ReactNode }) => { + return ( + + {children} + + ); +}; +interface Params { + loading: boolean; + hasItems: boolean; + checked: boolean; + onSelectAllClick(e: React.ChangeEvent): void; + + children: React.ReactNode; +} + +export default ({ loading, hasItems, checked, onSelectAllClick, children }: Params) => { + return ( +
+
+ { loading ? +
+ +
+ : + !hasItems ? +
+
+ {'No +
+ +

No items could be found, it's almost like they are hiding.

+
+ : + <> +
+
+ + + + + +
+ +
+ + + + + + + +
+
+ +
+ + {children} +
+
+ +
+

+ Showing 1 to 10 of 97 results +

+ +
+ +
+
+ + } +
+
+ ); +}; diff --git a/resources/scripts/components/admin/nests/NestsContainer.tsx b/resources/scripts/components/admin/nests/NestsContainer.tsx index d44f448c6..26ee82df2 100644 --- a/resources/scripts/components/admin/nests/NestsContainer.tsx +++ b/resources/scripts/components/admin/nests/NestsContainer.tsx @@ -2,7 +2,6 @@ import React, { useEffect, useState } from 'react'; import getNests from '@/api/admin/nests/getNests'; import { httpErrorToHuman } from '@/api/http'; import NewNestButton from '@/components/admin/nests/NewNestButton'; -import Spinner from '@/components/elements/Spinner'; import FlashMessageRender from '@/components/FlashMessageRender'; import { useDeepMemoize } from '@/plugins/useDeepMemoize'; import useFlash from '@/plugins/useFlash'; @@ -10,7 +9,13 @@ import { AdminContext } from '@/state/admin'; import { NavLink, useRouteMatch } from 'react-router-dom'; import tw from 'twin.macro'; import AdminContentBlock from '@/components/admin/AdminContentBlock'; -import AdminCheckbox, { TableCheckbox } from '@/components/admin/AdminCheckbox'; +import AdminCheckbox from '@/components/admin/AdminCheckbox'; +import AdminTable, { + TableBody, + TableHead, + TableHeader, + TableRow, +} from '@/components/admin/AdminTable'; const RowCheckbox = ({ id }: { id: number}) => { const isChecked = AdminContext.useStoreState(state => state.nests.selectedNests.indexOf(id) >= 0); @@ -58,7 +63,7 @@ export default () => { }, []); const onSelectAllClick = (e: React.ChangeEvent) => { - setSelectedNests(e.currentTarget.checked ? (nests?.map(nest => nest.id) || []) : []); + setSelectedNests(e.currentTarget.checked ? (nests.map(nest => nest.id) || []) : []); }; return ( @@ -74,172 +79,40 @@ export default () => { -
-
- { loading ? -
- -
- : - nests.length < 1 ? -
-
- {'No -
+ 0} + checked={selectedNestsLength === (nests.length === 0 ? -1 : nests.length)} + onSelectAllClick={onSelectAllClick} + > + + + + -

No items could be found, it's almost like they are hiding.

-
- : - <> -
-
- + {/* */} + - - - -
+ + { + nests.map(nest => ( + + + + -
- - - - - - - -
-
- -
- - - - - - - - - - {/* - - - - { - nests.map(nest => ( - - - - - - - - )) - } - -
- - - - ID - -
- - - - -
-
-
- - Name - -
- - - - -
-
-
- - Description - -
- - - - -
-
-
*/} -
- - {nest.id} - - {nest.name} - - {nest.description}
-
- -
-

- Showing 1 to 10 of 97 results -

- -
- -
-
- + {nest.id} + + + {nest.name} + + + {nest.description} + + )) } -
-
+ + ); };