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

Refactor MoveToDatasetButton / MoveToDatasetModal components #386

Open
nozomione opened this issue Oct 15, 2024 · 0 comments · May be fixed by #435
Open

Refactor MoveToDatasetButton / MoveToDatasetModal components #386

nozomione opened this issue Oct 15, 2024 · 0 comments · May be fixed by #435
Assignees

Comments

@nozomione
Copy link
Member

nozomione commented Oct 15, 2024

Context

In the dataset route, we display the "Move to Dataset" button (MoveToDatasetButton) which allows a user to replace or add shared dataset samples to their “My Dataset”.

move-to-dataset-button

Upon clicking the MoveToDatasetButton button, we currently determine its behavior using the handleMoveToDataset method:

  • If any samples are present, the button opens MoveToDatasetModal that lets users to replace or add shared dataset samples to their "My Dataset".
  • If no samples are present, we directly append the shared dataset samples to the user’s “My Dataset” without opening MoveToDatasetModal.
 const handleMoveToDataset = async () => {
    if (totalSamples > 0) {
      openModal(id)
    } else {
      await addSamples(selectedDataset.data)
      ...
  }

Problem or idea

Instead of determining the button behavior using handleMoveToDataset, we want to utilize an early return to render different buttons in the UI based on the total sample count.

Additionally, we want to move some of the variables from MoveToDatasetButton to MoveToDatasetModal during this refactoring process.

e.g., New approach:

// Render a button to append shared dataset samples when no samples
if (totalSamples === 0) {
    return (
       <Button 
          label="Move to Dataset"
          secondary
          responsive
          onClick={handleMoveToDataset}
    />)
}

// Otherwise, render a button to open the modal
return (
    <Modal
      button={
        <Button
          label="Move to Dataset"
          secondary
          responsive
         onClick={openModal}
        />
      }
    >
    ...
  )

Solution or next step

  • Use the early return in MoveToDatasetButton to conditionally render:
    • A button for opening MoveToDatasetModal when samples are present
    • A button for adding the shared dataset directly when there are no samples
  • Move the following variables from MoveToDatasetButton to MoveToDatasetModal:
    • radioOptions
    • defaultValue
    • value/setValue
@nozomione nozomione self-assigned this Oct 15, 2024
@nozomione nozomione linked a pull request Jan 6, 2025 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant