Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: My Grants showing all grants #3513

Merged
merged 3 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: update this to a uuid. my concern is there is a possibility of collision if the state information here is stale and the IDs are too close to each other. I feel like using a uuid might eliminate the possibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 will update in next pr

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
Loading