From 720042bed9679c725e4e4640eeb4801984a121b9 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 14 Oct 2024 11:30:31 +0200 Subject: [PATCH 1/4] feat: added new filter param and refactored link colors --- src/pages/Item/ItemRequest.vue | 6 +++--- src/pages/Item/ItemRequestFilter.vue | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/pages/Item/ItemRequest.vue b/src/pages/Item/ItemRequest.vue index 8a41bbe04..82c3b48e0 100644 --- a/src/pages/Item/ItemRequest.vue +++ b/src/pages/Item/ItemRequest.vue @@ -229,7 +229,7 @@ onBeforeMount(() => { > @@ -251,7 +251,7 @@ onBeforeMount(() => { @@ -292,7 +292,7 @@ onBeforeMount(() => { diff --git a/src/pages/Item/ItemRequestFilter.vue b/src/pages/Item/ItemRequestFilter.vue index 0e81ff5a5..64bc0e575 100644 --- a/src/pages/Item/ItemRequestFilter.vue +++ b/src/pages/Item/ItemRequestFilter.vue @@ -174,6 +174,16 @@ const decrement = (paramsObj, key) => { + + + + + @@ -274,11 +284,11 @@ en: to: To mine: For me state: State + myTeam: My team dateFiltersTooltip: Cannot choose a range of dates and days onward at the same time denied: Denied accepted: Accepted pending: Pending - es: params: search: Búsqueda general @@ -291,6 +301,7 @@ es: to: Hasta mine: Para mi state: Estado + myTeam: Mi equipo dateFiltersTooltip: No se puede seleccionar un rango de fechas y días en adelante a la vez denied: Denegada accepted: Aceptada From 175ebbc3433db21ac2fda6ebbb0e6e15b2cd011d Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 18 Oct 2024 11:03:43 +0200 Subject: [PATCH 2/4] feat(navBar): refs #7632 isLoading --- src/boot/axios.js | 11 +++- src/components/NavBar.vue | 13 +++++ src/stores/useStateQueryStore.js | 31 ++++++++++ test/vitest/__tests__/boot/axios.spec.js | 52 ++++++++--------- .../stores/useStateQueryStore.spec.js | 56 +++++++++++++++++++ 5 files changed, 135 insertions(+), 28 deletions(-) create mode 100644 src/stores/useStateQueryStore.js create mode 100644 test/vitest/__tests__/stores/useStateQueryStore.spec.js diff --git a/src/boot/axios.js b/src/boot/axios.js index 99a163cca..25095f9cc 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -2,9 +2,11 @@ import axios from 'axios'; import { useSession } from 'src/composables/useSession'; import { Router } from 'src/router'; import useNotify from 'src/composables/useNotify.js'; +import { useStateQueryStore } from 'src/stores/useStateQueryStore'; const session = useSession(); const { notify } = useNotify(); +const stateQuery = useStateQueryStore(); const baseUrl = '/api/'; axios.defaults.baseURL = baseUrl; @@ -15,7 +17,7 @@ const onRequest = (config) => { if (token.length && !config.headers.Authorization) { config.headers.Authorization = token; } - + stateQuery.add(config); return config; }; @@ -24,9 +26,10 @@ const onRequestError = (error) => { }; const onResponse = (response) => { - const { method } = response.config; + const config = response.config; + stateQuery.remove(config); - const isSaveRequest = method === 'patch'; + const isSaveRequest = config.method === 'patch'; if (isSaveRequest) { notify('globals.dataSaved', 'positive'); } @@ -35,6 +38,8 @@ const onResponse = (response) => { }; const onResponseError = (error) => { + stateQuery.remove(error.config); + let message = ''; const response = error.response; diff --git a/src/components/NavBar.vue b/src/components/NavBar.vue index 00faaebc2..71d3b8a0f 100644 --- a/src/components/NavBar.vue +++ b/src/components/NavBar.vue @@ -3,6 +3,7 @@ import { onMounted, ref } from 'vue'; import { useI18n } from 'vue-i18n'; import { useState } from 'src/composables/useState'; import { useStateStore } from 'stores/useStateStore'; +import { useStateQueryStore } from 'src/stores/useStateQueryStore'; import { useQuasar } from 'quasar'; import PinnedModules from './PinnedModules.vue'; import UserPanel from 'components/UserPanel.vue'; @@ -12,6 +13,7 @@ import VnAvatar from './ui/VnAvatar.vue'; const { t } = useI18n(); const stateStore = useStateStore(); const quasar = useQuasar(); +const stateQuery = useStateQueryStore(); const state = useState(); const user = state.getUser(); const appName = 'Lilium'; @@ -50,6 +52,14 @@ const pinnedModulesRef = ref(); + @@ -104,6 +114,9 @@ const pinnedModulesRef = ref(); .q-header { background-color: var(--vn-section-color); } +.no-visible { + visibility: hidden; +} en: diff --git a/src/stores/useStateQueryStore.js b/src/stores/useStateQueryStore.js new file mode 100644 index 000000000..d25dbb921 --- /dev/null +++ b/src/stores/useStateQueryStore.js @@ -0,0 +1,31 @@ +import { ref, computed } from 'vue'; +import { defineStore } from 'pinia'; + +export const useStateQueryStore = defineStore('stateQueryStore', () => { + const queries = ref(new Set()); + + function add(query) { + queries.value.add(query); + return query; + } + + function isLoading() { + return computed(() => queries.value.size); + } + + function remove(query) { + queries.value.delete(query); + } + + function reset() { + queries.value = new Set(); + } + + return { + add, + isLoading, + remove, + queries, + reset, + }; +}); diff --git a/test/vitest/__tests__/boot/axios.spec.js b/test/vitest/__tests__/boot/axios.spec.js index feb0d93ea..7a802b4d2 100644 --- a/test/vitest/__tests__/boot/axios.spec.js +++ b/test/vitest/__tests__/boot/axios.spec.js @@ -7,41 +7,46 @@ vi.mock('src/composables/useSession', () => ({ getToken: () => 'DEFAULT_TOKEN', isLoggedIn: () => vi.fn(), destroy: () => vi.fn(), - }) + }), +})); + +vi.mock('src/stores/useStateQueryStore', () => ({ + useStateQueryStore: () => ({ + add: () => vi.fn(), + remove: () => vi.fn(), + }), })); describe('Axios boot', () => { - describe('onRequest()', async () => { it('should set the "Authorization" property on the headers', async () => { const config = { headers: {} }; const resultConfig = onRequest(config); - expect(resultConfig).toEqual(expect.objectContaining({ - headers: { - Authorization: 'DEFAULT_TOKEN' - } - })); + expect(resultConfig).toEqual( + expect.objectContaining({ + headers: { + Authorization: 'DEFAULT_TOKEN', + }, + }) + ); }); - }) + }); describe('onResponseError()', async () => { it('should call to the Notify plugin with a message error for an status code "500"', async () => { - Notify.create = vi.fn() + Notify.create = vi.fn(); const error = { response: { - status: 500 - } + status: 500, + }, }; const result = onResponseError(error); - - expect(result).rejects.toEqual( - expect.objectContaining(error) - ); + expect(result).rejects.toEqual(expect.objectContaining(error)); expect(Notify.create).toHaveBeenCalledWith( expect.objectContaining({ message: 'An internal server error has ocurred', @@ -51,25 +56,22 @@ describe('Axios boot', () => { }); it('should call to the Notify plugin with a message from the response property', async () => { - Notify.create = vi.fn() + Notify.create = vi.fn(); const error = { response: { status: 401, data: { error: { - message: 'Invalid user or password' - } - } - } + message: 'Invalid user or password', + }, + }, + }, }; const result = onResponseError(error); - - expect(result).rejects.toEqual( - expect.objectContaining(error) - ); + expect(result).rejects.toEqual(expect.objectContaining(error)); expect(Notify.create).toHaveBeenCalledWith( expect.objectContaining({ message: 'Invalid user or password', @@ -77,5 +79,5 @@ describe('Axios boot', () => { }) ); }); - }) + }); }); diff --git a/test/vitest/__tests__/stores/useStateQueryStore.spec.js b/test/vitest/__tests__/stores/useStateQueryStore.spec.js new file mode 100644 index 000000000..1ee70cbe0 --- /dev/null +++ b/test/vitest/__tests__/stores/useStateQueryStore.spec.js @@ -0,0 +1,56 @@ +import { describe, expect, it, beforeEach, beforeAll } from 'vitest'; +import { createWrapper } from 'app/test/vitest/helper'; + +import { useStateQueryStore } from 'src/stores/useStateQueryStore'; + +describe('useStateQueryStore', () => { + beforeAll(() => { + createWrapper({}, {}); + }); + + const stateQueryStore = useStateQueryStore(); + const { add, isLoading, remove, reset } = useStateQueryStore(); + const firstQuery = { url: 'myQuery' }; + const secondQuery = { url: 'myQuery' }; + + function getQueries() { + return stateQueryStore.queries; + } + + beforeEach(() => { + reset(); + expect(getQueries().size).toBeFalsy(); + }); + + it('should add two queries', async () => { + expect(getQueries().size).toBeFalsy(); + add(firstQuery); + + expect(getQueries().size).toBeTruthy(); + expect(getQueries().has(firstQuery)).toBeTruthy(); + + add(); + expect(getQueries().size).toBe(2); + }); + + it('should add and remove loading state', async () => { + expect(isLoading().value).toBeFalsy(); + add(firstQuery); + expect(isLoading().value).toBeTruthy(); + remove(firstQuery); + expect(isLoading().value).toBeFalsy(); + }); + + it('should add and remove hash', async () => { + add(firstQuery); + add(secondQuery); + + const beforeCount = getQueries().size; + const hash = add(); + expect(getQueries().has(hash)).toBeTruthy(); + + remove(hash); + expect(getQueries().has(hash)).toBeFalsy(); + expect(getQueries().size).toBe(beforeCount); + }); +}); From f4caf6aecc272327e971eee3d5b37333c1329965 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 18 Oct 2024 11:06:06 +0200 Subject: [PATCH 3/4] test: refs #7632 not use hash word --- .../__tests__/stores/useStateQueryStore.spec.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/vitest/__tests__/stores/useStateQueryStore.spec.js b/test/vitest/__tests__/stores/useStateQueryStore.spec.js index 1ee70cbe0..d33c6c821 100644 --- a/test/vitest/__tests__/stores/useStateQueryStore.spec.js +++ b/test/vitest/__tests__/stores/useStateQueryStore.spec.js @@ -12,6 +12,7 @@ describe('useStateQueryStore', () => { const { add, isLoading, remove, reset } = useStateQueryStore(); const firstQuery = { url: 'myQuery' }; const secondQuery = { url: 'myQuery' }; + const thirdQuery = { url: 'myQuery' }; function getQueries() { return stateQueryStore.queries; @@ -41,16 +42,16 @@ describe('useStateQueryStore', () => { expect(isLoading().value).toBeFalsy(); }); - it('should add and remove hash', async () => { + it('should add and remove query', async () => { add(firstQuery); add(secondQuery); const beforeCount = getQueries().size; - const hash = add(); - expect(getQueries().has(hash)).toBeTruthy(); + add(thirdQuery); + expect(getQueries().has(thirdQuery)).toBeTruthy(); - remove(hash); - expect(getQueries().has(hash)).toBeFalsy(); + remove(thirdQuery); + expect(getQueries().has(thirdQuery)).toBeFalsy(); expect(getQueries().size).toBe(beforeCount); }); }); From d221b8e3c4e85e78b3440fe7c515c04ace94bfac Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 21 Oct 2024 12:04:20 +0200 Subject: [PATCH 4/4] chore: refs #7632 change requests --- src/boot/axios.js | 3 +-- src/components/NavBar.vue | 3 --- src/css/app.scss | 4 ++++ test/vitest/__tests__/stores/useStateQueryStore.spec.js | 5 +++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/boot/axios.js b/src/boot/axios.js index 25095f9cc..3bd80f487 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -29,8 +29,7 @@ const onResponse = (response) => { const config = response.config; stateQuery.remove(config); - const isSaveRequest = config.method === 'patch'; - if (isSaveRequest) { + if (config.method === 'patch') { notify('globals.dataSaved', 'positive'); } diff --git a/src/components/NavBar.vue b/src/components/NavBar.vue index 71d3b8a0f..9b0393489 100644 --- a/src/components/NavBar.vue +++ b/src/components/NavBar.vue @@ -114,9 +114,6 @@ const pinnedModulesRef = ref(); .q-header { background-color: var(--vn-section-color); } -.no-visible { - visibility: hidden; -} en: diff --git a/src/css/app.scss b/src/css/app.scss index 905934d4c..d4c76ad6b 100644 --- a/src/css/app.scss +++ b/src/css/app.scss @@ -288,3 +288,7 @@ input::-webkit-inner-spin-button { color: $info; } } + +.no-visible { + visibility: hidden; +} diff --git a/test/vitest/__tests__/stores/useStateQueryStore.spec.js b/test/vitest/__tests__/stores/useStateQueryStore.spec.js index d33c6c821..ab3afb007 100644 --- a/test/vitest/__tests__/stores/useStateQueryStore.spec.js +++ b/test/vitest/__tests__/stores/useStateQueryStore.spec.js @@ -11,8 +11,6 @@ describe('useStateQueryStore', () => { const stateQueryStore = useStateQueryStore(); const { add, isLoading, remove, reset } = useStateQueryStore(); const firstQuery = { url: 'myQuery' }; - const secondQuery = { url: 'myQuery' }; - const thirdQuery = { url: 'myQuery' }; function getQueries() { return stateQueryStore.queries; @@ -43,6 +41,9 @@ describe('useStateQueryStore', () => { }); it('should add and remove query', async () => { + const secondQuery = { ...firstQuery }; + const thirdQuery = { ...firstQuery }; + add(firstQuery); add(secondQuery);