Skip to content

Commit ca67759

Browse files
authored
Merge pull request #392 from AppQuality/fix-tags-multiselect
Fix tags multiselect
2 parents c03750b + cfda90d commit ca67759

File tree

6 files changed

+51
-42
lines changed

6 files changed

+51
-42
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.4.0",
44
"private": true,
55
"dependencies": {
6-
"@appquality/unguess-design-system": "2.12.55",
6+
"@appquality/unguess-design-system": "2.12.57",
77
"@headwayapp/react-widget": "^0.0.4",
88
"@reduxjs/toolkit": "^1.8.0",
99
"@rtk-query/codegen-openapi": "^1.0.0-alpha.1",

src/features/api/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const apiSlice = createApi({
2424
'Reports',
2525
'Templates',
2626
'Bugs',
27+
'Tags',
2728
],
2829
endpoints: () => ({}),
2930
});

src/features/api/apiTags.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ unguessApi.enhanceEndpoints({
5959
getCampaignsByCidWidgets: {
6060
providesTags: ['Bugs'],
6161
},
62+
patchCampaignsByCidBugsAndBid: {
63+
invalidatesTags: ['Tags'],
64+
},
65+
getCampaignsByCidTags: {
66+
providesTags: ['Tags'],
67+
},
68+
getCampaignsByCidBugsAndBid: {
69+
providesTags: ['Tags'],
70+
},
6271
},
6372
});
6473

src/pages/Bugs/Detail/Tags.tsx

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MD, MultiSelect, Skeleton } from '@appquality/unguess-design-system';
1+
import { MD, Skeleton, MultiSelect } from '@appquality/unguess-design-system';
22
import { useTranslation } from 'react-i18next';
33
import {
44
Bug,
@@ -31,25 +31,11 @@ export default ({
3131
campaignId: number;
3232
}) => {
3333
const { t } = useTranslation();
34+
const [options, setOptions] = useState<{ id: number; label: string }[]>([]);
3435
const currentBugId = getSelectedBugId();
3536
const { tags: bugTags } = bug;
3637
const [patchBug] = usePatchCampaignsByCidBugsAndBidMutation();
3738

38-
const [selectedTags, setSelectedTags] = useState<
39-
{ id: number; label: string }[]
40-
>([]);
41-
42-
useEffect(() => {
43-
if (bugTags) {
44-
setSelectedTags(
45-
bugTags.map((tag) => ({
46-
id: tag.tag_id,
47-
label: tag.name,
48-
}))
49-
);
50-
}
51-
}, [bugTags]);
52-
5339
const {
5440
isLoading: isLoadingCampaign,
5541
isFetching: isFetchingCampaign,
@@ -59,6 +45,20 @@ export default ({
5945
cid: campaignId?.toString() ?? '0',
6046
});
6147

48+
useEffect(() => {
49+
if (cpTags) {
50+
setOptions(
51+
cpTags.map((tag) => ({
52+
id: tag.tag_id,
53+
label: tag.display_name,
54+
selected: bugTags
55+
? bugTags.some((selectedTag) => selectedTag.tag_id === tag.tag_id)
56+
: false,
57+
}))
58+
);
59+
}
60+
}, [cpTags, bugTags]);
61+
6262
if (isErrorCampaign) return null;
6363

6464
return (
@@ -77,19 +77,21 @@ export default ({
7777
maxItems={4}
7878
size="small"
7979
i18n={{}}
80-
onChange={async (selectedItems, newItem) => {
80+
onChange={async (selectedItems, newLabel) => {
8181
const { tags } = await patchBug({
8282
cid: campaignId.toString(),
8383
bid: currentBugId ? currentBugId.toString() : '0',
8484
body: {
8585
tags: [
86-
...selectedItems.map((item) => ({
87-
tag_id: Number(item.id),
88-
})),
89-
...(newItem
86+
...selectedItems
87+
.filter((o) => o.selected)
88+
.map((item) => ({
89+
tag_id: Number(item.id),
90+
})),
91+
...(newLabel
9092
? [
9193
{
92-
tag_name: newItem,
94+
tag_name: newLabel,
9395
},
9496
]
9597
: []),
@@ -103,19 +105,15 @@ export default ({
103105
label: tag.tag_name,
104106
}))
105107
: [];
106-
107-
setSelectedTags(results);
108-
return results;
108+
const unselectedItems = options.filter(
109+
(o) => !results.find((r) => r.id === o.id)
110+
);
111+
setOptions([
112+
...unselectedItems,
113+
...results.map((r) => ({ ...r, selected: true })),
114+
]);
109115
}}
110-
options={
111-
cpTags
112-
? cpTags.map((tag) => ({
113-
id: tag.tag_id,
114-
label: tag.display_name,
115-
}))
116-
: []
117-
}
118-
selectedItems={selectedTags}
116+
options={options}
119117
/>
120118
)}
121119
</Container>

src/pages/Bugs/Detail/lightbox.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
BugMedia,
1010
GetCampaignsByCidBugsAndBidApiResponse,
1111
} from 'src/features/api';
12-
import { useCallback, useEffect, useRef } from 'react';
12+
import { useCallback, useRef } from 'react';
1313
import { ReactComponent as DownloadIcon } from 'src/assets/icons/download-stroke.svg';
1414
import styled from 'styled-components';
1515
import BugMeta from './Meta';
@@ -78,7 +78,7 @@ export const LightboxContainer = ({
7878
onSlideChange={slideChange}
7979
initialSlide={currentIndex}
8080
>
81-
{items.map((item, index) => (
81+
{items.map((item) => (
8282
<Slider.Slide>
8383
{item.mime_type.type === 'image' && (
8484
<img src={item.url} alt={`bug ${item.mime_type}`} />
@@ -109,7 +109,8 @@ export const LightboxContainer = ({
109109
isBasic
110110
onClick={() => {
111111
if (currentIndex in items) {
112-
const media = items[currentIndex];
112+
const media = items[currentIndex as number];
113+
// eslint-disable-next-line security/detect-non-literal-fs-filename
113114
window.open(media.url, '_blank');
114115
}
115116
}}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
ajv-draft-04 "^1.0.0"
4848
call-me-maybe "^1.0.1"
4949

50-
"@appquality/unguess-design-system@2.12.55":
51-
version "2.12.55"
52-
resolved "https://registry.yarnpkg.com/@appquality/unguess-design-system/-/unguess-design-system-2.12.55.tgz#086992129040b6f0ef0e69521b1b4211afbbaeda"
53-
integrity sha512-1+GKWl2O/Q9WvyicOc/orNuFG2EtAP7kw99g/YJHN68qxISizeo5lURZEeJVQR5gcZeS78NI6oa3HK0tOEn1TQ==
50+
"@appquality/unguess-design-system@2.12.57":
51+
version "2.12.57"
52+
resolved "https://registry.yarnpkg.com/@appquality/unguess-design-system/-/unguess-design-system-2.12.57.tgz#260d16c0199888a6e8f5b93bd087d8ae21914fac"
53+
integrity sha512-0xUWLxdYTTdH1gFKndXoOyyR+Mo42KsegaI2fzF0Tvsz6csq6ygsLbb7r5ckqsl3TV+IaiXiTCdEiG1sekLecQ==
5454
dependencies:
5555
"@nivo/bar" "^0.80.0"
5656
"@nivo/bullet" "^0.80.0"

0 commit comments

Comments
 (0)