Skip to content

Commit

Permalink
First attempt to switch from vue-cli to vite
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminCharmes committed Dec 2, 2024
1 parent 1222921 commit 52e306e
Show file tree
Hide file tree
Showing 18 changed files with 1,470 additions and 37 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"cypress": "^13.16.0"
}
}
2 changes: 2 additions & 0 deletions webapp/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
printWidth: 100
trailingComma: all
1 change: 0 additions & 1 deletion webapp/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { defineConfig } from "cypress";

export default defineConfig({
projectId: "4kqx5i",
TZ: "UTC",
e2e: {
baseUrl: "http://localhost:8080",
apiUrl: "http://localhost:5001",
Expand Down
9 changes: 4 additions & 5 deletions webapp/cypress/e2e/editPage.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ describe("Edit Page", () => {
cy.findByText("editable_sample").click();

cy.findByText("Add a block").click();
cy.get(".dropdown-menu").findByText("Comment").click();
cy.get('[data-testid="add-block-dropdown"]').findByText("Comment").click();

cy.contains("Unsaved changes").should("not.exist");

cy.findByText("Add a block").click();
cy.get(".dropdown-menu").findByText("Comment").click();
cy.get('[data-testid="add-block-dropdown"]').findByText("Comment").click();

cy.contains("Unsaved changes").should("not.exist");

Expand Down Expand Up @@ -258,7 +258,6 @@ describe("Edit Page", () => {

cy.findByText("Add files from server...").click();
cy.findByText("Select files to add").should("exist");
cy.findAllByLabelText("Close").eq(1).click();
});

it("Uploads an XRD file, makes an XRD block and checks that the plot works", () => {
Expand All @@ -268,7 +267,7 @@ describe("Edit Page", () => {
cy.findByText("editable_sample").click();

cy.findByText("Add a block").click();
cy.get(".dropdown-menu").findByText("Powder XRD").click();
cy.get('[data-testid="add-block-dropdown"]').findByText("Powder XRD").click();

cy.findByText("Select a file:").should("exist");
cy.get("select.file-select-dropdown").select("example_data_XRD_example_bmb.xye");
Expand All @@ -285,7 +284,7 @@ describe("Edit Page", () => {
cy.findByText("editable_sample").click();

cy.findByText("Add a block").click();
cy.get(".dropdown-menu").findByText("Media").click();
cy.get('[data-testid="add-block-dropdown"]').findByText("Media").click();
cy.findAllByText("Select a file:").eq(1).should("exist");
cy.get("select.file-select-dropdown").eq(1).select(test_fname);

Expand Down
5 changes: 2 additions & 3 deletions webapp/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "webapp",
"name": "datalab-vue",
"version": "0.0.0-git",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/BatchCreateItemModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ import Modal from "@/components/Modal.vue";
import ItemSelect from "@/components/ItemSelect.vue";
import { createNewSamples } from "@/server_fetch_utils.js";
import { validateEntryID } from "@/field_utils.js";
import { itemTypes, SAMPLE_TABLE_TYPES } from "@/resources.js";
import { itemTypes, SAMPLE_TABLE_TYPES, AUTOMATICALLY_GENERATE_ID_DEFAULT } from "@/resources.js";
export default {
name: "BatchCreateItemModal",
components: {
Expand All @@ -356,7 +356,7 @@ export default {
epochStart: new Date("1970-01-01").toISOString().slice(0, -8),
oneYearOn: this.determineOneYearOn(),
nSamples: 3,
generateIDsAutomatically: false,
generateIDsAutomatically: AUTOMATICALLY_GENERATE_ID_DEFAULT,
item_type: "samples",
items: [
{
Expand Down
11 changes: 4 additions & 7 deletions webapp/src/components/CellInformation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@
<FormattedRefcode :refcode="Refcode" />
</div>
</div>
<div class="form-group col-md-3 col-sm-3 col-6 pb-3 pr-2">
<label id="cell-creators">Creators</label>
<div aria-labelledby="cell-creators" class="mx-auto">
<Creators :creators="ItemCreators" :size="36" />
</div>
<div class="form-group col-md-3 col-sm-3 col-6 pb-3">
<ToggleableCreatorsFormGroup v-model="ItemCreators" :refcode="Refcode" />
</div>
<div class="col-md-6 col-sm-7 pr-2">
<ToggleableCollectionFormGroup v-model="Collections" />
Expand Down Expand Up @@ -115,7 +112,7 @@ import TableOfContents from "@/components/TableOfContents";
import ItemRelationshipVisualization from "@/components/ItemRelationshipVisualization";
import FormattedRefcode from "@/components/FormattedRefcode";
import ToggleableCollectionFormGroup from "@/components/ToggleableCollectionFormGroup";
import Creators from "@/components/Creators";
import ToggleableCreatorsFormGroup from "@/components/ToggleableCreatorsFormGroup";
import { cellFormats } from "@/resources.js";
export default {
Expand All @@ -127,7 +124,7 @@ export default {
ItemRelationshipVisualization,
FormattedRefcode,
ToggleableCollectionFormGroup,
Creators,
ToggleableCreatorsFormGroup,
},
props: {
item_id: {
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/CreateItemModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ import Modal from "@/components/Modal.vue";
import ItemSelect from "@/components/ItemSelect.vue";
import { createNewItem } from "@/server_fetch_utils.js";
import { validateEntryID } from "@/field_utils.js";
import { itemTypes, SAMPLE_TABLE_TYPES } from "@/resources.js";
import { itemTypes, SAMPLE_TABLE_TYPES, AUTOMATICALLY_GENERATE_ID_DEFAULT } from "@/resources.js";
import CollectionSelect from "@/components/CollectionSelect.vue";
export default {
name: "CreateItemModal",
Expand Down Expand Up @@ -136,7 +136,7 @@ export default {
takenItemIds: [], // this holds ids that have been tried, whereas the computed takenSampleIds holds ids in the sample table
selectedItemToCopy: null,
startingConstituents: [],
generateIDAutomatically: false,
generateIDAutomatically: AUTOMATICALLY_GENERATE_ID_DEFAULT,
agesAgo: new Date("1970-01-01").toISOString().slice(0, -8), // a datetime for the unix epoch start
};
},
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/Creators.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {
},
showNames: {
type: Boolean,
default: false,
default: true,
required: false,
},
showBubble: {
Expand Down
12 changes: 8 additions & 4 deletions webapp/src/components/DynamicDataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,16 @@ export default {
const config = propsConfig[componentName] || {};
const props = Object.entries(config).reduce((acc, [prop, dataKey]) => {
if (dataKey !== true) {
const props = Object.entries(config).reduce((acc, [prop, setting]) => {
if (typeof setting === "object" && setting !== null && "value" in setting) {
acc[prop] = setting.value;
} else if (typeof setting === "boolean") {
acc[prop] = setting;
} else if (typeof setting === "string") {
if (prop === "itemType") {
acc[prop] = data.type !== undefined ? data.type : "starting_materials";
} else if (data[dataKey] !== undefined) {
acc[prop] = data[dataKey];
} else if (data[setting] !== undefined) {
acc[prop] = data[setting];
}
}
return acc;
Expand Down
9 changes: 3 additions & 6 deletions webapp/src/components/SampleInformation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
</div>
</div>
<div class="form-group col-md-3 col-sm-3 col-6 pb-3">
<label id="samp-creators">Creators</label>
<div aria-labelledby="samp-creators" class="mx-auto">
<Creators :creators="ItemCreators" :size="36" />
</div>
<ToggleableCreatorsFormGroup v-model="ItemCreators" :refcode="Refcode" />
</div>
<div class="col-md-6 col-sm-7 pr-2">
<ToggleableCollectionFormGroup v-model="Collections" />
Expand Down Expand Up @@ -62,11 +59,11 @@ import { createComputedSetterForItemField } from "@/field_utils.js";
import ChemFormulaInput from "@/components/ChemFormulaInput";
import FormattedRefcode from "@/components/FormattedRefcode";
import ToggleableCollectionFormGroup from "@/components/ToggleableCollectionFormGroup";
import ToggleableCreatorsFormGroup from "@/components/ToggleableCreatorsFormGroup";
import TinyMceInline from "@/components/TinyMceInline";
import SynthesisInformation from "@/components/SynthesisInformation";
import TableOfContents from "@/components/TableOfContents";
import ItemRelationshipVisualization from "@/components/ItemRelationshipVisualization";
import Creators from "@/components/Creators";
export default {
components: {
Expand All @@ -77,7 +74,7 @@ export default {
ItemRelationshipVisualization,
FormattedRefcode,
ToggleableCollectionFormGroup,
Creators,
ToggleableCreatorsFormGroup,
},
props: {
item_id: { type: String, required: true },
Expand Down
128 changes: 128 additions & 0 deletions webapp/src/components/ToggleableCreatorsFormGroup.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<template>
<div
ref="outerdiv"
class="h-100 form-group clickable"
@click="isEditingCreators = !isEditingCreators"
>
<label id="creators" class="clickable">
Creators
<font-awesome-icon
id="edit-icon"
class="pl-1"
icon="pen"
size="xs"
:fade="isEditingCreators"
/>
</label>
<div>
<Creators
v-if="!isEditingCreators"
:show-names="value.length <= 1"
aria-labelledby="creators"
:creators="shadowValue"
/>
<OnClickOutside
v-if="isEditingCreators"
:options="{ ignore: [outerDivRef] }"
@trigger="isEditingCreators = false"
>
<UserSelect v-model="shadowValue" aria-labelledby="creators" multiple @click.stop />
</OnClickOutside>
</div>
</div>
</template>

<script>
import Creators from "@/components/Creators";
import UserSelect from "@/components/UserSelect";
import { OnClickOutside } from "@vueuse/components";
import { updateItemPermissions } from "@/server_fetch_utils.js";
import { toRaw } from "vue";
export default {
components: {
UserSelect,
Creators,
OnClickOutside,
},
props: {
refcode: { type: String, required: true },
modelValue: {
type: Array,
required: true,
},
},
emits: ["update:modelValue"],
data() {
return {
isEditingCreators: false,
outerDivRef: null,
shadowValue: [],
};
},
computed: {
// computed setter to pass v-model through component:
value: {
get() {
return this.modelValue;
},
set(newValue) {
this.$emit("update:modelValue", newValue);
},
},
},
watch: {
async isEditingCreators(newValue, oldValue) {
// Check we are leaving the editing state
if (newValue === false && oldValue === true) {
// Check that the permissions have actually changed
if (JSON.stringify(toRaw(this.value)) === JSON.stringify(toRaw(this.shadowValue))) {
return;
}
try {
// Check if the user has just removed all creators and reset if so
if (this.shadowValue.length == 0) {
throw new Error("You must have at least one creator.");
}
let answer = confirm("Are you sure you want to update the permissions of this item?");
if (answer) {
await updateItemPermissions(this.refcode, this.shadowValue);
this.$emit("update:modelValue", [...this.shadowValue]);
} else {
this.shadowValue = [...this.value];
}
} catch (error) {
// Reset value to original
alert("Error updating permissions: " + error);
this.shadowValue = [...this.value];
}
}
},
modelValue: {
immediate: true,
handler(newVal) {
if (this.shadowValue !== newVal) {
this.shadowValue = [...newVal];
}
},
},
},
async mounted() {
this.outerDivRef = this.$refs.outerdiv; // we need to get the editIcon's ref to be accessible in the template so we can exclude it from the ClickOutside
},
};
</script>

<style scoped>
.text-italic {
opacity: 0.7;
}
#edit-icon {
color: grey;
}
.text-heavy {
font-weight: 600;
}
</style>
Loading

0 comments on commit 52e306e

Please sign in to comment.