Skip to content

Commit

Permalink
Merge branch 'ref/318/query-composables' into fix/homeselector-loading
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianoertel committed Aug 22, 2024
2 parents 359047d + 21daca8 commit 7825bba
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
14 changes: 5 additions & 9 deletions src/components/CreateAdministration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ import { onMounted, reactive, ref, toRaw, computed, watch } from 'vue';
import { useRouter } from 'vue-router';
import { storeToRefs } from 'pinia';
import { useToast } from 'primevue/usetoast';
import { useConfirm } from 'primevue/useconfirm';
import { useQuery } from '@tanstack/vue-query';
import _filter from 'lodash/filter';
import _isEmpty from 'lodash/isEmpty';
Expand All @@ -184,13 +185,12 @@ import _groupBy from 'lodash/groupBy';
import _values from 'lodash/values';
import { useVuelidate } from '@vuelidate/core';
import { required, requiredIf } from '@vuelidate/validators';
import { useAuthStore } from '@/store/auth';
import OrgPicker from '@/components/OrgPicker.vue';
import { fetchDocById, fetchDocsById } from '@/helpers/query/utils';
import { variantsFetcher } from '@/helpers/query/tasks';
import { useAuthStore } from '@/store/auth';
import useAdministrationVariantsQuery from '@/composables/queries/useAdministrationVariantsQuery';
import TaskPicker from './TaskPicker.vue';
import { useConfirm } from 'primevue/useconfirm';
import ConsentPicker from './ConsentPicker.vue';
import OrgPicker from '@/components/OrgPicker.vue';
const isLevante = import.meta.env.MODE === 'LEVANTE';
Expand Down Expand Up @@ -229,12 +229,8 @@ const confirm = useConfirm();
const authStore = useAuthStore();
const { roarfirekit, administrationQueryKeyIndex } = storeToRefs(authStore);
const { data: allVariants } = useQuery({
queryKey: ['variants', 'all'],
queryFn: () => variantsFetcher(true),
keepPreviousData: true,
const { data: allVariants } = useAdministrationVariantsQuery(true, {
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
});
// +------------------------------------------+
Expand Down
12 changes: 4 additions & 8 deletions src/components/tasks/ManageVariants.vue
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,13 @@
import { computed, onMounted, reactive, ref, watch } from 'vue';
import { required } from '@vuelidate/validators';
import { useVuelidate } from '@vuelidate/core';
import { useAuthStore } from '@/store/auth';
import { useQuery, useQueryClient } from '@tanstack/vue-query';
import { storeToRefs } from 'pinia';
import { useToast } from 'primevue/usetoast';
import { taskFetcher } from '@/helpers/query/tasks';
import { variantsFetcher } from '../../helpers/query/tasks';
import { cloneDeep, camelCase } from 'lodash';
import { useAuthStore } from '@/store/auth';
import { taskFetcher } from '@/helpers/query/tasks';
import useAdministrationVariantsQuery from '@/composables/queries/useAdministrationVariantsQuery';
const toast = useToast();
const initialized = ref(false);
Expand Down Expand Up @@ -514,12 +514,8 @@ const { isFetching: isFetchingTasks, data: tasks } = useQuery({
staleTime: 5 * 60 * 1000, // 5 minutes
});
const { data: allVariants } = useQuery({
queryKey: ['variants', 'all'],
queryFn: () => variantsFetcher(),
keepPreviousData: true,
const { data: allVariants } = useAdministrationVariantsQuery({
enabled: initialized,
staleTime: 5 * 60 * 1000, // 5 minutes
});
const formattedTasks = computed(() => {
Expand Down
26 changes: 26 additions & 0 deletions src/composables/queries/useAdministrationVariantsQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useQuery } from '@tanstack/vue-query';
import { variantsFetcher } from '@/helpers/query/tasks';
import { ADMINITRATION_VARIANTS_QUERY_KEY } from '@/constants/queryKeys';

/**
* Administration Variants query.
*
* @TODO: Consider separating into two queries, one for registered variants and one for all variants.
* @TODO: Consider moving the "registered" query key to a constant.
*
* @param {QueryOptions|undefined} queryOptions – Optional TanStack query options.
* @returns {UseQueryResult} The TanStack query result.
*/
const useAdministrationVariantsQuery = (registeredVariantsOnly = false, queryOptions = undefined) => {
const queryKey = registeredVariantsOnly
? [ADMINITRATION_VARIANTS_QUERY_KEY, 'registered']
: ADMINITRATION_VARIANTS_QUERY_KEY;

return useQuery({
queryKey,
queryFn: () => variantsFetcher(registeredVariantsOnly),
...queryOptions,
});
};

export default useAdministrationVariantsQuery;
File renamed without changes.
1 change: 1 addition & 0 deletions src/constants/queryKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export const USER_STUDENT_DATA_QUERY_KEY = 'user-student';
export const USER_CLAIMS_QUERY_KEY = 'user-claims';
export const LEGAL_DOCS_QUERY_KEY = 'legal-docs';
export const DSGF_ORGS_QUERY_KEY = 'dsgf-orgs';
export const ADMINITRATION_VARIANTS_QUERY_KEY = 'administration-variants';

0 comments on commit 7825bba

Please sign in to comment.