Skip to content
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

add download button for labels.txt #385

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ const InsertLabelNamesPopup: React.FC<IProps> = (
}) => {
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;
Expand Down Expand Up @@ -197,6 +212,14 @@ const InsertLabelNamesPopup: React.FC<IProps> = (
isActive={enablePerClassColoration}
externalClassName={enablePerClassColoration ? '' : 'monochrome'}
/>}
<ImageButton
image={'ico/download.png'}
imageAlt={'download'}
buttonSize={{ width: 40, height: 40 }}
padding={25}
onClick={handleDownloadLabels}
externalClassName={'monochrome'}
/>
</div>
<div className='RightContainer'>
<div className='Message'>
Expand Down