Skip to content

Commit

Permalink
fix: address PR comments and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianaCeric committed Oct 25, 2023
1 parent c52287d commit 8b1093d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 32 deletions.
25 changes: 5 additions & 20 deletions lib/editor/components/timetable/EditableCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,24 +205,19 @@ function EditableCell (props: Props) {
onStopEditing()
}

let alertShown = false
const save = () => {
const {column} = props
const {data} = state
const {data, originalData} = state

if (column.type === 'TEXT') {
if (data !== state.originalData) {
_handleSave(data)
} else {
cancel()
}
if (column.type === 'TEXT' && data !== originalData) {
_handleSave(data)
} else if (column.type === 'SECONDS') {
const value = +data

if (!isNaN(value) && value >= 0) {
_handleSave(value)
} else {
window.alert('Please enter a positive number.')
alert('Please enter a positive number.')
cancel()
}
} else if (isTimeFormat(column.type)) {
Expand All @@ -231,23 +226,13 @@ function EditableCell (props: Props) {
if (parsedValue !== null) {
_handleSave(parsedValue)
} else {
if (!alertShown) {
alert('Please enter a valid time format')
alertShown = true
}
cancel()
}
}
}

const handleBlur = () => {
setState((prevState) => ({
...prevState,
isEditing: false,
isFocused: false,
data: prevState.data
}))
props.onStopEditing()
save()
}

const handleChange = (evt) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/editor/components/timetable/TimetableGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export default class TimetableGrid extends Component<Props> {
addNewRow()
}
// Iterate over number of columns in pasted selection
for (var j = 0; j < pastedRows[i].length; j++) {
for (var j = 0; j < pastedRows[0].length; j++) {
activeCol = colIndex + j
const col = columns[activeCol]
const path = `${activeRow}.${col.key}`
Expand Down
22 changes: 11 additions & 11 deletions lib/editor/util/timetable.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ export function getHeaderColumns (
* Handles pasted data from clipboard (e.g. from CSV file)
* If departure/arrival time cell, pastes in time format, otherwise returns string as is
*/
let alertShown = false
let alertTimeout
export function parseCellValue (timeString: string, col: TimetableColumn) {
const date = moment().startOf('day').format('YYYY-MM-DD')
const parsedDate = moment(date + 'T' + timeString, TIMETABLE_FORMATS, true)

clearTimeout(alertTimeout)

if (isTimeFormat(col.type)) {
const date = moment().startOf('day').format('YYYY-MM-DD')
const parsedDate = moment(date + 'T' + timeString, TIMETABLE_FORMATS, true)
if (!parsedDate.isValid()) {
if (!alertShown) {
alert('Please enter a valid time format')
alertShown = true
}
alertTimeout = setTimeout(() => alert('Please enter a valid time format'), 500)
return null
} else {
return moment(date + 'T' + timeString, TIMETABLE_FORMATS).diff(date, 'seconds')
}
} else {
return timeString

return moment(date + 'T' + timeString, TIMETABLE_FORMATS).diff(date, 'seconds')
}

return timeString
}

export const LEFT_COLUMN_WIDTH = 30
Expand Down

0 comments on commit 8b1093d

Please sign in to comment.