mirror of
https://github.com/haiwen/seahub.git
synced 2025-10-21 19:00:12 +00:00
fix capture time editor's format (#8269)
Co-authored-by: zhouwenxuan <aries@Mac.local>
This commit is contained in:
@@ -98,6 +98,10 @@ class PopupEditorContainer extends React.Component {
|
||||
|
||||
if (column.type === CellType.DATE) {
|
||||
editorProps.format = column?.data?.format;
|
||||
if (column.key === PRIVATE_COLUMN_KEY.CAPTURE_TIME) {
|
||||
// convert hh:mm:ss to hh:mm if exists
|
||||
editorProps.format = editorProps.format.replace('HH:mm:ss', 'HH:mm');
|
||||
}
|
||||
}
|
||||
|
||||
if (column.type === CellType.TAGS) {
|
||||
@@ -169,27 +173,33 @@ class PopupEditorContainer extends React.Component {
|
||||
commit = () => {
|
||||
const { column, record } = this.props;
|
||||
if (!record._id) return;
|
||||
const editor = this.getEditor();
|
||||
if (!editor) return;
|
||||
const { key: columnKey, type: columnType } = column;
|
||||
if (columnType === CellType.TAGS) return;
|
||||
if (columnType === CellType.GEOLOCATION) {
|
||||
// For geolocation, get the value from the editor and transform it properly
|
||||
if (this.getEditor() && this.getEditor().getValue) {
|
||||
const geolocationValue = this.getEditor().getValue();
|
||||
if (editor.getValue) {
|
||||
const geolocationValue = editor.getValue();
|
||||
const { position, location_translated } = geolocationValue || { position: null, location_translated: null };
|
||||
const updated = { [columnKey]: position };
|
||||
updated[PRIVATE_COLUMN_KEY.LOCATION_TRANSLATED] = location_translated;
|
||||
this.commitData(updated, true);
|
||||
}
|
||||
// Always call onClose for geolocation editor
|
||||
if (this.getEditor() && this.getEditor().onClose) {
|
||||
this.getEditor().onClose();
|
||||
if (editor.onClose) {
|
||||
editor.onClose();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.getEditor()) return;
|
||||
let newValue = editor.getValue();
|
||||
if (columnType === CellType.DATE && columnKey === PRIVATE_COLUMN_KEY.CAPTURE_TIME && typeof newValue === 'string') {
|
||||
if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/.test(newValue)) {
|
||||
newValue = newValue + ':00';
|
||||
}
|
||||
}
|
||||
|
||||
const newValue = this.getEditor().getValue();
|
||||
let updated = columnType === CellType.DATE ? { [columnKey]: newValue } : newValue;
|
||||
if (columnType === CellType.SINGLE_SELECT) {
|
||||
updated[columnKey] = newValue[columnKey] ? getColumnOptionNameById(column, newValue[columnKey]) : '';
|
||||
|
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
|
||||
import DateEditor from '../../cell-editors/date-editor';
|
||||
import ClickOutside from '../../../../components/click-outside';
|
||||
import { getDateDisplayString, isCellValueChanged } from '../../../utils/cell';
|
||||
import { CellType, DEFAULT_DATE_FORMAT } from '../../../constants';
|
||||
import { CellType, DEFAULT_DATE_FORMAT, PRIVATE_COLUMN_KEY } from '../../../constants';
|
||||
import { gettext } from '../../../../utils/constants';
|
||||
import { getEventClassName } from '../../../../utils/dom';
|
||||
|
||||
@@ -11,16 +11,29 @@ import './index.css';
|
||||
|
||||
const DetailDateEditor = ({ value, field, onChange: onChangeAPI, lang }) => {
|
||||
const [showEditor, setShowEditor] = useState(false);
|
||||
const format = useMemo(() => field?.data?.format || DEFAULT_DATE_FORMAT, [field]);
|
||||
const format = useMemo(() => {
|
||||
let format = field?.data?.format || DEFAULT_DATE_FORMAT;
|
||||
if (field?.key === PRIVATE_COLUMN_KEY.CAPTURE_TIME) {
|
||||
format = format.replace('HH:mm:ss', 'HH:mm');
|
||||
}
|
||||
return format;
|
||||
}, [field]);
|
||||
const newValue = useRef(value);
|
||||
|
||||
const openEditor = useCallback(() => {
|
||||
setShowEditor(true);
|
||||
}, []);
|
||||
|
||||
const onChange = useCallback((value) => {
|
||||
newValue.current = value;
|
||||
}, []);
|
||||
const onChange = useCallback((val) => {
|
||||
let v = val;
|
||||
// Normalize capture time early: append :00 if only minutes are present.
|
||||
if (field?.key === PRIVATE_COLUMN_KEY.CAPTURE_TIME && typeof v === 'string') {
|
||||
if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/.test(v)) {
|
||||
v = v + ':00';
|
||||
}
|
||||
}
|
||||
newValue.current = v;
|
||||
}, [field]);
|
||||
|
||||
const onClear = useCallback(() => {
|
||||
onChangeAPI(null);
|
||||
|
Reference in New Issue
Block a user