-
Notifications
You must be signed in to change notification settings - Fork 4
feat: refactor typing and add better diff #17
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
Merged
+204
−79
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
37f2b13
refactor: enhance type hints and improve entry details handling
FriendlyUser1 eff1d55
refactor: enhance typing - apply review suggestions
FriendlyUser1 d52a9ca
feat: add better common/conflicting details and display in UI
FriendlyUser1 9d6d6d6
update tests and clean up
FriendlyUser1 70bb1ce
refactor: improve common entry conflict detection and enhance compare…
FriendlyUser1 a21aea3
Update comparison.py
FriendlyUser1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,42 @@ | ||
| from typing import Dict, Optional | ||
| from typing import List | ||
|
|
||
| import streamlit as st | ||
|
|
||
| from KeePassDiff.utils.database import EntryDetails | ||
|
|
||
| def show_entry_details(entry_details: Optional[Dict] = None, key: str = None): | ||
| if entry_details: | ||
| st.markdown("### Entry Details") | ||
| st.markdown(f"**Title:** {entry_details['title']}") | ||
| st.markdown(f"**Username:** {entry_details['username']}") | ||
| st.markdown(f"**Password:** {entry_details['password']}") | ||
| st.markdown(f"**URL:** {entry_details['url']}") | ||
| st.markdown("**Notes:**") | ||
| st.text_area( | ||
| "", | ||
| value=entry_details["notes"], | ||
| height=100, | ||
| disabled=True, | ||
| key=f"notes_{key}" if key else None, | ||
| ) | ||
| st.markdown(f"**Created:** {entry_details['created']}") | ||
| st.markdown(f"**Modified:** {entry_details['modified']}") | ||
| st.markdown(f"**Path:** {entry_details['path']}") | ||
| else: | ||
| st.warning("Entry details not found") | ||
|
|
||
| def show_entry_details( | ||
| entry_details: EntryDetails | None = None, | ||
| key: str | None = None, | ||
| conflicts: List[str] | None = None, | ||
| ): | ||
| if not entry_details: | ||
| return st.warning("Entry details not found") | ||
|
|
||
| def markdown(md_string: str, inner_key: str | None = None): | ||
| if not inner_key: | ||
| return st.markdown(md_string) | ||
|
|
||
| md_string = md_string.replace("{}", str(entry_details[inner_key])) | ||
| if conflicts and inner_key in conflicts: | ||
| md_string = f":red-background[{md_string}]" | ||
|
|
||
| st.markdown(md_string) | ||
|
|
||
| markdown("### Entry Details") | ||
| markdown("**Title:** {}", "title") | ||
| markdown("**Username:** {}", "username") | ||
| markdown("**Password:** {}", "password") | ||
| markdown("**URL:** {}", "url") | ||
| markdown("**Notes:**") | ||
| st.text_area( | ||
| "notes", | ||
| label_visibility="collapsed", | ||
| value=entry_details["notes"], | ||
| height=100, | ||
| disabled=True, | ||
| key=f"notes_{key}", | ||
| ) | ||
| markdown("**Created:** {}", "created") | ||
| markdown("**Modified:** {}", "modified") | ||
| markdown("**Path:** {}", "path") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,34 @@ | ||
| from typing import Dict, Set | ||
| from typing import Dict, Set, List | ||
|
|
||
| from KeePassDiff.utils.database import EntryDetails | ||
|
|
||
|
|
||
| def compare_databases( | ||
| db1_data: Dict[str, Set[str]], db2_data: Dict[str, Set[str]] | ||
| ) -> Dict: | ||
| ) -> Dict[str, List[str]]: | ||
| return { | ||
| "entries_only_in_db1": sorted(db1_data["entries"] - db2_data["entries"]), | ||
| "entries_only_in_db2": sorted(db2_data["entries"] - db1_data["entries"]), | ||
|
sourcery-ai[bot] marked this conversation as resolved.
|
||
| "common_entries": sorted(db1_data["entries"] & db2_data["entries"]), | ||
| "groups_only_in_db1": sorted(db1_data["groups"] - db2_data["groups"]), | ||
| "groups_only_in_db2": sorted(db2_data["groups"] - db2_data["groups"]), | ||
| "groups_only_in_db2": sorted(db2_data["groups"] - db1_data["groups"]), | ||
| "common_groups": sorted(db1_data["groups"] & db2_data["groups"]), | ||
| } | ||
|
|
||
|
|
||
| def compare_entries( | ||
| entry1: EntryDetails | None, entry2: EntryDetails | None | ||
| ) -> List[str]: | ||
|
|
||
| if entry1 is None or entry2 is None: | ||
| return [] | ||
| if entry1 == entry2: | ||
| return [] | ||
|
|
||
| conflicts = [] | ||
|
|
||
| for key in entry1.keys(): | ||
| if entry1[key] != entry2[key]: | ||
| conflicts.append(key) | ||
|
|
||
| return conflicts | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.