From 0ed4c5c3eb277a3bb20f5a17a63553bc5ad49cb3 Mon Sep 17 00:00:00 2001 From: Kevin O'Gorman Date: Wed, 13 Nov 2024 20:14:25 -0500 Subject: [PATCH 1/2] truncate source list displayed in delete dialog --- .../gui/source/delete/dialog.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/client/securedrop_client/gui/source/delete/dialog.py b/client/securedrop_client/gui/source/delete/dialog.py index f55f9dc56..b158402e1 100644 --- a/client/securedrop_client/gui/source/delete/dialog.py +++ b/client/securedrop_client/gui/source/delete/dialog.py @@ -23,6 +23,10 @@ from securedrop_client.db import Source from securedrop_client.gui.base import ModalDialog +# Maximum number of source names to display in delete dialog before +# truncation +MAX_DEL_DISP = 30 + class DeleteSourceDialog(ModalDialog): """Used to confirm deletion of source accounts.""" @@ -71,9 +75,25 @@ def make_body_text(self, sources: list[Source]) -> str: ) return "".join(message_tuple).format( - source_or_sources=f"{self._get_source_names(sources)}" + source_or_sources=f"{self._get_source_names_truncated(sources, MAX_DEL_DISP)}" ) + def _get_source_names_truncated(self, sources: list[Source], max_shown: int) -> str: + """ + Helper. Return a comma-separated list of journalist designations, truncated to avoid + text overflows. If the limit is N and there are N+2 sources, all N+2 are displayed. + If there are >N+2 sources, N sources and an additional message (approx 2 source names + long) is displayed. + """ + if len(sources) <= max_shown + 2: + return self._get_source_names(sources) + else: + shortlist = sources[:max_shown] + return _("{sources} ... plus {count} additional sources").format( + sources=", ".join([s.journalist_designation for s in shortlist]), + count=len(sources) - max_shown, + ) + def _get_source_names(self, sources: list[Source]) -> str: """ Helper. Return a comma-separated list of journalist designations. From 4fd8dcbc938e093335a984c29d583e339ba518e7 Mon Sep 17 00:00:00 2001 From: Kevin O'Gorman Date: Wed, 13 Nov 2024 20:27:19 -0500 Subject: [PATCH 2/2] Update string change in delete dialog --- client/securedrop_client/locale/messages.pot | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/securedrop_client/locale/messages.pot b/client/securedrop_client/locale/messages.pot index 15c8b1ec1..53db60742 100644 --- a/client/securedrop_client/locale/messages.pot +++ b/client/securedrop_client/locale/messages.pot @@ -410,6 +410,9 @@ msgstr "" msgid "All files and messages from that source will also be destroyed." msgstr "" +msgid "{sources} ... plus {count} additional sources" +msgstr "" + msgid "No sources have been selected." msgstr ""