mirror of
https://github.com/docmost/docmost.git
synced 2026-09-01 03:15:32 +08:00
feat(bases): scaffold kanban renderer (no DnD yet)
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { useMemo } from "react";
|
||||
import {
|
||||
IBase,
|
||||
IBaseRow,
|
||||
IBaseView,
|
||||
} from "@/features/base/types/base.types";
|
||||
import { useKanbanGroups } from "@/features/base/hooks/use-kanban-groups";
|
||||
import { KanbanColumn } from "./kanban-column";
|
||||
import classes from "@/features/base/styles/kanban.module.css";
|
||||
|
||||
type BaseKanbanProps = {
|
||||
base: IBase;
|
||||
rows: IBaseRow[];
|
||||
effectiveView: IBaseView | undefined;
|
||||
onCardClick: (rowId: string) => void;
|
||||
};
|
||||
|
||||
export function BaseKanban({
|
||||
base,
|
||||
rows,
|
||||
effectiveView,
|
||||
onCardClick,
|
||||
}: BaseKanbanProps) {
|
||||
const groupByPropertyId = effectiveView?.config?.groupByPropertyId;
|
||||
const property = useMemo(
|
||||
() =>
|
||||
groupByPropertyId
|
||||
? base.properties.find((p) => p.id === groupByPropertyId)
|
||||
: undefined,
|
||||
[groupByPropertyId, base.properties],
|
||||
);
|
||||
const primaryProperty = useMemo(
|
||||
() => base.properties.find((p) => p.isPrimary),
|
||||
[base.properties],
|
||||
);
|
||||
const isGroupable = property?.type === "select" || property?.type === "status";
|
||||
const { columns } = useKanbanGroups(
|
||||
rows,
|
||||
isGroupable ? property : undefined,
|
||||
effectiveView?.config?.hiddenChoiceIds,
|
||||
effectiveView?.config?.choiceOrder,
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={classes.board}>
|
||||
{columns.map((column) => (
|
||||
<KanbanColumn
|
||||
key={column.key}
|
||||
column={column}
|
||||
primaryProperty={primaryProperty}
|
||||
onCardClick={onCardClick}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { IBaseProperty, IBaseRow } from "@/features/base/types/base.types";
|
||||
import classes from "@/features/base/styles/kanban.module.css";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
type KanbanCardProps = {
|
||||
row: IBaseRow;
|
||||
primaryProperty: IBaseProperty | undefined;
|
||||
onClick: (rowId: string) => void;
|
||||
};
|
||||
|
||||
export function KanbanCard({ row, primaryProperty, onClick }: KanbanCardProps) {
|
||||
const { t } = useTranslation();
|
||||
const titleValue =
|
||||
primaryProperty
|
||||
? ((row.cells ?? {})[primaryProperty.id] as string | undefined)
|
||||
: undefined;
|
||||
const titleText = titleValue?.trim().length ? titleValue : t("Untitled");
|
||||
const isEmpty = !titleValue?.trim().length;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classes.card}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => onClick(row.id)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
onClick(row.id);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className={
|
||||
classes.cardTitle + (isEmpty ? " " + classes.cardTitleEmpty : "")
|
||||
}
|
||||
>
|
||||
{titleText}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Badge, Text } from "@mantine/core";
|
||||
import classes from "@/features/base/styles/kanban.module.css";
|
||||
|
||||
type KanbanColumnHeaderProps = {
|
||||
name: string;
|
||||
color: string | null;
|
||||
count: number;
|
||||
};
|
||||
|
||||
export function KanbanColumnHeader({
|
||||
name,
|
||||
color,
|
||||
count,
|
||||
}: KanbanColumnHeaderProps) {
|
||||
return (
|
||||
<div className={classes.columnHeader}>
|
||||
<div className={classes.columnHeaderLeft}>
|
||||
{color ? (
|
||||
<Badge color={color} variant="light" size="sm">
|
||||
{name}
|
||||
</Badge>
|
||||
) : (
|
||||
<Text size="sm" c="dimmed">
|
||||
{name}
|
||||
</Text>
|
||||
)}
|
||||
<span className={classes.columnCount}>{count}</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { KanbanColumn as KanbanColumnData } from "@/features/base/hooks/use-kanban-groups";
|
||||
import { IBaseProperty } from "@/features/base/types/base.types";
|
||||
import { KanbanCard } from "./kanban-card";
|
||||
import { KanbanColumnHeader } from "./kanban-column-header";
|
||||
import classes from "@/features/base/styles/kanban.module.css";
|
||||
|
||||
type KanbanColumnProps = {
|
||||
column: KanbanColumnData;
|
||||
primaryProperty: IBaseProperty | undefined;
|
||||
onCardClick: (rowId: string) => void;
|
||||
};
|
||||
|
||||
export function KanbanColumn({
|
||||
column,
|
||||
primaryProperty,
|
||||
onCardClick,
|
||||
}: KanbanColumnProps) {
|
||||
return (
|
||||
<div className={classes.column} data-column-key={column.key}>
|
||||
<KanbanColumnHeader
|
||||
name={column.name}
|
||||
color={column.color}
|
||||
count={column.rows.length}
|
||||
/>
|
||||
<div className={classes.columnBody} data-column-body={column.key}>
|
||||
{column.rows.map((row) => (
|
||||
<KanbanCard
|
||||
key={row.id}
|
||||
row={row}
|
||||
primaryProperty={primaryProperty}
|
||||
onClick={onCardClick}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user