[Query Copilot] Disable command bar buttons when sample container is used (#1514)

* Disable command bar buttons when sample container is used and point only to copilot tab

* Make disabled assignement for buttons simmpler
This commit is contained in:
v-darkora
2023-07-07 09:08:08 +02:00
committed by GitHub
parent 90178178c4
commit eb21193ae4
2 changed files with 49 additions and 21 deletions

View File

@@ -1,9 +1,8 @@
import { ConnectionStatusType } from "Common/Constants";
import { ConnectionStatusType, QueryCopilotSampleContainerId, QueryCopilotSampleDatabaseId } from "Common/Constants";
import { useNotebook } from "Explorer/Notebook/useNotebook";
import create, { UseStore } from "zustand";
import * as ViewModels from "../Contracts/ViewModels";
import { useTabs } from "../hooks/useTabs";
export interface SelectedNodeState {
selectedNode: ViewModels.TreeNode;
setSelectedNode: (node: ViewModels.TreeNode) => void;
@@ -15,6 +14,7 @@ export interface SelectedNodeState {
subnodeKinds?: ViewModels.CollectionTabKind[]
) => boolean;
isConnectedToContainer: () => boolean;
isQueryCopilotCollectionSelected: () => boolean;
}
export const useSelectedNode: UseStore<SelectedNodeState> = create((set, get) => ({
@@ -65,4 +65,15 @@ export const useSelectedNode: UseStore<SelectedNodeState> = create((set, get) =>
isConnectedToContainer: (): boolean => {
return useNotebook.getState().connectionInfo?.status === ConnectionStatusType.Connected;
},
isQueryCopilotCollectionSelected: (): boolean => {
const selectedNode = get().selectedNode;
if (
selectedNode &&
selectedNode.id() === QueryCopilotSampleContainerId &&
(selectedNode as ViewModels.Collection)?.databaseId === QueryCopilotSampleDatabaseId
) {
return true;
}
return false;
},
}));