AlexsLemonade / refinebio-web

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

Implement DatasetContextManager and useDatasetManager #178

Closed nozomione closed 1 year ago

nozomione commented 1 year ago

Context

This is a rewrite of the original issue: https://github.com/AlexsLemonade/refinebio-web/issues/101

As with the existing refine.bio, we want to be able to manage users' datasets when they use the application.

Problem or idea

Using the context API, we'll create a dataset manager context DatasetManagerContext and implement its hook useDatasetManager which manages a user's dataset and keeps it in sync with the API.

The general strategy should be to have a manager that;

❚ State Management

Context State

The DatasetManagerContext inherits the following states from the global context RefinebioContext that are shared across the application.

dataset: (object) the latest user-created dataset state retrieved from the API setDataset: an async method for setting dataset

datasetId: (uuid) a user-created dataset ID retrieved from the API at creation setDatasetId: an async method for setting datasetId

downloadOptions: (object) a user-selected download options for a file download setDownloadOptions: an async method for setting downloadOptions

email: (string) a user's provided email address entered in the email form for a file download

token: (uuid) a user's token required for a file download

Hook State

error: (object) an object that stores an error object (e.g., network) setError: an async method for setting error

loading: (boolean) the loading indicator for the dataset data setLoading: an async method for setting loading

❚ Method

The useDatasetManager hook contains the helper methods that are primarily used in the UI and each one corresponds to a specific application behavior.

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

Dataset

async createDataset(setCurrentDatasetId = false) return dataset Id

async getDataset(id) return dataset

async clearDataset(id) return dataset

async updateDataset(id*, params*) return dataset

Experiment

getTotalExperiments(data*) return number

formatExperiments() return object

async removeExperiment(experimentAccessionCode*) return dataset

Samples

async addSamples(samplesToAdd*) return dataset

formatSampleMetadata(metadata*) return array

getTotalSamples(data*) return number

async removeSamples(samplesToRemove*) return dataset

async replaceSamples(samplesToReplace*) return dataset

Example: To fetch the latest dataset state:

getDataset() // fetches the latest dataset associated with datasetId stored in the localStorage
getDataset(id) // fetches the latest dataset state with the given dataset Id

Solution or next step

Based on the above requirements, implement the dataset context manager and its hook.

nozomione commented 1 year ago

🗒️ Based on the 1:1 @davidsmejia, we should fetch datasets with the query string details: true by default (reason: future BE API revision is being taken into account). For this reason, we deleted getDatasetDetails and we also removed the details parameter from the rest of the methods.