Skip to content
Open
Changes from 2 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
11 changes: 10 additions & 1 deletion webui/src/ImportExport/Import/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,22 @@ export const ImportPageWizard = observer(function ImportPageWizard({
}
}, [snapshot.pages, snapshot.page, isSinglePage])

const { pageNumber, setPageNumber, changePage } = usePagePicker(pages.data.length, 1)
const {
pageNumber: importPageNumber,
setPageNumber: setImportPageNumber,
changePage: changeImportPage,
} = usePagePicker(pageCount, 1)

const defaultDestinationPage = useMemo(() => {
if (!isSinglePage) return importPageNumber
const oldPage = snapshot.oldPageNumber
if (typeof oldPage === 'number' && Number.isInteger(oldPage) && oldPage >= 1 && oldPage <= pages.data.length) {
return oldPage
}
return -1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice suggestion @tonypiper ! Some comments

  1. This will default to a new page (-1) rather than the first page (1), as was the pre-existing behavior. Is that your intention? This actually makes sense when oldPage is beyond pages.data.length, but otherwise it should probably default to 1.
  2. useMemo here seems a bit of overkill: you're just doing a couple of logical tests and all it's doing is setting a default, so it's a no-op if any of the dependents change, anyway. Suggestion: either it should be done only on mount or just take it out of a useMemo.
  3. Technically the !isSinglePage test isn't necessary, since full won't have an oldPageNumber, and really, if there is an oldPageNumber it should probably be used.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you for the quick and helpful feedback. Defaulting to a new page was intentional - original motivation was that I have important buttons on page 1 and they kept getting overwritten. It seems to me that it's safer to create a new page (and then move it manually if need be) than overwrite an existing page if we can't be sure that it's the right page to overwrite.

}, [isSinglePage, importPageNumber, snapshot.oldPageNumber, pages.data.length])
const { pageNumber, setPageNumber, changePage } = usePagePicker(pages.data.length, defaultDestinationPage)

const setConnectionRemap2 = useCallback(
(fromId: string, toId: string) => {
setConnectionRemap((oldRemap) => ({
Expand Down