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

Decouple formatExperiments from useDatasetManager #361

Open
nozomione opened this issue Sep 9, 2024 · 0 comments · May be fixed by #372
Open

Decouple formatExperiments from useDatasetManager #361

nozomione opened this issue Sep 9, 2024 · 0 comments · May be fixed by #372
Assignees

Comments

@nozomione
Copy link
Member

nozomione commented Sep 9, 2024

Context

Epic: #358

The formatExperiments method is currently used within the useDatasetManager hook to format the experiments field for the UI. We want to extract this method from the hook and have the data presentation components handle the formatting instead.

e.g., ) The experiments field detailing the dataset's experiments and is mainly used on the dataset page:

experiments: [
   {	
      title: "Drug-induced change in g…agents for 2, 6 and 24h",
      accession_code: "GSE116436",
      organism_names: [],
      sample_metadata: [],
      technology: "MICROARRAY"
    }
]

The formatExperiments function:

// formats the sample and experiment arrays from the API response
// to objects with experiment accession codes as their keys for UI
const formatExperiments = (experiments = []) => {
  if (!experiments.length) return {}

  return experiments.reduce(
    (acc, experiment) => ({
      ...acc,
      [experiment.accession_code]: experiment
    }),
    {}
  )
}

Problem or idea

To achieve this, we should decouple formatExperiments from the useDatasetManager and make it a standalone helper function that can be used in the data presentation components.

Solution or next step

  1. Move the formatExperiments function to a new helper file, helpers/getFormattedExperiments.

  2. Refactor all the useDatasetManager methods to return the API response without formatting

  3. Update the data presentation components to use helpers/getFormattedExperiments for formatting experiments

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