From 89b95ca0ff81bb93a67296427d35dedb1db2ae20 Mon Sep 17 00:00:00 2001 From: cosa65 Date: Tue, 19 Jul 2022 17:02:20 -0300 Subject: [PATCH 01/11] Remove metadata delete action dispatch --- .../__snapshots__/updateMetadataTrack.test.js.snap | 4 ---- .../actions/experiments/updateMetadataTrack.test.js | 8 +++----- .../actions/experiments/updateMetadataTrack.js | 13 +------------ 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/__test__/redux/actions/experiments/__snapshots__/updateMetadataTrack.test.js.snap b/src/__test__/redux/actions/experiments/__snapshots__/updateMetadataTrack.test.js.snap index ba32ce124e..be449be42e 100644 --- a/src/__test__/redux/actions/experiments/__snapshots__/updateMetadataTrack.test.js.snap +++ b/src/__test__/redux/actions/experiments/__snapshots__/updateMetadataTrack.test.js.snap @@ -15,9 +15,5 @@ Array [ }, "sampleUuid": "sample-1234", }, - Object { - "metadataKey": "Old_track", - "sampleUuid": "sample-1234", - }, ] `; diff --git a/src/__test__/redux/actions/experiments/updateMetadataTrack.test.js b/src/__test__/redux/actions/experiments/updateMetadataTrack.test.js index 504552df6d..2a5caca445 100644 --- a/src/__test__/redux/actions/experiments/updateMetadataTrack.test.js +++ b/src/__test__/redux/actions/experiments/updateMetadataTrack.test.js @@ -9,12 +9,10 @@ import updateMetadataTrack from 'redux/actions/experiments/updateMetadataTrack'; import initialExperimentState from 'redux/reducers/experiments'; import initialSampleState from 'redux/reducers/samples'; -import { - EXPERIMENTS_METADATA_UPDATE, -} from 'redux/actionTypes/experiments'; +import { EXPERIMENTS_METADATA_UPDATE } from 'redux/actionTypes/experiments'; import '__test__/test-utils/setupTests'; -import { SAMPLES_METADATA_DELETE, SAMPLES_UPDATE } from 'redux/actionTypes/samples'; +import { SAMPLES_UPDATE } from 'redux/actionTypes/samples'; const mockStore = configureStore([thunk]); @@ -75,7 +73,7 @@ describe('updateMetadataTrack action', () => { ); const actions = store.getActions(); - expect(_.map(actions, 'type')).toEqual([EXPERIMENTS_METADATA_UPDATE, SAMPLES_UPDATE, SAMPLES_METADATA_DELETE]); + expect(_.map(actions, 'type')).toEqual([EXPERIMENTS_METADATA_UPDATE, SAMPLES_UPDATE]); expect(_.map(actions, 'payload')).toMatchSnapshot(); expect(fetchMock).toHaveBeenCalledWith( diff --git a/src/redux/actions/experiments/updateMetadataTrack.js b/src/redux/actions/experiments/updateMetadataTrack.js index 45147301ba..691c19fb20 100644 --- a/src/redux/actions/experiments/updateMetadataTrack.js +++ b/src/redux/actions/experiments/updateMetadataTrack.js @@ -1,10 +1,7 @@ import _ from 'lodash'; import { EXPERIMENTS_METADATA_UPDATE } from 'redux/actionTypes/experiments'; -import { - SAMPLES_UPDATE, - SAMPLES_METADATA_DELETE, -} from 'redux/actionTypes/samples'; +import { SAMPLES_UPDATE } from 'redux/actionTypes/samples'; import fetchAPI from 'utils/http/fetchAPI'; @@ -58,14 +55,6 @@ const updateMetadataTrack = ( sample: { metadata: { [newMetadataKey]: samples[sampleUuid].metadata[oldMetadataKey] } }, }, }); - - dispatch({ - type: SAMPLES_METADATA_DELETE, - payload: { - metadataKey: oldMetadataKey, - sampleUuid, - }, - }); }); } catch (e) { pushNotificationMessage('error', endUserMessages.ERROR_SAVING); From 5e717a692969ef8b0a4287cea3be35b027b94fca Mon Sep 17 00:00:00 2001 From: cosa65 Date: Tue, 19 Jul 2022 18:48:18 -0300 Subject: [PATCH 02/11] Move metadata track key rename to reducer --- ....snap => renameMetadataTrack.test.js.snap} | 2 +- ...ck.test.js => renameMetadataTrack.test.js} | 10 ++++----- .../redux/reducers/experimentsReducer.test.js | 4 ++-- .../data-management/MetadataColumn.jsx | 4 ++-- src/redux/actionTypes/experiments.js | 4 ++-- src/redux/actions/experiments/index.js | 4 ++-- ...etadataTrack.js => renameMetadataTrack.js} | 20 ++++------------- .../experiments/experimentsMetadataDelete.js | 4 ++-- ...Update.js => experimentsMetadataRename.js} | 4 ++-- src/redux/reducers/experiments/index.js | 8 +++---- .../samples/experimentsMetadataRename.js | 22 +++++++++++++++++++ src/redux/reducers/samples/index.js | 7 ++++++ src/utils/validateInputs.js | 3 +++ 13 files changed, 58 insertions(+), 38 deletions(-) rename src/__test__/redux/actions/experiments/__snapshots__/{updateMetadataTrack.test.js.snap => renameMetadataTrack.test.js.snap} (83%) rename src/__test__/redux/actions/experiments/{updateMetadataTrack.test.js => renameMetadataTrack.test.js} (89%) rename src/redux/actions/experiments/{updateMetadataTrack.js => renameMetadataTrack.js} (70%) rename src/redux/reducers/experiments/{experimentsMetadataUpdate.js => experimentsMetadataRename.js} (74%) create mode 100644 src/redux/reducers/samples/experimentsMetadataRename.js diff --git a/src/__test__/redux/actions/experiments/__snapshots__/updateMetadataTrack.test.js.snap b/src/__test__/redux/actions/experiments/__snapshots__/renameMetadataTrack.test.js.snap similarity index 83% rename from src/__test__/redux/actions/experiments/__snapshots__/updateMetadataTrack.test.js.snap rename to src/__test__/redux/actions/experiments/__snapshots__/renameMetadataTrack.test.js.snap index be449be42e..58e7808111 100644 --- a/src/__test__/redux/actions/experiments/__snapshots__/updateMetadataTrack.test.js.snap +++ b/src/__test__/redux/actions/experiments/__snapshots__/renameMetadataTrack.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`updateMetadataTrack action Works correctly 1`] = ` +exports[`renameMetadataTrack action Works correctly 1`] = ` Array [ Object { "experimentId": "experiment-1234", diff --git a/src/__test__/redux/actions/experiments/updateMetadataTrack.test.js b/src/__test__/redux/actions/experiments/renameMetadataTrack.test.js similarity index 89% rename from src/__test__/redux/actions/experiments/updateMetadataTrack.test.js rename to src/__test__/redux/actions/experiments/renameMetadataTrack.test.js index 2a5caca445..139c495b52 100644 --- a/src/__test__/redux/actions/experiments/updateMetadataTrack.test.js +++ b/src/__test__/redux/actions/experiments/renameMetadataTrack.test.js @@ -5,11 +5,11 @@ import thunk from 'redux-thunk'; import fetchMock, { enableFetchMocks } from 'jest-fetch-mock'; import { metadataNameToKey } from 'utils/data-management/metadataUtils'; -import updateMetadataTrack from 'redux/actions/experiments/updateMetadataTrack'; +import renameMetadataTrack from 'redux/actions/experiments/renameMetadataTrack'; import initialExperimentState from 'redux/reducers/experiments'; import initialSampleState from 'redux/reducers/samples'; -import { EXPERIMENTS_METADATA_UPDATE } from 'redux/actionTypes/experiments'; +import { EXPERIMENTS_METADATA_RENAME } from 'redux/actionTypes/experiments'; import '__test__/test-utils/setupTests'; import { SAMPLES_UPDATE } from 'redux/actionTypes/samples'; @@ -56,7 +56,7 @@ const initialState = { }, }; -describe('updateMetadataTrack action', () => { +describe('renameMetadataTrack action', () => { beforeEach(() => { enableFetchMocks(); fetchMock.resetMocks(); @@ -69,11 +69,11 @@ describe('updateMetadataTrack action', () => { fetchMock.mockResolvedValue(new Response(JSON.stringify({}))); await store.dispatch( - updateMetadataTrack(oldMetadataTrack, newMetadataTrack, mockExperiment.id), + renameMetadataTrack(oldMetadataTrack, newMetadataTrack, mockExperiment.id), ); const actions = store.getActions(); - expect(_.map(actions, 'type')).toEqual([EXPERIMENTS_METADATA_UPDATE, SAMPLES_UPDATE]); + expect(_.map(actions, 'type')).toEqual([EXPERIMENTS_METADATA_RENAME, SAMPLES_UPDATE]); expect(_.map(actions, 'payload')).toMatchSnapshot(); expect(fetchMock).toHaveBeenCalledWith( diff --git a/src/__test__/redux/reducers/experimentsReducer.test.js b/src/__test__/redux/reducers/experimentsReducer.test.js index 0fd09bb2cd..81f89f5c44 100644 --- a/src/__test__/redux/reducers/experimentsReducer.test.js +++ b/src/__test__/redux/reducers/experimentsReducer.test.js @@ -12,7 +12,7 @@ import { EXPERIMENTS_DELETED, EXPERIMENTS_SAVING, EXPERIMENTS_METADATA_CREATE, - EXPERIMENTS_METADATA_UPDATE, + EXPERIMENTS_METADATA_RENAME, EXPERIMENTS_METADATA_DELETE, } from 'redux/actionTypes/experiments'; @@ -329,7 +329,7 @@ describe('experimentsReducer', () => { }; const newState = experimentsReducer(stateWithMetadata, { - type: EXPERIMENTS_METADATA_UPDATE, + type: EXPERIMENTS_METADATA_RENAME, payload: { oldKey: oldMetadataKey, newKey: newMetadataKey, diff --git a/src/components/data-management/MetadataColumn.jsx b/src/components/data-management/MetadataColumn.jsx index 8693959ecc..c8e12a9aed 100644 --- a/src/components/data-management/MetadataColumn.jsx +++ b/src/components/data-management/MetadataColumn.jsx @@ -3,7 +3,7 @@ import { Space, Input } from 'antd'; import { useDispatch } from 'react-redux'; import PropTypes from 'prop-types'; -import { updateMetadataTrack } from 'redux/actions/experiments'; +import { renameMetadataTrack } from 'redux/actions/experiments'; import validateInputs, { rules } from 'utils/validateInputs'; import { metadataNameToKey } from 'utils/data-management/metadataUtils'; @@ -62,7 +62,7 @@ const MetadataTitle = (props) => { deleteEnabled onDelete={(e, currentName) => deleteMetadataColumn(currentName)} onAfterSubmit={(newName) => dispatch( - updateMetadataTrack(name, newName, activeExperimentId), + renameMetadataTrack(name, newName, activeExperimentId), )} value={name} validationFunc={ diff --git a/src/redux/actionTypes/experiments.js b/src/redux/actionTypes/experiments.js index d1f24fbffc..21546b1bff 100644 --- a/src/redux/actionTypes/experiments.js +++ b/src/redux/actionTypes/experiments.js @@ -50,7 +50,7 @@ const EXPERIMENTS_METADATA_CREATE = `${EXPERIMENTS}/metadataCreate`; /** * Update project metadata. */ -const EXPERIMENTS_METADATA_UPDATE = `${EXPERIMENTS}/metadataUpdate`; +const EXPERIMENTS_METADATA_RENAME = `${EXPERIMENTS}/metadataRename`; /** * Delete project metadta. @@ -68,6 +68,6 @@ export { EXPERIMENTS_SWITCH, EXPERIMENTS_SET_ACTIVE, EXPERIMENTS_METADATA_CREATE, - EXPERIMENTS_METADATA_UPDATE, + EXPERIMENTS_METADATA_RENAME, EXPERIMENTS_METADATA_DELETE, }; diff --git a/src/redux/actions/experiments/index.js b/src/redux/actions/experiments/index.js index a4f76d71ef..0709f1b491 100644 --- a/src/redux/actions/experiments/index.js +++ b/src/redux/actions/experiments/index.js @@ -6,7 +6,7 @@ import setActiveExperiment from './setActiveExperiment'; import switchExperiment from './switchExperiment'; import reorderSamples from './reorderSamples'; import createMetadataTrack from './createMetadataTrack'; -import updateMetadataTrack from './updateMetadataTrack'; +import renameMetadataTrack from './renameMetadataTrack'; import deleteMetadataTrack from './deleteMetadataTrack'; import updateValueInMetadataTrack from './updateValueInMetadataTrack'; @@ -19,7 +19,7 @@ export { switchExperiment, reorderSamples, createMetadataTrack, - updateMetadataTrack, + renameMetadataTrack, deleteMetadataTrack, updateValueInMetadataTrack, }; diff --git a/src/redux/actions/experiments/updateMetadataTrack.js b/src/redux/actions/experiments/renameMetadataTrack.js similarity index 70% rename from src/redux/actions/experiments/updateMetadataTrack.js rename to src/redux/actions/experiments/renameMetadataTrack.js index 691c19fb20..608192bc4a 100644 --- a/src/redux/actions/experiments/updateMetadataTrack.js +++ b/src/redux/actions/experiments/renameMetadataTrack.js @@ -1,7 +1,6 @@ import _ from 'lodash'; -import { EXPERIMENTS_METADATA_UPDATE } from 'redux/actionTypes/experiments'; -import { SAMPLES_UPDATE } from 'redux/actionTypes/samples'; +import { EXPERIMENTS_METADATA_RENAME } from 'redux/actionTypes/experiments'; import fetchAPI from 'utils/http/fetchAPI'; @@ -9,10 +8,9 @@ import { metadataNameToKey } from 'utils/data-management/metadataUtils'; import endUserMessages from 'utils/endUserMessages'; import pushNotificationMessage from 'utils/pushNotificationMessage'; -const updateMetadataTrack = ( +const renameMetadataTrack = ( oldName, newName, experimentId, ) => async (dispatch, getState) => { - const { samples } = getState(); const experiment = getState().experiments[experimentId]; const oldMetadataKey = metadataNameToKey(oldName); @@ -39,26 +37,16 @@ const updateMetadataTrack = ( ); dispatch({ - type: EXPERIMENTS_METADATA_UPDATE, + type: EXPERIMENTS_METADATA_RENAME, payload: { oldKey: oldMetadataKey, newKey: newMetadataKey, experimentId, }, }); - - experiment.sampleIds.forEach((sampleUuid) => { - dispatch({ - type: SAMPLES_UPDATE, - payload: { - sampleUuid, - sample: { metadata: { [newMetadataKey]: samples[sampleUuid].metadata[oldMetadataKey] } }, - }, - }); - }); } catch (e) { pushNotificationMessage('error', endUserMessages.ERROR_SAVING); } }; -export default updateMetadataTrack; +export default renameMetadataTrack; diff --git a/src/redux/reducers/experiments/experimentsMetadataDelete.js b/src/redux/reducers/experiments/experimentsMetadataDelete.js index 4609efca3e..8ab035aab0 100644 --- a/src/redux/reducers/experiments/experimentsMetadataDelete.js +++ b/src/redux/reducers/experiments/experimentsMetadataDelete.js @@ -1,4 +1,4 @@ -const projectsMetadataDelete = (state, action) => { +const experimentsMetadataDelete = (state, action) => { const { key, experimentId } = action.payload; return { @@ -12,4 +12,4 @@ const projectsMetadataDelete = (state, action) => { }; }; -export default projectsMetadataDelete; +export default experimentsMetadataDelete; diff --git a/src/redux/reducers/experiments/experimentsMetadataUpdate.js b/src/redux/reducers/experiments/experimentsMetadataRename.js similarity index 74% rename from src/redux/reducers/experiments/experimentsMetadataUpdate.js rename to src/redux/reducers/experiments/experimentsMetadataRename.js index be4e401073..37940b1aba 100644 --- a/src/redux/reducers/experiments/experimentsMetadataUpdate.js +++ b/src/redux/reducers/experiments/experimentsMetadataRename.js @@ -1,4 +1,4 @@ -const projectsMetadataUpdate = (state, action) => { +const experimentsMetadataRename = (state, action) => { const { oldKey, newKey, experimentId } = action.payload; return { @@ -13,4 +13,4 @@ const projectsMetadataUpdate = (state, action) => { }; }; -export default projectsMetadataUpdate; +export default experimentsMetadataRename; diff --git a/src/redux/reducers/experiments/index.js b/src/redux/reducers/experiments/index.js index 2dc5fd5e75..1fd595824d 100644 --- a/src/redux/reducers/experiments/index.js +++ b/src/redux/reducers/experiments/index.js @@ -9,7 +9,7 @@ import { EXPERIMENTS_DELETED, EXPERIMENTS_METADATA_CREATE, EXPERIMENTS_METADATA_DELETE, - EXPERIMENTS_METADATA_UPDATE, + EXPERIMENTS_METADATA_RENAME, EXPERIMENTS_SET_ACTIVE, } from 'redux/actionTypes/experiments'; @@ -26,7 +26,7 @@ import experimentsLoaded from './experimentsLoaded'; import experimentsError from './experimentsError'; import experimentsSaving from './experimentsSaving'; import experimentsMetadataCreate from './experimentsMetadataCreate'; -import experimentsMetadataUpdate from './experimentsMetadataUpdate'; +import experimentsMetadataRename from './experimentsMetadataRename'; import experimentsMetadataDelete from './experimentsMetadataDelete'; import samplesCreate from './samplesCreate'; @@ -78,8 +78,8 @@ const experimentsReducer = (state = initialState, action) => { return experimentsMetadataCreate(state, action); } - case EXPERIMENTS_METADATA_UPDATE: { - return experimentsMetadataUpdate(state, action); + case EXPERIMENTS_METADATA_RENAME: { + return experimentsMetadataRename(state, action); } case EXPERIMENTS_METADATA_DELETE: { diff --git a/src/redux/reducers/samples/experimentsMetadataRename.js b/src/redux/reducers/samples/experimentsMetadataRename.js new file mode 100644 index 0000000000..cb822e1a7c --- /dev/null +++ b/src/redux/reducers/samples/experimentsMetadataRename.js @@ -0,0 +1,22 @@ +/* eslint-disable no-param-reassign */ +import produce, { original } from 'immer'; + +const experimentsMetadataRename = produce((draft, action) => { + const { oldKey, newKey, experimentId } = action.payload; + + const { meta, ...samples } = original(draft); + + const sampleEntries = Object.entries(samples); + + const sampleIdsFromExperiment = sampleEntries + .filter(([, { experimentId: currentExpId }]) => currentExpId === experimentId) + .map(([sampleId]) => sampleId); + + // Move the metadata in oldKey to newKey and then remove the old one + sampleIdsFromExperiment.forEach((sampleId) => { + draft[sampleId].metadata[newKey] = draft[sampleId].metadata[oldKey]; + delete draft[sampleId].metadata[oldKey]; + }); +}); + +export default experimentsMetadataRename; diff --git a/src/redux/reducers/samples/index.js b/src/redux/reducers/samples/index.js index abd4b82c5a..45174cefb9 100644 --- a/src/redux/reducers/samples/index.js +++ b/src/redux/reducers/samples/index.js @@ -1,3 +1,4 @@ +import { EXPERIMENTS_METADATA_RENAME } from 'redux/actionTypes/experiments'; import { SAMPLES_CREATE, SAMPLES_UPDATE, @@ -24,6 +25,8 @@ import samplesMetadataDelete from './samplesMetadataDelete'; import samplesLoading from './samplesLoading'; import samplesValueInMetadataTrackUpdated from './samplesValueInMetadataTrackUpdated'; +import experimentsMetadataRename from './experimentsMetadataRename'; + const samplesReducer = (state = initialState, action) => { switch (action.type) { case SAMPLES_CREATE: { @@ -70,6 +73,10 @@ const samplesReducer = (state = initialState, action) => { return samplesValueInMetadataTrackUpdated(state, action); } + case EXPERIMENTS_METADATA_RENAME: { + return experimentsMetadataRename(state, action); + } + default: { return state; } diff --git a/src/utils/validateInputs.js b/src/utils/validateInputs.js index 0761b39312..8c5fb4f831 100644 --- a/src/utils/validateInputs.js +++ b/src/utils/validateInputs.js @@ -72,6 +72,9 @@ const validationFns = { [rules.UNIQUE_NAME_CASE_INSENSITIVE](checkName, input, params) { if (!params?.existingNames || params.existingNames.length === 0) return true; + console.log('paramsDebug'); + console.log(params); + const { existingNames } = params; const existingNamesArr = existingNames instanceof Set From 4420bb46b4f8b303ac8191fd0d4d11e09267d5fa Mon Sep 17 00:00:00 2001 From: cosa65 Date: Tue, 19 Jul 2022 18:49:07 -0300 Subject: [PATCH 03/11] Make experimentsMetadataRename reducer in experiments slice not change the position of the renamed track --- .../reducers/experiments/experimentsMetadataRename.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/redux/reducers/experiments/experimentsMetadataRename.js b/src/redux/reducers/experiments/experimentsMetadataRename.js index 37940b1aba..3ebaeacc52 100644 --- a/src/redux/reducers/experiments/experimentsMetadataRename.js +++ b/src/redux/reducers/experiments/experimentsMetadataRename.js @@ -1,14 +1,16 @@ const experimentsMetadataRename = (state, action) => { const { oldKey, newKey, experimentId } = action.payload; + const { metadataKeys } = state[experimentId]; + const newMetadataKeys = metadataKeys.map((metadataKey) => ( + metadataKey === oldKey ? newKey : metadataKey + )); + return { ...state, [experimentId]: { ...state[experimentId], - metadataKeys: [ - ...state[experimentId].metadataKeys.filter((value) => value !== oldKey), - newKey, - ], + metadataKeys: newMetadataKeys, }, }; }; From f189152010dbe61d8f797d29b3f50af6e8e4bab5 Mon Sep 17 00:00:00 2001 From: cosa65 Date: Tue, 19 Jul 2022 19:02:29 -0300 Subject: [PATCH 04/11] Add some checks to wait for the sampleIds of the active experiment to be loaded before initializin the metadata columns --- .../data-management/LaunchAnalysisButton.jsx | 1 + src/components/data-management/SamplesTable.jsx | 11 +++++++++-- src/utils/validateInputs.js | 3 --- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/data-management/LaunchAnalysisButton.jsx b/src/components/data-management/LaunchAnalysisButton.jsx index 06f5291caf..fb9ed4c6d6 100644 --- a/src/components/data-management/LaunchAnalysisButton.jsx +++ b/src/components/data-management/LaunchAnalysisButton.jsx @@ -104,6 +104,7 @@ const LaunchAnalysisButton = () => { const allSampleMetadataInserted = (sample) => { if (!metadataKeysAvailable) return true; + if (Object.keys(sample.metadata).length !== metadataKeysAvailable) return false; return Object.values(sample.metadata) .every((value) => value.length > 0); diff --git a/src/components/data-management/SamplesTable.jsx b/src/components/data-management/SamplesTable.jsx index 2abf47990e..423bbe7ff0 100644 --- a/src/components/data-management/SamplesTable.jsx +++ b/src/components/data-management/SamplesTable.jsx @@ -96,9 +96,16 @@ const SamplesTable = forwardRef((props, ref) => { const [tableColumns, setTableColumns] = useState(initialTableColumns); useEffect(() => { - if (activeExperiment.sampleIds.length > 0) { + const samplesLoaded = activeExperiment?.sampleIds.every((sampleId) => samples[sampleId]); + + if (activeExperiment?.sampleIds.length > 0 && samplesLoaded) { // if there are samples - build the table columns - setSampleNames(new Set(activeExperiment.sampleIds.map((id) => samples[id]?.name.trim()))); + + const sanitizedSampleNames = new Set( + activeExperiment.sampleIds.map((id) => samples[id]?.name.trim()), + ); + + setSampleNames(sanitizedSampleNames); const metadataColumns = activeExperiment.metadataKeys.map( (metadataKey) => createInitializedMetadataColumn(metadataKeyToName(metadataKey)), ) || []; diff --git a/src/utils/validateInputs.js b/src/utils/validateInputs.js index 8c5fb4f831..0761b39312 100644 --- a/src/utils/validateInputs.js +++ b/src/utils/validateInputs.js @@ -72,9 +72,6 @@ const validationFns = { [rules.UNIQUE_NAME_CASE_INSENSITIVE](checkName, input, params) { if (!params?.existingNames || params.existingNames.length === 0) return true; - console.log('paramsDebug'); - console.log(params); - const { existingNames } = params; const existingNamesArr = existingNames instanceof Set From f898fe72a4e161f3b5f4913ab578ba86668dd919 Mon Sep 17 00:00:00 2001 From: cosa65 Date: Tue, 19 Jul 2022 19:08:13 -0300 Subject: [PATCH 05/11] Fix so it works with newKey === oldKey --- src/redux/reducers/samples/experimentsMetadataRename.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/redux/reducers/samples/experimentsMetadataRename.js b/src/redux/reducers/samples/experimentsMetadataRename.js index cb822e1a7c..c5263bffa7 100644 --- a/src/redux/reducers/samples/experimentsMetadataRename.js +++ b/src/redux/reducers/samples/experimentsMetadataRename.js @@ -14,8 +14,11 @@ const experimentsMetadataRename = produce((draft, action) => { // Move the metadata in oldKey to newKey and then remove the old one sampleIdsFromExperiment.forEach((sampleId) => { - draft[sampleId].metadata[newKey] = draft[sampleId].metadata[oldKey]; + const value = draft[sampleId].metadata[oldKey]; + delete draft[sampleId].metadata[oldKey]; + + draft[sampleId].metadata[newKey] = value; }); }); From 8036371d37621be8619031da27789d84476c9985 Mon Sep 17 00:00:00 2001 From: cosa65 Date: Tue, 19 Jul 2022 19:39:32 -0300 Subject: [PATCH 06/11] Update test --- .../data-management/SamplesTable.test.jsx | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/__test__/components/data-management/SamplesTable.test.jsx b/src/__test__/components/data-management/SamplesTable.test.jsx index 4c3ef1cf9c..2cf775d21c 100644 --- a/src/__test__/components/data-management/SamplesTable.test.jsx +++ b/src/__test__/components/data-management/SamplesTable.test.jsx @@ -102,6 +102,7 @@ describe('Samples table', () => { storeState = makeStore(); + await storeState.dispatch(loadUser()); await storeState.dispatch(loadExperiments()); // Loading experiment is usually called in Data Management, so we have to load them manually @@ -110,8 +111,6 @@ describe('Samples table', () => { // Defaults to project with samples await storeState.dispatch(setActiveExperiment(experimentWithSamplesId)); await storeState.dispatch(loadDeploymentInfo({ environment: 'test' })); - - await storeState.dispatch(loadUser()); }); it('Does not show prompt to upload datasets if samples are available', async () => { @@ -129,24 +128,22 @@ describe('Samples table', () => { }); }); - it('Should show an error if a sample fails to upload', async () => { + it('Should not show the samples until they are loaded', async () => { const missingSampleState = _.cloneDeep(storeState.getState()); + const createMockStore = configureMockStore([thunk]); - // Delete one of the samples + // Remove one of the samples of the experiment const deletedSampleUuid = Object.keys(missingSampleState.samples).find((key) => key !== 'meta'); - const deletedSampleObject = missingSampleState.samples[deletedSampleUuid]; delete missingSampleState.samples[deletedSampleUuid]; const missingSampleStore = createMockStore(missingSampleState); await renderSamplesTable(missingSampleStore); - // The sample name should not be in the document - expect(screen.queryByText(deletedSampleObject.name)).toBeNull(); - - // There should be an error entry for the missing sample - expect(screen.getByText(/UPLOAD ERROR: Please reupload sample/i)).toBeInTheDocument(); + Object.values(samples).forEach((sample) => { + expect(screen.queryByText(sample.name)).not.toBeInTheDocument(); + }); }); it('Renaming the sample renames the sample', async () => { From 613978c6f7a2d488d9a469208ecd2821acc919e0 Mon Sep 17 00:00:00 2001 From: cosa65 Date: Tue, 19 Jul 2022 19:52:18 -0300 Subject: [PATCH 07/11] Fix experimentsReducer --- .../experimentsReducer.test.js.snap | 42 +------------------ .../redux/reducers/experimentsReducer.test.js | 8 ++-- .../experiments/experimentsMetadataRename.js | 1 + 3 files changed, 6 insertions(+), 45 deletions(-) diff --git a/src/__test__/redux/reducers/__snapshots__/experimentsReducer.test.js.snap b/src/__test__/redux/reducers/__snapshots__/experimentsReducer.test.js.snap index a987f82546..4e651f47e6 100644 --- a/src/__test__/redux/reducers/__snapshots__/experimentsReducer.test.js.snap +++ b/src/__test__/redux/reducers/__snapshots__/experimentsReducer.test.js.snap @@ -53,18 +53,6 @@ Object { exports[`experimentsReducer Correctly creates project metadata 1`] = ` Object { - "[object Object]": Object { - "createdAt": "2021-01-01", - "description": "this is a test description", - "id": "experiment-1", - "metadataKeys": Array [], - "name": "experiment 1", - "notifyByEmail": true, - "sampleIds": Array [ - "testSampleId", - ], - "updatedAt": "2022-01-17", - }, "experiment-1": Object { "createdAt": "2021-01-01", "description": "this is a test description", @@ -92,20 +80,6 @@ Object { exports[`experimentsReducer Correctly deletes project metadata 1`] = ` Object { - "[object Object]": Object { - "createdAt": "2021-01-01", - "description": "this is a test description", - "id": "experiment-1", - "metadataKeys": Array [ - "metadata-old", - ], - "name": "experiment 1", - "notifyByEmail": true, - "sampleIds": Array [ - "testSampleId", - ], - "updatedAt": "2022-01-17", - }, "experiment-1": Object { "createdAt": "2021-01-01", "description": "this is a test description", @@ -129,22 +103,8 @@ Object { } `; -exports[`experimentsReducer Correctly updates project metadata 1`] = ` +exports[`experimentsReducer Correctly updates experiment metadata 1`] = ` Object { - "[object Object]": Object { - "createdAt": "2021-01-01", - "description": "this is a test description", - "id": "experiment-1", - "metadataKeys": Array [ - "metadata-old", - ], - "name": "experiment 1", - "notifyByEmail": true, - "sampleIds": Array [ - "testSampleId", - ], - "updatedAt": "2022-01-17", - }, "experiment-1": Object { "createdAt": "2021-01-01", "description": "this is a test description", diff --git a/src/__test__/redux/reducers/experimentsReducer.test.js b/src/__test__/redux/reducers/experimentsReducer.test.js index 81f89f5c44..e2b29aa670 100644 --- a/src/__test__/redux/reducers/experimentsReducer.test.js +++ b/src/__test__/redux/reducers/experimentsReducer.test.js @@ -299,7 +299,7 @@ describe('experimentsReducer', () => { const stateWithMetadata = { ...oneExperimentWithSampleState, - [oneExperimentWithSampleState[experiment1.id]]: { + [experiment1.id]: { ...oneExperimentWithSampleState[experiment1.id], metadataKeys: [], }, @@ -317,12 +317,12 @@ describe('experimentsReducer', () => { expect(newState).toMatchSnapshot(); }); - it('Correctly updates project metadata', () => { + it('Correctly updates experiment metadata', () => { const oldMetadataKey = 'metadata-old'; const newMetadataKey = 'metadata-new'; const stateWithMetadata = { ...oneExperimentWithSampleState, - [oneExperimentWithSampleState[experiment1.id]]: { + [experiment1.id]: { ...oneExperimentWithSampleState[experiment1.id], metadataKeys: [oldMetadataKey], }, @@ -345,7 +345,7 @@ describe('experimentsReducer', () => { const metadataKey = 'metadata-old'; const stateWithMetadata = { ...oneExperimentWithSampleState, - [oneExperimentWithSampleState[experiment1.id]]: { + [experiment1.id]: { ...oneExperimentWithSampleState[experiment1.id], metadataKeys: [metadataKey], }, diff --git a/src/redux/reducers/experiments/experimentsMetadataRename.js b/src/redux/reducers/experiments/experimentsMetadataRename.js index 3ebaeacc52..1c900c339a 100644 --- a/src/redux/reducers/experiments/experimentsMetadataRename.js +++ b/src/redux/reducers/experiments/experimentsMetadataRename.js @@ -2,6 +2,7 @@ const experimentsMetadataRename = (state, action) => { const { oldKey, newKey, experimentId } = action.payload; const { metadataKeys } = state[experimentId]; + const newMetadataKeys = metadataKeys.map((metadataKey) => ( metadataKey === oldKey ? newKey : metadataKey )); From 6fd610bec0272520d4e694458cfd1f68432fa638 Mon Sep 17 00:00:00 2001 From: cosa65 Date: Tue, 19 Jul 2022 19:53:22 -0300 Subject: [PATCH 08/11] Rename some tests --- .../reducers/__snapshots__/experimentsReducer.test.js.snap | 4 ++-- src/__test__/redux/reducers/experimentsReducer.test.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/__test__/redux/reducers/__snapshots__/experimentsReducer.test.js.snap b/src/__test__/redux/reducers/__snapshots__/experimentsReducer.test.js.snap index 4e651f47e6..828d161a17 100644 --- a/src/__test__/redux/reducers/__snapshots__/experimentsReducer.test.js.snap +++ b/src/__test__/redux/reducers/__snapshots__/experimentsReducer.test.js.snap @@ -51,7 +51,7 @@ Object { } `; -exports[`experimentsReducer Correctly creates project metadata 1`] = ` +exports[`experimentsReducer Correctly creates experiment metadata 1`] = ` Object { "experiment-1": Object { "createdAt": "2021-01-01", @@ -78,7 +78,7 @@ Object { } `; -exports[`experimentsReducer Correctly deletes project metadata 1`] = ` +exports[`experimentsReducer Correctly deletes experiment metadata 1`] = ` Object { "experiment-1": Object { "createdAt": "2021-01-01", diff --git a/src/__test__/redux/reducers/experimentsReducer.test.js b/src/__test__/redux/reducers/experimentsReducer.test.js index e2b29aa670..fda67e58fc 100644 --- a/src/__test__/redux/reducers/experimentsReducer.test.js +++ b/src/__test__/redux/reducers/experimentsReducer.test.js @@ -294,7 +294,7 @@ describe('experimentsReducer', () => { expect(newState).toMatchSnapshot(); }); - it('Correctly creates project metadata', () => { + it('Correctly creates experiment metadata', () => { const newMetadataKey = 'metadata-test'; const stateWithMetadata = { @@ -341,7 +341,7 @@ describe('experimentsReducer', () => { expect(newState).toMatchSnapshot(); }); - it('Correctly deletes project metadata', () => { + it('Correctly deletes experiment metadata', () => { const metadataKey = 'metadata-old'; const stateWithMetadata = { ...oneExperimentWithSampleState, From b6f3181cd162f2f23978c6c5213d4ae874b107c0 Mon Sep 17 00:00:00 2001 From: cosa65 Date: Tue, 19 Jul 2022 19:58:26 -0300 Subject: [PATCH 09/11] Fix test --- .../__snapshots__/renameMetadataTrack.test.js.snap | 8 -------- .../redux/actions/experiments/renameMetadataTrack.test.js | 4 +--- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/__test__/redux/actions/experiments/__snapshots__/renameMetadataTrack.test.js.snap b/src/__test__/redux/actions/experiments/__snapshots__/renameMetadataTrack.test.js.snap index 58e7808111..70644a495e 100644 --- a/src/__test__/redux/actions/experiments/__snapshots__/renameMetadataTrack.test.js.snap +++ b/src/__test__/redux/actions/experiments/__snapshots__/renameMetadataTrack.test.js.snap @@ -7,13 +7,5 @@ Array [ "newKey": "New_track", "oldKey": "Old_track", }, - Object { - "sample": Object { - "metadata": Object { - "New_track": "value", - }, - }, - "sampleUuid": "sample-1234", - }, ] `; diff --git a/src/__test__/redux/actions/experiments/renameMetadataTrack.test.js b/src/__test__/redux/actions/experiments/renameMetadataTrack.test.js index 139c495b52..cae5f08007 100644 --- a/src/__test__/redux/actions/experiments/renameMetadataTrack.test.js +++ b/src/__test__/redux/actions/experiments/renameMetadataTrack.test.js @@ -12,8 +12,6 @@ import initialSampleState from 'redux/reducers/samples'; import { EXPERIMENTS_METADATA_RENAME } from 'redux/actionTypes/experiments'; import '__test__/test-utils/setupTests'; -import { SAMPLES_UPDATE } from 'redux/actionTypes/samples'; - const mockStore = configureStore([thunk]); const mockExperimentId = 'experiment-1234'; @@ -73,7 +71,7 @@ describe('renameMetadataTrack action', () => { ); const actions = store.getActions(); - expect(_.map(actions, 'type')).toEqual([EXPERIMENTS_METADATA_RENAME, SAMPLES_UPDATE]); + expect(_.map(actions, 'type')).toEqual([EXPERIMENTS_METADATA_RENAME]); expect(_.map(actions, 'payload')).toMatchSnapshot(); expect(fetchMock).toHaveBeenCalledWith( From 44c9121d0c3fa47f6c80b3b149ae4bfe0b649348 Mon Sep 17 00:00:00 2001 From: cosa65 Date: Wed, 20 Jul 2022 09:09:01 -0300 Subject: [PATCH 10/11] Add test --- .../__snapshots__/samplesReducer.test.js.snap | 46 ++++++---------- .../redux/reducers/experimentsReducer.test.js | 2 +- .../redux/reducers/samplesReducer.test.js | 55 ++++++++++--------- 3 files changed, 47 insertions(+), 56 deletions(-) diff --git a/src/__test__/redux/reducers/__snapshots__/samplesReducer.test.js.snap b/src/__test__/redux/reducers/__snapshots__/samplesReducer.test.js.snap index 7fe9d2725b..009f44e02c 100644 --- a/src/__test__/redux/reducers/__snapshots__/samplesReducer.test.js.snap +++ b/src/__test__/redux/reducers/__snapshots__/samplesReducer.test.js.snap @@ -87,6 +87,22 @@ Object { } `; +exports[`samplesReducer Handles experimentMetadataRename correctly 1`] = ` +Object { + "asd123": Object { + "experimentId": "mockExpId", + "metadata": Object { + "metadata-new": "value", + }, + }, + "meta": Object { + "error": false, + "loading": false, + "saving": false, + }, +} +`; + exports[`samplesReducer Handles samplesValueInMetadataTrackUpdated correctly 1`] = ` Object { "asd123": Object { @@ -324,33 +340,3 @@ Object { }, } `; - -exports[`samplesReducer Updates sample metadata correctly 1`] = ` -Object { - "[object Object]": Object { - "metadata": Object { - "metadata-test": "old-value", - }, - }, - "asd123": Object { - "complete": false, - "createdDate": "2021-01-01T14:48:00.000Z", - "error": false, - "experimentId": null, - "fileNames": Array [], - "files": Object {}, - "lastModified": "2021-01-01T14:48:00.000Z", - "metadata": Object { - "metadata-test": "new-value", - }, - "name": "test sample", - "type": null, - "uuid": "asd123", - }, - "meta": Object { - "error": false, - "loading": false, - "saving": false, - }, -} -`; diff --git a/src/__test__/redux/reducers/experimentsReducer.test.js b/src/__test__/redux/reducers/experimentsReducer.test.js index fda67e58fc..1d77556748 100644 --- a/src/__test__/redux/reducers/experimentsReducer.test.js +++ b/src/__test__/redux/reducers/experimentsReducer.test.js @@ -317,7 +317,7 @@ describe('experimentsReducer', () => { expect(newState).toMatchSnapshot(); }); - it('Correctly updates experiment metadata', () => { + it('Correctly renames experiment metadata', () => { const oldMetadataKey = 'metadata-old'; const newMetadataKey = 'metadata-new'; const stateWithMetadata = { diff --git a/src/__test__/redux/reducers/samplesReducer.test.js b/src/__test__/redux/reducers/samplesReducer.test.js index 2ee0a8a00e..b425449bf3 100644 --- a/src/__test__/redux/reducers/samplesReducer.test.js +++ b/src/__test__/redux/reducers/samplesReducer.test.js @@ -13,6 +13,7 @@ import { SAMPLES_METADATA_DELETE, SAMPLES_VALUE_IN_METADATA_TRACK_UPDATED, } from 'redux/actionTypes/samples'; +import { EXPERIMENTS_METADATA_RENAME } from 'redux/actionTypes/experiments'; describe('samplesReducer', () => { const mockUuid1 = 'asd123'; @@ -236,80 +237,84 @@ describe('samplesReducer', () => { expect(newState).toMatchSnapshot(); }); - it('Updates sample metadata correctly', () => { + it('Deletes sample metadata correctly', () => { const metadataKey = 'metadata-test'; - const oldValue = 'old-value'; - const newValue = 'new-value'; + const metadataValue = 'old-value'; const sampleWithMetadata = { ...oneSampleState, [oneSampleState[mockUuid1]]: { metadata: { - [metadataKey]: oldValue, + [metadataKey]: metadataValue, }, }, }; const newState = samplesReducer(sampleWithMetadata, { - type: SAMPLES_UPDATE, + type: SAMPLES_METADATA_DELETE, payload: { sampleUuid: mockUuid1, - sample: { metadata: { [metadataKey]: newValue } }, + metadataKey, }, }); - expect(newState[mockUuid1].metadata[metadataKey]).toEqual(newValue); + expect(newState[mockUuid1].metadata[metadataKey]).toBeUndefined(); expect(newState).toMatchSnapshot(); }); - it('Deletes sample metadata correctly', () => { + it('Handles samplesValueInMetadataTrackUpdated correctly', () => { const metadataKey = 'metadata-test'; - const metadataValue = 'old-value'; + const metadataOldValue = 'old-value'; + const metadataNewValue = 'new-value'; const sampleWithMetadata = { ...oneSampleState, - [oneSampleState[mockUuid1]]: { + [mockUuid1]: { metadata: { - [metadataKey]: metadataValue, + [metadataKey]: metadataOldValue, }, }, }; const newState = samplesReducer(sampleWithMetadata, { - type: SAMPLES_METADATA_DELETE, + type: SAMPLES_VALUE_IN_METADATA_TRACK_UPDATED, payload: { sampleUuid: mockUuid1, - metadataKey, + key: metadataKey, + value: metadataNewValue, }, }); - expect(newState[mockUuid1].metadata[metadataKey]).toBeUndefined(); expect(newState).toMatchSnapshot(); }); - it('Handles samplesValueInMetadataTrackUpdated correctly', () => { - const metadataKey = 'metadata-test'; - const metadataOldValue = 'old-value'; - const metadataNewValue = 'new-value'; + it('Handles experimentMetadataRename correctly', () => { + const experimentId = 'mockExpId'; + const oldMetadataKey = 'metadata-old'; + const newMetadataKey = 'metadata-new'; + const metadataValue = 'value'; - const sampleWithMetadata = { + const stateWithMetadata = { ...oneSampleState, [mockUuid1]: { + experimentId, metadata: { - [metadataKey]: metadataOldValue, + [oldMetadataKey]: metadataValue, }, }, }; - const newState = samplesReducer(sampleWithMetadata, { - type: SAMPLES_VALUE_IN_METADATA_TRACK_UPDATED, + const newState = samplesReducer(stateWithMetadata, { + type: EXPERIMENTS_METADATA_RENAME, payload: { - sampleUuid: mockUuid1, - key: metadataKey, - value: metadataNewValue, + oldKey: oldMetadataKey, + newKey: newMetadataKey, + experimentId, }, }); + expect(newState[mockUuid1].metadata[newMetadataKey]).toEqual(metadataValue); + expect(newState[mockUuid1].metadata[oldMetadataKey]).not.toBeDefined(); expect(newState).toMatchSnapshot(); }); }); From 1a387c4b04766b0a6cd001e905518466fa4deba7 Mon Sep 17 00:00:00 2001 From: cosa65 Date: Wed, 20 Jul 2022 09:13:18 -0300 Subject: [PATCH 11/11] Update snapshot --- .../reducers/__snapshots__/experimentsReducer.test.js.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__test__/redux/reducers/__snapshots__/experimentsReducer.test.js.snap b/src/__test__/redux/reducers/__snapshots__/experimentsReducer.test.js.snap index 828d161a17..c70c137149 100644 --- a/src/__test__/redux/reducers/__snapshots__/experimentsReducer.test.js.snap +++ b/src/__test__/redux/reducers/__snapshots__/experimentsReducer.test.js.snap @@ -103,7 +103,7 @@ Object { } `; -exports[`experimentsReducer Correctly updates experiment metadata 1`] = ` +exports[`experimentsReducer Correctly renames experiment metadata 1`] = ` Object { "experiment-1": Object { "createdAt": "2021-01-01",