From 86ab6f42115370f21ef7138d86fc978581603443 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 10:18:10 +0000 Subject: [PATCH 01/17] feat(kanban): lane header create and menu, a lane-foot statistic and two card toggles Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01QsR2jRKaa4gJCNNF5QMd8t --- ui/packages/i18n/src/locales/ar.ts | 19 ++ ui/packages/i18n/src/locales/de.ts | 19 ++ ui/packages/i18n/src/locales/en.ts | 19 ++ ui/packages/i18n/src/locales/es.ts | 19 ++ ui/packages/i18n/src/locales/fr.ts | 19 ++ ui/packages/i18n/src/locales/ja.ts | 19 ++ ui/packages/i18n/src/locales/ko.ts | 19 ++ ui/packages/i18n/src/locales/pt-BR.ts | 19 ++ ui/packages/i18n/src/locales/ru.ts | 19 ++ ui/packages/i18n/src/locales/zh-Hans.ts | 19 ++ ui/packages/i18n/src/locales/zh-Hant.ts | 19 ++ .../plugin-kanban/src/KanbanCardDisplay.ts | 33 +++ .../plugin-kanban/src/KanbanColumnSummary.ts | 50 +++- ui/packages/plugin-kanban/src/KanbanImpl.tsx | 214 +++++++++++++++++- .../plugin-kanban/src/KanbanLaneMenu.ts | 110 +++++++++ .../src/ObjectKanban.laneMenu-36370.test.tsx | 177 +++++++++++++++ .../ObjectKanban.laneStatistic-36370.test.tsx | 142 ++++++++++++ .../plugin-kanban/src/ObjectKanban.tsx | 114 +++++++++- ui/packages/plugin-kanban/src/index.tsx | 1 + 19 files changed, 1036 insertions(+), 14 deletions(-) create mode 100644 ui/packages/plugin-kanban/src/KanbanCardDisplay.ts create mode 100644 ui/packages/plugin-kanban/src/KanbanLaneMenu.ts create mode 100644 ui/packages/plugin-kanban/src/ObjectKanban.laneMenu-36370.test.tsx create mode 100644 ui/packages/plugin-kanban/src/ObjectKanban.laneStatistic-36370.test.tsx diff --git a/ui/packages/i18n/src/locales/ar.ts b/ui/packages/i18n/src/locales/ar.ts index 960bb5b64d4..46d1b7c0e65 100644 --- a/ui/packages/i18n/src/locales/ar.ts +++ b/ui/packages/i18n/src/locales/ar.ts @@ -1126,6 +1126,15 @@ const ar = { inlineEditLabel: "حرّر السجلات مباشرة (انقر خلية للتحرير)", // The list's Options menu. optionsMenu: { + // objectstack#36370 — a board's own settings. + kanbanLaneField: "الأعمدة حسب", + kanbanLanes: "الأعمدة الظاهرة", + kanbanCardFields: "حقول البطاقة", + kanbanAddCardField: "إضافة حقل", + kanbanShowFieldLabels: "إظهار أسماء الحقول", + kanbanHideEmptyFields: "إخفاء الحقول الفارغة", + kanbanSummary: "ملخص العمود", + kanbanHiddenLanes: "الأعمدة المخفية", viewName: 'اسم العرض', fields: 'الحقول', fieldsShown: 'الحقول المعروضة: {{count}}', @@ -1173,6 +1182,15 @@ const ar = { }, }, kanban: { + // objectstack#36370 — the lane header's 「+」 and 「⋯」 menu, and an empty lane's create row. + laneMenu: { + actions: "إجراءات العمود {{column}}", + collapse: "طي العمود", + expand: "توسيع العمود", + hide: "إخفاء العمود", + createIn: "سجل جديد في {{column}}", + create: "جديد", + }, uncategorized: "غير مصنّف", loadMore: "تحميل المزيد", columns: "أعمدة", @@ -3012,6 +3030,7 @@ const ar = { }, linkFilterRefused: 'لم يُطبَّق عامل التصفية في هذا الرابط، لأنه يذكر حقلًا لا يمكنك التصفية حسبه هنا، لذا تعرض القائمة طريقة العرض دونه.', personalizedParts: { + kanban: "إعدادات اللوحة", filters: "عوامل التصفية", search: "البحث", sort: "الترتيب", diff --git a/ui/packages/i18n/src/locales/de.ts b/ui/packages/i18n/src/locales/de.ts index 705e38b763d..896d6fc674f 100644 --- a/ui/packages/i18n/src/locales/de.ts +++ b/ui/packages/i18n/src/locales/de.ts @@ -1005,6 +1005,15 @@ const de = { inlineEditLabel: "Datensätze inline bearbeiten (Zelle anklicken zum Bearbeiten)", // The list's Options menu. optionsMenu: { + // objectstack#36370 — a board's own settings. + kanbanLaneField: "Spalten nach", + kanbanLanes: "Sichtbare Spalten", + kanbanCardFields: "Kartenfelder", + kanbanAddCardField: "Feld hinzufügen", + kanbanShowFieldLabels: "Feldnamen anzeigen", + kanbanHideEmptyFields: "Leere Felder ausblenden", + kanbanSummary: "Spaltenauswertung", + kanbanHiddenLanes: "Ausgeblendete Spalten", viewName: 'Ansichtsname', fields: 'Felder', fieldsShown: '{{count}} angezeigt', @@ -1048,6 +1057,15 @@ const de = { }, }, kanban: { + // objectstack#36370 — the lane header's 「+」 and 「⋯」 menu, and an empty lane's create row. + laneMenu: { + actions: "Aktionen für Spalte {{column}}", + collapse: "Spalte einklappen", + expand: "Spalte ausklappen", + hide: "Spalte ausblenden", + createIn: "Neuer Datensatz in {{column}}", + create: "Neu", + }, uncategorized: "Nicht kategorisiert", loadMore: "Mehr laden", columns: "Spalten", @@ -2724,6 +2742,7 @@ const de = { }, linkFilterRefused: 'Der Filter dieses Links wurde nicht angewendet. Er nennt ein Feld, nach dem Sie hier nicht filtern können, daher zeigt die Liste die Ansicht ohne ihn.', personalizedParts: { + kanban: "Board-Einstellungen", filters: "Filter", search: "Suche", sort: "Sortierung", diff --git a/ui/packages/i18n/src/locales/en.ts b/ui/packages/i18n/src/locales/en.ts index 8a43689a990..bc662c14c6c 100644 --- a/ui/packages/i18n/src/locales/en.ts +++ b/ui/packages/i18n/src/locales/en.ts @@ -1300,6 +1300,15 @@ const en = { inlineEditLabel: 'Edit records inline (click a cell to edit)', // The list's Options menu. optionsMenu: { + // objectstack#36370 — a board's own settings. + kanbanLaneField: "Columns by", + kanbanLanes: "Visible columns", + kanbanCardFields: "Card fields", + kanbanAddCardField: "Add field", + kanbanShowFieldLabels: "Show field names", + kanbanHideEmptyFields: "Hide empty fields", + kanbanSummary: "Column summary", + kanbanHiddenLanes: "Hidden columns", viewName: 'View name', fields: 'Fields', fieldsShown: '{{count}} shown', @@ -1343,6 +1352,15 @@ const en = { }, }, kanban: { + // objectstack#36370 — the lane header's 「+」 and 「⋯」 menu, and an empty lane's create row. + laneMenu: { + actions: "{{column}} column actions", + collapse: "Collapse column", + expand: "Expand column", + hide: "Hide column", + createIn: "New record in {{column}}", + create: "New", + }, addCard: 'Add card', addColumn: 'Add column', moveCard: 'Move card', @@ -3321,6 +3339,7 @@ const en = { }, linkFilterRefused: 'This link’s filter was not applied. It names a field you can’t filter on here, so the list shows the view without it.', personalizedParts: { + kanban: "Board settings", filters: 'Filters', search: 'Search', sort: 'Sort', diff --git a/ui/packages/i18n/src/locales/es.ts b/ui/packages/i18n/src/locales/es.ts index f24e9816f31..552044dd252 100644 --- a/ui/packages/i18n/src/locales/es.ts +++ b/ui/packages/i18n/src/locales/es.ts @@ -1038,6 +1038,15 @@ const es = { inlineEditLabel: "Editar registros en línea (haga clic en una celda para editar)", // The list's Options menu. optionsMenu: { + // objectstack#36370 — a board's own settings. + kanbanLaneField: "Columnas por", + kanbanLanes: "Columnas visibles", + kanbanCardFields: "Campos de la tarjeta", + kanbanAddCardField: "Añadir campo", + kanbanShowFieldLabels: "Mostrar nombres de campo", + kanbanHideEmptyFields: "Ocultar campos vacíos", + kanbanSummary: "Resumen de columna", + kanbanHiddenLanes: "Columnas ocultas", viewName: 'Nombre de la vista', fields: 'Campos', fieldsShown: 'Visibles: {{count}}', @@ -1082,6 +1091,15 @@ const es = { }, }, kanban: { + // objectstack#36370 — the lane header's 「+」 and 「⋯」 menu, and an empty lane's create row. + laneMenu: { + actions: "Acciones de la columna {{column}}", + collapse: "Contraer columna", + expand: "Expandir columna", + hide: "Ocultar columna", + createIn: "Nuevo registro en {{column}}", + create: "Nuevo", + }, uncategorized: "Sin categoría", loadMore: "Cargar más", columns: "columnas", @@ -2798,6 +2816,7 @@ const es = { }, linkFilterRefused: 'No se aplicó el filtro de este enlace. Incluye un campo por el que no puede filtrar aquí, así que la lista muestra la vista sin él.', personalizedParts: { + kanban: "Ajustes del tablero", filters: "Filtros", search: "Búsqueda", sort: "Ordenación", diff --git a/ui/packages/i18n/src/locales/fr.ts b/ui/packages/i18n/src/locales/fr.ts index 868c80eb488..b6ebf535abb 100644 --- a/ui/packages/i18n/src/locales/fr.ts +++ b/ui/packages/i18n/src/locales/fr.ts @@ -1033,6 +1033,15 @@ const fr = { inlineEditLabel: "Modifier les enregistrements en ligne (cliquez sur une cellule pour modifier)", // The list's Options menu. optionsMenu: { + // objectstack#36370 — a board's own settings. + kanbanLaneField: "Colonnes par", + kanbanLanes: "Colonnes visibles", + kanbanCardFields: "Champs de la carte", + kanbanAddCardField: "Ajouter un champ", + kanbanShowFieldLabels: "Afficher les noms des champs", + kanbanHideEmptyFields: "Masquer les champs vides", + kanbanSummary: "Synthèse de colonne", + kanbanHiddenLanes: "Colonnes masquées", viewName: 'Nom de la vue', fields: 'Champs', fieldsShown: 'Affichés : {{count}}', @@ -1077,6 +1086,15 @@ const fr = { }, }, kanban: { + // objectstack#36370 — the lane header's 「+」 and 「⋯」 menu, and an empty lane's create row. + laneMenu: { + actions: "Actions de la colonne {{column}}", + collapse: "Réduire la colonne", + expand: "Développer la colonne", + hide: "Masquer la colonne", + createIn: "Nouvel enregistrement dans {{column}}", + create: "Nouveau", + }, uncategorized: "Non catégorisé", loadMore: "Charger plus", columns: "colonnes", @@ -2794,6 +2812,7 @@ const fr = { }, linkFilterRefused: 'Le filtre de ce lien n’a pas été appliqué. Il cite un champ sur lequel vous ne pouvez pas filtrer ici, la liste affiche donc la vue sans ce filtre.', personalizedParts: { + kanban: "Réglages du tableau", filters: "Filtres", search: "Recherche", sort: "Tri", diff --git a/ui/packages/i18n/src/locales/ja.ts b/ui/packages/i18n/src/locales/ja.ts index f5fefa091a6..0eeed0b69c8 100644 --- a/ui/packages/i18n/src/locales/ja.ts +++ b/ui/packages/i18n/src/locales/ja.ts @@ -1005,6 +1005,15 @@ const ja = { inlineEditLabel: "レコードをインラインで編集(セルをクリックして編集)", // The list's Options menu. optionsMenu: { + // objectstack#36370 — a board's own settings. + kanbanLaneField: "列の分け方", + kanbanLanes: "表示する列", + kanbanCardFields: "カードの項目", + kanbanAddCardField: "項目を追加", + kanbanShowFieldLabels: "項目名を表示", + kanbanHideEmptyFields: "空の項目を隠す", + kanbanSummary: "列の集計", + kanbanHiddenLanes: "非表示の列", viewName: 'ビュー名', fields: 'フィールド', fieldsShown: '{{count}} 件表示中', @@ -1048,6 +1057,15 @@ const ja = { }, }, kanban: { + // objectstack#36370 — the lane header's 「+」 and 「⋯」 menu, and an empty lane's create row. + laneMenu: { + actions: "{{column}} 列の操作", + collapse: "列を折りたたむ", + expand: "列を展開", + hide: "列を非表示", + createIn: "{{column}} に新規作成", + create: "新規", + }, uncategorized: "未分類", loadMore: "さらに読み込む", columns: "カラム", @@ -2726,6 +2744,7 @@ const ja = { }, linkFilterRefused: 'このリンクのフィルターは適用されませんでした。ここでは絞り込めないフィールドが含まれているため、ビュー本来の内容を表示しています。', personalizedParts: { + kanban: "ボードの設定", filters: "フィルター", search: "検索", sort: "並べ替え", diff --git a/ui/packages/i18n/src/locales/ko.ts b/ui/packages/i18n/src/locales/ko.ts index 5d3500174de..07567b1ef6b 100644 --- a/ui/packages/i18n/src/locales/ko.ts +++ b/ui/packages/i18n/src/locales/ko.ts @@ -1005,6 +1005,15 @@ const ko = { inlineEditLabel: "레코드를 인라인으로 편집(셀을 클릭하여 편집)", // The list's Options menu. optionsMenu: { + // objectstack#36370 — a board's own settings. + kanbanLaneField: "열 기준", + kanbanLanes: "표시할 열", + kanbanCardFields: "카드 필드", + kanbanAddCardField: "필드 추가", + kanbanShowFieldLabels: "필드 이름 표시", + kanbanHideEmptyFields: "빈 필드 숨기기", + kanbanSummary: "열 요약", + kanbanHiddenLanes: "숨긴 열", viewName: '보기 이름', fields: '필드', fieldsShown: '{{count}}개 표시됨', @@ -1048,6 +1057,15 @@ const ko = { }, }, kanban: { + // objectstack#36370 — the lane header's 「+」 and 「⋯」 menu, and an empty lane's create row. + laneMenu: { + actions: "{{column}} 열 작업", + collapse: "열 접기", + expand: "열 펼치기", + hide: "열 숨기기", + createIn: "{{column}}에 새로 만들기", + create: "새로 만들기", + }, uncategorized: "미분류", loadMore: "더 보기", columns: "열", @@ -2724,6 +2742,7 @@ const ko = { }, linkFilterRefused: '이 링크의 필터가 적용되지 않았습니다. 여기서 필터링할 수 없는 필드가 포함되어 있어 뷰를 그대로 표시합니다.', personalizedParts: { + kanban: "보드 설정", filters: "필터", search: "검색", sort: "정렬", diff --git a/ui/packages/i18n/src/locales/pt-BR.ts b/ui/packages/i18n/src/locales/pt-BR.ts index 53dc0b099f4..6d1a007f0c9 100644 --- a/ui/packages/i18n/src/locales/pt-BR.ts +++ b/ui/packages/i18n/src/locales/pt-BR.ts @@ -1033,6 +1033,15 @@ const pt = { inlineEditLabel: "Editar registros em linha (clique em uma célula para editar)", // The list's Options menu. optionsMenu: { + // objectstack#36370 — a board's own settings. + kanbanLaneField: "Colunas por", + kanbanLanes: "Colunas visíveis", + kanbanCardFields: "Campos do cartão", + kanbanAddCardField: "Adicionar campo", + kanbanShowFieldLabels: "Mostrar nomes dos campos", + kanbanHideEmptyFields: "Ocultar campos vazios", + kanbanSummary: "Resumo da coluna", + kanbanHiddenLanes: "Colunas ocultas", viewName: 'Nome da visualização', fields: 'Campos', fieldsShown: 'Exibidos: {{count}}', @@ -1077,6 +1086,15 @@ const pt = { }, }, kanban: { + // objectstack#36370 — the lane header's 「+」 and 「⋯」 menu, and an empty lane's create row. + laneMenu: { + actions: "Ações da coluna {{column}}", + collapse: "Recolher coluna", + expand: "Expandir coluna", + hide: "Ocultar coluna", + createIn: "Novo registro em {{column}}", + create: "Novo", + }, uncategorized: "Sem categoria", loadMore: "Carregar mais", columns: "colunas", @@ -2793,6 +2811,7 @@ const pt = { }, linkFilterRefused: 'O filtro deste link não foi aplicado. Ele cita um campo pelo qual você não pode filtrar aqui, então a lista mostra a visualização sem ele.', personalizedParts: { + kanban: "Configurações do quadro", filters: "Filtros", search: "Pesquisa", sort: "Ordenação", diff --git a/ui/packages/i18n/src/locales/ru.ts b/ui/packages/i18n/src/locales/ru.ts index 8f782fc7386..4f693101a34 100644 --- a/ui/packages/i18n/src/locales/ru.ts +++ b/ui/packages/i18n/src/locales/ru.ts @@ -1067,6 +1067,15 @@ const ru = { inlineEditLabel: "Редактировать записи в таблице (щёлкните ячейку для редактирования)", // The list's Options menu. optionsMenu: { + // objectstack#36370 — a board's own settings. + kanbanLaneField: "Столбцы по", + kanbanLanes: "Видимые столбцы", + kanbanCardFields: "Поля карточки", + kanbanAddCardField: "Добавить поле", + kanbanShowFieldLabels: "Показывать названия полей", + kanbanHideEmptyFields: "Скрывать пустые поля", + kanbanSummary: "Итог по столбцу", + kanbanHiddenLanes: "Скрытые столбцы", viewName: 'Название представления', fields: 'Поля', fieldsShown: 'Показано: {{count}}', @@ -1112,6 +1121,15 @@ const ru = { }, }, kanban: { + // objectstack#36370 — the lane header's 「+」 and 「⋯」 menu, and an empty lane's create row. + laneMenu: { + actions: "Действия со столбцом {{column}}", + collapse: "Свернуть столбец", + expand: "Развернуть столбец", + hide: "Скрыть столбец", + createIn: "Новая запись в {{column}}", + create: "Создать", + }, uncategorized: "Без категории", loadMore: "Загрузить ещё", columns: "колонок", @@ -2874,6 +2892,7 @@ const ru = { }, linkFilterRefused: 'Фильтр из этой ссылки не применён: в нём есть поле, по которому здесь нельзя фильтровать, поэтому список показан по представлению без него.', personalizedParts: { + kanban: "Настройки доски", filters: "Фильтры", search: "Поиск", sort: "Сортировка", diff --git a/ui/packages/i18n/src/locales/zh-Hans.ts b/ui/packages/i18n/src/locales/zh-Hans.ts index 677386b0bbd..ad37632e1f0 100644 --- a/ui/packages/i18n/src/locales/zh-Hans.ts +++ b/ui/packages/i18n/src/locales/zh-Hans.ts @@ -1032,6 +1032,15 @@ const zh = { inlineEditLabel: '行内编辑记录(点击单元格进行编辑)', // The list's Options menu. optionsMenu: { + // objectstack#36370 — a board's own settings. + kanbanLaneField: "分列字段", + kanbanLanes: "显示哪几列", + kanbanCardFields: "卡片上显示的字段", + kanbanAddCardField: "添加字段", + kanbanShowFieldLabels: "显示字段名", + kanbanHideEmptyFields: "隐藏空字段", + kanbanSummary: "列底统计", + kanbanHiddenLanes: "隐藏的列", viewName: '视图名称', fields: '字段', fieldsShown: '已显示 {{count}} 个', @@ -1075,6 +1084,15 @@ const zh = { }, }, kanban: { + // objectstack#36370 — the lane header's 「+」 and 「⋯」 menu, and an empty lane's create row. + laneMenu: { + actions: "{{column}} 列的操作", + collapse: "折叠这一列", + expand: "展开这一列", + hide: "隐藏这一列", + createIn: "在「{{column}}」新建", + create: "新建", + }, addCard: '添加卡片', addColumn: '添加列', moveCard: '移动卡片', @@ -2811,6 +2829,7 @@ const zh = { }, linkFilterRefused: '此链接的筛选条件未应用:其中包含你在此处无法筛选的字段,因此列表按视图本身显示。', personalizedParts: { + kanban: "看板设置", filters: '筛选', search: '搜索', sort: '排序', diff --git a/ui/packages/i18n/src/locales/zh-Hant.ts b/ui/packages/i18n/src/locales/zh-Hant.ts index 9e423c7f593..4271031ecc9 100644 --- a/ui/packages/i18n/src/locales/zh-Hant.ts +++ b/ui/packages/i18n/src/locales/zh-Hant.ts @@ -1032,6 +1032,15 @@ const zhHant = { inlineEditLabel: '行內編輯記錄(點選單元格進行編輯)', // The list's Options menu. optionsMenu: { + // objectstack#36370 — a board's own settings. + kanbanLaneField: "分列欄位", + kanbanLanes: "顯示哪幾列", + kanbanCardFields: "卡片上顯示的欄位", + kanbanAddCardField: "新增欄位", + kanbanShowFieldLabels: "顯示欄位名", + kanbanHideEmptyFields: "隱藏空欄位", + kanbanSummary: "列底統計", + kanbanHiddenLanes: "隱藏的列", viewName: '檢視名稱', fields: '欄位', fieldsShown: '已顯示 {{count}} 個', @@ -1075,6 +1084,15 @@ const zhHant = { }, }, kanban: { + // objectstack#36370 — the lane header's 「+」 and 「⋯」 menu, and an empty lane's create row. + laneMenu: { + actions: "{{column}} 列的操作", + collapse: "摺疊這一列", + expand: "展開這一列", + hide: "隱藏這一列", + createIn: "在「{{column}}」新建", + create: "新建", + }, addCard: '新增卡片', addColumn: '新增列', moveCard: '移動卡片', @@ -2811,6 +2829,7 @@ const zhHant = { }, linkFilterRefused: '此連結的篩選條件未應用:其中包含你在此處無法篩選的欄位,因此列表按檢視本身顯示。', personalizedParts: { + kanban: "看板設定", filters: '篩選', search: '搜尋', sort: '排序', diff --git a/ui/packages/plugin-kanban/src/KanbanCardDisplay.ts b/ui/packages/plugin-kanban/src/KanbanCardDisplay.ts new file mode 100644 index 00000000000..1061ff1c924 --- /dev/null +++ b/ui/packages/plugin-kanban/src/KanbanCardDisplay.ts @@ -0,0 +1,33 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * objectstack#36370 — how a card draws its fields, as the view's kanban block + * says (`kanban.showFieldLabels`): with each field's name beside its value + * (the default, what every board drew before the key), or the values alone. + * + * A package-private channel, as `KanbanColumnSummary` is: `ObjectKanban` + * provides it from the node `ListView` builds, and a board without a provider + * draws the names, as before. (`kanban.hideEmptyFields` needs no channel: + * `ObjectKanban` builds the cards' field rows itself.) + * + * @module + */ + +import { createContext, useContext } from 'react'; + +export interface KanbanCardDisplay { + /** Whether a card names each field beside its value. */ + showFieldLabels: boolean; +} + +export const KanbanCardDisplayContext = createContext({ showFieldLabels: true }); + +export function useKanbanCardDisplay(): KanbanCardDisplay { + return useContext(KanbanCardDisplayContext); +} diff --git a/ui/packages/plugin-kanban/src/KanbanColumnSummary.ts b/ui/packages/plugin-kanban/src/KanbanColumnSummary.ts index 3705aa2bf06..3c901dce4d3 100644 --- a/ui/packages/plugin-kanban/src/KanbanColumnSummary.ts +++ b/ui/packages/plugin-kanban/src/KanbanColumnSummary.ts @@ -36,8 +36,15 @@ import { isEmptyValue } from '@object-ui/core'; * and every board whose node carries no `summarizeField` render the header * exactly as they did before. */ +/** + * objectstack#36370 — the calculations a lane statistic computes on the board: + * the list footer's that read the lane's own cards (`ColumnSummary` in the + * spec), `count` and a number field's `sum`, `avg`, `min` and `max`. + */ +export type KanbanLaneStatisticType = 'count' | 'sum' | 'avg' | 'min' | 'max'; + export interface KanbanColumnSummary { - /** The record field each lane totals — the view's `summarizeField`. */ + /** The record field each lane totals — the view's `summarizeField`. Empty for a count. */ field: string; /** The field's display label: the tooltip and the screen-reader name of the total. */ label: string; @@ -47,6 +54,16 @@ export interface KanbanColumnSummary { * field keeps its declared `scale`. No format code of its own. */ renderTotal: (total: number) => ReactNode; + /** + * objectstack#36370 — what the lane computes (absent ⇒ `sum`, the + * `summarizeField` total) and where it is drawn: `header`, beside the count + * (absent; the `summarizeField` total, as before), or `foot`, under the + * lane's cards (the view's `kanban.summary`). + */ + type?: KanbanLaneStatisticType; + placement?: 'header' | 'foot'; + /** The calculation's name at the foot (「Sum」, 「Count」), beside `label`. */ + typeLabel?: string; } export const KanbanColumnSummaryContext = createContext(null); @@ -102,3 +119,34 @@ export function sumLaneField( } return widest === 0 ? total : Number(total.toFixed(widest)); } + +/** + * objectstack#36370 — a lane's statistic over its cards: the count of cards, + * or `type` over `field`'s values. The values are read as {@link sumLaneField} + * reads them (an empty value is no value; a non-number makes the result + * unknowable, `null`). `avg`, `min` and `max` over a lane with no value are + * `null`: there is nothing to average. + */ +export function laneStatistic( + cards: ReadonlyArray>, + field: string, + type: KanbanLaneStatisticType, +): number | null { + if (type === 'count') return cards.length; + if (type === 'sum') return sumLaneField(cards, field); + const values: number[] = []; + for (const card of cards) { + const raw = card[field]; + if (isEmptyValue(raw)) continue; + const value = typeof raw === 'number' ? raw : typeof raw === 'string' ? Number(raw) : Number.NaN; + if (!Number.isFinite(value)) return null; + values.push(value); + } + if (values.length === 0) return null; + if (type === 'min') return Math.min(...values); + if (type === 'max') return Math.max(...values); + const total = sumLaneField(cards, field); + if (total === null) return null; + const widest = Math.max(...values.map(fractionDigitsOf)); + return Number((total / values.length).toFixed(Math.min(widest + 2, 20))); +} diff --git a/ui/packages/plugin-kanban/src/KanbanImpl.tsx b/ui/packages/plugin-kanban/src/KanbanImpl.tsx index a89170ac2fb..07989060805 100644 --- a/ui/packages/plugin-kanban/src/KanbanImpl.tsx +++ b/ui/packages/plugin-kanban/src/KanbanImpl.tsx @@ -24,16 +24,18 @@ import { verticalListSortingStrategy, } from "@dnd-kit/sortable" import { CSS } from "@dnd-kit/utilities" -import { Avatar, AvatarFallback, AvatarImage, Badge, Card, CardHeader, CardTitle, CardDescription, CardContent, ScrollArea, Button, Input, useResizeObserver, DataEmptyState } from "@object-ui/components" +import { Avatar, AvatarFallback, AvatarImage, Badge, Card, CardHeader, CardTitle, CardDescription, CardContent, ScrollArea, Button, Input, useResizeObserver, DataEmptyState, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@object-ui/components" import { useHasDndProvider, useDnd, usePredicateScope } from "@object-ui/react" import { resolveConditionalFormatting } from "@object-ui/core" import type { KanbanConditionalFormattingRule } from "@object-ui/types" import type { KanbanCard, KanbanColumn } from './types' import { createSafeTranslation } from "@object-ui/i18n" -import { Plus, Sigma } from "lucide-react" +import { EyeOff, FoldHorizontal, MoreHorizontal, Plus, Sigma, UnfoldHorizontal } from "lucide-react" import { useKanbanRecordsSettled } from './KanbanRecordsSettled' -import { useKanbanColumnSummary, sumLaneField } from './KanbanColumnSummary' +import { useKanbanColumnSummary, sumLaneField, laneStatistic } from './KanbanColumnSummary' +import { useKanbanCardDisplay } from './KanbanCardDisplay' import { laneCount, useKanbanLanePaging } from './KanbanLanePaging' +import { readCollapsedLanes, useKanbanLaneMenu, writeCollapsedLanes } from './KanbanLaneMenu' import { ownerInitials, type KanbanCardOwner } from './KanbanCardOwner' import { createKanbanDndAnnouncer } from './kanbanDndAnnouncements' @@ -75,6 +77,14 @@ const useKanbanT = createSafeTranslation( // Why a lane refuses the dragged card (#27099), when the board's // `dropBlockedReason` gives no sentence of its own. 'kanban.dropBlocked': 'A card in {{from}} cannot be moved to {{to}}.', + // objectstack#36370 — the lane header's 「+」 and 「⋯」 menu, and the empty + // lane's create row, when the host asks for them (`KanbanLaneMenu.ts`). + 'kanban.laneMenu.actions': '{{column}} column actions', + 'kanban.laneMenu.collapse': 'Collapse column', + 'kanban.laneMenu.expand': 'Expand column', + 'kanban.laneMenu.hide': 'Hide column', + 'kanban.laneMenu.createIn': 'New record in {{column}}', + 'kanban.laneMenu.create': 'New', }, 'kanban.noCards', ) @@ -328,6 +338,8 @@ function SortableCard({ card, onCardClick, conditionalFormatting, objectFields } // `aria-disabled` (objectui#12082). const movable = React.useContext(KanbanCardsMovable) const opens = React.useContext(KanbanCardsOpenRecord) + // objectstack#36370 — `kanban.showFieldLabels: false` draws the values alone. + const { showFieldLabels } = useKanbanCardDisplay() // A card that neither drags nor opens (objectstack#33548) is no control: no // `button` role, no tab stop, no key activation and no hover-as-link face. // Its click still reaches `onCardClick`, which the host routes to nothing. @@ -449,7 +461,7 @@ function SortableCard({ card, onCardClick, conditionalFormatting, objectFields } className="flex min-w-0 items-baseline gap-1.5 text-foreground/85" title={cell.label || cell.field} > -
{cell.label || cell.field}
+ {showFieldLabels &&
{cell.label || cell.field}
}
{cell.node}
))} @@ -749,7 +761,8 @@ function LaneTotal({ className?: string }) { const summary = useKanbanColumnSummary() - if (!summary) return null + // objectstack#36370 — the view's lane statistic is drawn at the foot. + if (!summary || summary.placement === 'foot') return null const total = sumLaneField(cards, summary.field) if (total === null) return null return ( @@ -766,6 +779,143 @@ function LaneTotal({ ) } +/** + * objectstack#36370 — the view's lane statistic (`kanban.summary`), at the + * lane's foot: its calculation's name and its figure, 「Sum · Amount + * ¥1,200」. A count over a lane the board pages for itself is the server's + * count of the lane; every other figure covers the cards the lane holds and, + * over a lane that holds more than it drew, carries the windowed `+`. Renders + * nothing without the statistic, or while the figure is unknowable. + */ +function LaneFootStatistic({ + cards, + count, + partial, +}: { + cards: KanbanCard[] + /** The lane's count as its header writes it, for a `count`. */ + count: { count: number; atLeast: boolean } + partial: boolean +}) { + const summary = useKanbanColumnSummary() + if (!summary || summary.placement !== 'foot' || !summary.type) return null + const isCount = summary.type === 'count' + const value = isCount ? count.count : laneStatistic(cards, summary.field, summary.type) + if (value === null) return null + const name = isCount ? summary.typeLabel : `${summary.typeLabel} · ${summary.label}` + return ( +
+ {name} + + {summary.renderTotal(value)} + {(isCount ? count.atLeast : partial) ? '+' : null} + +
+ ) +} + +/** + * objectstack#36370 — the lane header's 「+」 and 「⋯」, drawn only where the + * host asked for the lane menu (`KanbanLaneMenu.ts`). 「+」 opens the host's + * create form with this lane's value filled in; 「⋯」 collapses the lane (the + * reader's own, in this browser) or hides it (the view's lanes, in the list's + * draft). The `Uncategorized` lane has no value to fill in or to hide, so it + * offers the collapse alone. + */ +function LaneHeaderActions({ + column, + collapsed, + onToggleCollapse, +}: { + column: KanbanColumn + collapsed: boolean + onToggleCollapse?: () => void +}) { + const { t } = useKanbanT() + const laneMenu = useKanbanLaneMenu() + if (!laneMenu) return null + const laneId = String(column.id) + const takesActions = laneMenu.laneTakesActions(laneId) + const create = takesActions ? laneMenu.onCreateInLane : undefined + const hide = takesActions ? laneMenu.onHideLane : undefined + return ( +
+ {create && ( + + )} + + + + + + {onToggleCollapse && ( + onToggleCollapse()} data-kanban-lane-menu-collapse=""> + {collapsed + ? + )} + {hide && ( + hide(laneId)} data-kanban-lane-menu-hide=""> + + )} + + +
+ ) +} + +/** + * objectstack#36370 — the 「+ New」 row of an empty lane, under the same + * conditions as the header's 「+」. + */ +function LaneCreateRow({ column }: { column: KanbanColumn }) { + const { t } = useKanbanT() + const laneMenu = useKanbanLaneMenu() + const laneId = String(column.id) + const create = laneMenu && laneMenu.laneTakesActions(laneId) ? laneMenu.onCreateInLane : undefined + if (!create) return null + return ( + + ) +} + function KanbanColumnView({ column, cards, @@ -902,7 +1052,11 @@ function KanbanColumnView({ onToggleCollapse?.()} /> @@ -925,6 +1079,7 @@ function KanbanColumnView({ )} {/* A total over cards that have not arrived is the same false `0`. */} {!isCollapsed && !countPending && } + {!isCollapsed && } @@ -961,6 +1116,7 @@ function KanbanColumnView({ ))} + {safeCards.length === 0 && !countPending && } {/* objectui#12619 — the next page of this lane, at its foot. */} {lanePaging && lanePage?.hasMore && ( )) : null; + // objectstack#36370 — a board's own settings for 视图设置 and its lanes' + // 「⋯」 and 「+」: what the view's kanban block holds now (the host lays the + // list's draft over it), and the whole next block a change writes. Plain + // per-render values, not memos (AGENTS.md #10). + const kanbanBlock = currentView === 'kanban' ? kanbanBlockOf(schema) : undefined; + const boardLaneField = kanbanBlock ? kanbanLaneFieldOf(schema, objectDef) : undefined; + const writeKanban = kanbanBlock && onKanbanChange + ? (patch: Record) => { + // `undefined` here is "the block without this key": `null` on the wire. + onKanbanChange!(Object.fromEntries(Object.entries(patch).map(([key, value]) => [key, value === undefined ? null : value]))); + } + : undefined; + const boardLaneDef = boardLaneField + ? (objectDef?.fields as Record | undefined)?.[boardLaneField] + : undefined; + // The lanes the lane field offers: its options, in their own order, under + // the labels the board draws. A field with no options (a person, a linked + // record) has its lanes from the data, and the panel lists none. + const boardLaneOptions: Array<{ value: string; label: string }> = (() => { + const raw = Array.isArray(boardLaneDef?.options) ? (boardLaneDef!.options as unknown[]) : []; + const translated = schema.objectName && boardLaneField ? translateOptions(schema.objectName, boardLaneField, raw as any[]) : raw; + return (translated as Array<{ value?: unknown; label?: unknown } | string>).flatMap((option) => { + const value = typeof option === 'string' ? option : option?.value; + if (typeof value !== 'string' || value === '') return []; + const label = typeof option === 'object' && typeof option?.label === 'string' && option.label ? option.label : value; + return [{ value, label }]; + }); + })(); + const boardShownLanes: string[] = Array.isArray(kanbanBlock?.lanes) && kanbanBlock!.lanes.length > 0 + ? (kanbanBlock!.lanes as unknown[]).filter((v): v is string => typeof v === 'string') + : boardLaneOptions.map((o) => o.value); + // `lanes` is written only while it differs from every option in its own + // order: the view with no `lanes` draws exactly that. + const writeShownLanes = writeKanban + ? (lanes: string[]) => { + if (lanes.length === 0) return; + const all = boardLaneOptions.map((o) => o.value); + writeKanban({ lanes: lanes.length === all.length && lanes.every((v, i) => v === all[i]) ? undefined : lanes }); + } + : undefined; + const boardCardFields: string[] = Array.isArray(kanbanBlock?.columns) && kanbanBlock!.columns.length > 0 + ? (kanbanBlock!.columns as unknown[]).filter((v): v is string => typeof v === 'string') + : kanbanBlock + ? kanbanCardFieldsFromView(effectiveFields, [ + kanbanBlock.titleField, + resolveNameField(objectDef), + boardLaneField, + kanbanOwnerFieldOf(objectDef), + ]) + : []; + // The fields a card may show: the object's fields the caller may read and + // the definition does not hide, business ones first, then the system ones. + const boardCardFieldCandidates: ViewSettingsField[] = (() => { + if (!kanbanBlock) return []; + const defs = objectDef?.fields as Record | undefined; + if (!defs) return boardCardFields.map((name) => ({ name, label: tFieldLabel(name, name) })); + const candidates = Object.entries(defs).filter(([name]) => + !isDeclaredHidden(defs, name) && canReadField(perms, schema.objectName, name)); + const out: ViewSettingsField[] = []; + for (const tier of [false, true]) { + for (const [name, def] of candidates) { + if (isSystemManagedField(name, def) !== tier) continue; + out.push({ name, label: tFieldLabel(name, def?.label || name) }); + } + } + return out; + })(); + // The lane statistic the board draws: the view's `summary`, else the sum + // of its `summarizeField` (objectui#11629), else none. + const boardLaneStatistic: { type: string; field?: string } | null = (() => { + const own = kanbanBlock?.summary as { type?: unknown; field?: unknown } | undefined; + if (own && typeof own.type === 'string') { + return own.type === 'none' ? null : { type: own.type, ...(typeof own.field === 'string' ? { field: own.field } : {}) }; + } + return typeof kanbanBlock?.summarizeField === 'string' && kanbanBlock.summarizeField + ? { type: 'sum', field: kanbanBlock.summarizeField } + : null; + })(); + // The fields a lane may total or average: the object's number fields the + // caller may read. + const boardNumberFields: Array<{ value: string; label: string }> = kanbanBlock + ? Object.entries((objectDef?.fields ?? {}) as Record) + .filter(([name, def]) => + !!def && LANE_STATISTIC_FIELD_TYPES.has(String(def.type)) && def.hidden !== true + && canReadField(perms, schema.objectName, name)) + .map(([name, def]) => ({ value: name, label: tFieldLabel(name, def?.label || name) })) + : []; + const kanbanSettings: ViewSettingsKanban | undefined = kanbanBlock + ? { + laneField: boardLaneField, + laneFieldOptions: groupOptions, + // A new lane field draws every lane it offers: the lanes chosen on the + // old field name none of its values. + onLaneFieldChange: writeKanban ? (field) => writeKanban({ groupByField: field, lanes: undefined }) : undefined, + lanes: boardLaneOptions, + shownLanes: boardShownLanes, + onShownLanesChange: writeShownLanes, + cardFields: boardCardFields, + cardFieldCandidates: boardCardFieldCandidates, + onCardFieldsChange: writeKanban ? (fields) => writeKanban({ columns: fields }) : undefined, + // Both default to on: what every board drew before the keys. Turning + // one back on writes no key (the view's absence is "on"). + ...(writeKanban + ? { + showFieldLabels: { + value: kanbanBlock.showFieldLabels !== false, + onChange: (next: boolean) => writeKanban({ showFieldLabels: next ? undefined : false }), + }, + hideEmptyFields: { + value: kanbanBlock.hideEmptyFields !== false, + onChange: (next: boolean) => writeKanban({ hideEmptyFields: next ? undefined : false }), + }, + } + : {}), + summary: writeKanban + ? { + value: boardLaneStatistic, + numberFields: boardNumberFields, + // 「None」 over a view that sums `summarizeField` says so + // (`{ type: 'none' }`); over one that shows nothing, the key goes. + onChange: (next) => writeKanban({ + summary: next ?? (kanbanBlock.summarizeField ? { type: 'none' } : undefined), + }), + } + : undefined, + } + : undefined; + // The lane header's 「⋯」 and 「+」 (objectstack#36370, `KanbanLaneMenu.ts` in + // plugin-kanban): hiding a lane is unticking it here; 「+」 opens the host's + // create form on a new record carrying the lane's value, as the calendar's + // empty-day hand-off does (`onEdit` with a record that has no id). + const boardLaneValue = (laneId: string): unknown => { + const type = typeof boardLaneDef?.type === 'string' ? boardLaneDef.type : undefined; + if (type === 'boolean' || type === 'toggle') return laneId === 'true' ? true : laneId === 'false' ? false : laneId; + return laneId; + }; + const boardLaneMenu = kanbanBlock + ? { + collapseKey: schema.objectName ? `${schema.objectName}:${schema.id ?? ''}` : undefined, + onHideLane: writeShownLanes && boardLaneOptions.length > 0 + ? (laneId: string) => { + if (!boardShownLanes.includes(laneId) || boardShownLanes.length <= 1) return; + writeShownLanes(boardShownLanes.filter((v) => v !== laneId)); + } + : undefined, + onCreateInLane: props.onAddRecord && props.onEdit && boardLaneField + ? (laneId: string) => props.onEdit!({ [boardLaneField]: boardLaneValue(laneId) }) + : undefined, + } + : undefined; + // 视图设置's props, once: the desktop draws them as the popover beside the // view's name, the phone as the content of its bottom sheet // (objectstack#35883: a row of the view panel opens it there). @@ -7285,6 +7459,7 @@ export const ListView = React.forwardRef(({ { const type = (objectDef?.fields as Record | undefined)?.[name]?.type; return typeof type === 'string' ? type : undefined; @@ -8471,6 +8646,11 @@ export const ListView = React.forwardRef(({ // the board's host channel (a React prop, never a node key). ? { onRowGroupsChange: handleBoardRowGroups } : {})} + {...(viewComponentSchema.type === 'object-kanban' && boardLaneMenu + // objectstack#36370 — the lane header's 「⋯」 and 「+」, on the + // board's host channel (a React prop, never a node key). + ? { laneMenu: boardLaneMenu } + : {})} {...(viewComponentSchema.type === 'object-grid' && rowAdornment // objectui#13330 — the host's node beside each row's title, on // the grid's host channel (a React prop, never a node key). diff --git a/ui/packages/plugin-list/src/__tests__/ViewSettingsPopover.kanban-36370.test.tsx b/ui/packages/plugin-list/src/__tests__/ViewSettingsPopover.kanban-36370.test.tsx new file mode 100644 index 00000000000..2b09ce4488d --- /dev/null +++ b/ui/packages/plugin-list/src/__tests__/ViewSettingsPopover.kanban-36370.test.tsx @@ -0,0 +1,180 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * objectstack#36370 — 视图设置 on a board: the board's own settings in place + * of the table's. + * + * Pinned here: + * - the first level shows the lane field, 「5 / 7」 shown lanes, the card + * fields in place, the two card toggles and the lane statistic, and none + * of the table's 「Shown columns」, Group, Row height or Row colour; + * - the lane field level lists the fields offered and writes a pick; + * - the lanes level hides a lane, shows a hidden one at the end, and keeps + * the last lane (no eye on it); + * - the card fields hide in place, and 「+ Add field」 adds one at the end; + * - each toggle writes its next value; the statistic level writes the pick + * (`null` for None); + * - the zh pack names every row. + */ +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { render, screen, fireEvent, cleanup } from '@testing-library/react'; +import { I18nProvider, useObjectTranslation } from '@object-ui/i18n'; +import { + ViewSettingsPopover, + type ViewSettingsKanban, + type ViewSettingsPopoverProps, +} from '../components/ViewSettingsPopover'; + +afterEach(cleanup); + +const FIELDS = [ + { name: 'name', label: 'Name' }, + { name: 'stage', label: 'Stage' }, +]; + +function kanbanOf(overrides: Partial = {}): ViewSettingsKanban { + return { + laneField: 'stage', + laneFieldOptions: [{ value: 'stage', label: 'Stage' }, { value: 'owner', label: 'Owner' }], + onLaneFieldChange: vi.fn(), + lanes: [ + { value: 'new', label: 'New' }, + { value: 'proposal', label: 'Proposal' }, + { value: 'won', label: 'Won' }, + ], + shownLanes: ['new', 'proposal'], + onShownLanesChange: vi.fn(), + cardFields: ['amount', 'account'], + cardFieldCandidates: [ + { name: 'amount', label: 'Amount' }, + { name: 'account', label: 'Account' }, + { name: 'close_date', label: 'Close date' }, + ], + onCardFieldsChange: vi.fn(), + showFieldLabels: { value: true, onChange: vi.fn() }, + hideEmptyFields: { value: true, onChange: vi.fn() }, + summary: { + value: { type: 'sum', field: 'amount' }, + numberFields: [{ value: 'amount', label: 'Amount' }], + onChange: vi.fn(), + }, + ...overrides, + }; +} + +type Overrides = Partial>; + +function Harness(props: Overrides) { + const { t } = useObjectTranslation(); + return ( + string} + allFields={FIELDS} + showHideFields + hiddenFields={new Set()} + updateHiddenFields={() => {}} + showGroup + setGroupingConfig={() => {}} + showDensity + density={{ mode: 'comfortable', cycle: () => {}, setMode: () => {} }} + showColor + setRowColorConfig={() => {}} + {...props} + /> + ); +} + +function openMenu(props: Overrides, language = 'en') { + const view = render( + + + , + ); + fireEvent.click(screen.getByTestId('toolbar-display-trigger')); + return view; +} + +const value = (testId: string) => screen.getByTestId(`${testId}-value`).textContent; + +describe('视图设置 on a board (objectstack#36370)', () => { + it('shows the board settings and none of the table ones', () => { + openMenu({ kanban: kanbanOf() }); + expect(value('options-row-lane-field')).toBe('Stage'); + expect(value('options-row-lanes')).toBe('2 / 3'); + expect(screen.getByTestId('options-card-fields-list-row-amount')).toBeTruthy(); + expect(screen.getByTestId('options-toggle-field-labels')).toBeTruthy(); + expect(screen.getByTestId('options-toggle-hide-empty')).toBeTruthy(); + expect(value('options-row-lane-summary')).toBe('Sum · Amount'); + for (const gone of ['options-columns', 'options-row-group', 'options-row-row-height', 'options-row-color']) { + expect(screen.queryByTestId(gone)).toBeNull(); + } + }); + + it('picks another lane field', () => { + const kanban = kanbanOf(); + openMenu({ kanban }); + fireEvent.click(screen.getByTestId('options-row-lane-field')); + fireEvent.click(screen.getByTestId('options-lane-field-owner')); + expect(kanban.onLaneFieldChange).toHaveBeenCalledWith('owner'); + }); + + it('hides a lane, shows a hidden one at the end, and keeps the last lane', () => { + const kanban = kanbanOf(); + openMenu({ kanban }); + fireEvent.click(screen.getByTestId('options-row-lanes')); + // Lanes are no fields: their own heading over the hidden ones, no type icon. + expect(screen.getByTestId('options-page-lanes').textContent).toContain('Hidden columns'); + expect(screen.queryByTestId('options-lanes-icon')).toBeNull(); + fireEvent.click(screen.getByTestId('options-lanes-hide-new')); + expect(kanban.onShownLanesChange).toHaveBeenLastCalledWith(['proposal']); + fireEvent.click(screen.getByTestId('options-lanes-item-won')); + expect(kanban.onShownLanesChange).toHaveBeenLastCalledWith(['new', 'proposal', 'won']); + cleanup(); + + openMenu({ kanban: kanbanOf({ shownLanes: ['won'] }) }); + fireEvent.click(screen.getByTestId('options-row-lanes')); + expect(screen.queryByTestId('options-lanes-hide-won')).toBeNull(); + }); + + it('hides a card field in place and adds one at the end', () => { + const kanban = kanbanOf(); + openMenu({ kanban }); + fireEvent.click(screen.getByTestId('options-card-fields-list-hide-amount')); + expect(kanban.onCardFieldsChange).toHaveBeenLastCalledWith(['account']); + fireEvent.click(screen.getByTestId('options-add-card-field')); + fireEvent.click(screen.getByTestId('options-card-field-candidates-item-close_date')); + expect(kanban.onCardFieldsChange).toHaveBeenLastCalledWith(['amount', 'account', 'close_date']); + }); + + it('writes each toggle and the statistic', () => { + const kanban = kanbanOf(); + openMenu({ kanban }); + fireEvent.click(screen.getByTestId('options-toggle-field-labels-switch')); + expect(kanban.showFieldLabels!.onChange).toHaveBeenCalledWith(false); + fireEvent.click(screen.getByTestId('options-toggle-hide-empty-switch')); + expect(kanban.hideEmptyFields!.onChange).toHaveBeenCalledWith(false); + fireEvent.click(screen.getByTestId('options-row-lane-summary')); + fireEvent.click(screen.getByTestId('options-lane-summary-count')); + expect(kanban.summary!.onChange).toHaveBeenLastCalledWith({ type: 'count' }); + fireEvent.click(screen.getByTestId('options-row-lane-summary')); + fireEvent.click(screen.getByTestId('options-lane-summary-avg:amount')); + expect(kanban.summary!.onChange).toHaveBeenLastCalledWith({ type: 'avg', field: 'amount' }); + fireEvent.click(screen.getByTestId('options-row-lane-summary')); + fireEvent.click(screen.getByTestId('options-lane-summary-none')); + expect(kanban.summary!.onChange).toHaveBeenLastCalledWith(null); + }); + + it('names every board row in the zh pack', () => { + openMenu({ kanban: kanbanOf() }, 'zh'); + const text = screen.getByTestId('options-menu').textContent ?? ''; + for (const words of ['分列字段', '显示哪几列', '卡片上显示的字段', '添加字段', '显示字段名', '隐藏空字段', '列底统计']) { + expect(text).toContain(words); + } + }); +}); diff --git a/ui/packages/plugin-list/src/components/ViewSettingsPopover.tsx b/ui/packages/plugin-list/src/components/ViewSettingsPopover.tsx index 1fa63db96c7..1bc050e0bc0 100644 --- a/ui/packages/plugin-list/src/components/ViewSettingsPopover.tsx +++ b/ui/packages/plugin-list/src/components/ViewSettingsPopover.tsx @@ -37,6 +37,7 @@ import { SelectItem, SelectTrigger, SelectValue, + Switch, } from '@object-ui/components'; import { SlidersHorizontal, @@ -172,10 +173,66 @@ export interface ViewSettingsViewName { onRename?: (next: string) => boolean | Promise; } +/** One on/off setting of the panel: its value, and the writer of a change. */ +export interface ViewSettingsToggle { + value: boolean; + onChange: (next: boolean) => void; +} + +/** + * objectstack#36370 — a lane statistic as the board's `kanban.summary` holds + * it: one of the list footer's calculations (`ColumnSummary`), over `field` + * where the calculation reads one. `null` = none. + */ +export interface ViewSettingsKanbanSummaryValue { + type: string; + field?: string; +} + +/** + * objectstack#36370 — the board's own settings, which the panel shows IN + * PLACE OF the table's columns, grouping, row height and row colour while the + * view is a kanban. Every part is the view's (the host holds a change in the + * list's draft); the panel writes nothing itself. A part whose writer is + * absent is shown and not changed; a part that is absent is not shown. + */ +export interface ViewSettingsKanban { + /** The field the lanes come from, and the fields that may be it (objectstack#36204's range). */ + laneField?: string; + laneFieldOptions: ReadonlyArray<{ value: string; label: string }>; + onLaneFieldChange?: (field: string) => void; + /** Every lane the lane field offers, in its own order. */ + lanes: ReadonlyArray<{ value: string; label: string }>; + /** The lanes the board draws, in board order. */ + shownLanes: readonly string[]; + onShownLanesChange?: (lanes: string[]) => void; + /** The fields each card shows, in order, and the fields that may be added. */ + cardFields: readonly string[]; + cardFieldCandidates: readonly ViewSettingsField[]; + onCardFieldsChange?: (fields: string[]) => void; + /** Whether a card names each field beside its value. */ + showFieldLabels?: ViewSettingsToggle; + /** Whether a card leaves out a field that holds nothing. */ + hideEmptyFields?: ViewSettingsToggle; + /** The statistic each lane shows at its foot: none, a count, or a number field's sum or average. */ + summary?: { + value: ViewSettingsKanbanSummaryValue | null; + numberFields: ReadonlyArray<{ value: string; label: string }>; + onChange: (next: ViewSettingsKanbanSummaryValue | null) => void; + }; +} + export interface ViewSettingsPopoverProps { t: (key: string, opts?: any) => string; allFields: ViewSettingsField[]; + /** + * objectstack#36370 — the board's own settings. Present ⇒ the panel shows + * them instead of the table's 「Shown columns」, Group, Row height and Row + * colour; Layout, the name and the footer stay. + */ + kanban?: ViewSettingsKanban; + /** The view's name, at the top of the menu. Absent ⇒ no name row. */ viewName?: ViewSettingsViewName; @@ -276,7 +333,10 @@ export interface ViewSettingsPopoverProps { } /** The second levels of the menu; `root` is the menu itself. */ -type MenuPage = 'root' | 'layout' | 'fields' | 'group' | 'color' | 'rowHeight'; +type MenuPage = + | 'root' | 'layout' | 'fields' | 'group' | 'color' | 'rowHeight' + // objectstack#36370 — a board's second levels. + | 'laneField' | 'lanes' | 'cardFields' | 'laneSummary'; /** * One row of the menu: the setting's name on the left, its current value on @@ -579,6 +639,7 @@ export function ViewSettingsContent(props: ViewSettingsPopoverProps & { closeMen onExport, exportBusy, exportError, + kanban, } = props; // The panel opens on its first level every time: the content unmounts @@ -599,7 +660,7 @@ export function ViewSettingsContent(props: ViewSettingsPopoverProps & { closeMen const DensityIcon = density?.mode === 'compact' ? Rows4 : density?.mode === 'comfortable' ? Rows3 : Rows2; - const titles: Record, string> = { + const titles: Record<'layout' | 'fields' | 'group' | 'color' | 'rowHeight', string> = { layout: t('list.layout', { defaultValue: 'Layout' }), fields: t('list.optionsMenu.addColumn', { defaultValue: 'Add column' }), group: t('list.group', { defaultValue: 'Group' }), @@ -619,7 +680,163 @@ export function ViewSettingsContent(props: ViewSettingsPopoverProps & { closeMen ? orderFields(allFields, fieldOrder).filter((f) => !hiddenFields!.has(f.name)) : []; - const rootMenu = ( + // objectstack#36370 — a board's first level: its lane field, the lanes it + // shows, the card fields in place (drag to reorder, the eye to hide) with + // 「+ Add field」 one step away, the card toggles and the lane statistic. + // The table's columns, Group, Row height and Row colour are not offered. + const kanbanTitles = { + laneField: t('list.optionsMenu.kanbanLaneField', { defaultValue: 'Columns by' }), + lanes: t('list.optionsMenu.kanbanLanes', { defaultValue: 'Visible columns' }), + cardFields: t('list.optionsMenu.kanbanCardFields', { defaultValue: 'Card fields' }), + addCardField: t('list.optionsMenu.kanbanAddCardField', { defaultValue: 'Add field' }), + showFieldLabels: t('list.optionsMenu.kanbanShowFieldLabels', { defaultValue: 'Show field names' }), + hideEmptyFields: t('list.optionsMenu.kanbanHideEmptyFields', { defaultValue: 'Hide empty fields' }), + summary: t('list.optionsMenu.kanbanSummary', { defaultValue: 'Column summary' }), + }; + const kanbanFieldLabel = (name: string) => + kanban?.cardFieldCandidates.find((f) => f.name === name)?.label || fieldLabel(name); + const summaryWord = (type: string) => + type === 'count' + ? t('grid.summary.count', { defaultValue: 'Count' }) + : type === 'sum' + ? t('grid.summary.sum', { defaultValue: 'Sum' }) + : type === 'avg' + ? t('grid.summary.avg', { defaultValue: 'Avg' }) + : type; + const summaryText = (value: ViewSettingsKanbanSummaryValue | null): string => { + if (!value || value.type === 'none') return none; + if (!value.field || value.type === 'count') return summaryWord(value.type); + const label = kanban?.summary?.numberFields.find((f) => f.value === value.field)?.label || kanbanFieldLabel(value.field); + return `${summaryWord(value.type)} · ${label}`; + }; + const toggleRow = (label: string, toggle: ViewSettingsToggle, testId: string) => ( + + ); + const kanbanRootMenu = kanban ? ( +
+ {viewName && } +
+ o.value === kanban.laneField)?.label || fieldLabel(kanban.laneField) + : none} + onOpen={() => setPage('laneField')} + testId="options-row-lane-field" + /> + {kanban.lanes.length > 0 && ( + setPage('lanes')} + testId="options-row-lanes" + /> + )} +
+
+

