Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a5255ff

Browse files
committedMay 18, 2024·
Cleanup
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
1 parent f95c4ee commit a5255ff

File tree

1 file changed

+107
-261
lines changed

1 file changed

+107
-261
lines changed
 

‎public/utils/utils.ts

+107-261
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ export function uiConfigToWorkspaceFlow(
346346
edges.push(...searchWorkspaceFlow.edges);
347347

348348
return {
349-
nodes,
349+
nodes: nodes.map((node) => addDefaults(node)),
350350
edges,
351351
};
352352
}
@@ -368,73 +368,42 @@ function ingestConfigToWorkspaceFlow(
368368
height: 400,
369369
},
370370
className: 'reactflow__group-node__ingest',
371-
selectable: false,
372-
draggable: false,
373-
deletable: false,
374371
} as ReactFlowComponent;
375372

376373
nodes.push(parentNode);
377374

375+
// By default, always include a document node and an index node.
376+
const docNodeId = generateId(COMPONENT_CLASS.DOCUMENT);
377+
const docNode = {
378+
id: docNodeId,
379+
position: { x: 100, y: 70 },
380+
data: initComponentData(new Document().toObj(), docNodeId),
381+
type: NODE_CATEGORY.CUSTOM,
382+
parentNode: parentNode.id,
383+
extent: 'parent',
384+
} as ReactFlowComponent;
385+
const indexNodeId = generateId(COMPONENT_CLASS.KNN_INDEXER);
386+
const indexNode = {
387+
id: indexNodeId,
388+
position: { x: 900, y: 70 },
389+
data: initComponentData(new KnnIndexer().toObj(), indexNodeId),
390+
type: NODE_CATEGORY.CUSTOM,
391+
parentNode: parentNode.id,
392+
extent: 'parent',
393+
} as ReactFlowComponent;
394+
nodes.push(docNode, indexNode);
395+
378396
// Get nodes/edges from the sub-configurations
379-
const sourceWorkspaceFlow = sourceConfigToWorkspaceFlow(
380-
ingestConfig.source,
381-
parentNode.id
382-
);
383397
const enrichWorkspaceFlow = enrichConfigToWorkspaceFlow(
384398
ingestConfig.enrich,
385399
parentNode.id
386400
);
387-
const indexWorkspaceFlow = indexConfigToWorkspaceFlow(
388-
ingestConfig.index,
389-
parentNode.id
390-
);
391401

392-
nodes.push(
393-
...sourceWorkspaceFlow.nodes,
394-
...enrichWorkspaceFlow.nodes,
395-
...indexWorkspaceFlow.nodes
396-
);
397-
edges.push(
398-
...sourceWorkspaceFlow.edges,
399-
...enrichWorkspaceFlow.edges,
400-
...indexWorkspaceFlow.edges
401-
);
402+
nodes.push(...enrichWorkspaceFlow.nodes);
403+
edges.push(...enrichWorkspaceFlow.edges);
402404

403405
// Link up the set of localized nodes/edges per sub-workflow
404-
edges.push(
405-
...getIngestEdges(
406-
sourceWorkspaceFlow,
407-
enrichWorkspaceFlow,
408-
indexWorkspaceFlow
409-
)
410-
);
411-
412-
return {
413-
nodes,
414-
edges,
415-
};
416-
}
417-
418-
// TODO: make more generic.
419-
// Currently hardcoding a single Document node as the source.
420-
function sourceConfigToWorkspaceFlow(
421-
sourceConfig: IConfig,
422-
parentNodeId: string
423-
): WorkspaceFlowState {
424-
const nodes = [] as ReactFlowComponent[];
425-
const edges = [] as ReactFlowEdge[];
426-
427-
const docNodeId = generateId(COMPONENT_CLASS.DOCUMENT);
428-
nodes.push({
429-
id: docNodeId,
430-
position: { x: 100, y: 70 },
431-
data: initComponentData(new Document().toObj(), docNodeId),
432-
type: NODE_CATEGORY.CUSTOM,
433-
parentNode: parentNodeId,
434-
extent: 'parent',
435-
draggable: true,
436-
deletable: false,
437-
});
406+
edges.push(...getIngestEdges(docNode, enrichWorkspaceFlow, indexNode));
438407

439408
return {
440409
nodes,
@@ -481,107 +450,43 @@ function enrichConfigToWorkspaceFlow(
481450
type: NODE_CATEGORY.CUSTOM,
482451
parentNode: parentNodeId,
483452
extent: 'parent',
484-
draggable: true,
485-
deletable: false,
486453
});
487454
return {
488455
nodes,
489456
edges,
490457
};
491458
}
492459

