Skip to content

Commit

Permalink
Merge pull request galaxyproject#17119 from davelopez/migrate_job_des…
Browse files Browse the repository at this point in the history
…tination_params_store_pinia

Migrate job destination parameters store to Pinia
  • Loading branch information
jmchilton authored Dec 7, 2023
2 parents 2f74a84 + aa14a32 commit e7a1680
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 144 deletions.
6 changes: 5 additions & 1 deletion client/src/api/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { fetcher } from "@/api/schema";
import { components, fetcher } from "@/api/schema";

export type JobDestinationParams = components["schemas"]["JobDestinationParams"];

export const jobLockStatus = fetcher.path("/api/job_lock").method("get").create();
export const jobLockUpdate = fetcher.path("/api/job_lock").method("put").create();

export const fetchJobDestinationParams = fetcher.path("/api/jobs/{job_id}/destination_params").method("get").create();

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { shallowMount } from "@vue/test-utils";
import flushPromises from "flush-promises";
import { createPinia } from "pinia";
import { getLocalVue } from "tests/jest/helpers";

import { mockFetcher } from "@/api/schema/__mocks__";
import { useUserStore } from "@/stores/userStore";

import jobDestinationResponseData from "./testData/jobDestinationResponse.json";

import JobDestinationParams from "./JobDestinationParams.vue";

const JOB_ID = "foo_job_id";

jest.mock("@/api/schema");

const localVue = getLocalVue();

const jobDestinationResponse = jobDestinationResponseData as Record<string, string | null>;

async function mountJobDestinationParams() {
mockFetcher.path("/api/jobs/{job_id}/destination_params").method("get").mock({ data: jobDestinationResponse });

const pinia = createPinia();
const wrapper = shallowMount(JobDestinationParams as object, {
propsData: {
jobId: JOB_ID,
},
localVue,
pinia,
});

const userStore = useUserStore();
userStore.currentUser = {
email: "admin@email",
id: "1",
tags_used: [],
isAnonymous: false,
total_disk_usage: 1048576,
is_admin: true,
};

await flushPromises();

return wrapper;
}

describe("JobDestinationParams/JobDestinationParams.vue", () => {
const responseKeys = Object.keys(jobDestinationResponse);
expect(responseKeys.length > 0).toBeTruthy();

it("should render destination parameters", async () => {
const wrapper = await mountJobDestinationParams();

const paramsTable = wrapper.find("#destination_parameters");
expect(paramsTable.exists()).toBe(true);
const params = paramsTable.findAll("tbody > tr");
expect(params.length).toBe(responseKeys.length);

for (let counter = 0; counter < responseKeys.length - 1; counter++) {
const parameter = params.at(counter).findAll("td");
const parameterTitle = parameter.at(0).text();
const parameterValue = parameter.at(1).text();

expect(responseKeys.includes(parameterTitle)).toBeTruthy();
// since we render null as an empty string, rendered empty string should always equal null in test data
expect(
jobDestinationResponse[parameterTitle] === (parameterValue === "" ? null : parameterValue)
).toBeTruthy();
}
});
});
49 changes: 21 additions & 28 deletions client/src/components/JobDestinationParams/JobDestinationParams.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
<script setup lang="ts">
import { storeToRefs } from "pinia";
import { computed } from "vue";
import { useJobDestinationParametersStore } from "@/stores/jobDestinationParametersStore";
import { useUserStore } from "@/stores/userStore";
const { currentUser } = storeToRefs(useUserStore());
const jobDestinationParametersStore = useJobDestinationParametersStore();
interface Props {
jobId: string;
}
const props = defineProps<Props>();
const jobDestinationParams = computed(() => {
return jobDestinationParametersStore.getJobDestinationParams(props.jobId);
});
</script>

<template>
<div v-if="currentUser?.is_admin">
<h2 class="h-md">Destination Parameters</h2>
Expand All @@ -11,31 +32,3 @@
</table>
</div>
</template>

<script>
import { mapState } from "pinia";
import { mapCacheActions } from "vuex-cache";
import { useUserStore } from "@/stores/userStore";
export default {
props: {
jobId: {
type: String,
required: true,
},
},
computed: {
...mapState(useUserStore, ["currentUser"]),
jobDestinationParams: function () {
return this.$store.getters.jobDestinationParams(this.jobId);
},
},
created: function () {
this.fetchJobDestinationParams(this.jobId);
},
methods: {
...mapCacheActions(["fetchJobDestinationParams"]),
},
};
</script>
2 changes: 0 additions & 2 deletions client/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { datasetExtFilesStore } from "./datasetExtFilesStore";
import { datasetPathDestinationStore } from "./datasetPathDestinationStore";
import { gridSearchStore } from "./gridSearchStore";
import { invocationStore } from "./invocationStore";
import { jobDestinationParametersStore } from "./jobDestinationParametersStore";
import { syncVuextoGalaxy } from "./syncVuextoGalaxy";
import { tagStore } from "./tagStore";

Expand Down Expand Up @@ -42,7 +41,6 @@ export function createStore() {
const storeConfig = {
plugins: [createCache(), panelsPersistence.plugin],
modules: {
destinationParameters: jobDestinationParametersStore,
datasetExtFiles: datasetExtFilesStore,
datasetPathDestination: datasetPathDestinationStore,
invocations: invocationStore,
Expand Down
33 changes: 0 additions & 33 deletions client/src/store/jobDestinationParametersStore.js

This file was deleted.

43 changes: 43 additions & 0 deletions client/src/stores/jobDestinationParametersStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { defineStore } from "pinia";
import { computed, del, ref, set } from "vue";

import { fetchJobDestinationParams, type JobDestinationParams } from "@/api/jobs";

export const useJobDestinationParametersStore = defineStore("jobDestinationParametersStore", () => {
const storedJobDestinationParameters = ref<{ [key: string]: JobDestinationParams }>({});
const loadingParameters = ref<{ [key: string]: boolean }>({});

const getJobDestinationParams = computed(() => {
return (jobId: string) => {
const destinationParams = storedJobDestinationParameters.value[jobId];
if (!destinationParams && !loadingParameters.value[jobId]) {
fetchJobDestinationParamsByJobId({ id: jobId });
}
return destinationParams ?? null;
};
});

const isLoadingJobDestinationParams = computed(() => {
return (jobId: string) => {
return loadingParameters.value[jobId] ?? false;
};
});

async function fetchJobDestinationParamsByJobId(params: { id: string }) {
const jobId = params.id;
set(loadingParameters.value, jobId, true);
try {
const { data: destinationParams } = await fetchJobDestinationParams({ job_id: jobId });
set(storedJobDestinationParameters.value, jobId, destinationParams);
return destinationParams;
} finally {
del(loadingParameters.value, jobId);
}
}

return {
storedJobDestinationParameters,
getJobDestinationParams,
isLoadingJobDestinationParams,
};
});
1 change: 1 addition & 0 deletions client/src/stores/userStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface User extends QuotaUsageResponse {

export interface AnonymousUser {
isAnonymous: true;
is_admin?: false;
}

export type GenericUser = User | AnonymousUser;
Expand Down

0 comments on commit e7a1680

Please sign in to comment.