Skip to content

Commit

Permalink
Update "Connect with GUI" section, add universal context menu (gravit…
Browse files Browse the repository at this point in the history
…ational#926)

* Add universal context menu

* Update text of "Connect with GUI" section
  • Loading branch information
ravicious authored Jun 28, 2022
1 parent 17e9a71 commit 1e8275c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
36 changes: 34 additions & 2 deletions web/packages/teleterm/src/mainProcess/windowsManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrowserWindow, Rectangle, screen } from 'electron';
import { BrowserWindow, Menu, Rectangle, screen } from 'electron';
import { getAssetPath } from 'teleterm/mainProcess/runtimeSettings';
import path from 'path';
import { FileStorage } from 'teleterm/services/fileStorage';
Expand All @@ -9,11 +9,24 @@ type WindowState = Rectangle;

export class WindowsManager {
private storageKey = 'windowState';
private selectionContextMenu: Menu;
private inputContextMenu: Menu;

constructor(
private fileStorage: FileStorage,
private settings: RuntimeSettings
) {}
) {
this.selectionContextMenu = Menu.buildFromTemplate([{ role: 'copy' }]);

this.inputContextMenu = Menu.buildFromTemplate([
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
]);
}

createWindow(): void {
const windowState = this.getWindowState();
Expand Down Expand Up @@ -43,6 +56,10 @@ export class WindowsManager {
} else {
window.loadFile(path.join(__dirname, '../renderer/index.html'));
}

window.webContents.on('context-menu', (_, props) => {
this.popupUniversalContextMenu(window, props);
});
}

private saveWindowState(window: BrowserWindow): void {
Expand All @@ -53,6 +70,21 @@ export class WindowsManager {
this.fileStorage.put(this.storageKey, windowState);
}

private popupUniversalContextMenu(
window: BrowserWindow,
props: Electron.ContextMenuParams
): void {
// Taken from https://github.com/electron/electron/issues/4068#issuecomment-274159726
// selectall was removed from menus because it doesn't make sense in our context.
const { selectionText, isEditable } = props;

if (isEditable) {
this.inputContextMenu.popup({ window });
} else if (selectionText && selectionText.trim() !== '') {
this.selectionContextMenu.popup({ window });
}
}

private getWindowState(): WindowState {
const windowState = this.fileStorage.get<WindowState>(this.storageKey);
const getDefaults = () => ({
Expand Down
21 changes: 14 additions & 7 deletions web/packages/teleterm/src/ui/DocumentGateway/DocumentGateway.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function DocumentGateway(props: State) {
}

return (
<Box maxWidth="580px" mx="auto" mt="4" px="5">
<Box maxWidth="590px" mx="auto" mt="4" px="5">
<Flex justifyContent="space-between" mb="4">
<Text typography="h3" color="text.secondary">
Database Connection
Expand All @@ -109,7 +109,9 @@ export function DocumentGateway(props: State) {
Close Connection
</ButtonSecondary>
</Flex>
<Text typography="h4">Connect with CLI</Text>
<Text typography="h4" mb={1}>
Connect with CLI
</Text>
<Flex>
<Validation>
<ConfigInput
Expand All @@ -131,18 +133,24 @@ export function DocumentGateway(props: State) {
Could not change the database name: {changeDbNameAttempt.statusText}
</Alerts.Danger>
)}
<Text typography="h4" mt={3}>
<Text typography="h4" mt={3} mb={1}>
Connect with GUI
</Text>
<Text>
To connect with a GUI database client, see our{' '}
Configure the GUI database client to connect to host{' '}
<code>{gateway.localAddress}</code> on port{' '}
<code>{gateway.localPort}</code>.
</Text>
<Text>
The connection is made through an authenticated proxy so no extra
credentials are necessary. See{' '}
<Link
href="https://goteleport.com/docs/database-access/guides/gui-clients/"
target="_blank"
>
documentation
the documentation
</Link>{' '}
for instructions.
for more details.
</Text>
</Box>
);
Expand Down Expand Up @@ -179,7 +187,6 @@ function CliCommand({
justifyContent="space-between"
borderRadius={2}
bg={'primary.dark'}
mb={2}
>
<Flex
mr="2"
Expand Down

0 comments on commit 1e8275c

Please sign in to comment.