Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes before making an official V1.0 release #1251

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions app/src/gui/components/autoincrement/edit-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export const AutoIncrementEditForm = ({
);
return ranges;
},
initialData: [],
enabled: true,
});

Expand Down Expand Up @@ -112,9 +111,11 @@ export const AutoIncrementEditForm = ({

const updateRange = (index: number) => {
return (range: LocalAutoIncrementRange) => {
const rangesCopy = [...ranges];
rangesCopy[index] = range;
updateRanges(rangesCopy);
if (ranges) {
const rangesCopy = [...ranges];
rangesCopy[index] = range;
updateRanges(rangesCopy);
}
};
};

Expand Down Expand Up @@ -207,20 +208,25 @@ type IncremenenterRangeProps = {
* @param props component props
*/
const IncrementerRange = (props: IncremenenterRangeProps) => {
const [start, setStart] = useState(props.range.start);
const [stop, setStop] = useState(props.range.stop);
const [start, setStart] = useState<number | string>(props.range.start);
const [stop, setStop] = useState<number | string>(props.range.stop);
Comment on lines +211 to +212
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do they really need to be a number or a string? Might be better to on each render parse the value as a number - just choose one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to allow for the empty string, if I don't, you can't delete the number that's there to enter a new one. Note this is only for the field value, not for the final data structure which is a number.


const handleStartChange = (event: any) => {
if (event.target.value === '') {
// set start but don't update the range
setStart('');
return;
}
const newStart = parseInt(event.target.value);
if (newStart >= 0) {
setStart(newStart);
if (newStart >= props.range.stop) {
// initialise a range of 100 if they enter a start > stop
setStop(newStart + 100);
setStop(newStart + 99);
props.updateRange({
...props.range,
start: newStart,
stop: newStart + 100,
stop: newStart + 99,
});
} else {
props.updateRange({
Expand All @@ -232,6 +238,11 @@ const IncrementerRange = (props: IncremenenterRangeProps) => {
};

const handleStopChange = (event: any) => {
if (event.target.value === '') {
// set stop but don't update the range
setStop('');
return;
}
const newStop = parseInt(event.target.value);
if (newStop > props.range.start) {
setStop(newStop);
Expand Down
1 change: 0 additions & 1 deletion app/src/gui/components/record/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import {
upsertFAIMSData,
} from '@faims3/data-model';
import {NavigateFunction} from 'react-router-dom';
import {DEBUG_APP} from '../../../buildconfig';
import * as ROUTES from '../../../constants/routes';
import {store} from '../../../context/store';
import {getFieldPersistentData} from '../../../local-data/field-persistent';
Expand Down
Loading