493-
function indexConfigToWorkspaceFlow(
494-
indexConfig: IndexConfig,
495-
parentNodeId: string
496-
): WorkspaceFlowState {
497-
const nodes = [] as ReactFlowComponent[];
498-
const edges = [] as ReactFlowEdge[];
499-
500-
const indexNodeId = generateId(COMPONENT_CLASS.KNN_INDEXER);
501-
nodes.push({
502-
id: indexNodeId,
503-
position: { x: 900, y: 70 },
504-
data: initComponentData(new KnnIndexer().toObj(), indexNodeId),
505-
type: NODE_CATEGORY.CUSTOM,
506-
parentNode: parentNodeId,
507-
extent: 'parent',
508-
draggable: true,
509-
deletable: false,
510-
});
511-
512-
return {
513-
nodes,
514-
edges,
515-
};
516-
}
517-
518460
// Given the set of localized flows per sub-configuration, generate the global ingest-level edges.
519461
// This takes the assumption the flow is linear, and all sub-configuration flows are fully connected.
520462
function getIngestEdges(
521-
sourceFlow: WorkspaceFlowState,
463+
docNode: ReactFlowComponent,
522464
enrichFlow: WorkspaceFlowState,
523-
indexFlow: WorkspaceFlowState
465+
indexNode: ReactFlowComponent
524466
): ReactFlowEdge[] {
525-
const startAndEndNodesSource = getStartAndEndNodes(sourceFlow) as {
526-
startNode: ReactFlowComponent;
527-
endNode: ReactFlowComponent;
528-
};
529-
// May be undefined if no ingest processors defined
530467
const startAndEndNodesEnrich = getStartAndEndNodes(enrichFlow);
531-
const startAndEndNodesIndex = getStartAndEndNodes(indexFlow) as {
532-
startNode: ReactFlowComponent;
533-
endNode: ReactFlowComponent;
534-
};
535468

536469
// Users may omit search request processors altogether. Need to handle cases separately.
537470
if (startAndEndNodesEnrich !== undefined) {
538471
const sourceToEnrichEdgeId = generateId('edge');
539472
const enrichToIndexEdgeId = generateId('edge');
540473

541474
return [
542-
{
543-
id: sourceToEnrichEdgeId,
544-
key: sourceToEnrichEdgeId,
545-
source: startAndEndNodesSource.endNode.id,
546-
target: startAndEndNodesEnrich.startNode.id,
547-
markerEnd: {
548-
type: MarkerType.ArrowClosed,
549-
width: 20,
550-
height: 20,
551-
},
552-
zIndex: 2,
553-
deletable: false,
554-
},
555-
{
556-
id: enrichToIndexEdgeId,
557-
key: enrichToIndexEdgeId,
558-
source: startAndEndNodesEnrich.endNode.id,
559-
target: startAndEndNodesIndex.startNode.id,
560-
markerEnd: {
561-
type: MarkerType.ArrowClosed,
562-
width: 20,
563-
height: 20,
564-
},
565-
zIndex: 2,
566-
deletable: false,
567-
},
475+
generateReactFlowEdge(
476+
sourceToEnrichEdgeId,
477+
docNode.id,
478+
startAndEndNodesEnrich.startNode.id
479+
),
480+
generateReactFlowEdge(
481+
enrichToIndexEdgeId,
482+
startAndEndNodesEnrich.endNode.id,
483+
indexNode.id
484+
),
568485
] as ReactFlowEdge[];
569486
} else {
570487
const sourceToIndexEdgeId = generateId('edge');
571488
return [
572-
{
573-
id: sourceToIndexEdgeId,
574-
key: sourceToIndexEdgeId,
575-
source: startAndEndNodesSource.endNode.id,
576-
target: startAndEndNodesIndex.startNode.id,
577-
markerEnd: {
578-
type: MarkerType.ArrowClosed,
579-
width: 20,
580-
height: 20,
581-
},
582-
zIndex: 2,
583-
deletable: false,
584-
},
489+
generateReactFlowEdge(sourceToIndexEdgeId, docNode.id, indexNode.id),
585490
] as ReactFlowEdge[];
586491
}
587492
}
@@ -603,14 +508,20 @@ function searchConfigToWorkspaceFlow(
603508
height: 400,
604509
},
605510
className: 'reactflow__group-node__search',
606-
selectable: true,
607-
draggable: true,
608-
deletable: false,
609511
} as ReactFlowComponent;
610512

