8000 feat(crux-ui): add sorting to tables by robot9706 · Pull Request #798 · dyrector-io/dyrectorio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(crux-ui): add sorting to tables #798

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

Merged
merged 6 commits into from
Aug 30, 2023
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
2 changes: 1 addition & 1 deletion web/crux-ui/e2e/utils/node-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const installDagent = async (page: Page) => {
}

const waitForDeployment = async (page: Page) => {
await page.waitForSelector('span:text-is("Successful"), span:text-is("Failed")')
await page.waitForSelector('span:text-is("Successful"), span:text-is("Failed")', { timeout: 2 * 60 * 1000 })

if (await page.isVisible('span:text-is("Failed")')) {
await page.pause()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ test.describe('Versioned Project', () => {
args: [],
name: 'sleep',
image: 'alpine:3.14',
command: ['sleep', '2'],
command: ['sleep', '20'],
volumes: [],
environment: {},
useParentConfig: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('In progress deployment should be not deletable', async ({ page }) => {
args: [],
name: 'sleep',
image: 'alpine:3.14',
command: ['sleep', '2'],
command: ['sleep', '20'],
volumes: [],
environment: {},
useParentConfig: false,
Expand Down
2 changes: 1 addition & 1 deletion web/crux-ui/e2e/with-login/deployment/deployment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ test('Select specific instances to deploy', async ({ page }) => {
const instanceBody = await page.locator('.table-row-group')
const instanceRow = await instanceBody.locator('.table-row')

await instanceRow.nth(1).locator('img[alt="check"]').click()
await instanceRow.locator('img[alt="check"]:left-of(div:text-is("busybox"))').click()

await deploy(page, deploymentId, false, false)

Expand Down
29 changes: 25 additions & 4 deletions web/crux-ui/src/components/nodes/node-audit-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import clsx from 'clsx'
import useTranslation from 'next-translate/useTranslation'
import { useEffect, useState } from 'react'
import JsonEditor from '../shared/json-editor'
import { dateSort, sortHeaderBuilder, stringSort, useSorting } from '@app/hooks/use-sorting'

type NodeAuditFilter = {
from: Date
Expand All @@ -32,6 +33,8 @@ interface NodeAuditListProps {
node: DyoNode
}

type NodeAuditLogSorting = 'createdAt' | 'event'

const defaultHeaderClass = 'uppercase text-bright text-sm font-semibold bg-medium-eased px-2 py-3 h-11'
const defaultItemClass = 'h-12 min-h-min text-light-eased p-2'
const columnWidths = ['w-2/12', 'w-48', '', 'w-24']
Expand All @@ -43,6 +46,7 @@ const NodeAuditList = (props: NodeAuditListProps) => {

const { t } = useTranslation('nodes')
const routes = useTeamRoutes()
const throttle = useThrottling(1000)

const endOfToday = getEndOfToday()

6D4E Expand All @@ -54,7 +58,7 @@ const NodeAuditList = (props: NodeAuditListProps) => {
eventType: null,
})
const [pagination, setPagination] = useState<PaginationSettings>(defaultPagination)
const throttle = useThrottling(1000)
const [showInfo, setShowInfo] = useState<NodeAuditLog>(null)

const fetchData = async () => {
const { from, to } = filter
Expand All @@ -77,12 +81,21 @@ const NodeAuditList = (props: NodeAuditListProps) => {
}
}

const sorting = useSorting<NodeAuditLog, NodeAuditLogSorting>(data, {
initialField: 'createdAt',
initialDirection: 'asc',
initialDataSorted: true,
sortFunctions: {
createdAt: dateSort,
event: stringSort,
},
})

useEffect(() => {
throttle(fetchData, true)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [pagination, filter])

const [showInfo, setShowInfo] = useState<NodeAuditLog>(null)
const NodeAuditLog) => setShowInfo(logEntry)

const => {
Expand All @@ -92,7 +105,7 @@ const NodeAuditList = (props: NodeAuditListProps) => {
setFilter({ ...filter, from: start, to: end })
}

const listHeaders = ['common:date', 'common:event', 'common:data', 'common:actions'].map(it => t(it))
const listHeaders = ['common:date', 'common:event', 'common:data', 'common:actions']
const headerClasses = [
clsx('rounded-tl-lg pl-6', defaultHeaderClass),
...Array.from({ length: listHeaders.length - 2 }).map(() => defaultHeaderClass),
Expand Down Expand Up @@ -160,10 +173,18 @@ const NodeAuditList = (props: NodeAuditListProps) => {
headerClassName={headerClasses}
itemClassName={itemClasses}
columnWidths={columnWidths}
data={data}
data={sorting.items}
headers={listHeaders}
footer={<Paginator length={total} defaultPagination={defaultPagination} />}
itemBuilder={itemTemplate}
headerBuilder={sortHeaderBuilder<NodeAuditLog, NodeAuditLogSorting>(
sorting,
{
'common:date': 'createdAt',
'common:event': 'event',
},
text => t(text),
)}
/>
</DyoCard>
{!showInfo ? null : (
Expand Down
35 changes: 33 additions & 2 deletions web/crux-ui/src/components/nodes/node-containers-list.tsx
F438
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import DyoIcon from '@app/elements/dyo-icon'
import DyoImgButton from '@app/elements/dyo-img-button'
import { DyoList } from '@app/elements/dyo-list'
import LoadingIndicator from '@app/elements/loading-indicator'
import { dateSort, enumSort, sortHeaderBuilder, stringSort, useSorting } from '@app/hooks/use-sorting'
import useTeamRoutes from '@app/hooks/use-team-routes'
import {
CONTAINER_STATE_VALUES,
Container,
containerIsRestartable,
containerIsStartable,
Expand All @@ -26,6 +28,8 @@ interface NodeContainersListProps {
actions: NodeDetailsActions
}

type ContainerSorting = 'name' | 'imageTag' | 'state' | 'reason' | 'createdAt'

const NodeContainersList = (props: NodeContainersListProps) => {
const { state, actions } = props
const {
Expand All @@ -36,6 +40,22 @@ const NodeContainersList = (props: NodeContainersListProps) => {
const { t } = useTranslation('nodes')
const routes = useTeamRoutes()

const sorting = useSorting<Container, ContainerSorting>(containerItems, {
initialField: 'createdAt',
initialDirection: 'asc',
sortFunctions: {
name: stringSort,
imageTag: stringSort,
state: enumSort(CONTAINER_STATE_VALUES),
reason: stringSort,
createdAt: dateSort,
},
fieldGetters: {
name: it => containerPrefixNameOf(it.id),
imageTag: it => imageName(it.imageName, it.imageTag),
},
})

const headers = [
'common:name',
'images:imageTag',
Expand Down Expand Up @@ -124,12 +144,23 @@ const NodeContainersList = (props: NodeContainersListProps) => {
return (
<DyoCard className="mt-4">
<DyoList
headers={[...headers.map(h => t(h))]}
headers={headers}
headerClassName={headerClasses}
columnWidths={columnWidths}
itemClassName={itemClasses}
data={containerItems}
data={sorting.items}
itemBuilder={itemBuilder}
headerBuilder={sortHeaderBuilder<Container, ContainerSorting>(
sorting,
{
'common:name': 'name',
'images:imageTag': 'imageTag',
'common:state': 'state',
'common:reason': 'reason',
'common:createdAt': 'createdAt',
},
text => t(text),
)}
footer={
<Paginator
>
Expand Down
41 changes: 38 additions & 3 deletions web/crux-ui/src/components/projects/project-view-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,50 @@ import { DyoCard } from '@app/elements/dyo-card'
import DyoIcon from '@app/elements/dyo-icon'
import { DyoList } from '@app/elements/dyo-list& 10000 #39;
import useTeamRoutes from '@app/hooks/use-team-routes'
import { Project } from '@app/models'
import { PROJECT_TYPE_VALUES, Project } from '@app/models'
import { auditToLocaleDate } from '@app/utils'
import clsx from 'clsx'
import useTranslation from 'next-translate/useTranslation'
import Link from 'next/link'
import { useRouter } from 'next/router'
import ProjectTypeTag from './project-type-tag'
import {
auditFieldGetter,
dateSort,
enumSort,
numberSort,
sortHeaderBuilder,
stringSort,
useSorting,
} from '@app/hooks/use-sorting'

export interface ProjectViewListProps {
projects: Project[]
}

type ProjectSorting = 'name' | 'versionCount' | 'updatedAt' | 'type'

const ProjectViewList = (props: ProjectViewListProps) => {
const { projects } = props

const { t } = useTranslation('projects')
const routes = useTeamRoutes()
const router = useRouter()

const sorting = useSorting<Project, ProjectSorting>(projects, {
initialField: 'name',
initialDirection: 'asc',
sortFunctions: {
name: stringSort,
versionCount: numberSort,
updatedAt: dateSort,
type: enumSort(PROJECT_TYPE_VALUES),
},
fieldGetters: {
updatedAt: auditFieldGetter,
},
})

const columnWidths = ['w-6/12', 'w-1/12', 'w-2/12', 'w-2/12', 'w-1/12']
const headers = ['name', 'versions', 'common:updatedAt', 'type', 'common:actions']
const defaultHeaderClass = 'uppercase text-bright text-sm font-semibold bg-medium-eased px-2 py-3 h-11'
Expand Down Expand Up @@ -61,13 +86,23 @@ const ProjectViewList = (props: ProjectViewListProps) => {
return (
<DyoCard className="relative mt-4">
<DyoList
headers={[...headers.map(h => t(h)), '']}
headers={[...headers, '']}
headerClassName={headerClasses}
columnWidths={columnWidths}
itemClassName={itemClasses}
data={projects}
data={sorting.items}
noSeparator
itemBuilder={itemTemplate}
headerBuilder={sortHeaderBuilder<Project, ProjectSorting>(
sorting,
{
name: 'name',
versions: 'versionCount',
'common:updatedAt': 'updatedAt',
type: 'type',
},
text => t(text),
)}
cellClick={onCellClick}
/>
</DyoCard>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,41 @@ import clsx from 'clsx'
import useTranslation from 'next-translate/useTranslation'
import Link from 'next/link'
import { DeploymentActions, DeploymentState } from './use-deployment-state'
import { dateSort, sortHeaderBuilder, stringSort, useSorting } from '@app/hooks/use-sorting'

export interface DeploymentViewListProps {
state: DeploymentState
actions: DeploymentActions
}

type InstanceSorting = 'containerName' | 'registry' | 'imageTag' | 'createdAt'

const DeploymentViewList = (props: DeploymentViewListProps) => {
const { t } = useTranslation('images')
const routes = useTeamRoutes()

const { state, actions } = props
const { instances, deployInstances } = state

const sorting = useSorting<Instance, InstanceSorting>(instances, {
initialField: 'createdAt',
initialDirection: 'asc',
sortFunctions: {
containerName: stringSort,
registry: stringSort,
imageTag: stringSort,
createdAt: dateSort,
},
fieldGetters: {
containerName: it => it.config?.name ?? it.image.config.name,
registry: it => it.image.registry.name,
imageTag: it => `${it.image.name}${it.image.tag ? `:${it.image.tag}` : null}`,
createdAt: it => it.image.createdAt,
},
})

const columnWidths = ['w-12', 'w-4/12', 'w-2/12', 'w-2/12', 'w-4/12', 'w-28']
const headers = [
'',
...['containerName', 'common:registry', 'imageTag', 'common:createdAt', 'common:actions'].map(it => t(it)),
'',
]
const headers = ['', 'containerName', 'common:registry', 'imageTag', 'common:createdAt', 'common:actions', '']
const defaultHeaderClass = 'uppercase text-bright text-sm font-semibold bg-medium-eased px-2 py-3 h-11'
const headerClasses = [
clsx('rounded-tl-lg pl-6', defaultHeaderClass),
Expand Down Expand Up @@ -69,6 +85,16 @@ const DeploymentViewList = (props: DeploymentViewListProps) => {
</div>,
]

const sortingHeaderBuilder = sortHeaderBuilder<Instance, InstanceSorting>(
sorting,
{
containerName: 'containerName',
'common:registry': 'registry',
imageTag: 'imageTag',
'common:createdAt': 'createdAt',
},
text => t(text),
)
const headerBuilder = (header: string, index: number) =>
index === 0 ? (
<DyoCheckbox
Expand All @@ -77,7 +103,7 @@ const DeploymentViewList = (props: DeploymentViewListProps) => {
=> actions.onAllInstancesToggled(it)}
/>
) : (
header
sortingHeaderBuilder(header)
)

return (
Expand All @@ -87,7 +113,7 @@ const DeploymentViewList = (props: DeploymentViewListProps) => {
headerClassName={headerClasses}
columnWidths={columnWidths}
itemClassName={itemClasses}
data={instances}
data={sorting.items}
noSeparator
itemBuilder={itemTemplate}
headerBuilder={headerBuilder}
Expand Down
Loading
0