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

Fix [UI] "add a tag" UI should not check uniqueness but rather update the existing tag 1.7.1 #2807

Open
wants to merge 1 commit into
base: 1.7.x
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
110 changes: 64 additions & 46 deletions src/elements/AddArtifactTagPopUp/AddArtifactTagPopUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import { Form } from 'react-final-form'
import { createForm } from 'final-form'

import { Button, FormInput, Modal } from 'igz-controls/components'
import Loader from '../../common/Loader/Loader'

import { DATASET_TYPE, MODEL_TYPE } from '../../constants'
import { SECONDARY_BUTTON, TERTIARY_BUTTON } from 'igz-controls/constants'
import { addTag } from '../../reducers/artifactsReducer'
import { addTag, fetchArtifacts } from '../../reducers/artifactsReducer'
import { getValidationRules } from 'igz-controls/utils/validation.util'
import { setNotification } from '../../reducers/notificationReducer'
import { showErrorNotification } from '../../utils/notifications.util'
Expand All @@ -37,7 +38,6 @@ import { isSubmitDisabled } from 'igz-controls/utils/form.util'

const AddArtifactTagPopUp = ({
artifact,
getArtifact,
isOpen,
onAddTag = () => {},
onResolve,
Expand All @@ -47,7 +47,8 @@ const AddArtifactTagPopUp = ({
const [initialValues] = useState({
artifactTag: ''
})
const [existingTags, setExistingTags] = useState([])
const [artifactTags, setArtifactTags] = useState([])
const [isLoading, setIsLoading] = useState(true)

const formRef = React.useRef(
createForm({
Expand All @@ -58,16 +59,6 @@ const AddArtifactTagPopUp = ({
const location = useLocation()
const { handleCloseModal, resolveModal } = useModalBlockHistory(onResolve, formRef.current)

useEffect(() => {
getArtifact &&
dispatch(getArtifact())
.unwrap()
.then(results => {
const tags = results.filter(result => result.tag).map(result => result.tag)
setExistingTags(tags)
})
}, [dispatch, getArtifact])

const addArtifactTag = values => {
const identifier = {
key: artifact.db_key || artifact.key,
Expand Down Expand Up @@ -127,52 +118,79 @@ const AddArtifactTagPopUp = ({
return actions.map(action => <Button {...action} />)
}

useEffect(() => {
setIsLoading(true)
dispatch(
fetchArtifacts({
project: projectName,
filters: { name: artifact.db_key },
config: {
params: {
format: 'minimal'
}
},
withExactName: true
})
)
.unwrap()
.then(artifacts => {
if (artifacts.length) {
setArtifactTags(artifacts.map(artifact => artifact.tag))
}
})
.finally(() => {
setIsLoading(false)
})
}, [artifact.db_key, dispatch, projectName])

return (
<Form form={formRef.current} initialValues={initialValues} onSubmit={addArtifactTag}>
{formState => {
return (
<Modal
actions={getModalActions(formState)}
location={location}
onClose={handleCloseModal}
show={isOpen}
size="min"
title="Add a tag"
>
<div className="form">
<div className="form-row">
<div className="form-col-1">
<FormInput
name="artifactTag"
label={`${
artifact.kind === MODEL_TYPE
? 'Model tag'
: artifact.kind === DATASET_TYPE
? 'Dataset tag'
: 'Artifact tag'
}`}
focused
required
validationRules={getValidationRules('common.name', [
{
name: 'uniqueness',
label: 'Tag name must be unique',
pattern: value => !existingTags.includes(value)
}
])}
/>
<>
{isLoading && <Loader />}
<Modal
actions={getModalActions(formState)}
location={location}
onClose={handleCloseModal}
show={isOpen}
size="min"
title="Add a tag"
>
<div className="form">
<div className="form-row">
<div className="form-col-1">
<FormInput
name="artifactTag"
label={`${
artifact.kind === MODEL_TYPE
? 'Model tag'
: artifact.kind === DATASET_TYPE
? 'Dataset tag'
: 'Artifact tag'
}`}
focused
required
validationRules={getValidationRules('common.name', [
{
name: 'uniqueness',
label: 'Tag name must be unique',
pattern: value => !artifactTags.includes(value)
}
])}
/>
</div>
</div>
</div>
</div>
</Modal>
</Modal>
</>
)
}}
</Form>
)
}

AddArtifactTagPopUp.propTypes = {
getArtifact: PropTypes.func.isRequired,
isOpen: PropTypes.bool.isRequired,
artifact: PropTypes.shape({}).isRequired,
onAddTag: PropTypes.func,
Expand Down
Loading