11import { reactive } from 'vue' ;
22import { GET , POST } from '../../modules/fetch.ts' ;
3- import { showInfoToast , showErrorToast } from '../../modules/toast.ts' ;
3+ import { showErrorToast } from '../../modules/toast.ts' ;
44
55type WorkflowFiltersState = {
66 issue_type : string ;
@@ -23,7 +23,7 @@ type WorkflowDraftState = {
2323 actions : WorkflowActionsState ;
2424} ;
2525
26- const createDefaultFilters = ( ) : WorkflowFiltersState => ( { issue_type : '' , source_column : '' , target_column : '' , labels : [ ] } ) ;
26+ const createDefaultFilters = ( ) : WorkflowFiltersState => ( { issue_type : '' , source_column : '' , target_column : '' , labels : [ ] } ) ;
2727const createDefaultActions = ( ) : WorkflowActionsState => ( { column : '' , add_labels : [ ] , remove_labels : [ ] , issue_state : '' } ) ;
2828
2929function convertFilters ( workflow : any ) : WorkflowFiltersState {
@@ -80,10 +80,10 @@ const cloneActions = (actions: WorkflowActionsState): WorkflowActionsState => ({
8080 issue_state : actions . issue_state ,
8181} ) ;
8282
83- export function createWorkflowStore ( projectLink : string , eventID : string ) {
83+ export function createWorkflowStore ( props : any ) {
8484 const store = reactive ( {
8585 workflowEvents : [ ] ,
86- selectedItem : eventID ,
86+ selectedItem : props . eventID ,
8787 selectedWorkflow : null ,
8888 projectColumns : [ ] ,
8989 projectLabels : [ ] , // Add labels data
@@ -113,19 +113,15 @@ export function createWorkflowStore(projectLink: string, eventID: string) {
113113 } ,
114114
115115 async loadEvents ( ) {
116- const response = await GET ( `${ projectLink } /workflows/events` ) ;
116+ const response = await GET ( `${ props . projectLink } /workflows/events` ) ;
117117 store . workflowEvents = await response . json ( ) ;
118118 return store . workflowEvents ;
119119 } ,
120120
121121 async loadProjectColumns ( ) {
122122 try {
123- const response = await GET ( `${ projectLink } /workflows/columns` ) ;
123+ const response = await GET ( `${ props . projectLink } /workflows/columns` ) ;
124124 store . projectColumns = await response . json ( ) ;
125- console . log ( '[WorkflowStore] Loaded columns:' , store . projectColumns ) ;
126- if ( store . projectColumns . length > 0 ) {
127- console . log ( '[WorkflowStore] First column.id type:' , typeof store . projectColumns [ 0 ] . id , 'value:' , store . projectColumns [ 0 ] . id ) ;
128- }
129125 } catch ( error ) {
130126 console . error ( 'Failed to load project columns:' , error ) ;
131127 store . projectColumns = [ ] ;
@@ -159,7 +155,7 @@ export function createWorkflowStore(projectLink: string, eventID: string) {
159155
160156 async loadProjectLabels ( ) {
161157 try {
162- const response = await GET ( `${ projectLink } /workflows/labels` ) ;
158+ const response = await GET ( `${ props . projectLink } /workflows/labels` ) ;
163159 store . projectLabels = await response . json ( ) ;
164160 } catch ( error ) {
165161 console . error ( 'Failed to load project labels:' , error ) ;
@@ -192,10 +188,7 @@ export function createWorkflowStore(projectLink: string, eventID: string) {
192188 actions : store . workflowActions ,
193189 } ;
194190
195- // Send workflow data
196- console . info ( 'Sending workflow data:' , postData ) ;
197-
198- const response = await POST ( `${ projectLink } /workflows/${ eventId } ` , {
191+ const response = await POST ( `${ props . projectLink } /workflows/${ eventId } ` , {
199192 data : postData ,
200193 headers : {
201194 'Content-Type' : 'application/json' ,
@@ -205,12 +198,11 @@ export function createWorkflowStore(projectLink: string, eventID: string) {
205198 if ( ! response . ok ) {
206199 const errorText = await response . text ( ) ;
207200 console . error ( 'Response error:' , errorText ) ;
208- showErrorToast ( `Failed to save workflow : ${ response . status } ${ response . statusText } \n${ errorText } ` ) ;
201+ showErrorToast ( `${ props . locale . failedToSaveWorkflow } : ${ response . status } ${ response . statusText } \n${ errorText } ` ) ;
209202 return ;
210203 }
211204
212205 const result = await response . json ( ) ;
213- console . log ( 'Response result:' , result ) ;
214206 if ( result . success && result . workflow ) {
215207 // Always reload the events list to get the updated structure
216208 // This ensures we have both the base event and the new filtered event
@@ -247,18 +239,16 @@ export function createWorkflowStore(projectLink: string, eventID: string) {
247239
248240 // Update URL to use the new workflow ID
249241 if ( wasNewWorkflow ) {
250- const newUrl = `${ projectLink } /workflows/${ store . selectedWorkflow . event_id } ` ;
242+ const newUrl = `${ props . projectLink } /workflows/${ store . selectedWorkflow . event_id } ` ;
251243 window . history . replaceState ( { eventId : store . selectedWorkflow . event_id } , '' , newUrl ) ;
252244 }
253-
254- showInfoToast ( 'Workflow saved successfully!' ) ;
255245 } else {
256246 console . error ( 'Unexpected response format:' , result ) ;
257- showErrorToast ( 'Failed to save workflow : Unexpected response format' ) ;
247+ showErrorToast ( ` ${ props . locale . failedToSaveWorkflow } : Unexpected response format` ) ;
258248 }
259249 } catch ( error ) {
260- console . error ( 'Error saving workflow:' , error ) ;
261- showErrorToast ( `Error saving workflow : ${ error . message } ` ) ;
250+ console . error ( 'Failed to save workflow:' , error ) ;
251+ showErrorToast ( `${ props . locale . failedToSaveWorkflow } : ${ error . message } ` ) ;
262252 } finally {
263253 store . saving = false ;
264254 }
@@ -273,14 +263,14 @@ export function createWorkflowStore(projectLink: string, eventID: string) {
273263
274264 // Use workflow ID for status update
275265 const workflowId = store . selectedWorkflow . id ;
276- const response = await POST ( `${ projectLink } /workflows/${ workflowId } /status` , {
266+ const response = await POST ( `${ props . projectLink } /workflows/${ workflowId } /status` , {
277267 data : formData ,
278268 } ) ;
279269
280270 if ( ! response . ok ) {
281271 const errorText = await response . text ( ) ;
282272 console . error ( 'Failed to update workflow status:' , errorText ) ;
283- showErrorToast ( `Failed to update workflow status : ${ response . status } ${ response . statusText } ` ) ;
273+ showErrorToast ( `${ props . locale . failedToUpdateWorkflowStatus } : ${ response . status } ${ response . statusText } ` ) ;
284274 // Revert the status change on error
285275 store . selectedWorkflow . enabled = ! store . selectedWorkflow . enabled ;
286276 return ;
@@ -296,13 +286,13 @@ export function createWorkflowStore(projectLink: string, eventID: string) {
296286 } else {
297287 // Revert the status change on failure
298288 store . selectedWorkflow . enabled = ! store . selectedWorkflow . enabled ;
299- showErrorToast ( 'Failed to update workflow status' ) ;
289+ showErrorToast ( ` ${ props . locale . failedToUpdateWorkflowStatus } : Unexpected error` ) ;
300290 }
301291 } catch ( error ) {
302- console . error ( 'Error updating workflow status:' , error ) ;
292+ console . error ( 'Failed to update workflow status:' , error ) ;
303293 // Revert the status change on error
304294 store . selectedWorkflow . enabled = ! store . selectedWorkflow . enabled ;
305- showErrorToast ( `Error updating workflow status : ${ error . message } ` ) ;
295+ showErrorToast ( `${ props . locale . failedToUpdateWorkflowStatus } : ${ error . message } ` ) ;
306296 }
307297 } ,
308298
@@ -312,14 +302,14 @@ export function createWorkflowStore(projectLink: string, eventID: string) {
312302 try {
313303 // Use workflow ID for deletion
314304 const workflowId = store . selectedWorkflow . id ;
315- const response = await POST ( `${ projectLink } /workflows/${ workflowId } /delete` , {
305+ const response = await POST ( `${ props . projectLink } /workflows/${ workflowId } /delete` , {
316306 data : new FormData ( ) ,
317307 } ) ;
318308
319309 if ( ! response . ok ) {
320310 const errorText = await response . text ( ) ;
321311 console . error ( 'Failed to delete workflow:' , errorText ) ;
322- showErrorToast ( `Failed to delete workflow : ${ response . status } ${ response . statusText } ` ) ;
312+ showErrorToast ( `${ props . locale . failedToDeleteWorkflow } : ${ response . status } ${ response . statusText } ` ) ;
323313 return ;
324314 }
325315
@@ -331,11 +321,11 @@ export function createWorkflowStore(projectLink: string, eventID: string) {
331321 store . workflowEvents . splice ( existingIndex , 1 ) ;
332322 }
333323 } else {
334- showErrorToast ( 'Failed to delete workflow' ) ;
324+ showErrorToast ( ` ${ props . locale . failedToDeleteWorkflow } : Unexpected error` ) ;
335325 }
336326 } catch ( error ) {
337327 console . error ( 'Error deleting workflow:' , error ) ;
338- showErrorToast ( `Error deleting workflow : ${ error . message } ` ) ;
328+ showErrorToast ( `${ props . locale . failedToDeleteWorkflow } : ${ error . message } ` ) ;
339329 }
340330 } ,
341331
0 commit comments