mirror of
https://github.com/docmost/docmost.git
synced 2026-08-28 17:27:06 +08:00
feat: rename kanban group by clicking column name
This commit is contained in:
@@ -30,7 +30,7 @@ type BaseKanbanProps = {
|
|||||||
|
|
||||||
export function BaseKanban({ base, view, pageId, embedded, editable, viewFilter }: BaseKanbanProps) {
|
export function BaseKanban({ base, view, pageId, embedded, editable, viewFilter }: BaseKanbanProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { groupByPropertyId, columns, hasValidGroupBy } = useKanbanColumns(base, view);
|
const { groupByPropertyId, groupByProperty, columns, hasValidGroupBy } = useKanbanColumns(base, view);
|
||||||
const updateView = useUpdateViewMutation();
|
const updateView = useUpdateViewMutation();
|
||||||
const moveCard = useKanbanMoveCardMutation();
|
const moveCard = useKanbanMoveCardMutation();
|
||||||
const { openRow } = useRowDetailModal(pageId);
|
const { openRow } = useRowDetailModal(pageId);
|
||||||
@@ -201,6 +201,7 @@ export function BaseKanban({ base, view, pageId, embedded, editable, viewFilter
|
|||||||
column={column}
|
column={column}
|
||||||
viewFilter={viewFilter}
|
viewFilter={viewFilter}
|
||||||
groupByPropertyId={groupByPropertyId!}
|
groupByPropertyId={groupByPropertyId!}
|
||||||
|
groupByProperty={groupByProperty}
|
||||||
canEdit={editable}
|
canEdit={editable}
|
||||||
onOpenRow={handleOpenRow}
|
onOpenRow={handleOpenRow}
|
||||||
onHide={hideColumn}
|
onHide={hideColumn}
|
||||||
|
|||||||
@@ -3,22 +3,24 @@ import { useTranslation } from "react-i18next";
|
|||||||
import { ActionIcon, Menu, Text } from "@mantine/core";
|
import { ActionIcon, Menu, Text } from "@mantine/core";
|
||||||
import { IconDots, IconPlus, IconGripVertical } from "@tabler/icons-react";
|
import { IconDots, IconPlus, IconGripVertical } from "@tabler/icons-react";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
import { KanbanColumn } from "@/ee/base/types/base.types";
|
import { IBaseProperty, KanbanColumn } from "@/ee/base/types/base.types";
|
||||||
import { choiceColor } from "@/ee/base/components/cells/choice-color";
|
import { choiceColor } from "@/ee/base/components/cells/choice-color";
|
||||||
import { useKanbanColumnDnd } from "@/ee/base/hooks/use-kanban-column-dnd";
|
import { useKanbanColumnDnd } from "@/ee/base/hooks/use-kanban-column-dnd";
|
||||||
import { BaseDropEdgeIndicator } from "@/ee/base/components/grid/base-drop-edge-indicator";
|
import { BaseDropEdgeIndicator } from "@/ee/base/components/grid/base-drop-edge-indicator";
|
||||||
|
import { KanbanColumnTitle } from "@/ee/base/components/kanban/kanban-column-title";
|
||||||
import classes from "@/ee/base/styles/kanban.module.css";
|
import classes from "@/ee/base/styles/kanban.module.css";
|
||||||
|
|
||||||
type KanbanColumnHeaderProps = {
|
type KanbanColumnHeaderProps = {
|
||||||
column: KanbanColumn;
|
column: KanbanColumn;
|
||||||
pageId: string;
|
pageId: string;
|
||||||
|
property: IBaseProperty | undefined;
|
||||||
count?: string;
|
count?: string;
|
||||||
canEdit: boolean;
|
canEdit: boolean;
|
||||||
onHide: () => void;
|
onHide: () => void;
|
||||||
onAddCard: () => void;
|
onAddCard: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function KanbanColumnHeader({ column, pageId, count, canEdit, onHide, onAddCard }: KanbanColumnHeaderProps) {
|
export function KanbanColumnHeader({ column, pageId, property, count, canEdit, onHide, onAddCard }: KanbanColumnHeaderProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const dotColor = column.color
|
const dotColor = column.color
|
||||||
? choiceColor(column.color).color as string
|
? choiceColor(column.color).color as string
|
||||||
@@ -49,9 +51,7 @@ export function KanbanColumnHeader({ column, pageId, count, canEdit, onHide, onA
|
|||||||
background: dotColor,
|
background: dotColor,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Text fw={600} size="sm" flex={1} truncate>
|
<KanbanColumnTitle column={column} property={property} pageId={pageId} canEdit={canEdit} />
|
||||||
{column.isNoValue ? t("No value") : column.name}
|
|
||||||
</Text>
|
|
||||||
{count !== undefined && <Text className={classes.count}>{count}</Text>}
|
{count !== undefined && <Text className={classes.count}>{count}</Text>}
|
||||||
{canEdit && (
|
{canEdit && (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
import { useCallback, useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { Button, Group, Popover, Text, TextInput, UnstyledButton } from "@mantine/core";
|
||||||
|
import { IBaseProperty, KanbanColumn, SelectTypeOptions } from "@/ee/base/types/base.types";
|
||||||
|
import { useUpdatePropertyMutation } from "@/ee/base/queries/base-property-query";
|
||||||
|
import classes from "@/ee/base/styles/kanban.module.css";
|
||||||
|
|
||||||
|
type KanbanColumnTitleProps = {
|
||||||
|
column: KanbanColumn;
|
||||||
|
property: IBaseProperty | undefined;
|
||||||
|
pageId: string;
|
||||||
|
canEdit: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function KanbanColumnTitle({ column, property, pageId, canEdit }: KanbanColumnTitleProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [opened, setOpened] = useState(false);
|
||||||
|
const [draft, setDraft] = useState("");
|
||||||
|
const updateProperty = useUpdatePropertyMutation();
|
||||||
|
|
||||||
|
const commit = useCallback(() => {
|
||||||
|
setOpened(false);
|
||||||
|
const name = draft.trim();
|
||||||
|
const options = property?.typeOptions as SelectTypeOptions | undefined;
|
||||||
|
if (!property || !options || !name || name === column.name) return;
|
||||||
|
if (!options.choices.some((c) => c.id === column.key)) return;
|
||||||
|
updateProperty.mutate({
|
||||||
|
propertyId: property.id,
|
||||||
|
pageId,
|
||||||
|
typeOptions: {
|
||||||
|
...options,
|
||||||
|
choices: options.choices.map((c) =>
|
||||||
|
c.id === column.key ? { ...c, name } : c,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}, [draft, property, column.name, column.key, pageId, updateProperty]);
|
||||||
|
|
||||||
|
const toggle = useCallback(() => {
|
||||||
|
if (opened) {
|
||||||
|
commit();
|
||||||
|
} else {
|
||||||
|
setDraft(column.name);
|
||||||
|
setOpened(true);
|
||||||
|
}
|
||||||
|
}, [opened, commit, column.name]);
|
||||||
|
|
||||||
|
const cancel = useCallback(() => setOpened(false), []);
|
||||||
|
|
||||||
|
if (!canEdit || column.isNoValue || !property) {
|
||||||
|
return (
|
||||||
|
<Text fw={600} size="sm" flex={1} truncate>
|
||||||
|
{column.isNoValue ? t("No value") : column.name}
|
||||||
|
</Text>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Popover
|
||||||
|
opened={opened}
|
||||||
|
onChange={(next) => {
|
||||||
|
if (!next) commit();
|
||||||
|
}}
|
||||||
|
position="bottom-start"
|
||||||
|
shadow="md"
|
||||||
|
width={240}
|
||||||
|
withinPortal
|
||||||
|
trapFocus
|
||||||
|
returnFocus
|
||||||
|
closeOnClickOutside
|
||||||
|
closeOnEscape={false}
|
||||||
|
>
|
||||||
|
<Popover.Target>
|
||||||
|
<UnstyledButton className={classes.columnTitleButton} onClick={toggle}>
|
||||||
|
<Text fw={600} size="sm" truncate flex={1} ta="left">
|
||||||
|
{column.name}
|
||||||
|
</Text>
|
||||||
|
</UnstyledButton>
|
||||||
|
</Popover.Target>
|
||||||
|
<Popover.Dropdown
|
||||||
|
p="xs"
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Escape") {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
cancel();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Group gap="xs" wrap="nowrap">
|
||||||
|
<TextInput
|
||||||
|
size="xs"
|
||||||
|
flex={1}
|
||||||
|
value={draft}
|
||||||
|
data-autofocus
|
||||||
|
onFocus={(e) => e.currentTarget.select()}
|
||||||
|
onChange={(e) => setDraft(e.currentTarget.value)}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
commit();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button size="xs" onClick={commit}>
|
||||||
|
{t("Done")}
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
</Popover.Dropdown>
|
||||||
|
</Popover>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useCallback, useEffect, useMemo, useRef } from "react";
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
||||||
import { generateJitteredKeyBetween } from "fractional-indexing-jittered";
|
import { generateJitteredKeyBetween } from "fractional-indexing-jittered";
|
||||||
import { dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
import { dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
||||||
import { type IBase, type IBaseRow, type IBaseView, type FilterGroup, type KanbanColumn as KanbanColumnType, KANBAN_CARD_DRAG_TYPE } from "@/ee/base/types/base.types";
|
import { type IBase, type IBaseProperty, type IBaseRow, type IBaseView, type FilterGroup, type KanbanColumn as KanbanColumnType, KANBAN_CARD_DRAG_TYPE } from "@/ee/base/types/base.types";
|
||||||
import { buildColumnFilter } from "@/ee/base/services/kanban-column-filter";
|
import { buildColumnFilter } from "@/ee/base/services/kanban-column-filter";
|
||||||
import { formatKanbanCount } from "@/ee/base/services/format-kanban-count";
|
import { formatKanbanCount } from "@/ee/base/services/format-kanban-count";
|
||||||
import { useKanbanColumnAutoScroll } from "@/ee/base/hooks/use-kanban-autoscroll";
|
import { useKanbanColumnAutoScroll } from "@/ee/base/hooks/use-kanban-autoscroll";
|
||||||
@@ -19,6 +19,7 @@ type KanbanColumnProps = {
|
|||||||
column: KanbanColumnType;
|
column: KanbanColumnType;
|
||||||
viewFilter: FilterGroup | undefined;
|
viewFilter: FilterGroup | undefined;
|
||||||
groupByPropertyId: string;
|
groupByPropertyId: string;
|
||||||
|
groupByProperty: IBaseProperty | undefined;
|
||||||
canEdit: boolean;
|
canEdit: boolean;
|
||||||
onOpenRow: (rowId: string) => void;
|
onOpenRow: (rowId: string) => void;
|
||||||
onHide: (columnKey: string) => void;
|
onHide: (columnKey: string) => void;
|
||||||
@@ -33,6 +34,7 @@ export function KanbanColumn({
|
|||||||
column,
|
column,
|
||||||
viewFilter,
|
viewFilter,
|
||||||
groupByPropertyId,
|
groupByPropertyId,
|
||||||
|
groupByProperty,
|
||||||
canEdit,
|
canEdit,
|
||||||
onOpenRow,
|
onOpenRow,
|
||||||
onHide,
|
onHide,
|
||||||
@@ -139,6 +141,7 @@ export function KanbanColumn({
|
|||||||
<KanbanColumnHeader
|
<KanbanColumnHeader
|
||||||
column={column}
|
column={column}
|
||||||
pageId={pageId}
|
pageId={pageId}
|
||||||
|
property={groupByProperty}
|
||||||
count={count}
|
count={count}
|
||||||
canEdit={canEdit}
|
canEdit={canEdit}
|
||||||
onHide={() => onHide(column.key)}
|
onHide={() => onHide(column.key)}
|
||||||
|
|||||||
@@ -76,6 +76,21 @@
|
|||||||
cursor: grabbing;
|
cursor: grabbing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.columnTitleButton {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 2px 6px;
|
||||||
|
margin: -2px -6px;
|
||||||
|
border-radius: 6px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.columnTitleButton:hover {
|
||||||
|
background: light-dark(var(--mantine-color-gray-1), var(--mantine-color-dark-5));
|
||||||
|
}
|
||||||
|
|
||||||
.cardList {
|
.cardList {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|||||||
Reference in New Issue
Block a user