diff --git a/src/elements/AddArtifactTagPopUp/AddArtifactTagPopUp.js b/src/elements/AddArtifactTagPopUp/AddArtifactTagPopUp.js index 13248bcb9..f7a640eb5 100644 --- a/src/elements/AddArtifactTagPopUp/AddArtifactTagPopUp.js +++ b/src/elements/AddArtifactTagPopUp/AddArtifactTagPopUp.js @@ -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' @@ -37,7 +38,6 @@ import { isSubmitDisabled } from 'igz-controls/utils/form.util' const AddArtifactTagPopUp = ({ artifact, - getArtifact, isOpen, onAddTag = () => {}, onResolve, @@ -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({ @@ -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, @@ -127,44 +118,72 @@ const AddArtifactTagPopUp = ({ return actions.map(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 (