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

Y24-338 - Pacbio libraries store migration from axios to native fetch #2011

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions src/components/pacbio/PacbioLibraryCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
id="create-btn"
theme="create"
:disabled="!selectedSample.sample_name"
@click="createLibrary"
@click="create"
>
Create
</traction-button>
Expand Down Expand Up @@ -121,12 +121,12 @@ const toggleDisplayCreatePanel = () => {
}

/**
* @method createLibrary
* @description Creates a new library by calling the createLibraryInTraction method from the 'pacbioLibraries' store.
* @method create
* @description Creates a new library by calling the create method from the 'pacbioLibraries' store.
* @returns {void} Displays a success message if the library is created successfully, otherwise displays a failure message.
*/
const createLibrary = async () => {
const { success, barcode, errors } = await librariesStore.createLibraryInTraction(
const create = async () => {
const { success, barcode, errors } = await librariesStore.createLibrary(
formRef?.value?.formLibrary,
)
if (success) {
Expand Down
84 changes: 32 additions & 52 deletions src/stores/pacbioLibraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import useRootStore from '@/stores'
import { handleResponse } from '@/api/v1/ResponseHelper.js'
import { groupIncludedByResource, dataToObjectById } from '@/api/JsonApi.js'
import { usePacbioRootStore } from '@/stores/pacbioRoot.js'
import { libraryPayload } from '@/stores//utilities/pacbioLibraries.js'

/**
* @function validateFields
Expand Down Expand Up @@ -44,17 +45,17 @@ export const usePacbioLibrariesStore = defineStore('pacbioLibraries', {
*/
requests: {},
/**
* @property {Object} libraryTags - An object to store all tags from all libraries indexed by id.
* @property {Object} tags - An object to store all tags from all libraries indexed by id.
*/
libraryTags: {},
tags: {},
}),

getters: {
/**
* Transforms the libraries in the state into an array with additional properties.
*
* @function librariesArray
* @param {Object} state - The state object containing libraries, libraryTags, requests, and tubes.
* @param {Object} state - The state object containing libraries, tags, requests, and tubes.
* @returns {Array<Object>} - An array of library objects, each with id, tag_group_id, sample_name, barcode, and other attributes.
*/
librariesArray: (state) => {
Expand All @@ -67,15 +68,15 @@ export const usePacbioLibrariesStore = defineStore('pacbioLibraries', {

/*Get the tag group ID from the library's tag ID or from the tag in pacbioRoot store(where all pacbio tags are kept). Why is this required?
The librariesArray is called in multiple places (in create and edit context) to get the libraries.
Therefore, librariesArray needs to search for the tag first in libraryTags.
Therefore, librariesArray needs to search for the tag first in tags.
If not found, it should then look for it in 'pacbioRoot' store tags.
It's important to note that 'pacbioRoot' store tags will only get populated if a 'pacbioRoot' store action fetchPacbioTagSets is called before,
which may not happen in all the places where it's called.
Hence, a search in both places is required to ensure that librariesArray returns the correct tag
associated with all libraries."*/

const tagGroupId = state.libraryTags[tagId]
? state.libraryTags[tagId].group_id
const tagGroupId = state.tags[tagId]
? state.tags[tagId].group_id
: pacbioRootStore.tags[tagId]
? pacbioRootStore.tags[tagId].group_id
: ''
Expand All @@ -100,35 +101,33 @@ export const usePacbioLibrariesStore = defineStore('pacbioLibraries', {
* @returns {Promise} A promise that resolves when the library is successfully created.
*
* @example
* await createLibraryInTraction(library, tagId);
* await createLibrary(library, tagId);
*/
async createLibraryInTraction(library) {
async createLibrary({
template_prep_kit_box_barcode,
tag_id,
concentration,
volume,
insert_size,
sample: { id: pacbio_request_id },
}) {
const rootState = useRootStore()
const request = rootState.api.v1.traction.pacbio.libraries
const body = {
data: {
type: 'libraries',
attributes: {
pacbio_request_id: library.sample.id,
template_prep_kit_box_barcode: library.template_prep_kit_box_barcode,
tag_id: library.tag_id,
concentration: library.concentration,
volume: library.volume,
insert_size: library.insert_size,
primary_aliquot_attributes: {
template_prep_kit_box_barcode: library.template_prep_kit_box_barcode,
volume: library.volume,
concentration: library.concentration,
insert_size: library.insert_size,
tag_id: library.tag_id,
},
},
},
}
const payload = libraryPayload({
pacbio_request_id,
template_prep_kit_box_barcode,
tag_id,
concentration,
volume,
insert_size,
})

const promise = request.create({
data: body,
data: payload,
include: 'tube,primary_aliquot',
})

console.log(promise)
const { success, data: { included = [] } = {}, errors } = await handleResponse(promise)
const { tubes: [tube = {}] = [] } = groupIncludedByResource(included)
const { attributes: { barcode = '' } = {} } = tube
Expand Down Expand Up @@ -157,7 +156,7 @@ export const usePacbioLibrariesStore = defineStore('pacbioLibraries', {
* @param {number} page - The page number to fetch from the server.
* @returns {Promise<{success: boolean, errors: Array}>} - A promise that resolves to an object containing a success boolean and an array of errors.
*/
async fetchLibraries(filter, page) {
async fetchLibraries(filter = {}, page = {}) {
const rootStore = useRootStore()
const pacbioLibraries = rootStore.api.v1.traction.pacbio.libraries
const promise = pacbioLibraries.get({
Expand All @@ -173,7 +172,7 @@ export const usePacbioLibrariesStore = defineStore('pacbioLibraries', {
const { tubes, tags, requests } = groupIncludedByResource(included)
this.libraries = dataToObjectById({ data, includeRelationships: true })
this.tubes = dataToObjectById({ data: tubes })
this.libraryTags = dataToObjectById({ data: tags })
this.tags = dataToObjectById({ data: tags })
this.requests = dataToObjectById({ data: requests })
}
return { success, errors, meta }
Expand All @@ -195,27 +194,8 @@ export const usePacbioLibrariesStore = defineStore('pacbioLibraries', {

const rootStore = useRootStore()
const request = rootStore.api.v1.traction.pacbio.libraries
const body = {
data: {
type: 'libraries',
id: libraryFields.id,
attributes: {
template_prep_kit_box_barcode: libraryFields.template_prep_kit_box_barcode,
tag_id: libraryFields.tag_id,
concentration: libraryFields.concentration,
volume: libraryFields.volume,
insert_size: libraryFields.insert_size,
primary_aliquot_attributes: {
template_prep_kit_box_barcode: libraryFields.template_prep_kit_box_barcode,
volume: libraryFields.volume,
concentration: libraryFields.concentration,
insert_size: libraryFields.insert_size,
tag_id: libraryFields.tag_id,
},
},
},
}
const promise = request.update(body)
const payload = libraryPayload(libraryFields)
const promise = request.update(payload)
const { success, errors } = await handleResponse(promise)
if (success) {
//Update all fields of the library in the store with matching ID with the given values.
Expand Down
45 changes: 45 additions & 0 deletions src/stores/utilities/pacbioLibraries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const libraryPayload = ({
id,
pacbio_request_id,
template_prep_kit_box_barcode,
tag_id,
concentration,
volume,
insert_size,
}) => {
const requiredAttributes = {
template_prep_kit_box_barcode,
tag_id,
concentration,
volume,
insert_size,
}

return id
? {
data: {
type: 'libraries',
id,
attributes: {
...requiredAttributes,
primary_aliquot_attributes: {
...requiredAttributes,
},
},
},
}
: {
data: {
type: 'libraries',
attributes: {
...requiredAttributes,
pacbio_request_id,
primary_aliquot_attributes: {
...requiredAttributes,
},
},
},
}
}

export { libraryPayload }
6 changes: 0 additions & 6 deletions tests/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import Samples from './samples'
import TestResponse from './testResponse'
import TubeWithLibrary from './tubeWithLibrary'
import CreatePacbioRequest from './createPacbioRequest'
import TractionPacbioLibrary from './tractionPacbioLibrary'
import TractionPacbioLibraries from './tractionPacbioLibraries'
import TractionPacbioLibrariesNoRelationships from './tractionPacbioLibrariesNoRelationships'
import TractionPacbioPool from './tractionPacbioPool.json'
import TractionPacbioPoolsWithAliquots from './tractionPacbioPools.json'
import TractionPacbioPools from './tractionPacbioPools.json'
Expand Down Expand Up @@ -49,13 +46,10 @@ export default {
TestResponse,
TubeWithLibrary,
CreatePacbioRequest,
TractionPacbioLibraries,
TractionPacbioLibrariesNoRelationships,
TractionPacbioPool,
TractionPacbioPools,
TractionPacbioPoolsNoRelationships,
TractionPacbioPoolsWithAliquots,
TractionPacbioLibrary,
TractionPacbioSample,
PacbioRuns,
PacbioRun,
Expand Down
Loading