1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-23 12:27:48 +00:00

show tags as tree in table tags editor (#7797)

Co-authored-by: zhouwenxuan <aries@Mac.local>
This commit is contained in:
Aries
2025-05-10 15:14:48 +08:00
committed by GitHub
parent 7d794157e9
commit 1474c95794
3 changed files with 22 additions and 17 deletions

View File

@@ -12,6 +12,8 @@ const NOT_SUPPORT_EDITOR_COLUMN_TYPES = [
CellType.CTIME, CellType.MTIME, CellType.CREATOR, CellType.LAST_MODIFIER, CellType.FILE_NAME, CellType.CTIME, CellType.MTIME, CellType.CREATOR, CellType.LAST_MODIFIER, CellType.FILE_NAME,
]; ];
const TAGS_EDITOR_WIDTH = 400;
class PopupEditorContainer extends React.Component { class PopupEditorContainer extends React.Component {
static displayName = 'PopupEditorContainer'; static displayName = 'PopupEditorContainer';
@@ -23,6 +25,9 @@ class PopupEditorContainer extends React.Component {
if (column.type === CellType.SINGLE_SELECT || column.type === CellType.MULTIPLE_SELECT) { if (column.type === CellType.SINGLE_SELECT || column.type === CellType.MULTIPLE_SELECT) {
additionalStyles = { width, height }; additionalStyles = { width, height };
} }
if (column.type === CellType.TAGS) {
additionalStyles = { left: left - (TAGS_EDITOR_WIDTH - column.width) };
}
this.state = { this.state = {
isInvalid: false, isInvalid: false,
style: { style: {
@@ -82,12 +87,23 @@ class PopupEditorContainer extends React.Component {
readOnly, readOnly,
onPressTab, onPressTab,
updateFileTags, updateFileTags,
showTagsAsTree: true,
}; };
if (column.type === CellType.DATE) { if (column.type === CellType.DATE) {
editorProps.format = column?.data?.format; editorProps.format = column?.data?.format;
} }
if (column.type === CellType.TAGS) {
editorProps = {
...editorProps,
column: {
...column,
width: TAGS_EDITOR_WIDTH,
}
};
}
return (<Editor {...editorProps} />); return (<Editor {...editorProps} />);
}; };

View File

@@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
import classnames from 'classnames'; import classnames from 'classnames';
import CommonAddTool from '../../../../components/common-add-tool'; import CommonAddTool from '../../../../components/common-add-tool';
import SearchInput from '../../../../components/search-input'; import SearchInput from '../../../../components/search-input';
import DeleteTags from './delete-tags';
import { Utils } from '../../../../utils/utils'; import { Utils } from '../../../../utils/utils';
import { KeyCodes } from '../../../../constants'; import { KeyCodes } from '../../../../constants';
import { gettext } from '../../../../utils/constants'; import { gettext } from '../../../../utils/constants';
@@ -95,17 +94,6 @@ const TagsEditor = forwardRef(({
localStorage.setItem(RECENTLY_USED_TAG_IDS, JSON.stringify(newIds)); localStorage.setItem(RECENTLY_USED_TAG_IDS, JSON.stringify(newIds));
}, [value, record, tagsData, updateFileTags, recentlyUsed, localStorage]); }, [value, record, tagsData, updateFileTags, recentlyUsed, localStorage]);
const onDeleteTag = useCallback((tagId) => {
const newValue = value.slice(0);
let optionIdx = value.indexOf(tagId);
if (optionIdx > -1) {
newValue.splice(optionIdx, 1);
}
setValue(newValue);
const recordId = getRecordIdFromRecord(record);
updateFileTags([{ record_id: recordId, tags: newValue, old_tags: value }]);
}, [value, record, updateFileTags]);
const onMenuMouseEnter = useCallback((i, id) => { const onMenuMouseEnter = useCallback((i, id) => {
setHighlightIndex(i); setHighlightIndex(i);
}, []); }, []);
@@ -306,7 +294,9 @@ const TagsEditor = forwardRef(({
return searchedNodes; return searchedNodes;
}, [tagsData, searchValue, searchedKeyNodeFoldedMap]); }, [tagsData, searchValue, searchedKeyNodeFoldedMap]);
const toggleExpandTreeNode = useCallback((nodeKey) => { const toggleExpandTreeNode = useCallback((e, nodeKey) => {
e.preventDefault();
e.stopPropagation();
if (!searchValue) { if (!searchValue) {
const updatedKeyNodeFoldedMap = { ...keyNodeFoldedMap }; const updatedKeyNodeFoldedMap = { ...keyNodeFoldedMap };
if (updatedKeyNodeFoldedMap[nodeKey]) { if (updatedKeyNodeFoldedMap[nodeKey]) {
@@ -448,7 +438,7 @@ const TagsEditor = forwardRef(({
depth={getTreeNodeDepth(node)} depth={getTreeNodeDepth(node)}
hasChildren={checkTreeNodeHasChildNodes(node)} hasChildren={checkTreeNodeHasChildNodes(node)}
isFolded={!searchValue ? keyNodeFoldedMap[nodeKey] : searchedKeyNodeFoldedMap[nodeKey]} isFolded={!searchValue ? keyNodeFoldedMap[nodeKey] : searchedKeyNodeFoldedMap[nodeKey]}
onToggleExpand={() => toggleExpandTreeNode(nodeKey)} onToggleExpand={(e) => toggleExpandTreeNode(e, nodeKey)}
/> />
); );
})} })}
@@ -458,7 +448,6 @@ const TagsEditor = forwardRef(({
return ( return (
<div className={classnames('sf-metadata-tags-editor', { 'tags-tree-container': showTagsAsTree })} style={style} ref={editorRef}> <div className={classnames('sf-metadata-tags-editor', { 'tags-tree-container': showTagsAsTree })} style={style} ref={editorRef}>
<DeleteTags value={value} tags={tagsData} onDelete={onDeleteTag} />
<div className="sf-metadata-search-tags-container"> <div className="sf-metadata-search-tags-container">
<SearchInput <SearchInput
placeholder={gettext('Search tag')} placeholder={gettext('Search tag')}

View File

@@ -32,7 +32,7 @@ const TagItem = ({
'sf-metadata-tags-editor-tag-container-highlight': highlight, 'sf-metadata-tags-editor-tag-container-highlight': highlight,
})} })}
style={{ paddingLeft }} style={{ paddingLeft }}
onMouseDown={!node ? () => onSelect(tagId) : () => {}} onClick={() => onSelect(tagId)}
onMouseEnter={onMouseEnter} onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave} onMouseLeave={onMouseLeave}
> >
@@ -45,7 +45,7 @@ const TagItem = ({
<i className={classNames('sf3-font sf3-font-down', { 'rotate-270': isFolded })}></i> <i className={classNames('sf3-font sf3-font-down', { 'rotate-270': isFolded })}></i>
</span> </span>
)} )}
<div className="sf-metadata-tag-color-and-name" onClick={node ? () => onSelect(tagId) : () => {}}> <div className="sf-metadata-tag-color-and-name">
<div className="sf-metadata-tag-color" style={{ backgroundColor: tagColor }} /> <div className="sf-metadata-tag-color" style={{ backgroundColor: tagColor }} />
<div className="sf-metadata-tag-name">{tagName}</div> <div className="sf-metadata-tag-name">{tagName}</div>
</div> </div>