@@ -25,6 +25,7 @@ import {
2525 useUpdateDashboardMutation ,
2626 useCreateDashboardMutation ,
2727 useDeleteDashboardMutation ,
28+ useCreateProjectMutation ,
2829} from './dashboard-api' ;
2930import {
3031 renameDashboardDialogValidationSchema ,
@@ -44,6 +45,7 @@ import {
4445import { useToast } from './ToastProvider' ;
4546import { generateMetadataName } from './dashboard-utils' ;
4647import { useEditableProjects } from './hooks/useEditableProjects' ;
48+ import { usePerses } from './hooks/usePerses' ;
4749import { t_global_spacer_200 , t_global_font_weight_200 } from '@patternfly/react-tokens' ;
4850import { useNavigate } from 'react-router-dom-v5-compat' ;
4951import { usePerspective , getDashboardUrl } from '../../hooks/usePerspective' ;
@@ -193,6 +195,9 @@ export const DuplicateActionModal = ({ dashboard, isOpen, onClose }: ActionModal
193195 permissionsError,
194196 } = useEditableProjects ( ) ;
195197
198+ const { persesProjects } = usePerses ( ) ;
199+ const createProjectMutation = useCreateProjectMutation ( ) ;
200+
196201 const defaultProject = useMemo ( ( ) => {
197202 if ( ! dashboard ) return '' ;
198203
@@ -244,7 +249,30 @@ export const DuplicateActionModal = ({ dashboard, isOpen, onClose }: ActionModal
244249 return null ;
245250 }
246251
247- const processForm : SubmitHandler < CreateDashboardValidationType > = ( data ) => {
252+ const processForm : SubmitHandler < CreateDashboardValidationType > = async ( data ) => {
253+ // Check if project exists, create it if it doesn't
254+ const projectExists = persesProjects ?. some (
255+ ( project ) => project . metadata . name === data . projectName ,
256+ ) ;
257+
258+ if ( ! projectExists ) {
259+ try {
260+ await createProjectMutation . mutateAsync ( data . projectName ) ;
261+ addAlert (
262+ t ( 'Project "{{project}}" created successfully' , { project : data . projectName } ) ,
263+ 'success' ,
264+ ) ;
265+ } catch ( projectError ) {
266+ const errorMessage =
267+ projectError ?. message ||
268+ t ( 'Failed to create project "{{project}}". Please try again.' , {
269+ project : data . projectName ,
270+ } ) ;
271+ addAlert ( t ( 'Error creating project: {{error}}' , { error : errorMessage } ) , 'danger' ) ;
272+ return ;
273+ }
274+ }
275+
248276 const newDashboard : DashboardResource = {
249277 ...dashboard ,
250278 metadata : {
0 commit comments