Skip to content

Commit

Permalink
Merge pull request #15783 from jmchilton/object_store_ui_followup_2
Browse files Browse the repository at this point in the history
Convert more of the object store selection client to TypeScript.
  • Loading branch information
dannon authored Mar 16, 2023
2 parents ef6187d + 682cdf1 commit 0a34ae2
Show file tree
Hide file tree
Showing 23 changed files with 495 additions and 375 deletions.
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"@babel/preset-typescript": "^7.18.6",
"@cerner/duplicate-package-checker-webpack-plugin": "^2.3.0",
"@testing-library/jest-dom": "^5.16.4",
"@types/markdown-it": "^12.2.3",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"@vue/test-utils": "^1.3.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,27 @@ describe("SelectPreferredStore.vue", () => {
const emitted = wrapper.emitted();
expect(emitted["updated"][0][0]).toEqual(null);
});

it("updates object store to on non-null selection", async () => {
const wrapper = mountComponent();
await flushPromises();
const els = wrapper.findAll(PREFERENCES.object_store_selection.option_buttons.selector);
expect(els.length).toBe(3);
const galaxyDefaultOption = wrapper.find(
PREFERENCES.object_store_selection.option_button({ object_store_id: "object_store_2" }).selector
);
expect(galaxyDefaultOption.exists()).toBeTruthy();
axiosMock
.onPut(
`/api/histories/${TEST_HISTORY_ID}`,
expect.objectContaining({ preferred_object_store_id: "object_store_2" })
)
.reply(202);
await galaxyDefaultOption.trigger("click");
await flushPromises();
const errorEl = wrapper.find(".object-store-selection-error");
expect(errorEl.exists()).toBeFalsy();
const emitted = wrapper.emitted();
expect(emitted["updated"][0][0]).toEqual("object_store_2");
});
});
129 changes: 61 additions & 68 deletions client/src/components/History/CurrentHistory/SelectPreferredStore.vue
Original file line number Diff line number Diff line change
@@ -1,76 +1,69 @@
<script lang="ts" setup>
import { computed, ref } from "vue";
import axios from "axios";
import SelectObjectStore from "@/components/ObjectStore/SelectObjectStore.vue";
import { prependPath } from "@/utils/redirect";
import { errorMessageAsString } from "@/utils/simple-error";
const props = defineProps({
userPreferredObjectStoreId: {
type: String,
default: null,
},
history: {
type: Object,
required: true,
},
});
const error = ref<string | null>(null);
const selectedObjectStoreId = ref(props.history.preferred_object_store_id);
const newDatasetsDescription = "New dataset outputs from tools and workflows executed in this history";
const galaxySelectionDefaultTitle = "Use Galaxy Defaults";
const galaxySelectionDefaultDescription =
"Selecting this will reset Galaxy to default behaviors configured by your Galaxy administrator.";
const userSelectionDefaultTitle = "Use Your User Preference Defaults";
const userSelectionDefaultDescription =
"Selecting this will cause the history to not set a default and to fallback to your user preference defined default.";
const defaultOptionTitle = computed(() => {
if (props.userPreferredObjectStoreId) {
return userSelectionDefaultTitle;
} else {
return galaxySelectionDefaultTitle;
}
});
const defaultOptionDescription = computed(() => {
if (props.userPreferredObjectStoreId) {
return userSelectionDefaultDescription;
} else {
return galaxySelectionDefaultDescription;
}
});
const emit = defineEmits<{
(e: "updated", id: string | null): void;
}>();
async function handleSubmit(preferredObjectStoreId: string | null) {
const payload = { preferred_object_store_id: preferredObjectStoreId };
const url = prependPath(`api/histories/${props.history.id}`);
try {
await axios.put(url, payload);
} catch (e) {
error.value = errorMessageAsString(e);
}
selectedObjectStoreId.value = preferredObjectStoreId;
emit("updated", preferredObjectStoreId);
}
</script>
<template>
<SelectObjectStore
:parent-error="error"
:parent-error="error || undefined"
:for-what="newDatasetsDescription"
:selected-object-store-id="selectedObjectStoreId"
:default-option-title="defaultOptionTitle"
:default-option-description="defaultOptionDescription"
@onSubmit="handleSubmit" />
</template>

