diff --git a/frontend/src/metadata/components/cell-editors/editor-container/popup-editor-container.js b/frontend/src/metadata/components/cell-editors/editor-container/popup-editor-container.js index 3abfbacfd6..66a3fa873a 100644 --- a/frontend/src/metadata/components/cell-editors/editor-container/popup-editor-container.js +++ b/frontend/src/metadata/components/cell-editors/editor-container/popup-editor-container.js @@ -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]) : ''; diff --git a/frontend/src/metadata/components/detail-editor/date-editor/index.js b/frontend/src/metadata/components/detail-editor/date-editor/index.js index e5592bd894..a64ca28993 100644 --- a/frontend/src/metadata/components/detail-editor/date-editor/index.js +++ b/frontend/src/metadata/components/detail-editor/date-editor/index.js @@ -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);