Skip to content

Commit

Permalink
put org_uuid base check for status filter functionality on the org ho…
Browse files Browse the repository at this point in the history
…mepage
  • Loading branch information
MahtabBukhari committed Jan 23, 2024
1 parent 18747e8 commit 9eebef7
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 15 deletions.
3 changes: 2 additions & 1 deletion frontend/app/src/pages/tickets/org/OrgTickets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function OrgBodyComponent() {
await main.getBadgeList();
await main.getPeople();
if (uuid) {
await main.getOrganizationBounties(uuid, { page: 1, resetPage: true });
await main.getSpecificOrganizationBounties(uuid, { page: 1, resetPage: true });
}
setLoading(false);
})();
Expand Down Expand Up @@ -188,6 +188,7 @@ function OrgBodyComponent() {
fromBountyPage={true}
selectedWidget={selectedWidget}
loading={loading}
org_uuid={uuid}
/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/pages/tickets/org/orgHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export const OrgHeader = ({

useEffect(() => {
if (org_uuid) {
main.getOrganizationBounties(org_uuid, {
main.getSpecificOrganizationBounties(org_uuid, {
page: 1,
resetPage: true,
...checkboxIdToSelectedMap,
Expand Down
5 changes: 4 additions & 1 deletion frontend/app/src/people/widgetViews/WidgetSwitchViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function WidgetSwitchViewer(props: any) {

const { peoplePosts, peopleBounties, peopleOffers } = main;

const { selectedWidget, onPanelClick } = props;
const { selectedWidget, onPanelClick, org_uuid } = props;

if (!selectedWidget) {
return <div style={{ height: 200 }} />;
Expand All @@ -110,6 +110,9 @@ function WidgetSwitchViewer(props: any) {

const activeList = [...listSource[selectedWidget]].filter(({ body }: any) => {
const value = { ...body };
if (org_uuid) {
return value.org_uuid === org_uuid;
}
return value;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const MockProps: OrgBountyHeaderProps = {

describe('OrgHeader Component', () => {
beforeEach(() => {
jest.spyOn(mainStore, 'getOrganizationBounties').mockReset();
jest.spyOn(mainStore, 'getSpecificOrganizationBounties').mockReset();
});

afterEach(() => {
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('OrgHeader Component', () => {
<OrgHeader {...MockProps} checkboxIdToSelectedMap={updatedCheckboxIdToSelectedMap} />
);

expect(mainStore.getOrganizationBounties).toHaveBeenCalledWith(MockProps.org_uuid, {
expect(mainStore.getSpecificOrganizationBounties).toHaveBeenCalledWith(MockProps.org_uuid, {
page: 1,
resetPage: true,
...updatedCheckboxIdToSelectedMap,
Expand Down
70 changes: 60 additions & 10 deletions frontend/app/src/store/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export interface OrgBountyStatus {
}

export const defaultOrgBountyStatus: OrgBountyStatus = {
Open: true,
Open: false,
Assigned: false,
Paid: false,
Completed: false
Expand Down Expand Up @@ -1088,8 +1088,8 @@ export class MainStore {
}
}

getWantedsOrgPrevParams?: QueryParams = {};
async getOrganizationBounties(uuid: string, params?: any): Promise<PersonBounty[]> {
getWantedsSpecOrgPrevParams?: QueryParams = {};
async getSpecificOrganizationBounties(uuid: string, params?: any): Promise<PersonBounty[]> {
const queryParams: QueryParams = {
limit: queryLimit,
sortBy: 'created',
Expand All @@ -1101,7 +1101,7 @@ export class MainStore {

if (params) {
// save previous params
this.getWantedsOrgPrevParams = queryParams;
this.getWantedsSpecOrgPrevParams = queryParams;
}

// if we don't pass the params, we should use previous params for invalidate query
Expand Down Expand Up @@ -1129,13 +1129,63 @@ export class MainStore {
organization = { ...ps2[i].organization };
}

if (bounty.org_uuid === uuid) {
ps3.push({
body: { ...bounty, assignee: assignee || '' },
person: { ...owner, wanteds: [] } || { wanteds: [] },
organization: { ...organization }
});
ps3.push({
body: { ...bounty, assignee: assignee || '' },
person: { ...owner, wanteds: [] } || { wanteds: [] },
organization: { ...organization }
});
}
}

// for search always reset page
if (queryParams && queryParams.resetPage) {
this.setPeopleBounties(ps3);
uiStore.setPeopleBountiesPageNumber(1);
} else {
// all other cases, merge
const wanteds = this.doPageListMerger(
this.peopleBounties,
ps3,
(n: any) => uiStore.setPeopleBountiesPageNumber(n),
queryParams,
'wanted'
);

this.setPeopleBounties(wanteds);
}
return ps3;
} catch (e) {
console.log('fetch failed getOrganizationBounties: ', e);
return [];
}
}

async getOrganizationBounties(uuid: string, queryParams?: any): Promise<PersonBounty[]> {
queryParams = { ...queryParams, search: uiStore.searchText };
try {
const ps2 = await api.get(`organizations/bounties/${uuid}`);
const ps3: any[] = [];

if (ps2 && ps2.length) {
for (let i = 0; i < ps2.length; i++) {
const bounty = { ...ps2[i].bounty };
let assignee;
let organization;
const owner = { ...ps2[i].owner };

if (bounty.assignee) {
assignee = { ...ps2[i].assignee };
}

if (bounty.org_uuid) {
organization = { ...ps2[i].organization };
}

ps3.push({
body: { ...bounty, assignee: assignee || '' },
person: { ...owner, wanteds: [] } || { wanteds: [] },
organization: { ...organization }
});
}
}

Expand Down

0 comments on commit 9eebef7

Please sign in to comment.