Skip to content

Commit

Permalink
Bug fix: My Grants showing all grants (#3513)
Browse files Browse the repository at this point in the history
* resolve visible console errors

* resolve race condition
  • Loading branch information
greg-adams authored Sep 17, 2024
1 parent 0c06f9a commit 835d833
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 33 deletions.
25 changes: 4 additions & 21 deletions packages/client/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const routes = [
{
path: '/grants',
name: 'grants',
component: () => import('../views/GrantsView.vue'),
component: () => import('@/views/GrantsView.vue'),
meta: {
requiresAuth: true,
},
Expand All @@ -86,27 +86,10 @@ export const routes = [
path: '/my-grants',
redirect: { name: 'myGrants', params: { tab: myGrantsTabs[0] } },
},
{
path: '/my-grants/assigned',
name: 'assigned',
redirect: { name: shareTerminologyEnabled ? 'shared-with-your-team' : undefined },
meta: {
requiresAuth: true,
},
},
{
path: '/my-grants/shared-with-your-team',
name: 'shared-with-your-team',
component: () => import('@/views/MyGrantsView.vue'),
meta: {
requiresAuth: true,
requiresShareTerminologyEnabled: true,
},
},
{
path: '/my-grants/:tab',
name: 'myGrants',
component: () => import('../views/MyGrantsView.vue'),
component: () => import('@/views/MyGrantsView.vue'),
meta: {
tabNames: myGrantsTabs,
requiresAuth: true,
Expand Down Expand Up @@ -166,7 +149,7 @@ export const routes = [
{
path: '/my-profile',
name: 'myProfile',
component: () => import('../views/MyProfileView.vue'),
component: () => import('@/views/MyProfileView.vue'),
meta: {
requiresAuth: true,
hideLayoutTabs: true,
Expand All @@ -176,7 +159,7 @@ export const routes = [
},
{
path: '/:pathMatch(.*)*',
component: () => import('../views/NotFoundView.vue'),
component: () => import('@/views/NotFoundView.vue'),
name: 'notFound',
meta: {
requiresAuth: true,
Expand Down
24 changes: 17 additions & 7 deletions packages/client/src/store/modules/grants.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function initialState() {
totalUpcomingGrants: 0,
totalInterestedGrants: 0,
currentGrant: {},
grantsRequestId: 0,
searchFormFilters: {
costSharing: null,
opportunityStatuses: [],
Expand Down Expand Up @@ -139,16 +140,23 @@ export default {
return fetchApi.get(`/api/organizations/${rootGetters['users/selectedAgencyId']}/grants?${query}`)
.then((data) => commit('SET_GRANTS', data));
},
fetchGrantsNext({ commit, rootGetters }, {
fetchGrantsNext({ state, commit, rootGetters }, {
currentPage, perPage, orderBy, orderDesc,
}) {
const pagination = { currentPage, perPage };
const ordering = { orderBy, orderDesc };
const filters = { ...this.state.grants.searchFormFilters };
const { criteriaQuery, paginationQuery, orderingQuery } = buildGrantsNextQuery({ filters, ordering, pagination });

// Avoid race conditions for tabs sharing grant fetching
const requestId = state.grantsRequestId + 1;
commit('SET_GRANTS_REQUEST_ID', requestId);
return fetchApi.get(`/api/organizations/${rootGetters['users/selectedAgencyId']}/grants/next?${paginationQuery}&${orderingQuery}&${criteriaQuery}`)
.then((data) => commit('SET_GRANTS', data));
.then((data) => {
if (requestId === state.grantsRequestId) {
commit('SET_GRANTS', data);
}
});
},
// Retrieves grants that the user's team (or any subteam) has interacted with (either by setting status or assigning to a user).
// Sorted in descending order by the date on which the interaction occurred (recently interacted with are first).
Expand Down Expand Up @@ -185,16 +193,15 @@ export default {
agencyIds,
});
},
unmarkGrantAsInterested({ rootGetters }, {
async unmarkGrantAsInterested({ rootGetters, commit, dispatch }, {
grantId, agencyIds, interestedCode, agencyId,
}) {
return fetchApi.deleteRequest(`/api/organizations/${rootGetters['users/selectedAgencyId']}/grants/${grantId}/interested/${agencyId}`, {
await fetchApi.deleteRequest(`/api/organizations/${rootGetters['users/selectedAgencyId']}/grants/${grantId}/interested/${agencyId}`, {
agencyIds,
interestedCode,
});
},
fetchInterestedAgencies({ rootGetters }, { grantId }) {
return fetchApi.get(`/api/organizations/${rootGetters['users/selectedAgencyId']}/grants/${grantId}/interested`);
const interestedAgencies = await dispatch('getInterestedAgencies', { grantId });
commit('UPDATE_GRANT', { grantId, data: { interested_agencies: interestedAgencies } });
},
async markGrantAsInterested({ commit, rootGetters }, { grantId, agencyId, interestedCode }) {
const interestedAgencies = await fetchApi.put(`/api/organizations/${rootGetters['users/selectedAgencyId']}/grants/${grantId}/interested/${agencyId}`, {
Expand Down Expand Up @@ -408,5 +415,8 @@ export default {
SET_TABLE_MODE(state, tableMode) {
state.tableMode = tableMode;
},
SET_GRANTS_REQUEST_ID(state, id) {
state.grantsRequestId = id;
},
},
};
4 changes: 1 addition & 3 deletions packages/client/src/views/GrantDetailsView.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import GrantDetailsView from '@/views/GrantDetailsView.vue';

import {
describe, it, expect, vi,
} from 'vitest';
import { shallowMount } from '@vue/test-utils';
import { createStore } from 'vuex';
import GrantDetailsView from '@/views/GrantDetailsView.vue';

describe('GrantDetailsView', () => {
const store = createStore({
Expand All @@ -23,7 +22,6 @@ describe('GrantDetailsView', () => {
'grants/markGrantAsViewed': vi.fn(),
'grants/markGrantAsInterested': vi.fn(),
'grants/unmarkGrantAsInterested': vi.fn(),
'grants/getInterestedAgencies': vi.fn(),
'grants/getGrantAssignedAgencies': vi.fn(),
'grants/assignAgenciesToGrant': vi.fn(),
'grants/unassignAgenciesToGrant': vi.fn(),
Expand Down
2 changes: 0 additions & 2 deletions packages/client/src/views/GrantDetailsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ export default {
markGrantAsViewedAction: 'grants/markGrantAsViewed',
markGrantAsInterestedAction: 'grants/markGrantAsInterested',
unmarkGrantAsInterestedAction: 'grants/unmarkGrantAsInterested',
getInterestedAgencies: 'grants/getInterestedAgencies',
fetchAgencies: 'agencies/fetchAgencies',
fetchGrantDetails: 'grants/fetchGrantDetails',
}),
Expand Down Expand Up @@ -421,7 +420,6 @@ export default {
agencyIds: [agency.agency_id],
interestedCode: agency.interested_code_id,
});
this.currentGrant.interested_agencies = await this.getInterestedAgencies({ grantId: this.currentGrant.grant_id });
const eventName = 'remove team status for grant';
gtagEvent(eventName);
datadogRum.addAction(eventName);
Expand Down

0 comments on commit 835d833

Please sign in to comment.