611513
nodes.push(parentNode);
612514

613-
// By default, always include an index node and a results node.
515+
// By default, always include a query node, an index node, and a results node.
516+
const queryNodeId = generateId(COMPONENT_CLASS.NEURAL_QUERY);
517+
const queryNode = {
518+
id: queryNodeId,
519+
position: { x: 100, y: 70 },
520+
data: initComponentData(new NeuralQuery().toObj(), queryNodeId),
521+
type: NODE_CATEGORY.CUSTOM,
522+
parentNode: parentNode.id,
523+
extent: 'parent',
524+
} as ReactFlowComponent;
614525
const indexNodeId = generateId(COMPONENT_CLASS.KNN_INDEXER);
615526
const indexNode = {
616527
id: indexNodeId,
@@ -619,8 +530,6 @@ function searchConfigToWorkspaceFlow(
619530
type: NODE_CATEGORY.CUSTOM,
620531
parentNode: parentNode.id,
621532
extent: 'parent',
622-
draggable: true,
623-
deletable: false,
624533
} as ReactFlowComponent;
625534
const resultsNodeId = generateId(COMPONENT_CLASS.RESULTS);
626535
const resultsNode = {
@@ -630,16 +539,10 @@ function searchConfigToWorkspaceFlow(
630539
type: NODE_CATEGORY.CUSTOM,
631540
parentNode: parentNode.id,
632541
extent: 'parent',
633-
draggable: true,
634-
deletable: false,
635542
} as ReactFlowComponent;
636-
nodes.push(indexNode, resultsNode);
543+
nodes.push(queryNode, indexNode, resultsNode);
637544

638545
// Get nodes/edges from the sub-configurations
639-
const requestWorkspaceFlow = requestConfigToWorkspaceFlow(
640-
searchConfig.request,
641-
parentNode.id
642-
);
643546
const enrichRequestWorkspaceFlow = enrichRequestConfigToWorkspaceFlow(
644547
searchConfig.enrichRequest,
645548
parentNode.id
@@ -650,20 +553,18 @@ function searchConfigToWorkspaceFlow(
650553
);
651554

652555
nodes.push(
653-
...requestWorkspaceFlow.nodes,
654556
...enrichRequestWorkspaceFlow.nodes,
655557
...enrichResponseWorkspaceFlow.nodes
656558
);
657559
edges.push(
658-
...requestWorkspaceFlow.edges,
659560
...enrichRequestWorkspaceFlow.edges,
660561
...enrichResponseWorkspaceFlow.edges
661562
);
662563

663564
// Link up the set of localized nodes/edges per sub-workflow
664565
edges.push(
665566
...getSearchEdges(
666-
requestWorkspaceFlow,
567+
queryNode,
667568
enrichRequestWorkspaceFlow,
668569
indexNode,
669570
enrichResponseWorkspaceFlow,
@@ -677,33 +578,6 @@ function searchConfigToWorkspaceFlow(
677578
};
678579
}
679580

680-
// TODO: make more generic.
681-
// Currently hardcoding a single NeuralQuery node as the source.
682-
function requestConfigToWorkspaceFlow(
683-
requestConfig: IConfig,
684-
parentNodeId: string
685-
): WorkspaceFlowState {
686-
const nodes = [] as ReactFlowComponent[];
687-
const edges = [] as ReactFlowEdge[];
688-
689-
const queryNodeId = generateId(COMPONENT_CLASS.NEURAL_QUERY);
690-
nodes.push({
691-
id: queryNodeId,
692-
position: { x: 100, y: 70 },
693-
data: initComponentData(new NeuralQuery().toObj(), queryNodeId),
694-
type: NODE_CATEGORY.CUSTOM,
695-
parentNode: parentNodeId,
696-
extent: 'parent',
697-
draggable: true,
698-
deletable: false,
699-
});
700-
701-
return {
702-
nodes,
703-
edges,
704-
};
705-
}
706-
707581
// TODO: implement this
708582
function enrichRequestConfigToWorkspaceFlow(
709583
enrichConfig: IConfig,
@@ -735,19 +609,13 @@ function enrichResponseConfigToWorkspaceFlow(
735609
// Given the set of localized flows per sub-configuration, generate the global search-level edges.
736610
// This takes the assumption the flow is linear, and all sub-configuration flows are fully connected.
737611
function getSearchEdges(
738-
requestFlow: WorkspaceFlowState,
612+
queryNode: ReactFlowComponent,
739613
enrichRequestFlow: WorkspaceFlowState,
740614
indexNode: ReactFlowComponent,
741615
enrichResponseFlow: WorkspaceFlowState,
742616
resultsNode: ReactFlowComponent
743617
): ReactFlowEdge[] {
744-
const startAndEndNodesRequest = getStartAndEndNodes(requestFlow) as {
745-
startNode: ReactFlowComponent;
746-
endNode: ReactFlowComponent;
747-
};
748-
// May be undefined if no search request processors defined
749618
const startAndEndNodesEnrichRequest = getStartAndEndNodes(enrichRequestFlow);
750-
// May be undefined if no search response processors defined
751619
const startAndEndNodesEnrichResponse = getStartAndEndNodes(
752620
enrichResponseFlow
753621
);
@@ -759,49 +627,24 @@ function getSearchEdges(
759627
const enrichRequestToIndexEdgeId = generateId('edge');
760628
edges.push(
761629
...([
762-
{
763-
id: requestToEnrichRequestEdgeId,
764-
key: requestToEnrichRequestEdgeId,
765-
source: startAndEndNodesRequest?.endNode.id,
766-
target: startAndEndNodesEnrichRequest.startNode.id,
767-
markerEnd: {
768-
type: MarkerType.ArrowClosed,
769-
width: 20,
770-
height: 20,
771-
},
772-
zIndex: 2,
773-
deletable: false,
774-
},
775-
{
776-
id: enrichRequestToIndexEdgeId,
777-
key: enrichRequestToIndexEdgeId,
778-
source: startAndEndNodesEnrichRequest.endNode.id,
779-
target: indexNode.id,
780-
markerEnd: {
781-
type: MarkerType.ArrowClosed,
782-
width: 20,
783-
height: 20,
784-
},
785-
zIndex: 2,
786-
deletable: false,
787-
},
630+
generateReactFlowEdge(
631+
requestToEnrichRequestEdgeId,
632+
queryNode.id,
633+
startAndEndNodesEnrichRequest.startNode.id
634+
),
635+
636+
generateReactFlowEdge(
637+
enrichRequestToIndexEdgeId,
638+
startAndEndNodesEnrichRequest.endNode.id,
639+
indexNode.id
640+
),
788641
] as ReactFlowEdge[])
789642
);
790643
} else {
791644
const requestToIndexEdgeId = generateId('edge');
792-
edges.push({
793-
id: requestToIndexEdgeId,
794-
key: requestToIndexEdgeId,
795-
source: startAndEndNodesRequest?.endNode.id,
796-
target: indexNode.id,
797-
markerEnd: {
798-
type: MarkerType.ArrowClosed,
799-
width: 20,
800-
height: 20,
801-
},
802-
zIndex: 2,
803-
deletable: false,
804-
} as ReactFlowEdge);
645+
edges.push(
646+
generateReactFlowEdge(requestToIndexEdgeId, queryNode.id, indexNode.id)
647+
);
805648
}
806649

807650
// Users may omit search response processors altogether. Need to handle cases separately.
@@ -811,49 +654,23 @@ function getSearchEdges(
811654

812655
edges.push(
813656
...([
814-
{
815-
id: indexToEnrichResponseEdgeId,
816-
key: indexToEnrichResponseEdgeId,
817-
source: indexNode.id,
818-
target: startAndEndNodesEnrichResponse.startNode.id,
819-
markerEnd: {
820-
type: MarkerType.ArrowClosed,
821-
width: 20,
822-
height: 20,
823-
},
824-
zIndex: 2,
825-
deletable: false,
826-
},
827-
{
828-
id: enrichResponseToResultsEdgeId,
829-
key: enrichResponseToResultsEdgeId,
830-
source: startAndEndNodesEnrichResponse.endNode.id,
831-
target: resultsNode.id,
832-
markerEnd: {
833-
type: MarkerType.ArrowClosed,
834-
width: 20,
835-
height: 20,
836-
},
837-
zIndex: 2,
838-
deletable: false,
839-
},
657+
generateReactFlowEdge(
658+
indexToEnrichResponseEdgeId,
659+
indexNode.id,
660+
startAndEndNodesEnrichResponse.startNode.id
661+
),
662+
generateReactFlowEdge(
663+
enrichResponseToResultsEdgeId,
664+
startAndEndNodesEnrichResponse.endNode.id,
665+
resultsNode.id
666+
),
840667
] as ReactFlowEdge[])
841668
);
842669
} else {
843670
const indexToResultsEdgeId = generateId('edge');
844-
edges.push({
845-
id: indexToResultsEdgeId,
846-
key: indexToResultsEdgeId,
847-
source: indexNode.id,
848-
target: resultsNode.id,
849-
markerEnd: {
850-
type: MarkerType.ArrowClosed,
851-
width: 20,
852-
height: 20,
853-
},
854-
zIndex: 2,
855-
deletable: false,
856-
} as ReactFlowEdge);
671+
edges.push(
672+
generateReactFlowEdge(indexToResultsEdgeId, indexNode.id, resultsNode.id)
673+
);
857674
}
858675

859676
return edges;
@@ -891,3 +708,32 @@ function getStartAndEndNodes(
891708
)[0],
892709
};
893710
}
711+
712+
function addDefaults(component: ReactFlowComponent): ReactFlowComponent {
713+
return {
714+
...component,
715+
draggable: false,
716+
selectable: false,
717+
deletable: false,
718+
};
719+
}
720+
721+
function generateReactFlowEdge(
722+
id: string,
723+
source: string,
724+
target: string
725+
): ReactFlowEdge {
726+
return {
727+
id,
728+
key: id,
729+
source,
730+
target,
731+
markerEnd: {
732+
type: MarkerType.ArrowClosed,
733+
width: 20,
734+
height: 20,
735+
},
736+
zIndex: 2,
737+
deletable: false,
738+
} as ReactFlowEdge;
739+
}

0 commit comments

Comments
 (0)
Please sign in to comment.