Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: Tables improvements #1595

Merged
merged 5 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@nivo/pie": "0.87.0",
"@nivo/radial-bar": "0.87.0",
"@nivo/tooltip": "0.87.0",
"@pluralsh/design-system": "3.78.0",
"@pluralsh/design-system": "3.79.0",
"@react-hooks-library/core": "0.6.0",
"@saas-ui/use-hotkeys": "1.1.3",
"@tanstack/react-table": "8.20.5",
Expand Down Expand Up @@ -192,12 +192,12 @@
"typescript": "5.6.2",
"typescript-eslint": "8.8.0",
"usehooks-ts": "2.9.1",
"vite": "5.4.8",
"vite": "5.4.11",
"vite-bundle-visualizer": "1.2.1",
"vite-plugin-pwa": "0.20.5",
"vite-plugin-rewrite-all": "1.0.2",
"vite-tsconfig-paths": "5.0.1",
"vitest": "2.1.1",
"vitest": "2.1.5",
"wait-on": "7.0.1"
},
"lint-staged": {
Expand Down
2 changes: 1 addition & 1 deletion assets/src/components/ai/AITable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from 'generated/graphql'
import { useTheme } from 'styled-components'
import { AITableEntry } from './AITableEntry.tsx'
import { TableProps } from '@pluralsh/design-system/dist/components/Table'
import { TableProps } from '@pluralsh/design-system/dist/components/table/Table'

export function AITable({
modal = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function ClusterOverViewTable({
return (
<Table
loose
fillLevel={1}
data={data}
columns={clusterOverviewColumns}
reactVirtualOptions={DEFAULT_REACT_VIRTUAL_OPTIONS}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function DeploymentsTable({
return (
<Table
loose
fillLevel={1}
data={data}
columns={deploymentsColumns}
reactVirtualOptions={DEFAULT_REACT_VIRTUAL_OPTIONS}
Expand Down
1 change: 1 addition & 0 deletions assets/src/components/home/pullrequests/PrTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function PrTable({
return (
<Table
loose
fillLevel={1}
data={data}
columns={columns}
reactVirtualOptions={DEFAULT_REACT_VIRTUAL_OPTIONS}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function ConstraintViolationsCard() {
) : (
<PoliciesTable
caret
fillLevel={1}
data={tableData}
refetch={refetch}
fetchNextPage={fetchNextPage}
Expand Down
68 changes: 14 additions & 54 deletions assets/src/components/kubernetes/common/ResourceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
QueryResult,
} from '@apollo/client/react/types/types'
import { Table } from '@pluralsh/design-system'
import styled from 'styled-components'
import { useNavigate } from 'react-router-dom'
import { Row, SortingState, TableOptions } from '@tanstack/react-table'

Expand Down Expand Up @@ -33,38 +32,7 @@ import {
usePageInfo,
useSortedTableOptions,
} from './utils'

const SKELETON_ITEMS = 10

const Skeleton = styled(SkeletonUnstyled)(({ theme }) => ({
'@keyframes moving-gradient': {
'0%': { backgroundPosition: '-250px 0' },
'100%': { backgroundPosition: '250px 0' },
},

maxWidth: '400px',
width: '100%',

span: {
borderRadius: theme.borderRadiuses.medium,
maxWidth: '400px',
width: 'unset',
minWidth: '150px',
display: 'block',
height: '12px',
background: `linear-gradient(to right, ${theme.colors.border} 20%, ${theme.colors['border-fill-two']} 50%, ${theme.colors.border} 80%)`,
backgroundSize: '500px 100px',
animation: 'moving-gradient 2s infinite linear forwards',
},
}))

function SkeletonUnstyled({ ...props }): ReactElement {
return (
<div {...props}>
<span />
</div>
)
}
import { TableSkeleton } from '../../utils/SkeletonLoaders.tsx'

interface ResourceListProps<
TResourceList,
Expand Down Expand Up @@ -126,30 +94,13 @@ export function ResourceList<
})

const resourceList = data?.[queryName] as TResourceList
const isLoading = useMemo(
() => loading && !resourceList,
[loading, resourceList]
)
const isLoading = loading && !resourceList
const items = useMemo(
() =>
isLoading
? Array(SKELETON_ITEMS).fill({})
: ((resourceList?.[itemsKey] as Array<TResource>) ?? []),
[isLoading, itemsKey, resourceList]
() => (resourceList?.[itemsKey] as Array<TResource>) ?? [],
[itemsKey, resourceList]
)
const { page, hasNextPage } = usePageInfo(items, resourceList?.listMeta)

const columnsData = useMemo(
() =>
isLoading
? columns.map((col) => ({
...col,
cell: <Skeleton />,
}))
: columns,
[isLoading, columns]
)

const fetchNextPage = useCallback(() => {
if (!hasNextPage) return
fetchMore({
Expand All @@ -163,13 +114,22 @@ export function ResourceList<
setNamespaced(namespaced)
}, [setNamespaced, namespaced])

if (isLoading) {
return (
<TableSkeleton
numColumns={6}
centered
/>
)
}

return (
<>
<ErrorToast errors={resourceList?.errors} />
<FullHeightTableWrap>
<Table
data={items}
columns={columnsData}
columns={columns}
hasNextPage={hasNextPage}
fetchNextPage={fetchNextPage}
isFetchingNextPage={loading}
Expand Down
4 changes: 4 additions & 0 deletions assets/src/components/policies/PoliciesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
ColPolicyName,
ColViolations,
} from './PoliciesColumns'
import { TableFillLevel } from '@pluralsh/design-system/dist/components/table/Table'

const columns = [ColPolicyName, ColCluster, ColViolations, ColDescription]
const columnsWithActions = [
Expand All @@ -40,6 +41,7 @@ export function PoliciesTable({
loading,
setVirtualSlice,
resetFilters,
fillLevel,
}: {
caret?: boolean
setRefetch?: (refetch: () => () => void) => void
Expand All @@ -49,6 +51,7 @@ export function PoliciesTable({
loading: boolean
setVirtualSlice: any
resetFilters?: () => void
fillLevel?: TableFillLevel
}) {
const theme = useTheme()
const navigate = useNavigate()
Expand Down Expand Up @@ -83,6 +86,7 @@ export function PoliciesTable({
<FullHeightTableWrap>
<Table
virtualizeRows
fillLevel={fillLevel}
data={data?.policyConstraints?.edges || []}
columns={caret ? columnsWithActions : columns}
css={{
Expand Down
Loading
Loading