memory: implement delete entry from automatic suggestions
Proposed changes
closes #6440
- Added a Delete entry button for removing translation suggestion from Automatic Suggestions
Checklist
- [x] Lint and unit tests pass locally with my changes.
- [x] I have added tests that prove my fix is effective or that my feature works.
- [x] I have added documentation to describe my feature.
- [x] I have squashed my commits into logic units.
- [x] I have described the changes in the commit messages.
Codecov Report
Merging #7984 (b77b201) into main (e92cb03) will increase coverage by
0.12%. The diff coverage is100.00%.
Additional details and impacted files
@@ Coverage Diff @@
## main #7984 +/- ##
==========================================
+ Coverage 90.82% 90.95% +0.12%
==========================================
Files 685 685
Lines 51251 51256 +5
Branches 7400 7934 +534
==========================================
+ Hits 46550 46619 +69
+ Misses 3305 3248 -57
+ Partials 1396 1389 -7
| Impacted Files | Coverage Δ | |
|---|---|---|
| weblate/memory/machine.py | 90.90% <100.00%> (+0.43%) |
:arrow_up: |
| weblate/memory/tests.py | 100.00% <100.00%> (ø) |
|
| weblate/vcs/ssh.py | 73.10% <0.00%> (ø) |
|
| weblate/checks/data.py | 100.00% <0.00%> (ø) |
|
| ...blate/trans/migrations/0127_fix_source_glossary.py | 62.50% <0.00%> (ø) |
|
| ...te/trans/migrations/0133_glossary_missing_files.py | 59.37% <0.00%> (ø) |
|
| weblate/trans/models/component.py | 82.90% <0.00%> (+0.06%) |
:arrow_up: |
| weblate/vcs/git.py | 85.34% <0.00%> (+0.12%) |
:arrow_up: |
| weblate/trans/models/translation.py | 88.60% <0.00%> (+0.36%) |
:arrow_up: |
| weblate/vcs/apps.py | 91.37% <0.00%> (+1.72%) |
:arrow_up: |
| ... and 4 more |
@nijel One thing that we discussed earlier for multiple origin suggestions, Should I add multiple delete buttons for them or an Icon with delete functionality would be more intuitive.
In the later case, then instead of delete button, we can have delete icon just next to origin instead of a Delete entry button.
What do you think would be good to go?
For example

We definitely need a way to delete it in selected origins only. I can see two approaches:
- Move the delete action to the origin column, probably making it icon only. This will pollute the UI quite a lot.
- Add confirmation dialog which would list all origins with checkboxes. That way the UI is consistent, and it is possible to uncheck origins which the user doesn't want to delete.
That reminds me cases which is not addressed in this PR yet:
- The code currently picks only first delete URL, and thus it always deletes first origin only.
- In case the matching string is first obtained from other sources (machine translation service), the delete button will not be present, even if later the suggestions from the translation memory arrives.
The preferred solution as I see it now (feedback welcome):
- Collect the delete URLs at origin element.
- Once there is at least one delete URL, display the Delete button in the row.
- Make the Delete button open a popup listing all origins for current translation which have the delete URL. All selected by default.
- The callback would then fire DELETE on all selected URLs.
The solution sounds good to me however it will result in more clicks required to delete an entry, imo it's not good for UX. Incase of the delete icon, the number of clicks remain same and user can just click on the delete icon of entries.
I am not sure what do you mean here by:
This will pollute the UI quite a lot.
I am okay with implementing the preferred solution though. Please point me to any similar popup implementations if we have any just in case.
wdyt?
I think we want confirmation here anyway - having a delete button next to copy without a confirmation doesn't sound good. The confirmation popups are used in several places, for example here:
https://github.com/WeblateOrg/weblate/blob/c8f507972102558803f29abb0f1cfacd048c3a96/weblate/templates/trans/project-access-row.html#L44-L59
@nijel I worked on the proposed solution. Apologies for the delay.
The preferred solution as I see it now (feedback welcome):
- [x] Collect the delete URLs at origin element.
- [x] Once there is at least one delete URL, display the Delete button in the row.
- [x] Make the Delete button open a popup listing all origins for current translation which have the delete URL. All selected by default.
The popup looks like this 
- [x] The callback would then fire DELETE on all selected URLs.
I am able to callback the DELETE request but the request gets blocked by firefox (I am not sure what;s the reason, might be related to csrf token or something else) and I get the following error notification


I've tested that and I can see few issues:
-
The UI looks weird when the delete button is not shown:

I suggest adding empty cell instead.
-
The delete button is rendered for some services where it should not be present:

Clicking on it yields empty dialog
-
The dialog is not cleared before display, so when you abort it, and show it again, it includes duplicate entries:

Thanks for review, I could reproduce 1 and 3.
- The empty cell screenshot if delete button is not present.

-
I couldn't reproduce 2, I am assuming 2 might have happened because of inconsistent state so I have simplified the logic for showing the delete button. I tried on multiple pages and cannot see unexpected delete button.
-
The modal screenshot after closing it several times, no duplicate entries present

Thanks, looks better. There is still some issue with the dismissed popup - the dialog shows three checkboxes, but the DELETE request is fired multiple times (it seems that each dismiss adds one repetition):

@nijel Please let me know if there is something left for this PR. Thanks
Tests passing 🎉
Merged, thanks for your contribution!