|
7 | 7 | <lf-button |
8 | 8 | type="secondary" |
9 | 9 | size="small" |
10 | | - :disabled="loading || offset <= 0 || count === 0" |
| 10 | + :disabled="loading || offset <= 0 || !hasSuggestion" |
11 | 11 | :icon-only="true" |
12 | 12 | @click="fetch(offset - 1)" |
13 | 13 | > |
|
16 | 16 | <lf-button |
17 | 17 | type="secondary" |
18 | 18 | size="small" |
19 | | - :disabled="loading || offset >= count - 1 || count === 0" |
| 19 | + :disabled="loading || !hasMore" |
20 | 20 | :icon-only="true" |
21 | 21 | @click="fetch(offset + 1)" |
22 | 22 | > |
|
26 | 26 |
|
27 | 27 | <app-loading v-if="loading" height="16px" width="128px" radius="3px" /> |
28 | 28 | <div |
29 | | - v-else-if="Math.ceil(count) > 1" |
| 29 | + v-else-if="hasSuggestion" |
30 | 30 | class="text-xs leading-5 text-gray-500" |
31 | 31 | > |
32 | | - <div>{{ offset + 1 }} of {{ Math.ceil(count) }} suggestions</div> |
33 | | - </div> |
34 | | - <div |
35 | | - v-else-if="Math.ceil(count) === 1" |
36 | | - class="text-xs leading-5 text-gray-500" |
37 | | - > |
38 | | - <div>1 suggestion</div> |
| 32 | + <div>Suggestion {{ offset + 1 }}</div> |
39 | 33 | </div> |
40 | 34 | <div |
41 | 35 | v-else |
|
48 | 42 | <app-member-merge-similarity v-if="!loading && membersToMerge.similarity" :similarity="membersToMerge.similarity" /> |
49 | 43 | <lf-button |
50 | 44 | type="secondary" |
51 | | - :disabled="loading || isEditLockedForSampleData || count === 0" |
| 45 | + :disabled="loading || isEditLockedForSampleData || !hasSuggestion" |
52 | 46 | :loading="sendingIgnore" |
53 | 47 | @click="ignoreSuggestion()" |
54 | 48 | > |
55 | 49 | Ignore suggestion |
56 | 50 | </lf-button> |
57 | 51 | <lf-button |
58 | 52 | type="primary" |
59 | | - :disabled="loading || isEditLockedForSampleData || count === 0" |
| 53 | + :disabled="loading || isEditLockedForSampleData || !hasSuggestion" |
60 | 54 | :loading="sendingMerge" |
61 | 55 | @click="mergeSuggestion()" |
62 | 56 | > |
|
66 | 60 | </div> |
67 | 61 | </header> |
68 | 62 |
|
69 | | - <div v-if="loading || count > 0"> |
| 63 | + <div v-if="loading || hasSuggestion"> |
70 | 64 | <!-- Comparison --> |
71 | 65 | <!-- Loading --> |
72 | 66 | <div v-if="loading" class="flex p-5"> |
@@ -170,7 +164,8 @@ const { getContributorMergeActions } = useContributorStore(); |
170 | 164 | const membersToMerge = ref([]); |
171 | 165 | const primary = ref(0); |
172 | 166 | const offset = ref(props.offset); |
173 | | -const count = ref(0); |
| 167 | +const hasMore = ref(false); |
| 168 | +const hasSuggestion = ref(false); |
174 | 169 | const loading = ref(false); |
175 | 170 |
|
176 | 171 | const sendingIgnore = ref(false); |
@@ -204,25 +199,45 @@ const preview = computed(() => { |
204 | 199 | return mergedMembers; |
205 | 200 | }); |
206 | 201 |
|
207 | | -const fetch = (page) => { |
| 202 | +const updateSuggestionsState = (res) => { |
| 203 | + hasMore.value = Boolean(res.hasMore); |
| 204 | + const rows = res.rows.filter((suggestion) => suggestion.similarity > 0); |
| 205 | +
|
| 206 | + if (rows.length > 0) { |
| 207 | + hasSuggestion.value = true; |
| 208 | + [membersToMerge.value] = rows; |
| 209 | + } else { |
| 210 | + hasSuggestion.value = false; |
| 211 | + membersToMerge.value = []; |
| 212 | + } |
| 213 | +}; |
| 214 | +
|
| 215 | +const fetch = (page, trackNavigation = true) => { |
208 | 216 | if (page > -1) { |
209 | 217 | offset.value = page; |
210 | 218 | } |
211 | 219 |
|
212 | | - trackEvent({ |
213 | | - key: FeatureEventKey.NAVIGATE_MEMBERS_MERGE_SUGGESTIONS, |
214 | | - type: EventType.FEATURE, |
215 | | - }); |
| 220 | + if (trackNavigation) { |
| 221 | + trackEvent({ |
| 222 | + key: FeatureEventKey.NAVIGATE_MEMBERS_MERGE_SUGGESTIONS, |
| 223 | + type: EventType.FEATURE, |
| 224 | + }); |
| 225 | + } |
216 | 226 |
|
217 | 227 | loading.value = true; |
218 | 228 |
|
219 | | - MemberService.fetchMergeSuggestions(1, offset.value, props.query ?? {}) |
| 229 | + return MemberService.fetchMergeSuggestions(1, offset.value, props.query ?? {}) |
220 | 230 | .then((res) => { |
221 | 231 | offset.value = +res.offset; |
222 | | - count.value = res.count; |
223 | | - [membersToMerge.value] = res.rows; |
| 232 | +
|
| 233 | + updateSuggestionsState(res); |
| 234 | +
|
| 235 | + if (!hasSuggestion.value && offset.value > 0) { |
| 236 | + return fetch(offset.value - 1, false); |
| 237 | + } |
224 | 238 |
|
225 | 239 | primary.value = 0; |
| 240 | + return undefined; |
226 | 241 | }) |
227 | 242 | .catch(() => { |
228 | 243 | ToastStore.error( |
@@ -252,8 +267,7 @@ const ignoreSuggestion = () => { |
252 | 267 | .then(() => { |
253 | 268 | ToastStore.success('Merging suggestion ignored successfully'); |
254 | 269 | getContributorMergeActions(); |
255 | | - const nextIndex = offset.value >= (count.value - 1) ? Math.max(count.value - 2, 0) : offset.value; |
256 | | - fetch(nextIndex); |
| 270 | + fetch(offset.value); |
257 | 271 | changed.value = true; |
258 | 272 | }) |
259 | 273 | .catch((error) => { |
@@ -304,8 +318,7 @@ const mergeSuggestion = () => { |
304 | 318 | ); |
305 | 319 | primary.value = 0; |
306 | 320 |
|
307 | | - const nextIndex = offset.value >= (count.value - 1) ? Math.max(count.value - 2, 0) : offset.value; |
308 | | - fetch(nextIndex); |
| 321 | + fetch(offset.value); |
309 | 322 | changed.value = true; |
310 | 323 | }) |
311 | 324 | .catch((error) => { |
|
0 commit comments