Skip to content

Commit 3004789

Browse files
authored
Rework resources.js when blocks require/do not require custom components (#1154)
1 parent 85088ec commit 3004789

File tree

7 files changed

+34
-224
lines changed

7 files changed

+34
-224
lines changed

webapp/cypress/e2e/editPage.cy.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,20 @@ describe("Edit Page", () => {
293293
// Check that the img with id "media-block-img" is present
294294
cy.get('img[data-testid="media-block-img"]').should("exist");
295295
});
296+
297+
it("Uploads an Raman data file, makes a Raman block and checks that the plot is shown", () => {
298+
cy.uploadFileViaAPI("editable_sample", "example_data/raman/labspec_raman_example.txt");
299+
300+
cy.get('[data-testid="search-input"]').type("editable_sample");
301+
cy.findByText("editable_sample").click();
302+
303+
cy.findByText("Add a block").click();
304+
cy.get('[data-testid="add-block-dropdown"]').findByText("Raman spectroscopy").click();
305+
cy.findAllByText("Select a file:").eq(2).should("exist");
306+
cy.get("select.file-select-dropdown")
307+
.eq(2)
308+
.select("example_data_raman_labspec_raman_example.txt");
309+
cy.contains("label", "X axis").should("exist");
310+
cy.contains("label", "Y axis").should("exist");
311+
});
296312
});

webapp/src/components/datablocks/EISBlock.vue

Lines changed: 0 additions & 68 deletions
This file was deleted.

webapp/src/components/datablocks/MassSpecBlock.vue

Lines changed: 0 additions & 70 deletions
This file was deleted.

webapp/src/components/datablocks/RamanBlock.vue

Lines changed: 0 additions & 67 deletions
This file was deleted.

webapp/src/resources.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
// Resources for the application
22
import DataBlockBase from "@/components/datablocks/DataBlockBase";
3-
import BokehBlock from "@/components/datablocks/BokehBlock";
43
import MediaBlock from "@/components/datablocks/MediaBlock";
54
import XRDBlock from "@/components/datablocks/XRDBlock";
65
import ChatBlock from "@/components/datablocks/ChatBlock";
7-
import RamanBlock from "@/components/datablocks/RamanBlock";
86
import CycleBlock from "@/components/datablocks/CycleBlock";
97
import NMRBlock from "@/components/datablocks/NMRBlock";
10-
import EISBlock from "@/components/datablocks/EISBlock";
11-
import MassSpecBlock from "@/components/datablocks/MassSpecBlock";
128
import NMRInsituBlock from "@/components/datablocks/NMRInsituBlock";
139

1410
import SampleInformation from "@/components/SampleInformation";
@@ -59,18 +55,14 @@ export const UPPY_MAX_NUMBER_OF_FILES =
5955

6056
export const debounceTime = 250; // time after user stops typing before request is sent
6157

62-
export const blockTypes = {
58+
// A mapping for blocks that need custom Vue components
59+
export const customBlockTypes = {
6360
comment: { description: "Comment", component: DataBlockBase, name: "Comment" },
6461
media: { description: "Media", component: MediaBlock, name: "Media" },
65-
tabular: { description: "Tabular Data", component: BokehBlock, name: "Tabular data" },
6662
xrd: { description: "Powder XRD", component: XRDBlock, name: "Powder XRD" },
67-
raman: { description: "Raman", component: RamanBlock, name: "Raman" },
6863
cycle: { description: "Electrochemistry", component: CycleBlock, name: "Electrochemistry" },
69-
eis: { description: "Electrochemical Impedance Spectroscopy", component: EISBlock, name: "EIS" },
7064
nmr: { description: "Nuclear Magnetic Resonance Spectroscopy", component: NMRBlock, name: "NMR" },
71-
ms: { description: "Mass Spectrometry", component: MassSpecBlock, name: "Mass Spectrometry" },
7265
chat: { description: "Virtual assistant", component: ChatBlock, name: "Virtual Assistant" },
73-
ftir: { description: "FTIR", component: BokehBlock, name: "FTIR" },
7466
"insitu-nmr": { description: "NMR insitu", component: NMRInsituBlock, name: "NMR insitu" },
7567
};
7668

webapp/src/store/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ export default createStore({
342342
getHasUnverifiedUser(state) {
343343
return state.hasUnverifiedUser;
344344
},
345+
getBlocksInfos(state) {
346+
return Object.values(state.blocksInfos);
347+
},
345348
},
346349
actions: {},
347350
modules: {},

webapp/src/views/EditPage.vue

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ import setupUppy from "@/file_upload.js";
113113
114114
import tinymce from "tinymce/tinymce";
115115
116-
import { blockTypes, itemTypes } from "@/resources.js";
117-
import NotImplementedBlock from "@/components/datablocks/NotImplementedBlock.vue";
118-
import { API_URL } from "@/resources.js";
116+
import { itemTypes, API_URL, customBlockTypes } from "@/resources.js";
117+
import BokehBlock from "@/components/datablocks/BokehBlock.vue";
119118
import { formatDistanceToNow } from "date-fns";
120119
121120
import StyledBlockHelp from "@/components/StyledBlockHelp";
@@ -191,7 +190,13 @@ export default {
191190
return Object.fromEntries(this.files.map((file) => [file.immutable_id, file]));
192191
},
193192
blocksInfos() {
194-
return this.$store.state.blocksInfos;
193+
if (this.blockInfoLoaded) {
194+
const blocksInfos = Array.from(this.$store.getters.getBlocksInfos.values());
195+
return [...blocksInfos].sort((a, b) =>
196+
a?.attributes?.name.localeCompare(b?.attributes?.name),
197+
);
198+
}
199+
return [];
195200
},
196201
itemApiUrl() {
197202
return API_URL + "/items/" + this.refcode;
@@ -213,7 +218,7 @@ export default {
213218
this.interval = setInterval(() => this.setLastModified(), 30000);
214219
},
215220
beforeMount() {
216-
this.blockTypes = blockTypes; // bind blockTypes as a NON-REACTIVE object to the this context so that it is accessible by the template.
221+
this.customBlockTypes = customBlockTypes; // bind customBlockTypes as a NON-REACTIVE object to the this context so that it is accessible by the template.
217222
},
218223
mounted() {
219224
// overwrite ctrl-s and cmd-s to save the page
@@ -258,15 +263,14 @@ export default {
258263
},
259264
getBlockDisplayType(block_id) {
260265
var type = this.blocks[block_id].blocktype;
261-
if (type in blockTypes) {
262-
return blockTypes[type].component;
266+
if (type in customBlockTypes) {
267+
return customBlockTypes[type].component;
263268
} else {
264-
return NotImplementedBlock;
269+
return BokehBlock;
265270
}
266271
},
267272
saveSample() {
268273
// trigger the mce save so that they update the store with their content
269-
console.log("save sample clicked!");
270274
tinymce.editors.forEach((editor) => {
271275
editor.isDirty() && editor.save();
272276
});

0 commit comments

Comments
 (0)