Skip to content

Commit 8cca59f

Browse files
authored
Merge pull request #2814 from JoinColony/fix/2530-agreements-pagination
Fix/2530 agreements pagination
2 parents d230723 + b461b0e commit 8cca59f

File tree

9 files changed

+115
-18
lines changed

9 files changed

+115
-18
lines changed

src/components/common/ColonyActionsTable/partials/ActionDescription/ActionDescription.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const ActionDescription: FC<ActionDescriptionProps> = ({
2626
initiatorUser: user,
2727
initiatorAddress,
2828
metadata,
29+
decisionData,
2930
isMotion,
3031
motionData,
3132
motionState,
@@ -100,7 +101,10 @@ const ActionDescription: FC<ActionDescriptionProps> = ({
100101
},
101102
)}
102103
>
103-
{metadata?.customTitle || actionMetadataDescription || '-'}
104+
{metadata?.customTitle ||
105+
decisionData?.title ||
106+
actionMetadataDescription ||
107+
'-'}
104108
</p>
105109
{colony && (
106110
<p

src/components/frame/v5/pages/AgreementsPage/hooks.ts

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,117 @@
1-
import { useMemo } from 'react';
1+
import { useEffect, useMemo } from 'react';
2+
import { useSearchParams } from 'react-router-dom';
23

34
import { useColonyContext } from '~context/ColonyContext/ColonyContext.ts';
45
import {
56
useGetColonyActionsQuery,
67
ColonyActionType,
78
ModelSortDirection,
9+
useGetColonyActionQuery,
810
} from '~gql';
911
import {
1012
filterActionByMotionState,
1113
makeWithMotionStateMapper,
1214
} from '~hooks/useActivityFeed/helpers.ts';
1315
import useNetworkMotionStates from '~hooks/useNetworkMotionStates.ts';
1416
import { notNull } from '~utils/arrays/index.ts';
17+
import { isTransactionFormat } from '~utils/web3/index.ts';
1518

1619
import { useFiltersContext } from './FiltersContext/FiltersContext.ts';
1720

18-
export const useGetAgreements = () => {
21+
const QUERY_PAGE_SIZE = 20;
22+
23+
const useGetAllAgreements = () => {
1924
const {
2025
colony: { colonyAddress },
2126
} = useColonyContext();
22-
const { activeFilters, searchFilter } = useFiltersContext();
23-
const { data, loading } = useGetColonyActionsQuery({
27+
28+
const { data, loading, fetchMore, refetch } = useGetColonyActionsQuery({
2429
variables: {
2530
colonyAddress,
2631
filter: {
2732
type: { eq: ColonyActionType.CreateDecisionMotion },
2833
},
2934
sortDirection: ModelSortDirection.Desc,
35+
limit: QUERY_PAGE_SIZE,
3036
},
3137
fetchPolicy: 'network-only',
38+
onCompleted: (newData) => {
39+
if (newData?.getActionsByColony?.nextToken) {
40+
fetchMore({
41+
variables: { nextToken: newData?.getActionsByColony?.nextToken },
42+
updateQuery: (prev, { fetchMoreResult }) => {
43+
if (!fetchMoreResult) return prev;
44+
45+
// Here, combine the previous items with the newly fetched items
46+
return {
47+
...prev,
48+
getActionsByColony: {
49+
...prev.getActionsByColony,
50+
items: [
51+
...(prev.getActionsByColony?.items ?? []),
52+
...(fetchMoreResult.getActionsByColony?.items ?? []),
53+
],
54+
nextToken: fetchMoreResult?.getActionsByColony?.nextToken,
55+
},
56+
};
57+
},
58+
});
59+
}
60+
},
3261
});
3362

3463
const agreementsData = data?.getActionsByColony?.items.filter(notNull);
64+
65+
return {
66+
agreementsData,
67+
loading,
68+
refetchAgreements: refetch,
69+
};
70+
};
71+
72+
export const useGetCurrentOpenedAgreement = () => {
73+
const [searchParams] = useSearchParams();
74+
const transactionHash = searchParams.get('tx');
75+
const isInvalidTx = !isTransactionFormat(transactionHash ?? undefined);
76+
const { data: actionData } = useGetColonyActionQuery({
77+
skip: isInvalidTx,
78+
variables: {
79+
transactionHash: transactionHash ?? '',
80+
},
81+
});
82+
const action = actionData?.getColonyAction;
83+
const motionData = action?.motionData;
84+
85+
return action?.type === ColonyActionType.CreateDecisionMotion
86+
? motionData
87+
: null;
88+
};
89+
90+
export const useGetAgreements = () => {
91+
const currentAgreement = useGetCurrentOpenedAgreement();
92+
93+
const { activeFilters, searchFilter } = useFiltersContext();
94+
95+
const { agreementsData, refetchAgreements, loading } = useGetAllAgreements();
96+
3597
const motionIds = useMemo(
3698
() =>
3799
agreementsData
38100
?.map((action) => action?.motionData?.motionId ?? '')
39101
.filter(Boolean) || [],
40102
[agreementsData],
41103
);
104+
105+
useEffect(() => {
106+
if (
107+
!loading &&
108+
currentAgreement?.motionId &&
109+
!motionIds.includes(currentAgreement?.motionId)
110+
) {
111+
refetchAgreements();
112+
}
113+
}, [currentAgreement?.motionId, motionIds, loading, refetchAgreements]);
114+
42115
const {
43116
motionStatesMap,
44117
loading: motionStatesLoading,

src/components/v5/common/ActionSidebar/partials/ActionSidebarContent/ActionSidebarContent.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ActionForm } from '~shared/Fields/index.ts';
1515
import { DecisionMethod } from '~types/actions.ts';
1616
import { getDraftDecisionFromStore } from '~utils/decisions.ts';
1717
import { formatText } from '~utils/intl.ts';
18+
import { isQueryActive } from '~utils/isQueryActive.ts';
1819
import FormTextareaBase from '~v5/common/Fields/TextareaBase/FormTextareaBase.tsx';
1920
import NotificationBanner from '~v5/shared/NotificationBanner/index.ts';
2021

@@ -222,9 +223,11 @@ const ActionSidebarContent: FC<ActionSidebarContentProps> = ({
222223
className="flex h-full flex-col"
223224
innerRef={formRef}
224225
onSuccess={() => {
225-
client.refetchQueries({
226-
include: [SearchActionsDocument],
227-
});
226+
if (isQueryActive('SearchActions')) {
227+
client.refetchQueries({
228+
include: [SearchActionsDocument],
229+
});
230+
}
228231
}}
229232
>
230233
<ActionSidebarFormContent

src/components/v5/common/ActionSidebar/partials/Motions/steps/FinalizeStep/FinalizeStep.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,18 @@ const FinalizeStep: FC<FinalizeStepProps> = ({
8181
return stopPollingAction;
8282
}, [isClaimed, stopPollingAction]);
8383

84-
/* Update colony object when motion gets finalized. */
84+
/* Update colony object when motion gets finalized or is agreement. */
8585
useEffect(() => {
86-
if (actionData.motionData.isFinalized && !hasFinalizedHandlerRun.current) {
86+
if (
87+
(isMotionAgreement || isMotionFinalized) &&
88+
!hasFinalizedHandlerRun.current
89+
) {
8790
refetchColony();
8891
setIsPolling(false);
8992
handleMotionFinalized(actionData);
9093
hasFinalizedHandlerRun.current = true;
9194
}
92-
}, [actionData, refetchColony]);
95+
}, [isMotionAgreement, isMotionFinalized, actionData, refetchColony]);
9396

9497
let action = {
9598
actionType: ActionTypes.MOTION_FINALIZE,

src/components/v5/common/ActionSidebar/partials/Motions/steps/FinalizeStep/utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { ColonyActionType } from '~gql';
1+
import { apolloClient } from '~apollo';
2+
import { ColonyActionType, SearchActionsDocument } from '~gql';
23
import { type MotionAction } from '~types/motions.ts';
4+
import { isQueryActive } from '~utils/isQueryActive.ts';
35
import { updateContributorVerifiedStatus } from '~utils/members.ts';
46

57
export const handleMotionFinalized = (action: MotionAction) => {
@@ -24,6 +26,13 @@ export const handleMotionFinalized = (action: MotionAction) => {
2426
}
2527
break;
2628
}
29+
case ColonyActionType.CreateDecisionMotion: {
30+
if (isQueryActive('SearchActions')) {
31+
apolloClient.refetchQueries({ include: [SearchActionsDocument] });
32+
}
33+
34+
break;
35+
}
2736
default: {
2837
break;
2938
}

src/components/v5/common/CompletedAction/partials/CreateDecision/CreateDecision.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ interface CreateDecisionProps {
2626
const MSG = defineMessages({
2727
defaultTitle: {
2828
id: `${displayName}.defaultTitle`,
29-
defaultMessage: 'Create decision',
29+
defaultMessage: 'Create agreement',
3030
},
3131
subtitle: {
3232
id: `${displayName}.subtitle`,
33-
defaultMessage: 'Decision by {user}',
33+
defaultMessage: 'Agreement by {user}',
3434
},
3535
});
3636

src/hooks/useActivityFeed/helpers.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ export const getBaseSearchActionsFilterVariable = (
141141
showInActionsList: {
142142
eq: true,
143143
},
144-
colonyDecisionId: {
145-
exists: false,
146-
},
147144
isMotionFinalization: {
148145
ne: true,
149146
},

src/i18n/en-actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const actionsMessageDescriptors = {
8181
${ColonyActionType.EmitDomainReputationPenaltyMotion} {Manage reputation}
8282
${ColonyActionType.EmitDomainReputationReward} {Manage reputation}
8383
${ColonyActionType.EmitDomainReputationRewardMotion} {Manage reputation}
84-
${ColonyActionType.CreateDecisionMotion} {Decision}
84+
${ColonyActionType.CreateDecisionMotion} {Agreement}
8585
${ColonyActionType.AddVerifiedMembers} {Manage verified members}
8686
${ColonyActionType.AddVerifiedMembersMotion} {Manage verified members}
8787
${ColonyActionType.RemoveVerifiedMembers} {Manage verified members}

src/utils/isQueryActive.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { apolloClient } from '~apollo';
2+
3+
export const isQueryActive = (queryName: string) => {
4+
const activeQueries = apolloClient.getObservableQueries();
5+
return Array.from(activeQueries.values()).some((query) => {
6+
return query.queryName?.includes(queryName);
7+
});
8+
};

0 commit comments

Comments
 (0)