{kanbanTitles.cardFields}

+ ({ value: name, label: kanbanFieldLabel(name), type: fieldType?.(name) }))} + shownFields={kanban.cardFields} + order={kanban.cardFields} + onOrderChange={kanban.onCardFieldsChange + ? (order) => kanban.onCardFieldsChange!(order.filter((name) => kanban.cardFields.includes(name))) + : undefined} + onHide={kanban.onCardFieldsChange + ? (name) => kanban.onCardFieldsChange!(kanban.cardFields.filter((n) => n !== name)) + : undefined} + searchable={false} + testId="options-card-fields-list" + className="w-full" + /> + {kanban.onCardFieldsChange && ( + + )} +
+ {(kanban.showFieldLabels || kanban.hideEmptyFields) && ( +
+ {kanban.showFieldLabels && toggleRow(kanbanTitles.showFieldLabels, kanban.showFieldLabels, 'options-toggle-field-labels')} + {kanban.hideEmptyFields && toggleRow(kanbanTitles.hideEmptyFields, kanban.hideEmptyFields, 'options-toggle-hide-empty')} +
+ )} +
+ {layout && ( + {layout(closeMenu)}} + onOpen={() => setPage('layout')} + testId="options-row-layout" + /> + )} + {kanban.summary && ( + setPage('laneSummary')} + testId="options-row-lane-summary" + /> + )} +
+
+ ) : null; + + /** A one-of-many level: each option a radio row, the current one ticked. */ + const radioLevel = ( + label: string, + options: ReadonlyArray<{ value: string; label: string }>, + current: string | undefined, + onPick: (value: string) => void, + testId: string, + ) => ( +
+ {options.map((option) => { + const active = option.value === current; + return ( + + ); + })} +
+ ); + + const rootMenu = kanbanRootMenu ?? (
{viewName && } {fieldsOffered && ( @@ -707,7 +924,100 @@ export function ViewSettingsContent(props: ViewSettingsPopoverProps & { closeMen ); let body: React.ReactNode = rootMenu; - if (page === 'layout' && layout) { + if (kanban && page === 'laneField') { + body = ( + + {kanban.laneFieldOptions.length > 0 + ? radioLevel(kanbanTitles.laneField, kanban.laneFieldOptions, kanban.laneField, (field) => { + if (field !== kanban.laneField) kanban.onLaneFieldChange?.(field); + back(); + }, 'options-lane-field') + : ( +

+ {t('list.noGroupableFields', { defaultValue: 'No field here can group the list' })} +

+ )} +
+ ); + } else if (kanban && page === 'lanes') { + const shown = kanban.shownLanes; + const write = kanban.onShownLanesChange; + body = ( + write([...shown, ...kanban.lanes.map((l) => l.value).filter((v) => !shown.includes(v))])} + data-testid="options-lanes-show-all" + > + {t('list.showAll', { defaultValue: 'Show all' })} + + ) + : undefined} + > + ({ value: lane.value, label: lane.label }))} + shownFields={shown} + order={shown} + onOrderChange={write ? (order) => write(order.filter((v) => shown.includes(v))) : undefined} + // The board keeps at least one lane: the last one shown has no eye. + onHide={write && shown.length > 1 ? (value) => write(shown.filter((v) => v !== value)) : undefined} + onShow={write ? (value) => write([...shown.filter((v) => v !== value), value]) : undefined} + searchable={kanban.lanes.length > 8} + hiddenTitle={t('list.optionsMenu.kanbanHiddenLanes', { defaultValue: 'Hidden columns' })} + typeIcons={false} + testId="options-lanes" + className="w-full" + /> + + ); + } else if (kanban && page === 'cardFields' && kanban.onCardFieldsChange) { + const write = kanban.onCardFieldsChange; + const shown = kanban.cardFields; + body = ( + + ({ value: f.name, label: f.label || f.name, type: fieldType?.(f.name) }))} + shownFields={shown} + order={shown} + onOrderChange={(order) => write(order.filter((name) => shown.includes(name)))} + onHide={(name) => write(shown.filter((n) => n !== name))} + onShow={(name) => write([...shown.filter((n) => n !== name), name])} + testId="options-card-field-candidates" + className="w-full" + /> + + ); + } else if (kanban?.summary && page === 'laneSummary') { + const summary = kanban.summary; + const options: Array<{ value: string; label: string; pick: ViewSettingsKanbanSummaryValue | null }> = [ + { value: 'none', label: none, pick: null }, + { value: 'count', label: summaryWord('count'), pick: { type: 'count' } }, + ...summary.numberFields.flatMap((f) => (['sum', 'avg'] as const).map((type) => ({ + value: `${type}:${f.value}`, + label: `${summaryWord(type)} · ${f.label}`, + pick: { type, field: f.value }, + }))), + ]; + const current = !summary.value || summary.value.type === 'none' + ? 'none' + : summary.value.type === 'count' ? 'count' : `${summary.value.type}:${summary.value.field ?? ''}`; + body = ( + + {radioLevel(kanbanTitles.summary, options, current, (value) => { + const picked = options.find((o) => o.value === value); + if (picked && value !== current) summary.onChange(picked.pick); + back(); + }, 'options-lane-summary')} + + ); + } else if (page === 'layout' && layout) { body = ( {layout(closeMenu)} diff --git a/ui/packages/plugin-list/src/conditions/FieldList.tsx b/ui/packages/plugin-list/src/conditions/FieldList.tsx index 7ba19c00314..17f42b467ed 100644 --- a/ui/packages/plugin-list/src/conditions/FieldList.tsx +++ b/ui/packages/plugin-list/src/conditions/FieldList.tsx @@ -103,6 +103,12 @@ export interface FieldListProps { testId?: string; className?: string; autoFocus?: boolean; + /** + * objectstack#36370 — a list of things that are not fields (a board's + * lanes): its own heading over the hidden rows, and no field-type icon. + */ + hiddenTitle?: string; + typeIcons?: boolean; } const TYPE_ICONS: Readonly> = { @@ -213,6 +219,8 @@ export function FieldList({ testId = 'field-list', className, autoFocus = true, + hiddenTitle, + typeIcons = true, }: FieldListProps) { const { t } = useListConditionTranslation(); const [query, setQuery] = React.useState(''); @@ -296,7 +304,7 @@ export function FieldList({ const neighbour = (step: -1 | 1) => sections.shown[sections.shown.findIndex((f) => f.value === field.value) + step]; const body = ( <> -