Skip to content

Commit b223e21

Browse files
committed
refactoring
1 parent ab3310a commit b223e21

File tree

16 files changed

+229
-415
lines changed

16 files changed

+229
-415
lines changed

src/GraphQl/Queries/userTagQueries.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const USER_TAGS_ASSIGNED_MEMBERS = gql`
1515
$first: PositiveInt
1616
$last: PositiveInt
1717
) {
18-
getUserTag(id: $id) {
18+
getAssignedUsers: getUserTag(id: $id) {
1919
name
2020
usersAssignedTo(
2121
after: $after
@@ -57,7 +57,7 @@ export const USER_TAG_SUB_TAGS = gql`
5757
$first: PositiveInt
5858
$last: PositiveInt
5959
) {
60-
getUserTag(id: $id) {
60+
getChildTags: getUserTag(id: $id) {
6161
name
6262
childTags(after: $after, before: $before, first: $first, last: $last) {
6363
edges {
@@ -99,7 +99,7 @@ export const USER_TAGS_MEMBERS_TO_ASSIGN_TO = gql`
9999
$first: PositiveInt
100100
$last: PositiveInt
101101
) {
102-
getUserTag(id: $id) {
102+
getUsersToAssignTo: getUserTag(id: $id) {
103103
name
104104
usersToAssignTo(
105105
after: $after

src/components/AddPeopleToTag/AddPeopleToTag.tsx

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const AddPeopleToTag: React.FC<InterfaceAddPeopleToTagProps> = ({
6767
first: TAGS_QUERY_PAGE_SIZE,
6868
},
6969
skip: !addPeopleToTagModalIsOpen,
70+
fetchPolicy: 'no-cache',
7071
},
7172
);
7273

@@ -75,29 +76,31 @@ const AddPeopleToTag: React.FC<InterfaceAddPeopleToTagProps> = ({
7576
variables: {
7677
first: TAGS_QUERY_PAGE_SIZE,
7778
after:
78-
userTagsMembersToAssignToData?.getUserTag.usersToAssignTo.pageInfo
79-
.endCursor, // Fetch after the last loaded cursor
79+
userTagsMembersToAssignToData?.getUsersToAssignTo.usersToAssignTo
80+
.pageInfo.endCursor, // Fetch after the last loaded cursor
8081
},
8182
updateQuery: (
82-
prevResult: { getUserTag: InterfaceQueryUserTagsMembersToAssignTo },
83+
prevResult: {
84+
getUsersToAssignTo: InterfaceQueryUserTagsMembersToAssignTo;
85+
},
8386
{
8487
fetchMoreResult,
8588
}: {
8689
fetchMoreResult: {
87-
getUserTag: InterfaceQueryUserTagsMembersToAssignTo;
90+
getUsersToAssignTo: InterfaceQueryUserTagsMembersToAssignTo;
8891
};
8992
},
9093
) => {
9194
if (!fetchMoreResult) return prevResult;
9295

9396
return {
94-
getUserTag: {
95-
...fetchMoreResult.getUserTag,
97+
getUsersToAssignTo: {
98+
...fetchMoreResult.getUsersToAssignTo,
9699
usersToAssignTo: {
97-
...fetchMoreResult.getUserTag.usersToAssignTo,
100+
...fetchMoreResult.getUsersToAssignTo.usersToAssignTo,
98101
edges: [
99-
...prevResult.getUserTag.usersToAssignTo.edges,
100-
...fetchMoreResult.getUserTag.usersToAssignTo.edges,
102+
...prevResult.getUsersToAssignTo.usersToAssignTo.edges,
103+
...fetchMoreResult.getUsersToAssignTo.usersToAssignTo.edges,
101104
],
102105
},
103106
},
@@ -106,8 +109,13 @@ const AddPeopleToTag: React.FC<InterfaceAddPeopleToTagProps> = ({
106109
});
107110
};
108111

112+
// const userTagMembersToAssignTo =
113+
// userTagsMembersToAssignToData?.getUsersToAssignTo.usersToAssignTo.edges.map(
114+
// (edge) => edge.node,
115+
// );
116+
109117
const userTagMembersToAssignTo =
110-
userTagsMembersToAssignToData?.getUserTag.usersToAssignTo.edges.map(
118+
userTagsMembersToAssignToData?.getUsersToAssignTo.usersToAssignTo.edges.map(
111119
(edge) => edge.node,
112120
);
113121

@@ -289,8 +297,8 @@ const AddPeopleToTag: React.FC<InterfaceAddPeopleToTagProps> = ({
289297
dataLength={userTagMembersToAssignTo?.length ?? 0} // This is important field to render the next data
290298
next={loadMoreMembersToAssignTo}
291299
hasMore={
292-
userTagsMembersToAssignToData?.getUserTag.usersToAssignTo
293-
.pageInfo.hasNextPage ?? false
300+
userTagsMembersToAssignToData?.getUsersToAssignTo
301+
.usersToAssignTo.pageInfo.hasNextPage ?? false
294302
}
295303
loader={<InfiniteScrollLoader />}
296304
scrollableTarget="scrollableDiv"

src/components/AddPeopleToTag/AddPeopleToTagsMocks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const MOCKS = [
1313
},
1414
result: {
1515
data: {
16-
getUserTag: {
16+
getUsersToAssignTo: {
1717
name: 'tag1',
1818
usersToAssignTo: {
1919
edges: [
@@ -121,7 +121,7 @@ export const MOCKS = [
121121
},
122122
result: {
123123
data: {
124-
getUserTag: {
124+
getUsersToAssignTo: {
125125
name: 'tag1',
126126
usersToAssignTo: {
127127
edges: [

src/components/TagActions/TagActions.test.tsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ const translations = {
5050

5151
const props: InterfaceTagActionsProps[] = [
5252
{
53-
assignToTagsModalIsOpen: true,
54-
hideAssignToTagsModal: () => {},
53+
tagActionsModalIsOpen: true,
54+
hideTagActionsModal: () => {},
5555
tagActionType: 'assignToTags',
5656
t: (key: string) => translations[key],
5757
tCommon: (key: string) => translations[key],
5858
},
5959
{
60-
assignToTagsModalIsOpen: true,
61-
hideAssignToTagsModal: () => {},
60+
tagActionsModalIsOpen: true,
61+
hideTagActionsModal: () => {},
6262
tagActionType: 'removeFromTags',
6363
t: (key: string) => translations[key],
6464
tCommon: (key: string) => translations[key],
@@ -120,6 +120,31 @@ describe('Organisation Tags Page', () => {
120120
});
121121
});
122122

123+
test('Component calls hideTagActionsModal when modal is closed', async () => {
124+
const hideTagActionsModalMock = jest.fn();
125+
126+
const props2: InterfaceTagActionsProps = {
127+
tagActionsModalIsOpen: true,
128+
hideTagActionsModal: hideTagActionsModalMock,
129+
tagActionType: 'assignToTags',
130+
t: (key: string) => key,
131+
tCommon: (key: string) => key,
132+
};
133+
134+
renderTagActionsModal(props2, link);
135+
136+
await wait();
137+
138+
await waitFor(() => {
139+
expect(screen.getByTestId('closeTagActionsModalBtn')).toBeInTheDocument();
140+
});
141+
userEvent.click(screen.getByTestId('closeTagActionsModalBtn'));
142+
143+
await waitFor(() => {
144+
expect(hideTagActionsModalMock).toHaveBeenCalled();
145+
});
146+
});
147+
123148
test('Renders error component when when query is unsuccessful', async () => {
124149
const { queryByText } = renderTagActionsModal(props[0], link2);
125150

src/components/TagActions/TagActions.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ interface InterfaceUserTagsAncestorData {
3535
* Props for the `AssignToTags` component.
3636
*/
3737
export interface InterfaceTagActionsProps {
38-
assignToTagsModalIsOpen: boolean;
39-
hideAssignToTagsModal: () => void;
38+
tagActionsModalIsOpen: boolean;
39+
hideTagActionsModal: () => void;
4040
tagActionType: TagActionType;
4141
t: (key: string) => string;
4242
tCommon: (key: string) => string;
4343
}
4444

4545
const TagActions: React.FC<InterfaceTagActionsProps> = ({
46-
assignToTagsModalIsOpen,
47-
hideAssignToTagsModal,
46+
tagActionsModalIsOpen,
47+
hideTagActionsModal,
4848
tagActionType,
4949
t,
5050
tCommon,
@@ -61,7 +61,7 @@ const TagActions: React.FC<InterfaceTagActionsProps> = ({
6161
id: orgId,
6262
first: TAGS_QUERY_PAGE_SIZE,
6363
},
64-
skip: !assignToTagsModalIsOpen,
64+
skip: !tagActionsModalIsOpen,
6565
});
6666

6767
const loadMoreUserTags = (): void => {
@@ -244,7 +244,7 @@ const TagActions: React.FC<InterfaceTagActionsProps> = ({
244244

245245
if (data) {
246246
toast.success(t('successfullyAssignedToTags'));
247-
hideAssignToTagsModal();
247+
hideTagActionsModal();
248248
}
249249
} catch (error: unknown) {
250250
/* istanbul ignore next */
@@ -271,7 +271,7 @@ const TagActions: React.FC<InterfaceTagActionsProps> = ({
271271

272272
if (data) {
273273
toast.success(t('successfullyRemovedFromTags'));
274-
hideAssignToTagsModal();
274+
hideTagActionsModal();
275275
}
276276
} catch (error: unknown) {
277277
/* istanbul ignore next */
@@ -299,8 +299,8 @@ const TagActions: React.FC<InterfaceTagActionsProps> = ({
299299
return (
300300
<>
301301
<Modal
302-
show={assignToTagsModalIsOpen}
303-
onHide={hideAssignToTagsModal}
302+
show={tagActionsModalIsOpen}
303+
onHide={hideTagActionsModal}
304304
backdrop="static"
305305
aria-labelledby="contained-modal-title-vcenter"
306306
centered
@@ -398,7 +398,7 @@ const TagActions: React.FC<InterfaceTagActionsProps> = ({
398398
<Modal.Footer>
399399
<Button
400400
variant="secondary"
401-
onClick={(): void => hideAssignToTagsModal()}
401+
onClick={(): void => hideTagActionsModal()}
402402
data-testid="closeTagActionsModalBtn"
403403
>
404404
{tCommon('cancel')}

src/components/TagActions/TagActionsMocks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export const MOCKS = [
230230
},
231231
result: {
232232
data: {
233-
getUserTag: {
233+
getChildTags: {
234234
name: 'userTag 1',
235235
childTags: {
236236
edges: [
@@ -388,7 +388,7 @@ export const MOCKS = [
388388
},
389389
result: {
390390
data: {
391-
getUserTag: {
391+
getChildTags: {
392392
name: 'tag1',
393393
childTags: {
394394
edges: [

src/components/TagActions/TagNode.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,26 @@ const TagNode: React.FC<InterfaceTagNodeProps> = ({
4242
fetchMoreSubTags({
4343
variables: {
4444
first: TAGS_QUERY_PAGE_SIZE,
45-
after: subTagsData?.getUserTag.childTags.pageInfo.endCursor,
45+
after: subTagsData?.getChildTags.childTags.pageInfo.endCursor,
4646
},
4747
updateQuery: (
48-
prevResult: { getUserTag: InterfaceQueryUserTagChildTags },
48+
prevResult: { getChildTags: InterfaceQueryUserTagChildTags },
4949
{
5050
fetchMoreResult,
5151
}: {
52-
fetchMoreResult?: { getUserTag: InterfaceQueryUserTagChildTags };
52+
fetchMoreResult?: { getChildTags: InterfaceQueryUserTagChildTags };
5353
},
5454
) => {
5555
if (!fetchMoreResult) return prevResult;
5656

5757
return {
58-
getUserTag: {
59-
...fetchMoreResult.getUserTag,
58+
getChildTags: {
59+
...fetchMoreResult.getChildTags,
6060
childTags: {
61-
...fetchMoreResult.getUserTag.childTags,
61+
...fetchMoreResult.getChildTags.childTags,
6262
edges: [
63-
...prevResult.getUserTag.childTags.edges,
64-
...fetchMoreResult.getUserTag.childTags.edges,
63+
...prevResult.getChildTags.childTags.edges,
64+
...fetchMoreResult.getChildTags.childTags.edges,
6565
],
6666
},
6767
},
@@ -70,7 +70,7 @@ const TagNode: React.FC<InterfaceTagNodeProps> = ({
7070
});
7171
};
7272

73-
const subTagsList = subTagsData?.getUserTag.childTags.edges.map(
73+
const subTagsList = subTagsData?.getChildTags.childTags.edges.map(
7474
(edge) => edge.node,
7575
);
7676

@@ -151,7 +151,8 @@ const TagNode: React.FC<InterfaceTagNodeProps> = ({
151151
dataLength={subTagsList?.length ?? 0}
152152
next={loadMoreSubTags}
153153
hasMore={
154-
subTagsData?.getUserTag.childTags.pageInfo.hasNextPage ?? false
154+
subTagsData?.getChildTags.childTags.pageInfo.hasNextPage ??
155+
false
155156
}
156157
loader={<InfiniteScrollLoader />}
157158
scrollableTarget={`subTagsScrollableDiv${tag._id}`}

0 commit comments

Comments
 (0)