aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx')
-rw-r--r--src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx45
1 files changed, 41 insertions, 4 deletions
diff --git a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
index 14fdd9b8d..7b7431bbe 100644
--- a/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
+++ b/src/client/views/nodes/chatbot/chatboxcomponents/ChatBox.tsx
@@ -427,10 +427,35 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
// this.createIndivDocInDash(parsedDoc.doc_type, parsedDoc.data, parsedDoc.options, '');
// });
// };
+ @action
+ private createCollectionWithChildren = async (data: string[]): Promise<Doc[]> => {
+ console.log('Creating collection with nested documents');
+
+ // Create an array of promises for each document
+ const childDocPromises = data.map(async doc => {
+ const parsedDoc = JSON.parse(doc);
+
+ if (parsedDoc.doc_type !== 'collection') {
+ // Handle non-collection documents
+ return await this.whichDoc(parsedDoc.doc_type, parsedDoc.data, parsedDoc.options, parsedDoc.id);
+ } else {
+ // Recursively process collections
+ const nestedDocs = await this.createCollectionWithChildren(parsedDoc.data);
+ return nestedDocs; // This will return an array of Docs
+ }
+ });
+
+ // Await all child document creations concurrently
+ const nestedResults = await Promise.all(childDocPromises);
+
+ // Flatten any nested arrays from recursive collection calls
+ const childDocs = nestedResults.flat();
+
+ return childDocs;
+ };
@action
- createDocInDash = async (doc_type: string, data: string, options: DocumentOptions, id: string) => {
- console.log('INDIV DOC' + doc_type);
+ whichDoc = async (doc_type: string, data: string, options: DocumentOptions, id: string): Promise<Doc> => {
let doc;
switch (doc_type) {
case 'text':
@@ -451,9 +476,12 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
case 'simulation':
doc = DocCast(Docs.Create.SimulationDocument(options));
break;
- case 'collection':
- doc = DocCast(Docs.Create.FreeformDocument([], options));
+ case 'collection': {
+ const par = JSON.parse(data);
+ const arr = await this.createCollectionWithChildren(par);
+ doc = DocCast(Docs.Create.FreeformDocument(arr, options));
break;
+ }
case 'web':
doc = DocCast(Docs.Create.WebDocument(data, options));
break;
@@ -499,6 +527,15 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() {
default:
doc = DocCast(Docs.Create.TextDocument(data, options));
}
+ return doc;
+ };
+
+ @action
+ createDocInDash = async (doc_type: string, data: string, options: DocumentOptions, id: string) => {
+ console.log('INDIV DOC' + doc_type);
+
+ const doc = await this.whichDoc(doc_type, data, options, id);
+
console.log('DOC' + doc_type);
const linkDoc = Docs.Create.LinkDocument(this.Document, doc);
LinkManager.Instance.addLink(linkDoc);