fix(marketplace): rollback open workflow on view mode

This commit is contained in:
Emir Karabeg
2025-03-25 15:59:56 -07:00
parent e6bf5cf521
commit d97641d6da
4 changed files with 7 additions and 84 deletions
+4 -54
View File
@@ -43,9 +43,6 @@ function WorkflowContent() {
// State
const [selectedEdgeId, setSelectedEdgeId] = useState<string | null>(null)
const [isInitialized, setIsInitialized] = useState(false)
const [isPublicWorkflow, setIsPublicWorkflow] = useState(false)
const [publicWorkflowData, setPublicWorkflowData] = useState<any>(null)
const [loadingPublicWorkflow, setLoadingPublicWorkflow] = useState(false)
// Hooks
const params = useParams()
@@ -54,16 +51,8 @@ function WorkflowContent() {
// Store access
const { workflows, setActiveWorkflow, createWorkflow } = useWorkflowRegistry()
const {
blocks,
edges,
loops,
addBlock,
updateBlockPosition,
addEdge,
removeEdge,
initializeWorkflow,
} = useWorkflowStore()
const { blocks, edges, loops, addBlock, updateBlockPosition, addEdge, removeEdge } =
useWorkflowStore()
const { setValue: setSubBlockValue } = useSubBlockStore()
const { markAllAsRead } = useNotificationStore()
const { resetLoaded: resetVariablesLoaded } = useVariablesStore()
@@ -162,47 +151,9 @@ function WorkflowContent() {
return
}
// Check if the workflow is in the user's registry
if (!workflows[currentId]) {
// If not in registry, try to load it as a public workflow
setLoadingPublicWorkflow(true)
try {
const response = await fetch(`/api/workflows/public/${currentId}`)
if (response.ok) {
// Workflow exists and is public
const data = await response.json()
setPublicWorkflowData(data.data)
setIsPublicWorkflow(true)
// Initialize the workflow store with the public workflow state
if (data.data?.state) {
const { blocks, edges, loops } = data.data.state
initializeWorkflow(blocks || {}, edges || [], loops || {})
// Initialize subblock store with workflow values
if (blocks) {
useSubBlockStore.getState().initializeFromWorkflow(currentId, blocks)
}
}
setLoadingPublicWorkflow(false)
return
} else if (response.status === 403) {
// Workflow exists but is not public, redirect to first workflow
router.replace(`/w/${workflowIds[0]}`)
return
} else {
// Workflow doesn't exist, redirect to first workflow
router.replace(`/w/${workflowIds[0]}`)
return
}
} catch (error) {
console.error('Error loading public workflow:', error)
router.replace(`/w/${workflowIds[0]}`)
return
} finally {
setLoadingPublicWorkflow(false)
}
router.replace(`/w/${workflowIds[0]}`)
return
}
// Import the isActivelyLoadingFromDB function to check sync status
@@ -239,7 +190,6 @@ function WorkflowContent() {
isInitialized,
markAllAsRead,
resetVariablesLoaded,
initializeWorkflow,
])
// Transform blocks and loops into ReactFlow nodes
@@ -1,7 +1,6 @@
'use client'
import { useEffect, useState } from 'react'
import Link from 'next/link'
import { Eye, Star } from 'lucide-react'
import { Card, CardContent, CardFooter, CardHeader } from '@/components/ui/card'
import { Workflow } from '../marketplace'
@@ -61,18 +60,10 @@ export function WorkflowCard({ workflow, onHover }: WorkflowCardProps) {
}
}
// Extract the actual workflow ID from workflow
const workflowUrl = workflow.workflowUrl || `/w/${workflow.id}`
return (
<Link
href={workflowUrl}
className="block"
aria-label={`View ${workflow.name} workflow`}
onClick={handleClick}
>
<div className="block" aria-label={`View ${workflow.name} workflow`} onClick={handleClick}>
<Card
className="overflow-hidden transition-all hover:shadow-md flex flex-col h-full"
className="overflow-hidden transition-all hover:shadow-md flex flex-col h-full cursor-pointer"
onMouseEnter={handleMouseEnter}
>
{/* Workflow preview/thumbnail area */}
@@ -126,6 +117,6 @@ export function WorkflowCard({ workflow, onHover }: WorkflowCardProps) {
</CardFooter>
</div>
</Card>
</Link>
</div>
)
}
-17
View File
@@ -306,23 +306,6 @@ export const useWorkflowStore = create<WorkflowStoreWithHistory>()(
}
},
// Initialize workflow from external state (used for public workflows)
initializeWorkflow: (blocks: any, edges: any, loops: any) => {
const newState = {
blocks: blocks || {},
edges: edges || [],
loops: loops || {},
lastSaved: Date.now(),
isDeployed: false,
deployedAt: undefined,
isPublished: true,
}
set(newState)
// Don't push to history since this is an initial load
// Don't sync to avoid overwriting the original workflow
},
toggleBlockEnabled: (id: string) => {
const newState = {
blocks: {
-1
View File
@@ -62,7 +62,6 @@ export interface WorkflowActions {
triggerUpdate: () => void
setDeploymentStatus: (isDeployed: boolean, deployedAt?: Date) => void
setPublishStatus: (isPublished: boolean) => void
initializeWorkflow: (blocks: any, edges: any, loops: any) => void
}
export type WorkflowStore = WorkflowState & WorkflowActions