Remove other options other than New Query for query copilot collection in the resource tree AB#2501532

This commit is contained in:
Darko Radivojevic 2023-06-30 23:24:58 +02:00
parent ceed162491
commit deb33daae3
1 changed files with 47 additions and 38 deletions

View File

@ -1,3 +1,4 @@
import { QueryCopilotSampleContainerId, QueryCopilotSampleDatabaseId } from "Common/Constants";
import React from "react"; import React from "react";
import AddCollectionIcon from "../../images/AddCollection.svg"; import AddCollectionIcon from "../../images/AddCollection.svg";
import AddSqlQueryIcon from "../../images/AddSqlQuery_16x16.svg"; import AddSqlQueryIcon from "../../images/AddSqlQuery_16x16.svg";
@ -61,6 +62,13 @@ export const createDatabaseContextMenu = (container: Explorer, databaseId: strin
return items; return items;
}; };
const isQueryCopilotMoreMenu = (selectedCollection: ViewModels.Collection): boolean => {
return (
selectedCollection.databaseId === QueryCopilotSampleDatabaseId &&
selectedCollection.id() === QueryCopilotSampleContainerId
);
};
export const createCollectionContextMenuButton = ( export const createCollectionContextMenuButton = (
container: Explorer, container: Explorer,
selectedCollection: ViewModels.Collection selectedCollection: ViewModels.Collection
@ -95,48 +103,49 @@ export const createCollectionContextMenuButton = (
}); });
} }
if (userContext.apiType === "SQL" || userContext.apiType === "Gremlin") { if (!isQueryCopilotMoreMenu(selectedCollection)) {
items.push({ if (userContext.apiType === "SQL" || userContext.apiType === "Gremlin") {
iconSrc: AddStoredProcedureIcon, items.push({
onClick: () => { iconSrc: AddStoredProcedureIcon,
const selectedCollection: ViewModels.Collection = useSelectedNode.getState().findSelectedCollection(); onClick: () => {
selectedCollection && selectedCollection.onNewStoredProcedureClick(selectedCollection, undefined); const selectedCollection: ViewModels.Collection = useSelectedNode.getState().findSelectedCollection();
}, selectedCollection && selectedCollection.onNewStoredProcedureClick(selectedCollection, undefined);
label: "New Stored Procedure", },
}); label: "New Stored Procedure",
});
items.push({
iconSrc: AddUdfIcon,
onClick: () => {
const selectedCollection: ViewModels.Collection = useSelectedNode.getState().findSelectedCollection();
selectedCollection && selectedCollection.onNewUserDefinedFunctionClick(selectedCollection);
},
label: "New UDF",
});
items.push({
iconSrc: AddTriggerIcon,
onClick: () => {
const selectedCollection: ViewModels.Collection = useSelectedNode.getState().findSelectedCollection();
selectedCollection && selectedCollection.onNewTriggerClick(selectedCollection, undefined);
},
label: "New Trigger",
});
}
items.push({ items.push({
iconSrc: AddUdfIcon, iconSrc: DeleteCollectionIcon,
onClick: () => { onClick: () =>
const selectedCollection: ViewModels.Collection = useSelectedNode.getState().findSelectedCollection(); useSidePanel
selectedCollection && selectedCollection.onNewUserDefinedFunctionClick(selectedCollection); .getState()
}, .openSidePanel(
label: "New UDF", "Delete " + getCollectionName(),
}); <DeleteCollectionConfirmationPane refreshDatabases={() => container.refreshAllDatabases()} />
),
items.push({ label: `Delete ${getCollectionName()}`,
iconSrc: AddTriggerIcon, styleClass: "deleteCollectionMenuItem",
onClick: () => {
const selectedCollection: ViewModels.Collection = useSelectedNode.getState().findSelectedCollection();
selectedCollection && selectedCollection.onNewTriggerClick(selectedCollection, undefined);
},
label: "New Trigger",
}); });
} }
items.push({
iconSrc: DeleteCollectionIcon,
onClick: () =>
useSidePanel
.getState()
.openSidePanel(
"Delete " + getCollectionName(),
<DeleteCollectionConfirmationPane refreshDatabases={() => container.refreshAllDatabases()} />
),
label: `Delete ${getCollectionName()}`,
styleClass: "deleteCollectionMenuItem",
});
return items; return items;
}; };