Skip to content

Commit

Permalink
Impl [Register artifact] does not allow to provide tag (#2111)
Browse files Browse the repository at this point in the history
  • Loading branch information
mavdryk authored Dec 19, 2023
1 parent 5ab50a7 commit 029b155
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 50 deletions.
5 changes: 3 additions & 2 deletions src/api/artifacts-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,9 @@ const artifactsApi = {

return fetchArtifacts(project, filters, newConfig)
},
registerArtifact: (project, data) =>
mainHttpClientV2.post(`/projects/${project}/artifacts`, data),
registerArtifact: (project, data) => {
return mainHttpClientV2.post(`/projects/${project}/artifacts`, data)
},
replaceTag: (project, tag, data) => mainHttpClient.post(`/projects/${project}/tags/${tag}`, data),
updateArtifact: (project, data) =>
mainHttpClientV2.put(`/projects/${project}/artifacts/${data.db_key || data.spec?.db_key}`, data)
Expand Down
33 changes: 13 additions & 20 deletions src/components/RegisterArtifactModal/RegisterArtifactModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ import arrayMutators from 'final-form-arrays'
import RegisterArtifactModalForm from '../../elements/RegisterArtifactModalForm/RegisterArtifactModalForm'
import { Button, Modal } from 'igz-controls/components'

import { messagesByKind } from './messagesByKind'
import { setNotification } from '../../reducers/notificationReducer'
import {
BADREQUEST_ERROR_STATUS_CODE,
FORBIDDEN_ERROR_STATUS_CODE,
MODAL_SM,
SECONDARY_BUTTON,
TERTIARY_BUTTON
} from 'igz-controls/constants'
import artifactApi from '../../api/artifacts-api'
import { ARTIFACT_TYPE } from '../../constants'
import { useModalBlockHistory } from '../../hooks/useModalBlockHistory.hook'
import { setFieldState } from 'igz-controls/utils/form.util'
import { convertChipsData } from '../../utils/convertChipsData'
import artifactApi from '../../api/artifacts-api'
import { messagesByKind } from './messagesByKind'
import { setFieldState } from 'igz-controls/utils/form.util'
import { setNotification } from '../../reducers/notificationReducer'
import { showErrorNotification } from '../../utils/notifications.util'
import { useModalBlockHistory } from '../../hooks/useModalBlockHistory.hook'

const RegisterArtifactModal = ({
actions,
Expand Down Expand Up @@ -88,6 +88,7 @@ const RegisterArtifactModal = ({
description: values.metadata.description,
labels: convertChipsData(values.metadata.labels),
key: values.metadata.key,
tag: values.metadata.tag,
project: params.projectName,
tree: uuidv4()
},
Expand Down Expand Up @@ -116,20 +117,12 @@ const RegisterArtifactModal = ({
)
})
.catch(error => {
dispatch(
setNotification({
status:
error.response.status === FORBIDDEN_ERROR_STATUS_CODE
? FORBIDDEN_ERROR_STATUS_CODE
: BADREQUEST_ERROR_STATUS_CODE,
id: Math.random(),
message:
error.response.status === FORBIDDEN_ERROR_STATUS_CODE
? 'You are not permitted to create a new resource'
: `${title} failed to initiate`,
retry: registerArtifact
})
)
const customErrorMsg =
error.response.status === FORBIDDEN_ERROR_STATUS_CODE
? 'You are not permitted to create a new resource'
: `${title} failed to initiate`

showErrorNotification(dispatch, error, '', customErrorMsg, () => registerArtifact(values))

resolveModal()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ const RegisterArtifactModalForm = ({
})}
/>
</div>
<div className="form-col-1">
<FormInput label="Tag" name="metadata.tag" />
</div>
{showType && (
<div className="form-col-1">
<FormSelect label="Type:" name="kind" options={kindOptions} />
Expand Down
57 changes: 29 additions & 28 deletions src/elements/RegisterModelModal/RegisterModelModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@ import { v4 as uuidv4 } from 'uuid'
import { Button, Modal, FormChipCell, FormInput, FormTextarea } from 'igz-controls/components'
import TargetPath from '../../common/TargetPath/TargetPath'

import { getChipOptions } from '../../utils/getChipOptions'
import artifactApi from '../../api/artifacts-api'
import { MLRUN_STORAGE_INPUT_PATH_SCHEME } from '../../constants'
import { MODAL_SM, SECONDARY_BUTTON, TERTIARY_BUTTON } from 'igz-controls/constants'
import { convertChipsData } from '../../utils/convertChipsData'
import { isArtifactNameUnique } from '../../utils/artifacts.util'
import { getChipOptions } from '../../utils/getChipOptions'
import { getValidationRules } from 'igz-controls/utils/validation.util'
import { isArtifactNameUnique } from '../../utils/artifacts.util'
import { setFieldState } from 'igz-controls/utils/form.util'
import { useModalBlockHistory } from '../../hooks/useModalBlockHistory.hook'
import { MODAL_SM, SECONDARY_BUTTON, TERTIARY_BUTTON } from 'igz-controls/constants'
import { MLRUN_STORAGE_INPUT_PATH_SCHEME } from '../../constants'
import { setNotification } from '../../reducers/notificationReducer'
import artifactApi from '../../api/artifacts-api'
import { showErrorNotification } from '../../utils/notifications.util'
import { useModalBlockHistory } from '../../hooks/useModalBlockHistory.hook'

import './RegisterModelModal.scss'

Expand Down Expand Up @@ -110,16 +111,11 @@ function RegisterModelModal({ actions, isOpen, onResolve, params, refresh }) {
})
)
})
.catch(() => {
resolveModal()
dispatch(
setNotification({
status: 400,
id: Math.random(),
message: 'Model failed to initiate',
retry: registerModel
})
.catch(error => {
showErrorNotification(dispatch, error, '', 'Model failed to initiate', () =>
registerModel(values)
)
resolveModal()
})
}

Expand Down Expand Up @@ -156,19 +152,24 @@ function RegisterModelModal({ actions, isOpen, onResolve, params, refresh }) {
title="Register model"
>
<div className="form-row">
<FormInput
async
label="Name"
name="metadata.key"
required
tip="Artifacts names in the same project must be unique."
validationRules={getValidationRules('artifact.name', {
name: 'ArtifactExists',
label: 'Artifact name must be unique',
pattern: isArtifactNameUnique(params.projectName),
async: true
})}
/>
<div className="form-col-2">
<FormInput
async
label="Name"
name="metadata.key"
required
tip="Artifacts names in the same project must be unique."
validationRules={getValidationRules('artifact.name', {
name: 'ArtifactExists',
label: 'Artifact name must be unique',
pattern: isArtifactNameUnique(params.projectName),
async: true
})}
/>
</div>
<div className="form-col-1">
<FormInput label="Tag" name="metadata.tag" />
</div>
</div>
<div className="form-row">
<FormTextarea name="metadata.description" label="Description" maxLength={500} />
Expand Down

0 comments on commit 029b155

Please sign in to comment.