<script>
import axios from "axios";
import SelectObjectStore from "components/ObjectStore/SelectObjectStore";
import { prependPath } from "utils/redirect";
import { errorMessageAsString } from "utils/simple-error";
export default {
components: {
SelectObjectStore,
},
props: {
userPreferredObjectStoreId: {
type: String,
default: null,
},
history: {
type: Object,
required: true,
},
},
data() {
const selectedObjectStoreId = this.history.preferred_object_store_id;
return {
error: null,
selectedObjectStoreId: selectedObjectStoreId,
newDatasetsDescription: "New dataset outputs from tools and workflows executed in this history",
popoverPlacement: "left",
galaxySelectionDefaultTitle: "Use Galaxy Defaults",
galaxySelectionDefaultDescription:
"Selecting this will reset Galaxy to default behaviors configured by your Galaxy administrator.",
userSelectionDefaultTitle: "Use Your User Preference Defaults",
userSelectionDefaultDescription:
"Selecting this will cause the history to not set a default and to fallback to your user preference defined default.",
};
},
computed: {
defaultOptionTitle() {
if (this.userPreferredObjectStoreId) {
return this.userSelectionDefaultTitle;
} else {
return this.galaxySelectionDefaultTitle;
}
},
defaultOptionDescription() {
if (this.userPreferredObjectStoreId) {
return this.userSelectionDefaultDescription;
} else {
return this.galaxySelectionDefaultDescription;
}
},
},
methods: {
async handleSubmit(preferredObjectStoreId) {
const payload = { preferred_object_store_id: preferredObjectStoreId };
const url = prependPath(`api/histories/${this.history.id}`);
try {
await axios.put(url, payload);
} catch (e) {
this.error = errorMessageAsString(e);
}
this.selectedObjectStoreId = preferredObjectStoreId;
this.$emit("updated", preferredObjectStoreId);
},
},
};
</script>
5 changes: 2 additions & 3 deletions client/src/components/ObjectStore/DescribeObjectStore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import ObjectStoreRestrictionSpan from "./ObjectStoreRestrictionSpan";
import QuotaUsageBar from "components/User/DiskUsage/Quota/QuotaUsageBar";
import { QuotaSourceUsageProvider } from "components/User/DiskUsage/Quota/QuotaUsageProvider";
import ObjectStoreBadges from "./ObjectStoreBadges";
import adminConfigMixin from "./adminConfigMixin";
import { adminMarkup } from "./adminConfig";
export default {
components: {
Expand All @@ -41,7 +41,6 @@ export default {
QuotaSourceUsageProvider,
QuotaUsageBar,
},
mixins: [adminConfigMixin],
props: {
storageInfo: {
type: Object,
Expand All @@ -57,7 +56,7 @@ export default {
return this.storageInfo.quota?.source;
},
descriptionRendered() {
return this.adminMarkup(this.storageInfo.description);
return adminMarkup(this.storageInfo.description);
},
isPrivate() {
return this.storageInfo.private;
Expand Down
12 changes: 8 additions & 4 deletions client/src/components/ObjectStore/ObjectStoreBadge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ describe("ObjectStoreBadge", () => {
const selector = ROOT_COMPONENT.object_store_details.badge_of_type({ type: "more_secure" }).selector;
const iconEl = wrapper.find(selector);
expect(iconEl.exists()).toBeTruthy();
expect(wrapper.vm.message).toContain(TEST_MESSAGE);
expect(wrapper.vm.stockMessage).toContain("more secure by the Galaxy adminstrator");
const popoverStub = wrapper.find("b-popover-stub");
const popoverText = popoverStub.text();
expect(popoverText).toContain(TEST_MESSAGE);
expect(popoverText).toContain("more secure by the Galaxy adminstrator");
});

it("should render a valid badge for less_secure type", async () => {
mountBadge({ type: "less_secure", message: TEST_MESSAGE });
const selector = ROOT_COMPONENT.object_store_details.badge_of_type({ type: "less_secure" }).selector;
const iconEl = wrapper.find(selector);
expect(iconEl.exists()).toBeTruthy();
expect(wrapper.vm.message).toContain(TEST_MESSAGE);
expect(wrapper.vm.stockMessage).toContain("less secure by the Galaxy adminstrator");
const popoverStub = wrapper.find("b-popover-stub");
const popoverText = popoverStub.text();
expect(popoverText).toContain(TEST_MESSAGE);
expect(popoverText).toContain("less secure by the Galaxy adminstrator");
});
});
Loading

0 comments on commit 0a34ae2

Please sign in to comment.