-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: inline edit for archive renaming #1734
Conversation
tests/test_archives.py
Outdated
@@ -168,31 +168,3 @@ def test_archive_delete(qapp, qtbot, mocker, borg_json_output): | |||
qtbot.waitUntil(lambda: 'Archive deleted.' in main.progressText.text(), **pytest._wait_defaults) | |||
assert ArchiveModel.select().count() == 1 | |||
assert tab.archiveTable.rowCount() == 1 | |||
|
|||
|
|||
def test_archive_rename(qapp, qtbot, mocker, borg_json_output): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will look at some docs online to add a new test here, according to the changes. Any help will also be appreciated!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested using simple double mouse click event and it works
pos = tab.archiveTable.visualRect(tab.archiveTable.model().index(0, 4)).center()
qtbot.mouseClick(tab.archiveTable.viewport(), QtCore.Qt.MouseButton.LeftButton, pos=pos)
qtbot.mouseDClick(tab.archiveTable.viewport(), QtCore.Qt.MouseButton.LeftButton, pos=pos)
This will trigger the double click and rename action. You can then send new name and enter key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Will review this after some of the other PRs are merged. Else you will have too many conflicts. |
I tried this: pos = tab.archiveTable.visualRect(tab.archiveTable.model().index(0, 4)).center()
qtbot.mouseClick(tab.archiveTable.viewport(), QtCore.Qt.MouseButton.LeftButton, pos=pos)
qtbot.mouseDClick(tab.archiveTable.viewport(), QtCore.Qt.MouseButton.LeftButton, pos=pos)
qtbot.keyClicks(tab.archiveTable.viewport().focusWidget(), new_archive_name)
qtbot.keyClick(tab.archiveTable.viewport(), QtCore.Qt.Key.Key_Return)
# Successful rename case
print(tab.archiveTable.model().index(0, 4).data())
print(tab.mountErrors.text()) but it did not work, it just printed the old name. Am I missing something? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add back the rename button and the context menu action?
The KDE HIG states:
Don’t use context menus as the only way to access functionality. Every item in a context menu must be available via a method that is somehow visible by default
This also applies for this new feature. Inexperienced user might not discover that you can double click the entry. The old buttons should now enter the edit mode of the code cell.
Done. |
@diivi It needs some time to update the model. Add this after sending Return key.
|
Thanks, but I did that first and did not work. It just says
Complete test: def test_archive_rename(qapp, qtbot, mocker, borg_json_output):
main = qapp.main_window
tab = main.archiveTab
main.tabWidget.setCurrentIndex(3)
tab.populate_from_profile()
qtbot.waitUntil(lambda: tab.archiveTable.rowCount() == 2)
tab.archiveTable.selectRow(0)
new_archive_name = 'idf89d8f9d8fd98'
stdout, stderr = borg_json_output('rename')
popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0)
mocker.patch.object(vorta.borg.borg_job, 'Popen', return_value=popen_result)
pos = tab.archiveTable.visualRect(tab.archiveTable.model().index(0, 4)).center()
qtbot.mouseClick(tab.archiveTable.viewport(), QtCore.Qt.MouseButton.LeftButton, pos=pos)
qtbot.mouseDClick(tab.archiveTable.viewport(), QtCore.Qt.MouseButton.LeftButton, pos=pos)
qtbot.keyClicks(tab.archiveTable.viewport().focusWidget(), new_archive_name)
qtbot.keyClick(tab.archiveTable.viewport(), QtCore.Qt.Key.Key_Return)
# Successful rename case
qtbot.waitUntil(lambda: tab.archiveTable.model().index(0, 4).data() == new_archive_name, **pytest._wait_defaults) |
You missed
+You can add |
🤦🏼 it works now, also thanks for the |
Worked as expected locally and doesn't add much new code by reusing the existing function. Good job! |
Minor comment: Better to make a feature branch in your personal fork of Vorta's repo. Else it can get messy when merging from the I.e.: Make a new branch named e.g. |
Yeah, I do that everytime but missed it for this PR🥲 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While your solution will work after some bugs are eliminated, I think this would be the perfect opportunity for implementing a QTableModel for the archive list which would be more elegant and probably easier to maintain.
Further Information:
https://doc.qt.io/qt-6/model-view-programming.html
https://doc.qt.io/qt-6/modelview.html#2-5-the-minimal-editing-example
How much time will that take, and will I have to scrape this off completely? Also, I started this 20 days ago, if it was the perfect time to implement this you should've told me a little early (or mentioned it in the task in the first place) 😅 |
You are right. However occupied with other things like mentoring my own contributor I didn't look into this PR in detail. Let's settle on the current approach then without a |
Clear implementation and works as expected. Just noticed that the archive duration and archive size get lost when renaming and then doing a "Refresh Archives". Possible that some row in the DB isn't updated? |
It was working the last time I checked, but now I can't understand why the Size and duration get lost :/ The error occurs here for me - https://github.com/diivi/vorta/blob/48204f8bfd087b0206421c515d3f11bdc803ddaa/src/vorta/borg/info_archive.py#L46 File "/home/divyansh/Desktop/vorta/src/vorta/borg/info_archive.py", line 46, in process_result
archive.name = remote_archive['name'] # incase name changed
AttributeError: 'NoneType' object has no attribute 'name' |
I deleted the database and tested this again, it worked. Maybe some migration is missing? Can someone with the old database test it and let me know, I'm a bit confused. |
This error occurs during a "recalculate" archive action done after a name change. Separately, I am seeing the size and duration information get lost during the "refresh" archive action. |
Figured out what the issue is. The Borg rename command changes the archive's ID too during renaming, so I need to update that here - https://github.com/diivi/vorta/blob/48204f8bfd087b0206421c515d3f11bdc803ddaa/src/vorta/borg/rename.py#L37. How can I get the archive's ID after the rename operation though? |
Since you know the new name I would think you can run |
1ac4240 Changed the code so that the name reverts to the original one if the new name is already taken. |
This is still the case. I think it is linked to Steps to reproduce
This doesn't happen when recalculating the archive size of the renamed archive between steps 1 and 2. |
So should I start an |
If there is no other way to deal with this issue, I would accept running borg once more. |
I don't think there is - https://borgbackup.readthedocs.io/en/stable/usage/list.html check I can only get the dedup size and duration by listing the archive that was renamed 😞 |
@real-yfprojects I added a call to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works as expected, including keeping stats.
Description
This PR adds the ability to rename archives in the archive tab. When a user double-clicks on the name of an archive, they can edit the name. If the new name is valid, the archive is renamed. If the new name is invalid, an error message is displayed. This feature is implemented using the
cellChanged
signal of theQTableWidget
. Therename_action
method has been removed.Related Issue
Part of #1723
Motivation and Context
Faster renaming of archives.
How Has This Been Tested?
Types of changes
Checklist:
I provide my contribution under the terms of the license of this repository and I affirm the Developer Certificate of Origin.