Skip to content

Commit

Permalink
feat: Disable virtual assistant with AssistantService property rather…
Browse files Browse the repository at this point in the history
… than QueryBuilderConfig
  • Loading branch information
travisstebbins committed Oct 22, 2024
1 parent 8691039 commit 95736d0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
7 changes: 7 additions & 0 deletions packages/legend-application/src/stores/AssistantService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export class AssistantService {
* This key is used to allow programmatic re-rendering of the assistant panel
*/
panelRenderingKey = uuid();
isDisabled = false;
isHidden = true; // hide by default unless specified by the application to show
isOpen = false;
isPanelMaximized = false;
Expand All @@ -123,6 +124,7 @@ export class AssistantService {

constructor(applicationStore: GenericLegendApplicationStore) {
makeObservable(this, {
isDisabled: observable,
isHidden: observable,
isOpen: observable,
isPanelMaximized: observable,
Expand All @@ -134,6 +136,7 @@ export class AssistantService {
currentDocumentationEntry: observable,
showSearchConfigurationMenu: observable,
currentContextualDocumentationEntry: computed,
setIsDisabled: action,
setIsHidden: action,
setIsOpen: action,
setIsPanelMaximized: action,
Expand Down Expand Up @@ -241,6 +244,10 @@ export class AssistantService {
}
}

setIsDisabled(val: boolean): void {
this.isDisabled = val;
}

setIsHidden(val: boolean): void {
this.isHidden = val;
}
Expand Down
12 changes: 6 additions & 6 deletions packages/legend-query-builder/src/components/QueryBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ const QueryBuilderStatusBar = observer(
onClick={toggleAssistant}
tabIndex={-1}
disabled={
queryBuilderState.config?.TEMPORARY__disableVirtualAssistant
queryBuilderState.applicationStore.assistantService.isDisabled
}
title={
queryBuilderState.config?.TEMPORARY__disableVirtualAssistant
queryBuilderState.applicationStore.assistantService.isDisabled
? 'Virtual Assistant is disabled'
: 'Toggle assistant'
}
Expand Down Expand Up @@ -944,12 +944,12 @@ export const QueryBuilder = observer(
<MenuContentItem
onClick={toggleAssistant}
disabled={
queryBuilderState.config
?.TEMPORARY__disableVirtualAssistant ?? false
queryBuilderState.applicationStore.assistantService
.isDisabled
}
title={
queryBuilderState.config
?.TEMPORARY__disableVirtualAssistant
queryBuilderState.applicationStore.assistantService
.isDisabled
? 'Virtual Assistant is disabled'
: ''
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import { STYLE_PREFIX, STYLE_PREFIX__DARK } from '@finos/legend-art';
import { expect } from '@jest/globals';
import { QueryBuilderAdvancedWorkflowState } from '../../stores/query-workflow/QueryBuilderWorkFlowState.js';
import { Route, Routes } from '@finos/legend-application/browser';
import type { QueryBuilderConfig } from '../../graph-manager/QueryBuilderConfig.js';

const getSelectorContainerClassName = (lightMode?: boolean): string =>
'.' + `${lightMode ? STYLE_PREFIX : STYLE_PREFIX__DARK}__value-container`;
Expand Down Expand Up @@ -196,7 +195,6 @@ export const TEST__setUpQueryBuilder = async (
mappingPath: string,
runtimePath: string,
rawMappingModelCoverageAnalysisResult?: RawMappingModelCoverageAnalysisResult,
queryBuilderConfig?: QueryBuilderConfig,
): Promise<{
renderResult: RenderResult;
queryBuilderState: QueryBuilderState;
Expand Down Expand Up @@ -229,7 +227,7 @@ export const TEST__setUpQueryBuilder = async (
MOCK__applicationStore,
graphManagerState,
QueryBuilderAdvancedWorkflowState.INSTANCE,
queryBuilderConfig,
undefined,
);
const mapping = graphManagerState.graph.getMapping(mappingPath);
queryBuilderState.executionContextState.setMapping(mapping);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,18 @@ test(
),

async () => {
const { renderResult } = await TEST__setUpQueryBuilder(
const { renderResult, queryBuilderState } = await TEST__setUpQueryBuilder(
TEST_DATA__QueryBuilder_Model_SimpleRelational,
stub_RawLambda(),
'execution::RelationalMapping',
'execution::Runtime',
TEST_DATA__ModelCoverageAnalysisResult_SimpleRelationalWithExists,
);

await act(async () => {
queryBuilderState.applicationStore.assistantService.setIsDisabled(false);
});

// Verify help menu button is enabled
fireEvent.click(renderResult.getByRole('button', { name: 'Help...' }));
expect(
Expand All @@ -127,22 +131,18 @@ test(
),

async () => {
const { renderResult } = await TEST__setUpQueryBuilder(
const { renderResult, queryBuilderState } = await TEST__setUpQueryBuilder(
TEST_DATA__QueryBuilder_Model_SimpleRelational,
stub_RawLambda(),
'execution::RelationalMapping',
'execution::Runtime',
TEST_DATA__ModelCoverageAnalysisResult_SimpleRelationalWithExists,
{
TEMPORARY__enableExportToCube: false,
TEMPORARY__disableQueryBuilderChat: false,
TEMPORARY__enableGridEnterpriseMode: false,
TEMPORARY__disableVirtualAssistant: true,
legendAIServiceURL: '',
zipkinTraceBaseURL: '',
},
);

await act(async () => {
queryBuilderState.applicationStore.assistantService.setIsDisabled(true);
});

// Verify status bar button is disabled
expect(
await renderResult.findByTitle('Virtual Assistant is disabled'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ export class QueryBuilderConfig {
*/
TEMPORARY__enableGridEnterpriseMode = false;

/**
* This flag is to disable the "Show Virtual Assistant" button
* in Query Builder
*/
TEMPORARY__disableVirtualAssistant = false;

/**
* This is the URL of the LegendAI service
*/
Expand All @@ -54,7 +48,6 @@ export class QueryBuilderConfig {
TEMPORARY__disableQueryBuilderChat: optional(primitive()),
TEMPORARY__enableExportToCube: optional(primitive()),
TEMPORARY__enableGridEnterpriseMode: optional(primitive()),
TEMPORARY__disableVirtualAssistant: optional(primitive()),
legendAIServiceURL: optional(primitive()),
zipkinTraceBaseURL: optional(primitive()),
}),
Expand Down

0 comments on commit 95736d0

Please sign in to comment.