-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
杨国璇
authored and
杨国璇
committed
Jul 5, 2024
1 parent
182b0f2
commit ab35068
Showing
11 changed files
with
301 additions
and
79 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
frontend/src/metadata/metadata-view/components/cell-editor/editor-container.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Editor from './editor'; | ||
|
||
const EditorContainer = (props) => { | ||
if (!props.column) return null; | ||
return (<Editor { ...props } />); | ||
}; | ||
|
||
|
||
EditorContainer.propTypes = { | ||
table: PropTypes.object, | ||
columns: PropTypes.array, | ||
isGroupView: PropTypes.bool, | ||
scrollTop: PropTypes.number, | ||
scrollLeft: PropTypes.number, | ||
firstEditorKeyDown: PropTypes.object, | ||
openEditorMode: PropTypes.string, | ||
portalTarget: PropTypes.any, | ||
editorPosition: PropTypes.object, | ||
record: PropTypes.object, | ||
column: PropTypes.object, | ||
width: PropTypes.number.isRequired, | ||
height: PropTypes.number.isRequired, | ||
left: PropTypes.number.isRequired, | ||
top: PropTypes.number.isRequired, | ||
onCommit: PropTypes.func, | ||
onCommitCancel: PropTypes.func, | ||
}; | ||
|
||
export default EditorContainer; |
42 changes: 42 additions & 0 deletions
42
frontend/src/metadata/metadata-view/components/cell-editor/editor-portal.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import PropTypes from 'prop-types'; | ||
|
||
class EditorPortal extends React.Component { | ||
static propTypes = { | ||
children: PropTypes.node.isRequired, | ||
target: PropTypes.instanceOf(Element).isRequired | ||
}; | ||
|
||
// Keep track of when the modal element is added to the DOM | ||
state = { | ||
isMounted: false | ||
}; | ||
|
||
el = document.createElement('div'); | ||
|
||
componentDidMount() { | ||
this.props.target.appendChild(this.el); | ||
// eslint-disable-next-line react/no-did-mount-set-state | ||
this.setState({ isMounted: true }); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.props.target.removeChild(this.el); | ||
} | ||
|
||
render() { | ||
// Don't render the portal until the component has mounted, | ||
// So the portal can safely access the DOM. | ||
if (!this.state.isMounted) { | ||
return null; | ||
} | ||
|
||
return ReactDOM.createPortal( | ||
this.props.children, | ||
this.el, | ||
); | ||
} | ||
} | ||
|
||
export default EditorPortal; |
22 changes: 22 additions & 0 deletions
22
frontend/src/metadata/metadata-view/components/cell-editor/editor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { CellType } from '../../_basic'; | ||
import FileNameEditor from './file-name-editor'; | ||
|
||
const Editor = (props) => { | ||
|
||
switch (props.column.type) { | ||
case CellType.FILE_NAME: { | ||
return (<FileNameEditor {...props} />); | ||
} | ||
default: { | ||
return null; | ||
} | ||
} | ||
}; | ||
|
||
Editor.propTypes = { | ||
column: PropTypes.object.isRequired, | ||
}; | ||
|
||
export default Editor; |
97 changes: 97 additions & 0 deletions
97
frontend/src/metadata/metadata-view/components/cell-editor/file-name-editor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import React, { useEffect, useMemo } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { ModalPortal } from '@seafile/sf-metadata-ui-component'; | ||
import { PRIVATE_COLUMN_KEY } from '../../_basic'; | ||
import { Utils } from '../../../../utils/utils'; | ||
import ImageDialog from '../../../../components/dialog/image-dialog'; | ||
import { serviceURL, siteRoot, thumbnailSizeForOriginal } from '../../../../utils/constants'; | ||
|
||
const FileNameEditor = ({ column, record, onCommitCancel }) => { | ||
const _isDir = useMemo(() => { | ||
const isDirValue = record[PRIVATE_COLUMN_KEY.IS_DIR]; | ||
if (typeof isDirValue === 'string') return isDirValue.toUpperCase() === 'TRUE'; | ||
return isDirValue; | ||
}, [record]); | ||
|
||
const fileName = useMemo(() => { | ||
const { key } = column; | ||
return record[key]; | ||
}, [column, record]); | ||
|
||
const fileType = useMemo(() => { | ||
if (_isDir) return 'folder'; | ||
if (!fileName) return ''; | ||
const index = fileName.lastIndexOf('.'); | ||
if (index === -1) return 'file'; | ||
const suffix = fileName.slice(index).toLowerCase(); | ||
if (Utils.imageCheck(fileName)) return 'image'; | ||
if (suffix === '.sdoc') return 'sdoc'; | ||
return 'file'; | ||
}, [_isDir, fileName]); | ||
|
||
const parentDir = useMemo(() => { | ||
const value = record[PRIVATE_COLUMN_KEY.PARENT_DIR]; | ||
if (value === '/') return ''; | ||
return value; | ||
}, [record]); | ||
|
||
const repoID = useMemo(() => { | ||
return window.sfMetadataContext.getSetting('repoID'); | ||
}, []); | ||
|
||
const path = useMemo(() => { | ||
return Utils.encodePath(Utils.joinPath(parentDir, fileName)); | ||
}, [parentDir, fileName]); | ||
|
||
const url = useMemo(() => { | ||
return `${siteRoot}lib/${repoID}/file${path}`; | ||
}, [path, repoID]); | ||
|
||
useEffect(() => { | ||
if (fileType === 'image') return; | ||
onCommitCancel && onCommitCancel(); | ||
}, [fileType, onCommitCancel]); | ||
|
||
if (!fileName) return null; | ||
|
||
if (fileType === 'image') { | ||
const fileExt = fileName.substr(fileName.lastIndexOf('.') + 1).toLowerCase(); | ||
const isGIF = fileExt === 'gif'; | ||
const useThumbnail = window.sfMetadataContext.getSetting('currentRepoInfo')?.encrypted; | ||
let src = ''; | ||
if (useThumbnail && !isGIF) { | ||
src = `${siteRoot}thumbnail/${repoID}/${thumbnailSizeForOriginal}${path}`; | ||
} else { | ||
src = `${siteRoot}repo/${repoID}/raw${path}`; | ||
} | ||
const images = [ | ||
{ 'name': fileName, 'url': url, 'src': src }, | ||
]; | ||
return ( | ||
<ModalPortal> | ||
<ImageDialog | ||
imageItems={images} | ||
imageIndex={0} | ||
closeImagePopup={onCommitCancel} | ||
moveToPrevImage={() => {}} | ||
moveToNextImage={() => {}} | ||
/> | ||
</ModalPortal> | ||
); | ||
} | ||
|
||
if (fileType === 'sdoc') { | ||
window.open(serviceURL + url); | ||
} else { | ||
window.open(window.location.href + Utils.encodePath(Utils.joinPath(parentDir, fileName))); | ||
} | ||
return null; | ||
}; | ||
|
||
FileNameEditor.propTypes = { | ||
column: PropTypes.object, | ||
record: PropTypes.object, | ||
onCommitCancel: PropTypes.func, | ||
}; | ||
|
||
export default FileNameEditor; |
7 changes: 7 additions & 0 deletions
7
frontend/src/metadata/metadata-view/components/cell-editor/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import EditorPortal from './editor-portal'; | ||
import EditorContainer from './editor-container'; | ||
|
||
export { | ||
EditorPortal, | ||
EditorContainer, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.