From 554de47f1c0ed3b040a376e8a98f27a108507f37 Mon Sep 17 00:00:00 2001 From: Yuri-Njathi Date: Fri, 20 Dec 2024 15:19:10 +0300 Subject: [PATCH 1/2] add download button for labels.txt --- .../InsertLabelNamesPopup/InsertLabelNamesPopup.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/views/PopupView/InsertLabelNamesPopup/InsertLabelNamesPopup.tsx b/src/views/PopupView/InsertLabelNamesPopup/InsertLabelNamesPopup.tsx index 74f4a6285..75dd8c8f2 100644 --- a/src/views/PopupView/InsertLabelNamesPopup/InsertLabelNamesPopup.tsx +++ b/src/views/PopupView/InsertLabelNamesPopup/InsertLabelNamesPopup.tsx @@ -197,6 +197,14 @@ const InsertLabelNamesPopup: React.FC = ( isActive={enablePerClassColoration} externalClassName={enablePerClassColoration ? '' : 'monochrome'} />} +
From d192ae947f9335af106d4ff1ecf0e26416194d99 Mon Sep 17 00:00:00 2001 From: Yuri-Njathi Date: Fri, 20 Dec 2024 16:06:04 +0300 Subject: [PATCH 2/2] add download on click functionality --- .../InsertLabelNamesPopup.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/views/PopupView/InsertLabelNamesPopup/InsertLabelNamesPopup.tsx b/src/views/PopupView/InsertLabelNamesPopup/InsertLabelNamesPopup.tsx index 75dd8c8f2..2ec82b85d 100644 --- a/src/views/PopupView/InsertLabelNamesPopup/InsertLabelNamesPopup.tsx +++ b/src/views/PopupView/InsertLabelNamesPopup/InsertLabelNamesPopup.tsx @@ -45,6 +45,21 @@ const InsertLabelNamesPopup: React.FC = ( }) => { const [labelNames, setLabelNames] = useState(LabelsSelector.getLabelNames()); + const handleDownloadLabels = () => { + if (labelNames.length === 0) { + alert('No labels to download'); + return; + } + + const fileContent = labelNames.map((label) => label.name).join('\n'); + const blob = new Blob([fileContent], { type: 'text/plain' }); + const link = document.createElement('a'); + link.href = URL.createObjectURL(blob); + link.download = 'labels.txt'; + link.click(); + URL.revokeObjectURL(link.href); + }; + const validateEmptyLabelNames = (): boolean => { const emptyLabelNames = filter(labelNames, (labelName: LabelName) => labelName.name === ''); return emptyLabelNames.length === 0; @@ -202,7 +217,7 @@ const InsertLabelNamesPopup: React.FC = ( imageAlt={'download'} buttonSize={{ width: 40, height: 40 }} padding={25} - onClick={safeAddLabelNameCallback} + onClick={handleDownloadLabels} externalClassName={'monochrome'} />