-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prepare the ground for Workflow integration
- Loading branch information
1 parent
df1a98f
commit a54bba5
Showing
33 changed files
with
637 additions
and
1,276 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useEffect } from 'react' | ||
|
||
import { FormInput } from '@/components/forms/FormInput' | ||
import { FormSection } from '@/components/forms/FormSection' | ||
import { useWorkflowEditor } from '@/services/editors' | ||
|
||
export function WorkflowEditor() { | ||
const current = useWorkflowEditor((s) => s.current) | ||
const setCurrent = useWorkflowEditor((s) => s.setCurrent) | ||
const history = useWorkflowEditor((s) => s.history) | ||
const undo = useWorkflowEditor((s) => s.undo) | ||
const redo = useWorkflowEditor((s) => s.redo) | ||
|
||
if (!current) { | ||
return ( | ||
<FormSection label={'Workflow Editor'} className="p-4"> | ||
Workflows are not implemented yet. | ||
</FormSection> | ||
) | ||
} | ||
|
||
return ( | ||
<FormSection label={'Workflow Editor'} className="p-4"> | ||
<div>Should be a form to edit the parameters.</div> | ||
<div> | ||
We can also display a link or an iframe with the actual workflow graph. | ||
</div> | ||
</FormSection> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// TODO: this isn't the best place for this as this is style, | ||
// and we are in a state manager | ||
export const libraryClassName = 'text-base font-semibold' | ||
|
||
export const collectionClassName = `text-base font-normal` | ||
|
||
export const itemClassName = | ||
'text-sm font-light text-gray-200/60 hover:text-gray-200/100' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
src/components/tree-browsers/stores/useWorkflowLibrary.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
'use client' | ||
|
||
import { create } from 'zustand' | ||
import { ClapEntity, UUID } from '@aitube/clap' | ||
import { LibraryNodeItem, LibraryNodeType, LibraryTreeNode } from '../types' | ||
import { icons } from '@/components/icons' | ||
import { collectionClassName, libraryClassName } from './treeNodeStyles' | ||
|
||
export const useWorkflowLibrary = create<{ | ||
builtInLibraryTreeNodeId: string | ||
communityLibraryTreeNodeId: string | ||
libraryTreeRoot: LibraryTreeNode[] | ||
init: () => void | ||
|
||
/** | ||
* Load built-in collections into the tree | ||
* | ||
* @param collections | ||
* @returns | ||
*/ | ||
//setBuiltInCollections: (collections: WorkflowCollection[]) => void | ||
|
||
/** | ||
* Load community collections into the tree | ||
* | ||
* @param collections | ||
* @returns | ||
*/ | ||
//setCommunityCollections: (collections: WorkflowCollection[]) => void | ||
|
||
// we support those all selection modes for convenience - please keep them! | ||
selectedNodeItem?: LibraryNodeItem | ||
selectedNodeType?: LibraryNodeType | ||
selectTreeNode: ( | ||
treeNodeId?: string | null, | ||
nodeType?: LibraryNodeType, | ||
nodeItem?: LibraryNodeItem | ||
) => void | ||
selectedTreeNodeId: string | null | ||
}>((set, get) => ({ | ||
builtInLibraryTreeNodeId: '', | ||
communityLibraryTreeNodeId: '', | ||
libraryTreeRoot: [], | ||
init: () => { | ||
const builtInLibrary: LibraryTreeNode = { | ||
id: UUID(), | ||
nodeType: 'LIB_NODE_WORKFLOWS', | ||
label: 'Built-in workflows', | ||
icon: icons.project, | ||
className: libraryClassName, | ||
isExpanded: true, | ||
children: [ | ||
{ | ||
id: UUID(), | ||
nodeType: 'LIB_NODE_GENERIC_EMPTY', | ||
label: 'A - 2', | ||
icon: icons.project, | ||
className: collectionClassName, | ||
}, | ||
], | ||
} | ||
|
||
const communityLibrary: LibraryTreeNode = { | ||
id: UUID(), | ||
nodeType: 'LIB_NODE_COMMUNITY_COLLECTION', | ||
label: 'Community workflows', | ||
icon: icons.community, | ||
className: libraryClassName, | ||
children: [ | ||
{ | ||
id: UUID(), | ||
nodeType: 'LIB_NODE_GENERIC_EMPTY', | ||
label: 'A - 2', | ||
icon: icons.community, | ||
className: collectionClassName, | ||
}, | ||
], | ||
} | ||
|
||
const libraryTreeRoot = [builtInLibrary, communityLibrary] | ||
|
||
set({ | ||
builtInLibraryTreeNodeId: builtInLibrary.id, | ||
communityLibraryTreeNodeId: communityLibrary.id, | ||
libraryTreeRoot, | ||
selectedNodeItem: undefined, | ||
selectedTreeNodeId: null, | ||
}) | ||
}, | ||
|
||
selectedNodeItem: undefined, | ||
selectEntity: (entity?: ClapEntity) => { | ||
if (entity) { | ||
console.log( | ||
'TODO julian: change this code to search in the entity collections' | ||
) | ||
const selectedTreeNode = get().libraryTreeRoot.find( | ||
(node) => node.data?.id === entity.id | ||
) | ||
|
||
// set({ selectedTreeNode }) | ||
set({ selectedTreeNodeId: selectedTreeNode?.id || null }) | ||
set({ selectedNodeItem: entity }) | ||
} else { | ||
// set({ selectedTreeNode: undefined }) | ||
set({ selectedTreeNodeId: null }) | ||
set({ selectedNodeItem: undefined }) | ||
} | ||
}, | ||
|
||
// selectedTreeNode: undefined, | ||
selectedTreeNodeId: null, | ||
selectTreeNode: ( | ||
treeNodeId?: string | null, | ||
nodeType?: LibraryNodeType, | ||
nodeItem?: LibraryNodeItem | ||
) => { | ||
set({ selectedTreeNodeId: treeNodeId ? treeNodeId : undefined }) | ||
set({ selectedNodeType: nodeType ? nodeType : undefined }) | ||
set({ selectedNodeItem: nodeItem ? nodeItem : undefined }) | ||
}, | ||
})) | ||
|
||
useWorkflowLibrary.getState().init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.