From 3ef5c7993dfb293d91287e9f1269c5f813dccfca Mon Sep 17 00:00:00 2001 From: zhouwenxuan Date: Tue, 29 Oct 2024 18:05:01 +0800 Subject: [PATCH] update add list button --- .../metadata/views/kanban/add-list/index.js | 56 ++++++++++++ .../src/metadata/views/kanban/card/index.js | 6 +- frontend/src/metadata/views/kanban/index.js | 88 ++++++------------- .../src/metadata/views/kanban/list/index.js | 12 +-- .../views/kanban/list/list-more-operations.js | 2 +- .../kanban/setting-panel/hidden-columns.js | 6 +- .../views/kanban/setting-panel/index.js | 16 ++-- 7 files changed, 102 insertions(+), 84 deletions(-) create mode 100644 frontend/src/metadata/views/kanban/add-list/index.js diff --git a/frontend/src/metadata/views/kanban/add-list/index.js b/frontend/src/metadata/views/kanban/add-list/index.js new file mode 100644 index 0000000000..3b991632d8 --- /dev/null +++ b/frontend/src/metadata/views/kanban/add-list/index.js @@ -0,0 +1,56 @@ +import React, { useState, useCallback, useMemo } from 'react'; +import PropTypes from 'prop-types'; +import { Icon } from '@seafile/sf-metadata-ui-component'; +import { gettext } from '../../../../utils/constants'; +import AddListPopover from '../../../components/popover/add-list-popover'; +import { COLUMN_DATA_OPERATION_TYPE } from '../../../store/operations'; +import { useMetadataView } from '../../../hooks/metadata-view'; + +const AddList = ({ groupByColumn }) => { + const [isShowAddListPopover, setShowAddListPopover] = useState(false); + const { store } = useMetadataView(); + + const options = useMemo(() => groupByColumn.data.options, [groupByColumn]); + + const handleAddListButtonClick = useCallback(() => { + setShowAddListPopover(true); + }, []); + + const handleAddNewList = useCallback((option) => { + const oldData = groupByColumn.data; + const options = [...oldData.options, option]; + const optionModifyType = COLUMN_DATA_OPERATION_TYPE.ADD_OPTION; + store.modifyColumnData(groupByColumn.key, { options }, { options: oldData.options }, { optionModifyType }); + setShowAddListPopover(false); + }, [store, groupByColumn]); + + const handleCancelAddList = useCallback(() => { + setShowAddListPopover(false); + }, []); + + return ( + <> +
+ + {gettext('Add a new list')} +
+ {isShowAddListPopover && ( + + )} + + ); +}; + +AddList.propTypes = { + groupByColumn: PropTypes.object.isRequired, +}; + +export default AddList; diff --git a/frontend/src/metadata/views/kanban/card/index.js b/frontend/src/metadata/views/kanban/card/index.js index 0ab4d13f8d..c4ff10056f 100644 --- a/frontend/src/metadata/views/kanban/card/index.js +++ b/frontend/src/metadata/views/kanban/card/index.js @@ -26,13 +26,13 @@ const Card = ({ return (
{title.field && ( -
+
)} @@ -41,7 +41,7 @@ const Card = ({ const value = getCellValueByColumn(record, field); if (settings.hideEmptyValues && !value) return null; return ( -
+
{settings.showFieldNames && } {value ? ( diff --git a/frontend/src/metadata/views/kanban/index.js b/frontend/src/metadata/views/kanban/index.js index 180a8f9da8..786c583c3f 100644 --- a/frontend/src/metadata/views/kanban/index.js +++ b/frontend/src/metadata/views/kanban/index.js @@ -1,6 +1,5 @@ import React, { useState, useMemo, useEffect, useCallback } from 'react'; import classNames from 'classnames'; -import { Icon } from '@seafile/sf-metadata-ui-component'; import { useMetadata } from '../../hooks/metadata'; import { useMetadataView } from '../../hooks/metadata-view'; import { useCollaborators } from '../../hooks'; @@ -10,16 +9,15 @@ import { gettext } from '../../../utils/constants'; import { getViewShownColumns } from '../../utils/view'; import toaster from '../../../components/toast'; import { getCellValueByColumn } from '../../utils/cell'; -import AddListPopover from '../../components/popover/add-list-popover'; import SettingPanel from './setting-panel'; import List from './list'; import useKanbanSettings from './useKanbanSettings'; import './index.css'; +import AddList from './add-list'; const Kanban = () => { - const [isSettingOpen, setSettingOpen] = useState(false); - const [isShowAddListPopover, setShowAddListPopover] = useState(false); + const [isSettingPanelOpen, setSettingPanelOpen] = useState(false); const [draggingListId, setDraggingListId] = useState(null); const [dragOverListId, setDragOverListId] = useState(null); @@ -41,12 +39,12 @@ const Kanban = () => { const shownColumns = useMemo(() => getViewShownColumns(metadata.view, metadata.view.columns), [metadata.view]); const groupByColumn = useMemo(() => { - return shownColumns.find(col => col.key === groupByColumnKey); - }, [shownColumns, groupByColumnKey]); + return metadata.columns.find(col => col.key === groupByColumnKey); + }, [metadata.columns, groupByColumnKey]); const titleField = useMemo(() => { - return shownColumns.find(col => col.key === titleFieldKey); - }, [shownColumns, titleFieldKey]); + return metadata.columns.find(col => col.key === titleFieldKey); + }, [metadata.columns, titleFieldKey]); const currentSettings = useMemo(() => ({ selectedViewId, @@ -58,10 +56,6 @@ const Kanban = () => { hiddenColumns, }), [selectedViewId, groupByColumnKey, titleFieldKey, hideEmptyValues, showFieldNames, textWrap, hiddenColumns]); - const contentFields = useMemo(() => { - return shownColumns.filter(col => col.key !== titleFieldKey); - }, [shownColumns, titleFieldKey]); - const lists = useMemo(() => { if (!groupByColumn) return []; @@ -108,7 +102,7 @@ const Kanban = () => { id: option.id, title: option.name, field: groupByColumn, - contentFields, + shownColumns, cards: isPrivateColumn ? groupedCardsMap[option.id] : groupedCardsMap[option.name], })); } else if (groupByColumn.type === CellType.COLLABORATOR) { @@ -117,7 +111,7 @@ const Kanban = () => { id: collaborator.email, title: [collaborator.email], field: groupByColumn, - contentFields, + shownColumns, cards: groupedCardsMap[collaborator.email], })); } @@ -127,35 +121,16 @@ const Kanban = () => { id: 'uncategorized', title: gettext('Uncategorized'), field: groupByColumn, - contentFields, + shownColumns, cards: ungroupedCards, }; groupedLists.push(ungroupedList); return groupedLists; - }, [metadata, collaborators, groupByColumnKey, groupByColumn, titleField, contentFields]); - - const canAddList = useMemo(() => { - const groupByCol = shownColumns.find(col => col.key === groupByColumn?.key); - return groupByCol?.editable; - }, [shownColumns, groupByColumn]); - - const handleAddListButtonClick = useCallback(() => { - setShowAddListPopover(true); - }, []); + }, [metadata, collaborators, groupByColumnKey, groupByColumn, titleField, shownColumns]); - const handleAddNewList = useCallback((option) => { - const oldData = groupByColumn.data; - const options = [...oldData.options, option]; - const optionModifyType = COLUMN_DATA_OPERATION_TYPE.ADD_OPTION; - store.modifyColumnData(groupByColumn.key, { options }, { options: oldData.options }, { optionModifyType }); - setShowAddListPopover(false); - }, [store, groupByColumn]); - - const handleCancelAddList = useCallback(() => { - setShowAddListPopover(false); - }, []); + const canAddList = useMemo(() => groupByColumn && groupByColumn.editable && groupByColumn.type !== CellType.COLLABORATOR, [groupByColumn]); const handleDeleteList = useCallback((listId) => { const oldData = groupByColumn.data; @@ -257,17 +232,17 @@ const Kanban = () => { }, [lists, groupByColumnKey, groupByColumn, modifyRecord, getOldRowData]); useEffect(() => { - const unsubscribeKanbanSetting = window.sfMetadataContext.eventBus.subscribe(EVENT_BUS_TYPE.TOGGLE_KANBAN_SETTING, () => setSettingOpen(!isSettingOpen)); + const unsubscribeKanbanSetting = window.sfMetadataContext.eventBus.subscribe(EVENT_BUS_TYPE.TOGGLE_KANBAN_SETTING, () => setSettingPanelOpen(!isSettingPanelOpen)); return () => { unsubscribeKanbanSetting(); }; - }, [isSettingOpen, viewsMap]); + }, [isSettingPanelOpen, viewsMap]); return ( -
-
-
+
+
+
{lists && lists.map((list, index) => (
{
))} {canAddList && ( -
- - {gettext('Add a new list')} -
- )} - {isShowAddListPopover && ( - + )}
- {isSettingOpen && - setSettingOpen(false)} - />} + {isSettingPanelOpen && ( + setSettingPanelOpen(false)} + /> + )}
); }; diff --git a/frontend/src/metadata/views/kanban/list/index.js b/frontend/src/metadata/views/kanban/list/index.js index 7f131c9705..4ac2815dfa 100644 --- a/frontend/src/metadata/views/kanban/list/index.js +++ b/frontend/src/metadata/views/kanban/list/index.js @@ -8,7 +8,7 @@ const List = ({ id, title, field, - contentFields, + shownColumns, cards, settings, moreOperationsList, @@ -35,11 +35,11 @@ const List = ({ return (
-
+
{id === 'uncategorized' ? ( {title} @@ -57,12 +57,12 @@ const List = ({
)}
-
+
{cards.map(card => ( { { const { metadata } = useMetadataView(); const columns = useMemo(() => { - return metadata.view.columns.filter(col => (col.key !== settings.groupByColumnKey && col.key !== settings.titleFieldKey)); - }, [metadata.view.columns, settings.groupByColumnKey, settings.titleFieldKey]); + return metadata.view.columns.filter(col => col.key !== settings.groupByColumnKey); + }, [metadata.view.columns, settings.groupByColumnKey]); const isEmpty = useMemo(() => { if (!Array.isArray(columns) || columns.length === 0) return true; @@ -73,7 +73,7 @@ const KanbanHiddenColumns = ({ settings, onChange }) => { }, [onChange]); return ( -
+
{isEmpty &&
{gettext('No properties available to be hidden')}
} {!isEmpty && columns.map((column, columnIndex) => { diff --git a/frontend/src/metadata/views/kanban/setting-panel/index.js b/frontend/src/metadata/views/kanban/setting-panel/index.js index d435523dec..f12dfcdae3 100644 --- a/frontend/src/metadata/views/kanban/setting-panel/index.js +++ b/frontend/src/metadata/views/kanban/setting-panel/index.js @@ -9,7 +9,7 @@ import { CellType, COLUMNS_ICON_CONFIG, KANBAN_SETTINGS_KEYS, VIEW_TYPE } from ' import Switch from '../../../../components/common/switch'; const SettingPanel = ({ - shownColumns, + columns, settings, onSettingChange, onClose @@ -24,30 +24,30 @@ const SettingPanel = ({ , [viewsMap]); const groupByOptions = useMemo(() => { - return shownColumns + return columns .filter(col => col.type === CellType.SINGLE_SELECT || col.type === CellType.COLLABORATOR) .map(col => ({ value: col.key, label: ( <> - {col.name} + {col.name} ) })); - }, [shownColumns]); + }, [columns]); const titleOptions = useMemo(() => { - return shownColumns.map(col => ({ + return columns.map(col => ({ value: col.key, label: ( <> - {col.name} + {col.name} ) })); - }, [shownColumns]); + }, [columns]); const selectedViewOption = viewOptions.find(option => option.value === settings.selectedViewId); const selectedGroupByOption = groupByOptions.find(option => option.value === settings.groupByColumnKey); @@ -157,7 +157,7 @@ const SettingPanel = ({ }; SettingPanel.propTypes = { - shownColumns: PropTypes.array.isRequired, + columns: PropTypes.array.isRequired, settings: PropTypes.object.isRequired, onSettingChange: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired,