Skip to content
Open
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
132 changes: 34 additions & 98 deletions web/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"cmdk": "^0.2.0",
"eslint-config-prettier": "^10.1.8",
"localforage": "^1.10.0",
"lucide-react": "^0.292.0",
"match-sorter": "^6.3.1",
Expand Down
118 changes: 93 additions & 25 deletions web/src/app/compose-library/compose-library-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,57 @@ import { Button } from "@/components/ui/button"
import useComposeLibraryItemList from "@/hooks/useComposeLibraryItemList"
import { CLASSES_CLICKABLE_TABLE_ROW } from "@/lib/utils"
import { TableNoData } from "@/components/widgets/table-no-data"
import { useMemo, useState } from "react"
import { SortableIcon } from "@/components/widgets/sortable-icon"

type SortKey = "projectName" | "type"

export default function ComposeLibraryList() {
const navigate = useNavigate()
const { isLoading, composeLibraryItems } = useComposeLibraryItemList()
const [sortKey, setSortKey] = useState<SortKey>("projectName")
const [sortOrder, setSortOrder] = useState<"asc" | "desc">("asc")

const handleSort = (key: SortKey) => {
if (sortKey === key) {
setSortOrder(sortOrder === "asc" ? "desc" : "asc")
} else {
setSortKey(key)
setSortOrder("asc")
}
}

const sortedAndFilteredLibraryItems = useMemo(() => {
if (!composeLibraryItems?.items) return []

const sorted = [...composeLibraryItems.items].sort((a, b) => {
let aValue: string = ""
let bValue: string = ""

switch (sortKey) {
case "projectName":
aValue = a.projectName
bValue = b.projectName
break
case "type":
aValue = a.type
bValue = b.type
break
default:
break
}

if (aValue < bValue) {
return sortOrder === "asc" ? -1 : 1
}
if (aValue > bValue) {
return sortOrder === "asc" ? 1 : -1
}
return 0
})

return sorted
}, [composeLibraryItems, sortKey, sortOrder])

if (isLoading) return <Loading />

Expand Down Expand Up @@ -49,37 +96,58 @@ export default function ComposeLibraryList() {
<Table>
<TableHeader>
<TableRow>
<TableHead scope="col">Library Project Name</TableHead>
<TableHead scope="col">Type</TableHead>
<TableHead
scope="col"
className="cursor-pointer"
onClick={() => handleSort("projectName")}
>
Library Project Name
<SortableIcon
sortKey="projectName"
currentSortKey={sortKey}
sortOrder={sortOrder}
/>
</TableHead>
<TableHead
scope="col"
className="cursor-pointer"
onClick={() => handleSort("type")}
>
Type
<SortableIcon
sortKey="type"
currentSortKey={sortKey}
sortOrder={sortOrder}
/>
</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{composeLibraryItems?.totalRows === -1 && (
<TableNoData colSpan={3} />
)}
{composeLibraryItems?.items &&
composeLibraryItems?.items.map((item) => (
<TableRow
key={item.projectName}
className={CLASSES_CLICKABLE_TABLE_ROW}
onClick={() => {
if (item.type === "filesystem") {
navigate(
`/composelibrary/${item.type}/${item.projectName}/edit`
)
}
if (item.type === "github") {
navigate(`/composelibrary/${item.type}/${item.id}/edit`)
}
}}
>
<TableCell>{item.projectName}</TableCell>
<TableCell>
{item.type === "filesystem" ? "File System" : ""}
{item.type === "github" ? "GitHub" : ""}
</TableCell>
</TableRow>
))}
{sortedAndFilteredLibraryItems.map((item) => (
<TableRow
key={item.projectName}
className={CLASSES_CLICKABLE_TABLE_ROW}
onClick={() => {
if (item.type === "filesystem") {
navigate(
`/composelibrary/${item.type}/${item.projectName}/edit`
)
}
if (item.type === "github") {
navigate(`/composelibrary/${item.type}/${item.id}/edit`)
}
}}
>
<TableCell>{item.projectName}</TableCell>
<TableCell>
{item.type === "filesystem" ? "File System" : ""}
{item.type === "github" ? "GitHub" : ""}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</MainContent>
Expand Down
Loading