-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
194 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 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
29 changes: 29 additions & 0 deletions
29
...sections/upload-dataset-files/uploaded-files-list/add-tags-modal/AddTagsModal.module.scss
This file contains 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@import "node_modules/@iqss/dataverse-design-system/src/lib/assets/styles/design-tokens/colors.module"; | ||
|
||
.add_tags_form { | ||
padding-top: 0.5em; | ||
padding-bottom: 0.5em; | ||
} | ||
|
||
.tags { | ||
display: flex; | ||
} | ||
|
||
.tags_select{ | ||
width: 100%; | ||
} | ||
|
||
.tag_options { | ||
padding-top: 0.5em; | ||
padding-bottom: 0.5em; | ||
} | ||
|
||
.tag_info { | ||
padding-top: 0.5em; | ||
padding-bottom: 0.5em; | ||
color: $dv-subtext-color; | ||
} | ||
|
||
.apply_button { | ||
height: 2.4rem; | ||
} |
113 changes: 113 additions & 0 deletions
113
src/sections/upload-dataset-files/uploaded-files-list/add-tags-modal/AddTagsModal.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { Button, Col, Form, Modal, SelectMultiple } from '@iqss/dataverse-design-system' | ||
import styles from './AddTagsModal.module.scss' | ||
import { FormEvent, useState, KeyboardEvent } from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
interface AddTagsModalProps { | ||
show: boolean | ||
availableTags: string[] | ||
setTagOptions: (newTags: string[]) => void | ||
update: (res: AddTagsModalResult) => void | ||
} | ||
|
||
export interface AddTagsModalResult { | ||
saved: boolean | ||
tags: string[] | ||
} | ||
|
||
export function AddTagsModal({ | ||
Check failure on line 18 in src/sections/upload-dataset-files/uploaded-files-list/add-tags-modal/AddTagsModal.tsx GitHub Actions / lint
|
||
show, | ||
availableTags, | ||
setTagOptions, | ||
update | ||
}: AddTagsModalProps) { | ||
const { t } = useTranslation('uploadDatasetFiles') | ||
const [tagsToAdd, setTagsToAdd] = useState<string[]>([]) | ||
const [tag, setTag] = useState('') | ||
const handleClose = (saved: boolean) => | ||
Check failure on line 27 in src/sections/upload-dataset-files/uploaded-files-list/add-tags-modal/AddTagsModal.tsx GitHub Actions / lint
|
||
update({ saved: saved, tags: tagsToAdd }) | ||
const addTagOption = () => { | ||
if (tag && !availableTags.includes(tag)) { | ||
setTagOptions([...availableTags, tag]) | ||
setTag('') | ||
} | ||
} | ||
const handleEnter = (event: KeyboardEvent<HTMLInputElement>) => { | ||
if (event.key === 'Enter') { | ||
addTagOption() | ||
event.preventDefault() | ||
} | ||
} | ||
Check failure on line 40 in src/sections/upload-dataset-files/uploaded-files-list/add-tags-modal/AddTagsModal.tsx GitHub Actions / lint
|
||
|
||
|
||
return ( | ||
<Modal show={show} onHide={() => handleClose(false)} size="lg"> | ||
<Modal.Header> | ||
<Modal.Title>{t('addTags.title')}</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<div className={styles.add_tags_form}> | ||
<Form> | ||
<Form.Group> | ||
<Form.Group.Label column sm={3}> | ||
{t('fileForm.tags')} | ||
</Form.Group.Label> | ||
<Col sm={9} className={styles.tags}> | ||
<div className={styles.tags_select} title={t('fileForm.selectTags')}> | ||
<SelectMultiple | ||
options={availableTags} | ||
onChange={(newTags) => setTagsToAdd(newTags)}></SelectMultiple> | ||
</div> | ||
</Col> | ||
</Form.Group> | ||
<Form.Group> | ||
<Form.Group.Label column sm={3}> | ||
{t('tags.customFileTag')} | ||
</Form.Group.Label> | ||
<Col sm={9}> | ||
<div className={styles.tag_info}>{t('tags.creatingNewTag')}</div> | ||
<div className="input-group mb-3" onKeyDown={handleEnter} > | ||
Check failure on line 69 in src/sections/upload-dataset-files/uploaded-files-list/add-tags-modal/AddTagsModal.tsx GitHub Actions / lint
|
||
<Form.Group.Input | ||
type="text" | ||
placeholder={t('tags.addNewTag')} | ||
value={tag} | ||
onChange={(event: FormEvent<HTMLInputElement>) => | ||
setTag(event.currentTarget.value) | ||
} | ||
/> | ||
<Button | ||
className={styles.apply_button} | ||
variant="secondary" | ||
type="button" | ||
{...{ size: 'sm' }} | ||
withSpacing | ||
onClick={addTagOption}> | ||
{t('tags.apply')} | ||
</Button> | ||
</div> | ||
<div className={styles.tag_info}> | ||
{t('tags.availableTagOptions')} | ||
{availableTags.join(', ')} | ||
</div> | ||
</Col> | ||
</Form.Group> | ||
</Form> | ||
</div> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button | ||
variant="primary" | ||
onClick={() => handleClose(true)} | ||
disabled={tagsToAdd.length === 0}> | ||
{t('addTags.saveChanges')} | ||
</Button> | ||
<Button | ||
variant="secondary" | ||
onClick={() => handleClose(false)} | ||
title={t('addTags.cancelChanges')}> | ||
{t('cancel')} | ||
</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
) | ||
} |
This file contains 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 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 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