[Task 3061766] Additional Keyboard Shortcuts (#1805)
* [Task 3061766] Additional Keyboard Shortcuts refmt and fix lints shortcuts for: discard, new item/sproc/udf/trigger, delete item/sproc/udf/trigger copilot shortcut * remove 'Ctrl+I' due to conflict with Monaco Autocomplete
This commit is contained in:
parent
e3fab9b5bf
commit
a5a5a95973
|
@ -41,7 +41,7 @@ export const CommandBar: React.FC<Props> = ({ container }: Props) => {
|
||||||
const buttons = useCommandBar((state) => state.contextButtons);
|
const buttons = useCommandBar((state) => state.contextButtons);
|
||||||
const isHidden = useCommandBar((state) => state.isHidden);
|
const isHidden = useCommandBar((state) => state.isHidden);
|
||||||
const backgroundColor = StyleConstants.BaseLight;
|
const backgroundColor = StyleConstants.BaseLight;
|
||||||
const setKeyboardShortcutHandlers = useKeyboardActionHandlers((state) => state.setHandlers);
|
const setKeyboardActionHandlers = useKeyboardActionHandlers((state) => state.setHandlers);
|
||||||
|
|
||||||
if (userContext.apiType === "Postgres" || userContext.apiType === "VCoreMongo") {
|
if (userContext.apiType === "Postgres" || userContext.apiType === "VCoreMongo") {
|
||||||
const buttons =
|
const buttons =
|
||||||
|
@ -109,7 +109,7 @@ export const CommandBar: React.FC<Props> = ({ container }: Props) => {
|
||||||
|
|
||||||
const allButtons = staticButtons.concat(contextButtons).concat(controlButtons);
|
const allButtons = staticButtons.concat(contextButtons).concat(controlButtons);
|
||||||
const keyboardHandlers = CommandBarUtil.createKeyboardHandlers(allButtons);
|
const keyboardHandlers = CommandBarUtil.createKeyboardHandlers(allButtons);
|
||||||
setKeyboardShortcutHandlers(keyboardHandlers);
|
setKeyboardActionHandlers(keyboardHandlers);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="commandBarContainer" style={{ display: isHidden ? "none" : "initial" }}>
|
<div className="commandBarContainer" style={{ display: isHidden ? "none" : "initial" }}>
|
||||||
|
|
|
@ -58,6 +58,7 @@ export function createStaticCommandBarButtons(
|
||||||
buttons.push(homeBtn);
|
buttons.push(homeBtn);
|
||||||
|
|
||||||
const newCollectionBtn = createNewCollectionGroup(container);
|
const newCollectionBtn = createNewCollectionGroup(container);
|
||||||
|
newCollectionBtn.keyboardAction = KeyboardAction.NEW_COLLECTION; // Just for the root button, not the child version we create below.
|
||||||
buttons.push(newCollectionBtn);
|
buttons.push(newCollectionBtn);
|
||||||
if (userContext.apiType !== "Tables" && userContext.apiType !== "Cassandra") {
|
if (userContext.apiType !== "Tables" && userContext.apiType !== "Cassandra") {
|
||||||
const addSynapseLink = createOpenSynapseLinkDialogButton(container);
|
const addSynapseLink = createOpenSynapseLinkDialogButton(container);
|
||||||
|
@ -95,6 +96,7 @@ export function createStaticCommandBarButtons(
|
||||||
const newStoredProcedureBtn: CommandButtonComponentProps = {
|
const newStoredProcedureBtn: CommandButtonComponentProps = {
|
||||||
iconSrc: AddStoredProcedureIcon,
|
iconSrc: AddStoredProcedureIcon,
|
||||||
iconAlt: label,
|
iconAlt: label,
|
||||||
|
keyboardAction: KeyboardAction.NEW_SPROC,
|
||||||
onCommandClick: () => {
|
onCommandClick: () => {
|
||||||
const selectedCollection: ViewModels.Collection = selectedNodeState.findSelectedCollection();
|
const selectedCollection: ViewModels.Collection = selectedNodeState.findSelectedCollection();
|
||||||
selectedCollection && selectedCollection.onNewStoredProcedureClick(selectedCollection);
|
selectedCollection && selectedCollection.onNewStoredProcedureClick(selectedCollection);
|
||||||
|
@ -278,6 +280,7 @@ function createNewDatabase(container: Explorer): CommandButtonComponentProps {
|
||||||
return {
|
return {
|
||||||
iconSrc: AddDatabaseIcon,
|
iconSrc: AddDatabaseIcon,
|
||||||
iconAlt: label,
|
iconAlt: label,
|
||||||
|
keyboardAction: KeyboardAction.NEW_DATABASE,
|
||||||
onCommandClick: async () => {
|
onCommandClick: async () => {
|
||||||
const throughputCap = userContext.databaseAccount?.properties.capacity?.totalThroughputLimit;
|
const throughputCap = userContext.databaseAccount?.properties.capacity?.totalThroughputLimit;
|
||||||
if (throughputCap && throughputCap !== -1) {
|
if (throughputCap && throughputCap !== -1) {
|
||||||
|
@ -340,6 +343,7 @@ export function createScriptCommandButtons(selectedNodeState: SelectedNodeState)
|
||||||
const newStoredProcedureBtn: CommandButtonComponentProps = {
|
const newStoredProcedureBtn: CommandButtonComponentProps = {
|
||||||
iconSrc: AddStoredProcedureIcon,
|
iconSrc: AddStoredProcedureIcon,
|
||||||
iconAlt: label,
|
iconAlt: label,
|
||||||
|
keyboardAction: KeyboardAction.NEW_SPROC,
|
||||||
onCommandClick: () => {
|
onCommandClick: () => {
|
||||||
const selectedCollection: ViewModels.Collection = selectedNodeState.findSelectedCollection();
|
const selectedCollection: ViewModels.Collection = selectedNodeState.findSelectedCollection();
|
||||||
selectedCollection && selectedCollection.onNewStoredProcedureClick(selectedCollection);
|
selectedCollection && selectedCollection.onNewStoredProcedureClick(selectedCollection);
|
||||||
|
@ -359,6 +363,7 @@ export function createScriptCommandButtons(selectedNodeState: SelectedNodeState)
|
||||||
const newUserDefinedFunctionBtn: CommandButtonComponentProps = {
|
const newUserDefinedFunctionBtn: CommandButtonComponentProps = {
|
||||||
iconSrc: AddUdfIcon,
|
iconSrc: AddUdfIcon,
|
||||||
iconAlt: label,
|
iconAlt: label,
|
||||||
|
keyboardAction: KeyboardAction.NEW_UDF,
|
||||||
onCommandClick: () => {
|
onCommandClick: () => {
|
||||||
const selectedCollection: ViewModels.Collection = selectedNodeState.findSelectedCollection();
|
const selectedCollection: ViewModels.Collection = selectedNodeState.findSelectedCollection();
|
||||||
selectedCollection && selectedCollection.onNewUserDefinedFunctionClick(selectedCollection);
|
selectedCollection && selectedCollection.onNewUserDefinedFunctionClick(selectedCollection);
|
||||||
|
@ -378,6 +383,7 @@ export function createScriptCommandButtons(selectedNodeState: SelectedNodeState)
|
||||||
const newTriggerBtn: CommandButtonComponentProps = {
|
const newTriggerBtn: CommandButtonComponentProps = {
|
||||||
iconSrc: AddTriggerIcon,
|
iconSrc: AddTriggerIcon,
|
||||||
iconAlt: label,
|
iconAlt: label,
|
||||||
|
keyboardAction: KeyboardAction.NEW_TRIGGER,
|
||||||
onCommandClick: () => {
|
onCommandClick: () => {
|
||||||
const selectedCollection: ViewModels.Collection = selectedNodeState.findSelectedCollection();
|
const selectedCollection: ViewModels.Collection = selectedNodeState.findSelectedCollection();
|
||||||
selectedCollection && selectedCollection.onNewTriggerClick(selectedCollection);
|
selectedCollection && selectedCollection.onNewTriggerClick(selectedCollection);
|
||||||
|
|
|
@ -894,6 +894,7 @@ export default class DocumentsTab extends TabsBase {
|
||||||
buttons.push({
|
buttons.push({
|
||||||
iconSrc: NewDocumentIcon,
|
iconSrc: NewDocumentIcon,
|
||||||
iconAlt: label,
|
iconAlt: label,
|
||||||
|
keyboardAction: KeyboardAction.NEW_ITEM,
|
||||||
onCommandClick: this.onNewDocumentClick,
|
onCommandClick: this.onNewDocumentClick,
|
||||||
commandButtonLabel: label,
|
commandButtonLabel: label,
|
||||||
ariaLabel: label,
|
ariaLabel: label,
|
||||||
|
@ -923,6 +924,7 @@ export default class DocumentsTab extends TabsBase {
|
||||||
buttons.push({
|
buttons.push({
|
||||||
iconSrc: DiscardIcon,
|
iconSrc: DiscardIcon,
|
||||||
iconAlt: label,
|
iconAlt: label,
|
||||||
|
keyboardAction: KeyboardAction.CANCEL_OR_DISCARD,
|
||||||
onCommandClick: this.onRevertNewDocumentClick,
|
onCommandClick: this.onRevertNewDocumentClick,
|
||||||
commandButtonLabel: label,
|
commandButtonLabel: label,
|
||||||
ariaLabel: label,
|
ariaLabel: label,
|
||||||
|
@ -953,6 +955,7 @@ export default class DocumentsTab extends TabsBase {
|
||||||
buttons.push({
|
buttons.push({
|
||||||
iconSrc: DiscardIcon,
|
iconSrc: DiscardIcon,
|
||||||
iconAlt: label,
|
iconAlt: label,
|
||||||
|
keyboardAction: KeyboardAction.CANCEL_OR_DISCARD,
|
||||||
onCommandClick: this.onRevertExisitingDocumentClick,
|
onCommandClick: this.onRevertExisitingDocumentClick,
|
||||||
commandButtonLabel: label,
|
commandButtonLabel: label,
|
||||||
ariaLabel: label,
|
ariaLabel: label,
|
||||||
|
@ -968,6 +971,7 @@ export default class DocumentsTab extends TabsBase {
|
||||||
buttons.push({
|
buttons.push({
|
||||||
iconSrc: DeleteDocumentIcon,
|
iconSrc: DeleteDocumentIcon,
|
||||||
iconAlt: label,
|
iconAlt: label,
|
||||||
|
keyboardAction: KeyboardAction.DELETE_ITEM,
|
||||||
onCommandClick: this.onDeleteExisitingDocumentClick,
|
onCommandClick: this.onDeleteExisitingDocumentClick,
|
||||||
commandButtonLabel: label,
|
commandButtonLabel: label,
|
||||||
ariaLabel: label,
|
ariaLabel: label,
|
||||||
|
|
|
@ -440,7 +440,7 @@ export default class QueryTabComponent extends React.Component<IQueryTabComponen
|
||||||
hasPopup: false,
|
hasPopup: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const launchCopilotButton = {
|
const launchCopilotButton: CommandButtonComponentProps = {
|
||||||
iconSrc: LaunchCopilot,
|
iconSrc: LaunchCopilot,
|
||||||
iconAlt: mainButtonLabel,
|
iconAlt: mainButtonLabel,
|
||||||
onCommandClick: this.launchQueryCopilotChat,
|
onCommandClick: this.launchQueryCopilotChat,
|
||||||
|
@ -453,9 +453,10 @@ export default class QueryTabComponent extends React.Component<IQueryTabComponen
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.props.copilotEnabled) {
|
if (this.props.copilotEnabled) {
|
||||||
const toggleCopilotButton = {
|
const toggleCopilotButton: CommandButtonComponentProps = {
|
||||||
iconSrc: QueryCommandIcon,
|
iconSrc: QueryCommandIcon,
|
||||||
iconAlt: "Copilot",
|
iconAlt: "Copilot",
|
||||||
|
keyboardAction: KeyboardAction.TOGGLE_COPILOT,
|
||||||
onCommandClick: () => {
|
onCommandClick: () => {
|
||||||
this._toggleCopilot(!this.state.copilotActive);
|
this._toggleCopilot(!this.state.copilotActive);
|
||||||
},
|
},
|
||||||
|
@ -471,7 +472,7 @@ export default class QueryTabComponent extends React.Component<IQueryTabComponen
|
||||||
buttons.push({
|
buttons.push({
|
||||||
iconSrc: CancelQueryIcon,
|
iconSrc: CancelQueryIcon,
|
||||||
iconAlt: label,
|
iconAlt: label,
|
||||||
keyboardAction: KeyboardAction.CANCEL_QUERY,
|
keyboardAction: KeyboardAction.CANCEL_OR_DISCARD,
|
||||||
onCommandClick: () => this.queryAbortController.abort(),
|
onCommandClick: () => this.queryAbortController.abort(),
|
||||||
commandButtonLabel: label,
|
commandButtonLabel: label,
|
||||||
ariaLabel: label,
|
ariaLabel: label,
|
||||||
|
|
|
@ -350,6 +350,7 @@ export default class StoredProcedureTabComponent extends React.Component<
|
||||||
buttons.push({
|
buttons.push({
|
||||||
iconSrc: DiscardIcon,
|
iconSrc: DiscardIcon,
|
||||||
iconAlt: label,
|
iconAlt: label,
|
||||||
|
keyboardAction: KeyboardAction.CANCEL_OR_DISCARD,
|
||||||
onCommandClick: this.onDiscard,
|
onCommandClick: this.onDiscard,
|
||||||
commandButtonLabel: label,
|
commandButtonLabel: label,
|
||||||
ariaLabel: label,
|
ariaLabel: label,
|
||||||
|
|
|
@ -271,6 +271,7 @@ export class TriggerTabContent extends Component<TriggerTab, ITriggerTabContentS
|
||||||
...this,
|
...this,
|
||||||
iconSrc: DiscardIcon,
|
iconSrc: DiscardIcon,
|
||||||
iconAlt: label,
|
iconAlt: label,
|
||||||
|
keyboardAction: KeyboardAction.CANCEL_OR_DISCARD,
|
||||||
onCommandClick: this.onDiscard,
|
onCommandClick: this.onDiscard,
|
||||||
commandButtonLabel: label,
|
commandButtonLabel: label,
|
||||||
ariaLabel: label,
|
ariaLabel: label,
|
||||||
|
|
|
@ -112,6 +112,7 @@ export default class UserDefinedFunctionTabContent extends Component<
|
||||||
...this,
|
...this,
|
||||||
iconSrc: DiscardIcon,
|
iconSrc: DiscardIcon,
|
||||||
iconAlt: label,
|
iconAlt: label,
|
||||||
|
keyboardAction: KeyboardAction.CANCEL_OR_DISCARD,
|
||||||
onCommandClick: this.onDiscard,
|
onCommandClick: this.onDiscard,
|
||||||
commandButtonLabel: label,
|
commandButtonLabel: label,
|
||||||
ariaLabel: label,
|
ariaLabel: label,
|
||||||
|
|
|
@ -18,10 +18,18 @@ export type KeyboardHandlerMap = Partial<Record<KeyboardAction, KeyboardActionHa
|
||||||
export enum KeyboardAction {
|
export enum KeyboardAction {
|
||||||
NEW_QUERY = "NEW_QUERY",
|
NEW_QUERY = "NEW_QUERY",
|
||||||
EXECUTE_ITEM = "EXECUTE_ITEM",
|
EXECUTE_ITEM = "EXECUTE_ITEM",
|
||||||
CANCEL_QUERY = "CANCEL_QUERY",
|
CANCEL_OR_DISCARD = "CANCEL_OR_DISCARD",
|
||||||
SAVE_ITEM = "SAVE_ITEM",
|
SAVE_ITEM = "SAVE_ITEM",
|
||||||
OPEN_QUERY = "OPEN_QUERY",
|
OPEN_QUERY = "OPEN_QUERY",
|
||||||
OPEN_QUERY_FROM_DISK = "OPEN_QUERY_FROM_DISK",
|
OPEN_QUERY_FROM_DISK = "OPEN_QUERY_FROM_DISK",
|
||||||
|
NEW_SPROC = "NEW_SPROC",
|
||||||
|
NEW_UDF = "NEW_UDF",
|
||||||
|
NEW_TRIGGER = "NEW_TRIGGER",
|
||||||
|
NEW_DATABASE = "NEW_DATABASE",
|
||||||
|
NEW_COLLECTION = "NEW_CONTAINER",
|
||||||
|
NEW_ITEM = "NEW_ITEM",
|
||||||
|
DELETE_ITEM = "DELETE_ITEM",
|
||||||
|
TOGGLE_COPILOT = "TOGGLE_COPILOT",
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,12 +41,20 @@ const bindings: Record<KeyboardAction, string[]> = {
|
||||||
// NOTE: The "$mod" special value is used to represent the "Control" key on Windows/Linux and the "Command" key on macOS.
|
// NOTE: The "$mod" special value is used to represent the "Control" key on Windows/Linux and the "Command" key on macOS.
|
||||||
// See https://www.npmjs.com/package/tinykeys#commonly-used-keys-and-codes for more information on the expected values for keyboard shortcuts.
|
// See https://www.npmjs.com/package/tinykeys#commonly-used-keys-and-codes for more information on the expected values for keyboard shortcuts.
|
||||||
|
|
||||||
[KeyboardAction.NEW_QUERY]: ["$mod+J"],
|
[KeyboardAction.NEW_QUERY]: ["$mod+J", "Alt+N Q"],
|
||||||
[KeyboardAction.EXECUTE_ITEM]: ["Shift+Enter"],
|
[KeyboardAction.EXECUTE_ITEM]: ["Shift+Enter"],
|
||||||
[KeyboardAction.CANCEL_QUERY]: ["Escape"],
|
[KeyboardAction.CANCEL_OR_DISCARD]: ["Escape"],
|
||||||
[KeyboardAction.SAVE_ITEM]: ["$mod+S"],
|
[KeyboardAction.SAVE_ITEM]: ["$mod+S"],
|
||||||
[KeyboardAction.OPEN_QUERY]: ["$mod+O"],
|
[KeyboardAction.OPEN_QUERY]: ["$mod+O"],
|
||||||
[KeyboardAction.OPEN_QUERY_FROM_DISK]: ["$mod+Shift+O"],
|
[KeyboardAction.OPEN_QUERY_FROM_DISK]: ["$mod+Shift+O"],
|
||||||
|
[KeyboardAction.NEW_SPROC]: ["Alt+N P"],
|
||||||
|
[KeyboardAction.NEW_UDF]: ["Alt+N F"],
|
||||||
|
[KeyboardAction.NEW_TRIGGER]: ["Alt+N T"],
|
||||||
|
[KeyboardAction.NEW_DATABASE]: ["Alt+N D"],
|
||||||
|
[KeyboardAction.NEW_COLLECTION]: ["Alt+N C"],
|
||||||
|
[KeyboardAction.NEW_ITEM]: ["Alt+N I"],
|
||||||
|
[KeyboardAction.DELETE_ITEM]: ["Alt+D"],
|
||||||
|
[KeyboardAction.TOGGLE_COPILOT]: ["$mod+P"],
|
||||||
};
|
};
|
||||||
|
|
||||||
interface KeyboardShortcutState {
|
interface KeyboardShortcutState {
|
||||||
|
|
Loading…
Reference in New Issue