-
Notifications
You must be signed in to change notification settings - Fork 0
feat(dashboards): add data copilot integration #167
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
88d3e92
feat(dashboards): add data copilot integration
asithade 27e94f4
fix(data-copilot): remove dead code and fix state management issues
asithade 45c9919
Merge branch 'main' into feat/LFXV2-768-clean
asithade 50da2a6
refactor(ui): rename to Ask LFX Lens
asithade 9d922f1
feat(ui): added feature flagging for lfx lens
asithade File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
22 changes: 22 additions & 0 deletions
22
apps/lfx-one/src/app/shared/components/data-copilot/data-copilot.component.html
This file contains hidden or 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,22 @@ | ||
| <!-- Copyright The Linux Foundation and each contributor to LFX. --> | ||
| <!-- SPDX-License-Identifier: MIT --> | ||
|
|
||
| <!-- Trigger Button --> | ||
| <lfx-button | ||
| severity="secondary" | ||
| icon="fa-light fa-microchip-ai" | ||
| (click)="openDrawer()" | ||
| data-testid="data-copilot-button" | ||
| label="Ask LFX One AI" | ||
| size="small"></lfx-button> | ||
|
|
||
| <!-- Drawer --> | ||
| <p-drawer | ||
| [(visible)]="visible" | ||
| header="LFX Data Copilot" | ||
| position="right" | ||
| styleClass="md:w-1/2 w-full" | ||
| (onHide)="onVisibleChange(false)" | ||
| data-testid="data-copilot-drawer"> | ||
asithade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <div #iframeContainer class="iframe-container" data-testid="data-copilot-iframe-container"></div> | ||
| </p-drawer> | ||
asithade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
10 changes: 10 additions & 0 deletions
10
apps/lfx-one/src/app/shared/components/data-copilot/data-copilot.component.scss
This file contains hidden or 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,10 @@ | ||
| // Copyright The Linux Foundation and each contributor to LFX. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| .iframe-container { | ||
| width: 100%; | ||
| height: 100%; | ||
| display: flex; | ||
| flex-direction: column; | ||
| overflow: hidden; | ||
| } |
111 changes: 111 additions & 0 deletions
111
apps/lfx-one/src/app/shared/components/data-copilot/data-copilot.component.ts
This file contains hidden or 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,111 @@ | ||
| // Copyright The Linux Foundation and each contributor to LFX. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| import { afterNextRender, Component, computed, ElementRef, inject, signal, viewChild } from '@angular/core'; | ||
| import { ButtonComponent } from '@app/shared/components/button/button.component'; | ||
| import { AccountContextService } from '@app/shared/services/account-context.service'; | ||
| import { ProjectContextService } from '@app/shared/services/project-context.service'; | ||
| import { DrawerModule } from 'primeng/drawer'; | ||
|
|
||
| @Component({ | ||
| selector: 'lfx-data-copilot', | ||
| standalone: true, | ||
| imports: [DrawerModule, ButtonComponent], | ||
| templateUrl: './data-copilot.component.html', | ||
| styleUrl: './data-copilot.component.scss', | ||
| }) | ||
| export class DataCopilotComponent { | ||
| public readonly iframeContainer = viewChild<ElementRef<HTMLDivElement>>('iframeContainer'); | ||
|
|
||
| private readonly accountContextService = inject(AccountContextService); | ||
| private readonly projectContextService = inject(ProjectContextService); | ||
|
|
||
| // Computed values from context services | ||
| private readonly organizationId = computed(() => this.accountContextService.selectedAccount().accountId); | ||
| private readonly organizationName = computed(() => this.accountContextService.selectedAccount().accountName); | ||
asithade marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private readonly projectContext = computed(() => this.projectContextService.selectedProject() || this.projectContextService.selectedFoundation()); | ||
| private readonly projectSlug = computed(() => this.projectContext()?.slug || ''); | ||
| private readonly projectName = computed(() => this.projectContext()?.name || ''); | ||
|
|
||
| // Drawer visibility control | ||
| public readonly visible = signal<boolean>(false); | ||
|
|
||
| private iframeCreated = false; | ||
|
|
||
| public constructor() { | ||
| afterNextRender(() => { | ||
| // Create iframe only when drawer is visible and hasn't been created yet | ||
| if (this.visible() && !this.iframeCreated) { | ||
| this.createIframe(); | ||
| } | ||
| }); | ||
| } | ||
asithade marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
asithade marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Open the drawer | ||
| */ | ||
| protected openDrawer(): void { | ||
| this.visible.set(true); | ||
|
|
||
| // Create iframe after drawer opens if not already created | ||
| if (!this.iframeCreated) { | ||
| setTimeout(() => this.createIframe(), 100); | ||
asithade marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
asithade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Handle drawer visibility change | ||
| */ | ||
| protected onVisibleChange(isVisible: boolean): void { | ||
| this.visible.set(isVisible); | ||
|
|
||
| // Destroy iframe when drawer is closed | ||
| if (!isVisible) { | ||
| this.destroyIframe(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Destroy the iframe and cleanup resources | ||
| */ | ||
| private destroyIframe(): void { | ||
| const container = this.iframeContainer(); | ||
| if (container?.nativeElement) { | ||
| // Remove all child nodes (iframe) | ||
| while (container.nativeElement.firstChild) { | ||
| container.nativeElement.removeChild(container.nativeElement.firstChild); | ||
| } | ||
| } | ||
| this.iframeCreated = false; | ||
| } | ||
|
|
||
| /** | ||
| * Create and append the iframe to the container | ||
| */ | ||
| private createIframe(): void { | ||
| const container = this.iframeContainer(); | ||
| if (this.iframeCreated || !container?.nativeElement) { | ||
| return; | ||
| } | ||
|
|
||
| const iframe = document.createElement('iframe'); | ||
|
|
||
| // Construct the iframe src with query parameters | ||
| const params = new URLSearchParams({ | ||
| organization_id: this.organizationId(), | ||
| organization_name: this.organizationName(), | ||
| project_slug: this.projectSlug(), | ||
| project_name: this.projectName(), | ||
| }); | ||
|
|
||
| iframe.src = `https://lfx-data-copilot.onrender.com/embed?${params.toString()}`; | ||
asithade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| iframe.width = '100%'; | ||
| iframe.height = '100%'; | ||
| iframe.style.border = 'none'; | ||
| iframe.title = 'LFX Data Copilot'; | ||
|
|
||
| // Append the iframe to the container | ||
| container.nativeElement.appendChild(iframe); | ||
| this.iframeCreated = true; | ||
| } | ||
asithade marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.