From 86392851751cd25996e21f5aef79ad9a7f3c7fac Mon Sep 17 00:00:00 2001 From: cosa65 Date: Mon, 9 May 2022 10:48:17 -0300 Subject: [PATCH 1/3] Add minor fixes for v2 of bakcend status and load sampels --- src/components/Loader.jsx | 5 ++++- src/redux/actions/samples/loadSamples.js | 28 ++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/components/Loader.jsx b/src/components/Loader.jsx index 98b040cc15..586f95b034 100644 --- a/src/components/Loader.jsx +++ b/src/components/Loader.jsx @@ -6,6 +6,9 @@ import useSWR from 'swr'; import fetchAPI from 'utils/http/fetchAPI'; +import config from 'config'; +import { api } from 'utils/constants'; + const { Text } = Typography; const slowLoad = () => ( @@ -50,7 +53,7 @@ const fastLoad = (message) => ( const Loader = ({ experimentId }) => { const { data: workerStatus } = useSWR( - () => (experimentId ? `/v1/experiments/${experimentId}/backendStatus` : null), + () => (experimentId ? `/${config.currentApiVersion}/experiments/${experimentId}/backendStatus` : null), fetchAPI, ); diff --git a/src/redux/actions/samples/loadSamples.js b/src/redux/actions/samples/loadSamples.js index afbd03afdd..7dc67bb22e 100644 --- a/src/redux/actions/samples/loadSamples.js +++ b/src/redux/actions/samples/loadSamples.js @@ -10,7 +10,7 @@ import { } from 'redux/actionTypes/samples'; const toApiV1 = (samples, experimentId) => { - const apiV1Samples = [{ samples: {} }]; + const apiV1Samples = {}; const buildApiv1Files = (files) => { const fileNames = []; @@ -49,7 +49,7 @@ const toApiV1 = (samples, experimentId) => { samples.forEach((sample) => { const { apiV1Files, fileNames } = buildApiv1Files(sample.files); - apiV1Samples[0].samples[sample.id] = { + apiV1Samples[sample.id] = { projectUuid: experimentId, metadata: sample.metadata, createdDate: sample.createdAt, @@ -83,21 +83,21 @@ const loadSamples = ( type: SAMPLES_LOADING, }); - let data = await fetchAPI(url); - - if (currentApiVersion === api.V2) { - data = toApiV1(data, experimentId ?? projectUuid); - } + const data = await fetchAPI(url); let samples; - // Querying using experimentId returns an object with a `samples` key - if (experimentId) samples = data; - - // Querying using projectUuid returns an array with oh objects with of `samples` key - // Data[0] because 1 project contains only 1 experiment right now. - // This has to be changed when we support multiple experiments per project. - if (projectUuid) [{ samples }] = data; + if (currentApiVersion === api.V2) { + samples = toApiV1(data, experimentId ?? projectUuid); + } else { + // Querying using experimentId returns an object with a `samples` key + if (experimentId) samples = data; + + // Querying using projectUuid returns an array with oh objects with of `samples` key + // Data[0] because 1 project contains only 1 experiment right now. + // This has to be changed when we support multiple experiments per project. + if (projectUuid) [{ samples }] = data; + } // throwIfRequestFailed(response, data, endUserMessages.ERROR_FETCHING_SAMPLES); From 6995b7f4a0aff447cf698be28695526fc2caea31 Mon Sep 17 00:00:00 2001 From: cosa65 Date: Mon, 9 May 2022 10:53:50 -0300 Subject: [PATCH 2/3] update --- .../__snapshots__/loadSamples.test.js.snap | 84 +++++++++---------- src/components/Loader.jsx | 9 +- 2 files changed, 48 insertions(+), 45 deletions(-) diff --git a/src/__test__/redux/actions/samples/__snapshots__/loadSamples.test.js.snap b/src/__test__/redux/actions/samples/__snapshots__/loadSamples.test.js.snap index 0b7fe573a6..f1aa572da1 100644 --- a/src/__test__/redux/actions/samples/__snapshots__/loadSamples.test.js.snap +++ b/src/__test__/redux/actions/samples/__snapshots__/loadSamples.test.js.snap @@ -2,54 +2,50 @@ exports[`loadSample action works with apiv2 1`] = ` Object { - "samples": Array [ - Object { - "samples": Object { - "e03ef6ea-5014-4e57-aecd-59964ac9172c": Object { - "createdDate": "2021-12-07 17:36:27.773+00", - "fileNames": Array [ - "matrix.mtx.gz", - "barcodes.tsv.gz", - "features.tsv.gz", - ], - "files": Object { - "barcodes.tsv.gz": Object { - "name": "barcodes.tsv.gz", - "size": undefined, - "upload": Object { - "status": "uploaded", - }, - "valid": true, - }, - "features.tsv.gz": Object { - "name": "features.tsv.gz", - "size": undefined, - "upload": Object { - "status": "uploaded", - }, - "valid": true, - }, - "matrix.mtx.gz": Object { - "name": "matrix.mtx.gz", - "size": undefined, - "upload": Object { - "status": "uploaded", - }, - "valid": true, - }, + "samples": Object { + "e03ef6ea-5014-4e57-aecd-59964ac9172c": Object { + "createdDate": "2021-12-07 17:36:27.773+00", + "fileNames": Array [ + "matrix.mtx.gz", + "barcodes.tsv.gz", + "features.tsv.gz", + ], + "files": Object { + "barcodes.tsv.gz": Object { + "name": "barcodes.tsv.gz", + "size": undefined, + "upload": Object { + "status": "uploaded", }, - "lastModified": "2021-12-07 17:38:42.036+00", - "metadata": Object { - "age": "BL", - "timePoint": "BL", + "valid": true, + }, + "features.tsv.gz": Object { + "name": "features.tsv.gz", + "size": undefined, + "upload": Object { + "status": "uploaded", + }, + "valid": true, + }, + "matrix.mtx.gz": Object { + "name": "matrix.mtx.gz", + "size": undefined, + "upload": Object { + "status": "uploaded", }, - "name": "BLp7", - "projectUuid": "1234", - "type": "10X Chromium", - "uuid": "e03ef6ea-5014-4e57-aecd-59964ac9172c", + "valid": true, }, }, + "lastModified": "2021-12-07 17:38:42.036+00", + "metadata": Object { + "age": "BL", + "timePoint": "BL", + }, + "name": "BLp7", + "projectUuid": "1234", + "type": "10X Chromium", + "uuid": "e03ef6ea-5014-4e57-aecd-59964ac9172c", }, - ], + }, } `; diff --git a/src/components/Loader.jsx b/src/components/Loader.jsx index 586f95b034..8013d11f1c 100644 --- a/src/components/Loader.jsx +++ b/src/components/Loader.jsx @@ -52,8 +52,15 @@ const fastLoad = (message) => ( ); const Loader = ({ experimentId }) => { + let url; + if (config.currentApiVersion === api.V1) { + url = `/v1/experiments/${experimentId}/backendStatus`; + } else if (config.currentApiVersion === api.V2) { + url = `/v2/experiments/${experimentId}/backendStatus`; + } + const { data: workerStatus } = useSWR( - () => (experimentId ? `/${config.currentApiVersion}/experiments/${experimentId}/backendStatus` : null), + () => (experimentId ? url : null), fetchAPI, ); From 021384ee350d091ad612075e8d6af3189d45f868 Mon Sep 17 00:00:00 2001 From: cosa65 Date: Mon, 9 May 2022 11:20:03 -0300 Subject: [PATCH 3/3] Add loader test for v2 --- .../heatmap/HeatmapPlot.test.jsx | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/__test__/components/data-exploration/heatmap/HeatmapPlot.test.jsx b/src/__test__/components/data-exploration/heatmap/HeatmapPlot.test.jsx index 122e6106f6..95b8b6eb5c 100644 --- a/src/__test__/components/data-exploration/heatmap/HeatmapPlot.test.jsx +++ b/src/__test__/components/data-exploration/heatmap/HeatmapPlot.test.jsx @@ -33,6 +33,11 @@ import { setCellSetHiddenStatus } from 'redux/actions/cellSets'; import { isSubset } from 'utils/arrayUtils'; import { updatePlotConfig } from 'redux/actions/componentConfig'; +import config from 'config'; +import { api } from 'utils/constants'; + +jest.mock('config'); + const experimentId = fake.EXPERIMENT_ID; // Mock hash so we can control the ETag that is produced by hash.MD5 when fetching work requests @@ -140,6 +145,21 @@ describe('HeatmapPlot', () => { expect(screen.getByText(/We're getting your data .../i)).toBeInTheDocument(); }); + it('Shows loader message if cellSets are loading in v2', async () => { + config.currentApiVersion = 'v2'; + + const mockLoadingAPIResponses = { + ...mockWorkerResponses, + [`experiments/${experimentId}/cellSets`]: () => delayedResponse({ body: 'Not found', status: 404 }, 4000), + }; + + fetchMock.mockIf(/.*/, mockAPI(mockLoadingAPIResponses)); + + await loadAndRenderDefaultHeatmap(storeState); + + expect(screen.getByText(/We're getting your data .../i)).toBeInTheDocument(); + }); + it('Shows loader message if the marker genes are loading', async () => { const customWorkerResponses = { ...mockWorkerResponses,