Skip to content

Commit

Permalink
Merge branch 'master' into cellsets-endpoint-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
aerlaut authored May 9, 2022
2 parents 9a1cfa1 + 15be5fe commit 14afd6d
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
},
}
`;
12 changes: 11 additions & 1 deletion src/components/Loader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => (
Expand Down Expand Up @@ -49,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 ? `/v1/experiments/${experimentId}/backendStatus` : null),
() => (experimentId ? url : null),
fetchAPI,
);

Expand Down
28 changes: 14 additions & 14 deletions src/redux/actions/samples/loadSamples.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from 'redux/actionTypes/samples';

const toApiV1 = (samples, experimentId) => {
const apiV1Samples = [{ samples: {} }];
const apiV1Samples = {};

const buildApiv1Files = (files) => {
const fileNames = [];
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 14afd6d

Please sign in to comment.