Skip to content

Commit 634cbe0

Browse files
authored
Tweak collection views (#896)
* fix: tweak collection labels * feat: make it possible to sort collections by id * feat: make it possible to specify column settings for collections * chore: use Nova button component for "Register new" actions
1 parent 04ae3fa commit 634cbe0

File tree

8 files changed

+56
-32
lines changed

8 files changed

+56
-32
lines changed

ami/main/api/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ class SourceImageCollectionViewSet(DefaultViewSet, ProjectMixin):
644644
]
645645
filterset_fields = ["method"]
646646
ordering_fields = [
647+
"id",
647648
"created_at",
648649
"updated_at",
649650
"name",

ui/src/design-system/components/table/column-settings/column-settings.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Button } from 'design-system/components/button/button'
21
import { Checkbox } from 'design-system/components/checkbox/checkbox'
3-
import { IconType } from 'design-system/components/icon/icon'
42
import * as Popover from 'design-system/components/popover/popover'
3+
import { ChevronDownIcon } from 'lucide-react'
4+
import { Button } from 'nova-ui-kit'
55
import { STRING, translate } from 'utils/language'
66
import styles from './column-settings.module.scss'
77

@@ -18,11 +18,10 @@ export const ColumnSettings = ({
1818
}: ColumnSettingsProps) => (
1919
<Popover.Root>
2020
<Popover.Trigger>
21-
<Button
22-
label={translate(STRING.COLUMNS)}
23-
icon={IconType.ToggleDown}
24-
customClass={styles.triggerButton}
25-
/>
21+
<Button variant="outline" size="small">
22+
<span>{translate(STRING.COLUMNS)}</span>
23+
<ChevronDownIcon className="w-4 h-4" />
24+
</Button>
2625
</Popover.Trigger>
2726
<Popover.Content
2827
ariaCloselabel={translate(STRING.CLOSE)}

ui/src/pages/deployment-details/new-deployment-dialog.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { useCreateDeployment } from 'data-services/hooks/deployments/useCreateDeployment'
22
import { DeploymentDetails } from 'data-services/models/deployment-details'
3-
import { Button } from 'design-system/components/button/button'
43
import * as Dialog from 'design-system/components/dialog/dialog'
5-
import { IconType } from 'design-system/components/icon/icon'
4+
import { PlusIcon } from 'lucide-react'
5+
import { Button } from 'nova-ui-kit'
66
import { useState } from 'react'
77
import { useParams } from 'react-router-dom'
88
import { STRING, translate } from 'utils/language'
@@ -24,7 +24,10 @@ export const NewDeploymentDialog = () => {
2424
return (
2525
<Dialog.Root open={isOpen} onOpenChange={setIsOpen}>
2626
<Dialog.Trigger>
27-
<Button label={label} icon={IconType.Plus} />
27+
<Button size="small" variant="outline">
28+
<PlusIcon className="w-4 h-4" />
29+
<span>{label}</span>
30+
</Button>
2831
</Dialog.Trigger>
2932
<Dialog.Content ariaCloselabel={translate(STRING.CLOSE)}>
3033
<DeploymentDetailsForm

ui/src/pages/job-details/new-job-dialog.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useCreateJob } from 'data-services/hooks/jobs/useCreateJob'
2-
import { Button, ButtonTheme } from 'design-system/components/button/button'
32
import * as Dialog from 'design-system/components/dialog/dialog'
4-
import { IconType } from 'design-system/components/icon/icon'
3+
import { PlusIcon } from 'lucide-react'
4+
import { Button } from 'nova-ui-kit'
55
import { useState } from 'react'
66
import { useParams } from 'react-router-dom'
77
import { STRING, translate } from 'utils/language'
@@ -26,11 +26,10 @@ export const NewJobDialog = () => {
2626
return (
2727
<Dialog.Root open={isOpen} onOpenChange={setIsOpen}>
2828
<Dialog.Trigger>
29-
<Button
30-
label={label}
31-
icon={IconType.Plus}
32-
theme={ButtonTheme.Default}
33-
/>
29+
<Button size="small" variant="outline">
30+
<PlusIcon className="w-4 h-4" />
31+
<span>{label}</span>
32+
</Button>
3433
</Dialog.Trigger>
3534
<Dialog.Content ariaCloselabel={translate(STRING.CLOSE)}>
3635
<Dialog.Header title={label} />

ui/src/pages/project-details/new-project-dialog.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { useCreateProject } from 'data-services/hooks/projects/useCreateProject'
22
import { Project } from 'data-services/models/project'
3-
import { Button, ButtonTheme } from 'design-system/components/button/button'
43
import * as Dialog from 'design-system/components/dialog/dialog'
5-
import { IconType } from 'design-system/components/icon/icon'
4+
import { PlusIcon } from 'lucide-react'
5+
import { Button } from 'nova-ui-kit'
66
import { useState } from 'react'
77
import { STRING, translate } from 'utils/language'
88
import { ProjectDetailsForm } from './project-details-form'
@@ -29,11 +29,10 @@ export const NewProjectDialog = () => {
2929
return (
3030
<Dialog.Root open={isOpen} onOpenChange={setIsOpen}>
3131
<Dialog.Trigger>
32-
<Button
33-
label={label}
34-
icon={IconType.Plus}
35-
theme={ButtonTheme.Default}
36-
/>
32+
<Button size="small" variant="outline">
33+
<PlusIcon className="w-4 h-4" />
34+
<span>{label}</span>
35+
</Button>
3736
</Dialog.Trigger>
3837
<Dialog.Content ariaCloselabel={translate(STRING.CLOSE)}>
3938
<Dialog.Header title={label} />

ui/src/pages/project/collections/collection-columns.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ export const columns: (projectId: string) => TableColumn<Collection>[] = (
2323
{
2424
id: 'id',
2525
name: translate(STRING.FIELD_LABEL_ID),
26-
renderCell: (item: Collection) => (
27-
<BasicTableCell value={item.id} theme={CellTheme.Primary} />
28-
),
26+
sortField: 'id',
27+
renderCell: (item: Collection) => <BasicTableCell value={item.id} />,
2928
},
3029
{
3130
id: 'name',

ui/src/pages/project/collections/collections.tsx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,34 @@ import { API_ROUTES } from 'data-services/constants'
22
import { useCollections } from 'data-services/hooks/collections/useCollections'
33
import { PageHeader } from 'design-system/components/page-header/page-header'
44
import { PaginationBar } from 'design-system/components/pagination-bar/pagination-bar'
5+
import { ColumnSettings } from 'design-system/components/table/column-settings/column-settings'
56
import { Table } from 'design-system/components/table/table/table'
67
import { TableSortSettings } from 'design-system/components/table/types'
78
import { NewEntityDialog } from 'pages/project/entities/new-entity-dialog'
89
import { useEffect, useState } from 'react'
910
import { useParams } from 'react-router-dom'
1011
import { STRING, translate } from 'utils/language'
12+
import { useColumnSettings } from 'utils/useColumnSettings'
1113
import { usePagination } from 'utils/usePagination'
1214
import { UserPermission } from 'utils/user/types'
1315
import { columns } from './collection-columns'
1416

1517
export const Collections = () => {
1618
const { projectId } = useParams()
1719
const [sort, setSort] = useState<TableSortSettings | undefined>({
18-
field: 'created_at',
19-
order: 'desc',
20+
field: 'id',
21+
order: 'asc',
2022
})
23+
const { columnSettings, setColumnSettings } = useColumnSettings(
24+
'collections',
25+
{
26+
id: true,
27+
name: true,
28+
settings: true,
29+
'captures-with-detections': true,
30+
status: true,
31+
}
32+
)
2133
const { pagination, setPage } = usePagination()
2234
const [poll, setPoll] = useState(false)
2335
const { collections, userPermissions, total, isLoading, isFetching, error } =
@@ -51,6 +63,11 @@ export const Collections = () => {
5163
isFetching={isFetching}
5264
tooltip={translate(STRING.TOOLTIP_COLLECTION)}
5365
>
66+
<ColumnSettings
67+
columns={columns(projectId as string)}
68+
columnSettings={columnSettings}
69+
onColumnSettingsChange={setColumnSettings}
70+
/>
5471
{canCreate && (
5572
<NewEntityDialog
5673
collection={API_ROUTES.COLLECTIONS}
@@ -59,7 +76,14 @@ export const Collections = () => {
5976
)}
6077
</PageHeader>
6178
<Table
62-
columns={columns(projectId as string)}
79+
columns={columns(projectId as string).filter((column) => {
80+
// Always show action column
81+
if (column.id === 'actions') {
82+
return true
83+
}
84+
85+
return !!columnSettings[column.id]
86+
})}
6387
error={error}
6488
isLoading={isLoading}
6589
items={collections}

ui/src/pages/project/entities/details-form/collection-details-form.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const config: FormConfig = {
8686
},
8787
},
8888
'kwargs.max_num': {
89-
label: 'Max number of images',
89+
label: 'Max number of captures',
9090
rules: {
9191
min: 0,
9292
validate: (value) => {
@@ -113,7 +113,7 @@ const config: FormConfig = {
113113
},
114114
},
115115
'kwargs.size': {
116-
label: 'Size',
116+
label: 'Number of captures',
117117
rules: {
118118
min: 0,
119119
required: true,

0 commit comments

Comments
 (0)