Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onboard custom node type to Workspace #47

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

export * from './constants';
export * from './interfaces';
export { IComponent } from '../public/component_types';
export * from '../public/component_types';
4 changes: 0 additions & 4 deletions public/component_types/indices/knn_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,4 @@ export class KnnIndex implements IComponent {
},
];
}

async init(): Promise<any> {
return new KnnIndex();
}
}
2 changes: 0 additions & 2 deletions public/component_types/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,4 @@ export interface IComponent {
// the user needs to fill out
createFields?: IComponentField[];
outputs?: IComponentOutput[];
// we will need some init function when the component is drug into the workspace
init?(): Promise<any>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,4 @@ export class TextEmbeddingProcessor implements IComponent {
},
];
}

async init(): Promise<any> {
return new TextEmbeddingProcessor();
}
}
23 changes: 5 additions & 18 deletions public/pages/workflow_detail/workspace/workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { EuiFlexItem, EuiFlexGroup } from '@elastic/eui';
import { rfContext } from '../../../store';
import { Workflow } from '../../../../common';
import { getCore } from '../../../services';
import { WorkspaceComponent } from '../workspace_component';

// styling
import 'reactflow/dist/style.css';
Expand All @@ -24,6 +25,9 @@ interface WorkspaceProps {
workflow?: Workflow;
}

const nodeTypes = { customComponent: WorkspaceComponent };
// TODO: probably have custom edge types here too

export function Workspace(props: WorkspaceProps) {
const reactFlowWrapper = useRef(null);
const { reactFlowInstance, setReactFlowInstance } = useContext(rfContext);
Expand Down Expand Up @@ -125,6 +129,7 @@ export function Workspace(props: WorkspaceProps) {
<ReactFlow
nodes={nodes}
edges={edges}
nodeTypes={nodeTypes}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
onConnect={onConnect}
Expand All @@ -143,21 +148,3 @@ export function Workspace(props: WorkspaceProps) {
</EuiFlexItem>
);
}

// TODO: remove later, leaving for reference

// export function Workspace() {
// const { components } = useSelector((state: AppState) => state.workspace);

// return (
// <EuiFlexGroup direction="row">
// {components.map((component, idx) => {
// return (
// <EuiFlexItem key={idx}>
// <WorkspaceComponent component={component} />
// </EuiFlexItem>
// );
// })}
// </EuiFlexGroup>
// );
// }
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@ import { InputFieldList } from './input_field_list';
import { NewOrExistingTabs } from './new_or_existing_tabs';

interface WorkspaceComponentProps {
component: IComponent;
data: IComponent;
}

/**
* TODO: This will be the ReactFlow node in the drag-and-drop workspace. It will take in the data passed
* to it from the workspace and render it appropriately (inputs / params / outputs / etc.)
* Similar to Flowise's CanvasNode - see
* https://github.com/FlowiseAI/Flowise/blob/main/packages/ui/src/views/canvas/CanvasNode.js
* The React component in the drag-and-drop workspace. It will take in the component data passed
* to it from the workspace and render it appropriately (inputs / params / outputs / etc.).
* As users interact with it (input data, add connections), the stored IComponent data will update.
*/
export function WorkspaceComponent(props: WorkspaceComponentProps) {
const { component } = props;
const component = props.data;

const [selectedTabId, setSelectedTabId] = useState<string>('existing');

Expand Down
38 changes: 15 additions & 23 deletions public/store/reducers/workflows_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,27 @@
*/

import { createSlice } from '@reduxjs/toolkit';
import { Workflow, ReactFlowComponent, ReactFlowEdge } from '../../../common';
import {
Workflow,
ReactFlowComponent,
ReactFlowEdge,
KnnIndex,
TextEmbeddingProcessor,
} from '../../../common';

// TODO: remove after fetching from server-side
const dummyNodes = [
{
id: 'semantic-search',
position: { x: 40, y: 10 },
data: { label: 'Semantic Search' },
type: 'group',
style: {
height: 110,
width: 700,
},
},
{
id: 'model',
position: { x: 25, y: 25 },
data: { label: 'Deployed Model ID' },
type: 'default',
parentNode: 'semantic-search',
extent: 'parent',
id: 'text-embedding-processor',
position: { x: 0, y: 500 },
data: new TextEmbeddingProcessor(),
type: 'customComponent',
},
{
id: 'ingest-pipeline',
position: { x: 262, y: 25 },
data: { label: 'Ingest Pipeline Name' },
type: 'default',
parentNode: 'semantic-search',
extent: 'parent',
id: 'knn-index',
position: { x: 500, y: 500 },
data: new KnnIndex(),
type: 'customComponent',
},
] as ReactFlowComponent[];

Expand Down
Loading