Revert "fix(workspaces init): fix switch workspace fully + first workflow sho…" (#562)

This reverts commit 99105841b1.
This commit is contained in:
Vikhyath Mondreti
2025-06-26 19:57:52 -07:00
committed by GitHub
parent 99105841b1
commit 76a04251a7
4 changed files with 11 additions and 60 deletions
@@ -32,12 +32,7 @@ const IS_DEV = process.env.NODE_ENV === 'development'
export function Sidebar() {
useGlobalShortcuts()
const {
workflows,
createWorkflow,
isLoading: workflowsLoading,
targetWorkspaceId,
} = useWorkflowRegistry()
const { workflows, createWorkflow, isLoading: workflowsLoading } = useWorkflowRegistry()
const { isPending: sessionLoading } = useSession()
const userPermissions = useUserPermissionsContext()
const isLoading = workflowsLoading || sessionLoading
@@ -67,12 +62,9 @@ export function Sidebar() {
const regular: WorkflowMetadata[] = []
const temp: WorkflowMetadata[] = []
// Use targetWorkspaceId during transitions to prevent empty sidebar
const effectiveWorkspaceId = targetWorkspaceId || workspaceId
if (!isLoading) {
Object.values(workflows).forEach((workflow) => {
if (workflow.workspaceId === effectiveWorkspaceId || !workflow.workspaceId) {
if (workflow.workspaceId === workspaceId || !workflow.workspaceId) {
if (workflow.marketplaceData?.status === 'temp') {
temp.push(workflow)
} else {
@@ -99,7 +91,7 @@ export function Sidebar() {
}
return { regularWorkflows: regular, tempWorkflows: temp }
}, [workflows, isLoading, workspaceId, targetWorkspaceId])
}, [workflows, isLoading, workspaceId])
// Create workflow handler
const handleCreateWorkflow = async (folderId?: string) => {
@@ -7,44 +7,20 @@ import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
export default function WorkflowsPage() {
const router = useRouter()
const { workflows, isLoading, loadWorkflows } = useWorkflowRegistry()
const { workflows, isLoading } = useWorkflowRegistry()
const params = useParams()
const workspaceId = params.workspaceId as string
// Always load workflows for the current workspace to ensure we have the correct ones
useEffect(() => {
if (!isLoading) {
loadWorkflows(workspaceId)
}
}, [workspaceId, loadWorkflows, isLoading])
const workspaceId = params.workspaceId
useEffect(() => {
// Wait for workflows to load
if (isLoading) return
// Filter workflows for this workspace only
const workspaceWorkflows = Object.values(workflows).filter(
(workflow) => workflow.workspaceId === workspaceId
)
const workflowIds = Object.keys(workflows)
// If we have workflows for this workspace, redirect to the first one
if (workspaceWorkflows.length > 0) {
// Sort by last modified date (newest first) - same logic as sidebar
const sortedWorkflows = workspaceWorkflows.sort((a, b) => {
const dateA =
a.lastModified instanceof Date
? a.lastModified.getTime()
: new Date(a.lastModified).getTime()
const dateB =
b.lastModified instanceof Date
? b.lastModified.getTime()
: new Date(b.lastModified).getTime()
return dateB - dateA
})
const firstWorkflowId = sortedWorkflows[0].id
router.replace(`/workspace/${workspaceId}/w/${firstWorkflowId}`)
// If we have workflows, redirect to the first one
if (workflowIds.length > 0) {
router.replace(`/workspace/${workspaceId}/w/${workflowIds[0]}`)
return
}
+2 -18
View File
@@ -155,17 +155,7 @@ async function fetchWorkflowsFromDB(workspaceId?: string): Promise<void> {
if (!currentState.activeWorkflowId && Object.keys(registryWorkflows).length > 0) {
const firstWorkflowId = Object.keys(registryWorkflows)[0]
useWorkflowRegistry.setState({ activeWorkflowId: firstWorkflowId })
logger.info(`Set first workflow as active: ${firstWorkflowId}`, {
workspaceId,
totalWorkflows: Object.keys(registryWorkflows).length,
workflowIds: Object.keys(registryWorkflows),
})
} else {
logger.info(`Not setting active workflow`, {
currentActiveWorkflowId: currentState.activeWorkflowId,
workflowCount: Object.keys(registryWorkflows).length,
workspaceId,
})
logger.info(`Set first workflow as active: ${firstWorkflowId}`)
}
logger.info(
@@ -264,8 +254,6 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
error: null,
// Initialize deployment statuses
deploymentStatuses: {},
// Track target workspace during transitions to prevent empty sidebar
targetWorkspaceId: null,
// Set loading state
setLoading: (loading: boolean) => {
@@ -333,13 +321,12 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
// Clear current workspace state
resetWorkflowStores()
// Update state with target workspace ID for sidebar filtering
// Update state
set({
activeWorkflowId: null,
workflows: {},
isLoading: true,
error: null,
targetWorkspaceId: workspaceId,
})
// Fetch workflows for the new workspace
@@ -351,12 +338,9 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
set({
error: `Failed to switch workspace: ${error instanceof Error ? error.message : 'Unknown error'}`,
isLoading: false,
targetWorkspaceId: null,
})
} finally {
setWorkspaceTransitioning(false)
// Clear target workspace ID after transition completes
set({ targetWorkspaceId: null })
}
},
@@ -27,7 +27,6 @@ export interface WorkflowRegistryState {
isLoading: boolean
error: string | null
deploymentStatuses: Record<string, DeploymentStatus>
targetWorkspaceId: string | null
}
export interface WorkflowRegistryActions {