diff --git a/ee/app/assets/javascripts/ai/catalog/components/ai_catalog_agent_form.vue b/ee/app/assets/javascripts/ai/catalog/components/ai_catalog_agent_form.vue index 51e98e1716e099093165c361d27e11ae9969d707..0a6a957b56514aa2a01f25e9a6039b0c83d0f809 100644 --- a/ee/app/assets/javascripts/ai/catalog/components/ai_catalog_agent_form.vue +++ b/ee/app/assets/javascripts/ai/catalog/components/ai_catalog_agent_form.vue @@ -77,7 +77,11 @@ export default { toolFilter: '', formValues: { ...this.initialValues, - visibilityLevel: this.initialValues.public + visibilityLevel: ( + this.initialValues && this.initialValues.public !== undefined + ? this.initialValues.public + : false + ) ? VISIBILITY_LEVEL_PUBLIC : VISIBILITY_LEVEL_PRIVATE, }, @@ -97,6 +101,11 @@ export default { submitButtonText() { return this.isEditMode ? s__('AICatalog|Save changes') : s__('AICatalog|Create agent'); }, + getInitialPublicValue() { + return this.initialValues && this.initialValues.public !== undefined + ? this.initialValues.public + : false; + }, fields() { const projectIdField = this.isEditMode ? {} @@ -314,7 +323,7 @@ export default { import { GlButton, GlDrawer, GlLoadingIcon, GlTooltipDirective } from '@gitlab/ui'; +import { s__ } from '~/locale'; import { getIdFromGraphQLId } from '~/graphql_shared/utils'; import { DRAWER_Z_INDEX } from '~/lib/utils/constants'; import { getContentWrapperHeight } from '~/lib/utils/dom_utils'; import { AI_CATALOG_TYPE_AGENT, AI_CATALOG_TYPE_FLOW } from '../constants'; +import { AI_CATALOG_AGENTS_NEW_ROUTE, AI_CATALOG_FLOWS_NEW_ROUTE } from '../router/constants'; +import setItemToDuplicateMutation from '../graphql/mutations/set_item_to_duplicate.mutation.graphql'; import AiCatalogAgentDetails from './ai_catalog_agent_details.vue'; import AiCatalogFlowDetails from './ai_catalog_flow_details.vue'; @@ -56,6 +59,40 @@ export default { detailsComponent() { return DETAILS_COMPONENT_MAP[this.activeItem.itemType]; }, + duplicateRoute() { + switch (this.activeItem.itemType) { + case AI_CATALOG_TYPE_AGENT: + return AI_CATALOG_AGENTS_NEW_ROUTE; + + case AI_CATALOG_TYPE_FLOW: + return AI_CATALOG_FLOWS_NEW_ROUTE; + + default: + return null; + } + }, + }, + methods: { + async handleDuplicate() { + try { + await this.$apollo.mutate({ + mutation: setItemToDuplicateMutation, + variables: { + item: { + id: this.activeItemId, + type: this.activeItem.itemType, + data: this.activeItem, + }, + }, + }); + + this.$router.push({ name: this.duplicateRoute }); + } catch (error) { + // Handle error if needed + // eslint-disable-next-line no-console + console.error(s__('AICatalog|Failed to set item to duplicate:'), error); + } + }, }, DRAWER_Z_INDEX, }; @@ -74,16 +111,30 @@ export default {

{{ activeItem.name }}

- +
+ + +