From e099953d87dfe18e0660a0aba75e0fcda8794311 Mon Sep 17 00:00:00 2001 From: meta-d Date: Thu, 25 Jan 2024 20:48:20 +0800 Subject: [PATCH] feat: copilot input & insight copilot --- .../home/insight/insight.component.html | 8 +-- .../home/insight/insight.component.ts | 9 ++- .../features/home/insight/insight.service.ts | 11 ++-- .../copilot/input/input.component.html | 56 ++++++++++--------- .../angular/copilot/input/input.component.ts | 34 +++++++++-- 5 files changed, 79 insertions(+), 39 deletions(-) diff --git a/apps/cloud/src/app/features/home/insight/insight.component.html b/apps/cloud/src/app/features/home/insight/insight.component.html index 856de464f..c1e4edf25 100644 --- a/apps/cloud/src/app/features/home/insight/insight.component.html +++ b/apps/cloud/src/app/features/home/insight/insight.component.html @@ -195,7 +195,7 @@ - +
@@ -245,9 +245,9 @@ - - - +@if (!copilotEnabled) { + +} !!model?.schema?.cubes?.length)) readonly cubes$ = this.model$.pipe( diff --git a/packages/angular/copilot/input/input.component.html b/packages/angular/copilot/input/input.component.html index a37c1d314..39a91e8de 100644 --- a/packages/angular/copilot/input/input.component.html +++ b/packages/angular/copilot/input/input.component.html @@ -1,32 +1,36 @@
+
+
+
+ 🤖 +
+ - - -
-
- 🤖 -
-
- -
- {{error}} -
-
+ @if(error) { +
+ {{error}} +
+ } +
- - - - {{prompt}} - + + @for (prompt of filteredSuggests(); track prompt) { + + + } \ No newline at end of file diff --git a/packages/angular/copilot/input/input.component.ts b/packages/angular/copilot/input/input.component.ts index fcd7fec20..50c08c055 100644 --- a/packages/angular/copilot/input/input.component.ts +++ b/packages/angular/copilot/input/input.component.ts @@ -1,9 +1,11 @@ import { NgFor, NgIf } from '@angular/common' -import { Component, signal } from '@angular/core' -import { FormControl, ReactiveFormsModule } from '@angular/forms' +import { Component, EventEmitter, Input, Output, computed, signal } from '@angular/core' +import { toSignal } from '@angular/core/rxjs-interop' +import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms' import { MatAutocompleteModule, MatAutocompleteSelectedEvent } from '@angular/material/autocomplete' import { MatChipInputEvent, MatChipsModule } from '@angular/material/chips' import { MatTooltipModule } from '@angular/material/tooltip' +import { NgmHighlightDirective } from '@metad/ocap-angular/common' import { TranslateModule } from '@ngx-translate/core' @Component({ @@ -11,15 +13,34 @@ import { TranslateModule } from '@ngx-translate/core' selector: 'ngm-copilot-input', templateUrl: './input.component.html', styleUrl: './input.component.scss', - imports: [NgIf, NgFor, TranslateModule, ReactiveFormsModule, MatTooltipModule, MatChipsModule, MatAutocompleteModule] + imports: [NgIf, NgFor, TranslateModule, ReactiveFormsModule, MatTooltipModule, MatChipsModule, MatAutocompleteModule, NgmHighlightDirective] }) export class NgmCopilotInputComponent { + @Input() get suggests() { + return this.#suggests() + } + set suggests(value) { + this.#suggests.set(value) + } + readonly #suggests = signal([]) + + @Output() ask = new EventEmitter<{command?: string; prompt: string}>() + answering = signal(false) suggesting = signal(false) error = '' promptControl = new FormControl('') + formGroup = new FormGroup({ prompt: this.promptControl }) - suggestedPrompts = signal([]) + readonly search = toSignal(this.promptControl.valueChanges, { initialValue: null }) + + readonly filteredSuggests = computed(() => { + if (this.#suggests()) { + const search = this.search()?.toLowerCase() + return search ? this.#suggests().filter((item) => item.toLowerCase().includes(search)) : this.#suggests().slice() + } + return [] + }) /** * Add an ask prompt @@ -43,4 +64,9 @@ export class NgmCopilotInputComponent { // this.promptInput.nativeElement.value = event.option.viewValue this.promptControl.setValue(event.option.viewValue) } + + onSubmit() { + this.promptControl.setValue(null) + this.ask.emit({ prompt: this.promptControl.value }) + } }