AlexsLemonade / refinebio-web

Refinebio Web
https://staging.web.refine.bio
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Implement useDatasetAction hook for dataset action button #179

Closed nozomione closed 11 months ago

nozomione commented 1 year ago

Context

To make dataset management easy, we provide users three main dataset action buttons in UI which they can use to quickly add or remove downloadable samples to/from their datasets.

The dataset action buttons have three different states, which are as follows:

Problem or idea

We'll implement the hook useDatasetAction which contains methods to render the correct button state in UI and to perform its corresponding dataset action. Each method corresponds to a specific application behavior.

❚ Parameters

Use of this hook requires the following parameters: data1: a data object in a dataset with datasetId stored in a user's localStorage data2: a data object in the API response selected by a user in UI (e.g., from the search results)

❚ Method

Following are the implementation details and pseudocode (parameters marked with * are required):

anyProcessedSamples() return boolean returns true if any samples that are processed and available for download in data2, otherwise false

allProcessedInDataset() return boolean returns true if all the processed samples in data2 were added to data1, otherwise false

anyProcessedInDataset() return boolean returns true if any processed samples in data2 were added in data1, otherwise false

getAddedSamples() return samples returns the samples in data2 that were added in data1

getSamplesInDatasets() return samples returns all the samples that are in both data1 and data2

hasSameSamples(d1*, d2*) return boolean returns true if two given datasets have the same samples, otherwise false

intersectDatasets(d1*, d2*) return object returns the intersection of two given datasets

totalSamplesInDataset() return number returns the total samples added in data1

Example: To use this hook, pass the required arguments and destructure the method(s) you want to use:

  const { totalSamplesInDataset } = useDatasetAction(dataset.data, data) 

Solution or next step

Based on the above requirements, implement the hook.