Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

[v9] Backport Teleport Connect (1 of 5) #762

Merged
merged 31 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
edda9ac
Add more tests to Teleterm (#601)
gzdunek Feb 25, 2022
4ba5aba
Update command for generating gRPC files for Teleterm
ravicious Feb 25, 2022
234c14b
Add cluster context switching (#624)
gzdunek Mar 4, 2022
14ad17a
Add connections switcher (#647)
gzdunek Mar 7, 2022
663a6cd
Add keyboard support to `Connections` popover (#651)
gzdunek Mar 8, 2022
4efd330
Add clusters picker (#668)
gzdunek Mar 14, 2022
29a5623
Improve identity picker (#670)
gzdunek Mar 16, 2022
1e39c86
Reformat commandLauncher.ts
ravicious Mar 7, 2022
6f230c3
Remove command palette commands from command launcher
ravicious Mar 7, 2022
a3218b2
Show autocomplete suggestions in command bar
ravicious Mar 7, 2022
1d50006
Remove code related to empty command bar item
ravicious Mar 7, 2022
58ad4e5
Remove old pickers, rename Item to Suggestion
ravicious Mar 9, 2022
e6234b9
Autocomplete commands and ssh logins
ravicious Mar 10, 2022
dc6c984
Ignore case for autocomplete
ravicious Mar 11, 2022
4c1c923
Automatically append @ after ssh login suggestion
ravicious Mar 11, 2022
42a77aa
QuickInputService.getAutocomplete: Return no-match on empty suggestions
ravicious Mar 11, 2022
ac48ac2
Autocomplete ssh hostnames
ravicious Mar 11, 2022
cca8a61
Open command bar commands in new local shell
ravicious Mar 16, 2022
9d2d26c
Append space after picking command suggestion
ravicious Mar 16, 2022
0e238dc
Adjust how showing & hiding autocomplete works in command bar
ravicious Mar 16, 2022
a0eafbb
Fix opening new terminal when there's no active document
ravicious Mar 16, 2022
c2a0bc4
useQuickInput: Rename serviceQuickInput to quickInputService
ravicious Mar 16, 2022
0e9617e
Include command to run in AutocompleteResult
ravicious Mar 17, 2022
f396974
Create DocumentTshNode after executing "tsh ssh" in command bar
ravicious Mar 17, 2022
e98c1dd
Update teleterm styles (#674)
gzdunek Mar 17, 2022
f1d5e12
Remove leftover cruft from quick pickers
ravicious Mar 17, 2022
4ff45ca
Launch unsupported invocations of tsh ssh in local shell
ravicious Mar 17, 2022
82579c4
add simple empty state to pickers
gzdunek Mar 17, 2022
77bba2c
adjust `QuickInput` to match designs
gzdunek Mar 17, 2022
b1af10f
always show active item in `QuickInputList`
gzdunek Mar 17, 2022
4fd8cf6
make middle part of `TopBar` central
gzdunek Mar 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@storybook/react": "^6.4.0",
"@testing-library/jest-dom": "^5.15.1",
"@testing-library/react": "^12.1.2",
"@types/jest": "^27.0.3",
"@types/jest": "^27.3.1",
"@types/lodash": "4.14.149",
"@types/node": "^16.11.10",
"@types/react": "^16.8.19",
Expand Down
16 changes: 15 additions & 1 deletion packages/design/src/Label/Label.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ const kind = ({ kind, theme }) => {
};
}

if (kind === 'success') {
return {
backgroundColor: theme.colors.success,
color: theme.colors.primary.contrastText,
};
}

// default is primary
return {
backgroundColor: theme.colors.secondary.main,
Expand All @@ -65,7 +72,14 @@ const Label = styled.div`
`;

Label.propTypes = {
kind: PropTypes.oneOf(['primary', 'secondary', 'warning', 'danger']),
kind: PropTypes.oneOf([
'primary',
'secondary',
'warning',
'danger',
'success',
]),
invert: PropTypes.oneOf([true, false]),
};

export default Label;
Expand Down
2 changes: 1 addition & 1 deletion packages/teleterm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ For quick restarts, that restarts all processes and `tsh` daemon, press `F6`.

```sh
$ cd teleport
$ make grpc
$ make grpc-teleterm
```

Resulting files both `nodejs` and `golang` can be found in `/teleport/lib/teleterm/api/protogen/` directory.
Expand Down
2 changes: 1 addition & 1 deletion packages/teleterm/src/mainProcess/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConfigService } from '../services/config';
import { Kind } from 'teleterm/ui/services/docs/types';
import { Kind } from 'teleterm/ui/services/workspacesService';

export type RuntimeSettings = {
dev: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export type KeyboardShortcutType =
| 'tab-new'
| 'tab-previous'
| 'tab-next'
| 'focus-global-search';
| 'focus-global-search'
| 'toggle-connections'
| 'toggle-clusters'
| 'toggle-identity';

export type KeyboardShortcutsConfig = Record<KeyboardShortcutType, string>;

Expand All @@ -42,6 +45,9 @@ export const keyboardShortcutsConfigProvider: ConfigServiceProvider<KeyboardShor
'tab-previous': 'Control-Shift-Tab',
'tab-next': 'Control-Tab',
'focus-global-search': 'F1',
'toggle-connections': 'Command-O',
'toggle-clusters': 'Command-E',
'toggle-identity': 'Command-I',
};

const linuxShortcuts: KeyboardShortcutsConfig = {
Expand All @@ -59,6 +65,9 @@ export const keyboardShortcutsConfigProvider: ConfigServiceProvider<KeyboardShor
'tab-previous': 'Ctrl-PageUp',
'tab-next': 'Ctrl-PageDown',
'focus-global-search': 'F1',
'toggle-connections': 'Ctrl-O',
'toggle-clusters': 'Ctrl-E',
'toggle-identity': 'Ctrl-I',
};

switch (platform) {
Expand Down
4 changes: 4 additions & 0 deletions packages/teleterm/src/services/pty/ptyProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class PtyProcess extends EventEmitter {

this._process.onData(data => this._handleData(data));
this._process.onExit(ev => this._handleExit(ev));

if (this.options.initCommand) {
this._process.write(this.options.initCommand + '\r');
}
}

send(data: string) {
Expand Down
11 changes: 6 additions & 5 deletions packages/teleterm/src/services/pty/ptyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function buildOptions(settings: RuntimeSettings, cmd: PtyCommand): PtyOptions {
args: [],
cwd: cmd.cwd,
env,
initCommand: cmd.initCommand,
};

case 'pty.tsh-kube-login':
Expand All @@ -93,13 +94,13 @@ function buildOptions(settings: RuntimeSettings, cmd: PtyCommand): PtyOptions {
env['TELEPORT_CLUSTER'] = cmd.leafClusterId;
}

const loginHost = cmd.login
? `${cmd.login}@${cmd.serverId}`
: cmd.serverId;

return {
path: settings.tshd.binaryPath,
args: [
`--proxy=${cmd.rootClusterId}`,
'ssh',
`${cmd.login}@${cmd.serverId}`,
],
args: [`--proxy=${cmd.rootClusterId}`, 'ssh', loginHost],
env,
};
default:
Expand Down
4 changes: 3 additions & 1 deletion packages/teleterm/src/services/pty/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type PtyOptions = {
path: string;
args: string[] | string;
cwd?: string;
initCommand?: string;
};

export type PtyProcess = {
Expand All @@ -24,11 +25,12 @@ export type PtyServiceClient = {
export type ShellCommand = {
kind: 'pty.shell';
cwd?: string;
initCommand?: string;
};

export type TshLoginCommand = {
kind: 'pty.tsh-login';
login: string;
login?: string;
serverId: string;
rootClusterId: string;
leafClusterId?: string;
Expand Down
7 changes: 5 additions & 2 deletions packages/teleterm/src/ui/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import AppContextProvider from './appContextProvider';
import AppContext from './appContext';
import ThemeProvider from './ThemeProvider';
import { LayoutManager } from './LayoutManager';
import { AppInitializer } from 'teleterm/ui/AppInitializer';

const App: React.FC<{ ctx: AppContext }> = ({ ctx }) => {
const { appearance } = ctx.mainProcessClient.configService.get();
Expand All @@ -17,8 +18,10 @@ const App: React.FC<{ ctx: AppContext }> = ({ ctx }) => {
<DndProvider backend={HTML5Backend}>
<AppContextProvider value={ctx}>
<ThemeProvider appearanceConfig={appearance}>
<LayoutManager />
<ModalsHost />
<AppInitializer>
<LayoutManager />
<ModalsHost />
</AppInitializer>
</ThemeProvider>
</AppContextProvider>
</DndProvider>
Expand Down
18 changes: 18 additions & 0 deletions packages/teleterm/src/ui/AppInitializer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React, { ReactNode, useEffect } from 'react';
import { useAppContext } from 'teleterm/ui/appContextProvider';

interface AppInitializerProps {
children?: ReactNode;
}

export function AppInitializer(props: AppInitializerProps) {
const ctx = useAppContext();
useEffect(() => {
const { rootClusterUri } = ctx.statePersistenceService.getWorkspaces();
if (rootClusterUri) {
ctx.workspacesService.setActiveWorkspace(rootClusterUri);
}
}, []);

return <>{props.children}</>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const StyledNavButton = styled.button(props => {
padding: '0',
marginRight: '24px',
textDecoration: 'none',
fontWeight: '500',
fontWeight: props.active ? 700 : 400,
outline: 'inherit',
border: 'none',
backgroundColor: 'inherit',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
import Table, { Cell } from 'design/DataTable';
import * as types from 'teleterm/ui/services/clusters/types';
import { useApps, State } from './useApps';
import { renderLabelCell } from '../renderLabelCell';

export default function Container() {
const state = useApps();
Expand Down Expand Up @@ -66,9 +67,9 @@ export function AppList(props: State) {
isSortable: true,
},
{
key: 'tags',
key: 'labelsList',
headerText: 'Labels',
render: renderLabels,
render: renderLabelCell,
},
{
altKey: 'launch-btn',
Expand Down Expand Up @@ -108,17 +109,6 @@ const renderAppIcon = (app: types.Application) => {
);
};

const renderLabels = ({ labelsList }: types.Kube) => {
const labels = labelsList.map(l => `${l.name}:${l.value}`);
const $labels = labels.map(label => (
<Label mb="1" mr="1" key={label} kind="secondary">
{label}
</Label>
));

return <Cell>{$labels}</Cell>;
};

const renderAddress = (app: types.Application) => {
return <Cell>https://{app.publicAddr}</Cell>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import Servers from './Servers';
import Databases from './Databases';
import Applications from './Applications';
import Kubes from './Kubes';
import ClusterSearch from './ClusterSearch';

export default function ClusterResources() {
const clusterCtx = useClusterContext();
Expand All @@ -40,7 +39,6 @@ export default function ClusterResources() {

return (
<StyledMain>
<ClusterSearch onChange={clusterCtx.changeSearchValue} />
<Flex mt={3} flexDirection="column">
<SideNav mb={2} />
<HorizontalSplit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ const Input = styled.input(props => {
color: theme.colors.text.primary,
width: '100%',
minHeight: '30px',
border: '1px solid',
borderColor: theme.colors.primary.lighter,
minWidth: '300px',
border: 'none',
outline: 'none',
borderRadius: '4px',
padding: '2px 12px',
'&:hover, &:focus': {
color: theme.colors.primary.contrastText,
background: theme.colors.primary.lighter,
borderColor: theme.colors.secondary.dark,
opacity: 1,
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ limitations under the License.

import React from 'react';
import { useDatabases, State } from './useDatabases';
import * as types from 'teleterm/ui/services/clusters/types';
import { Label, ButtonBorder } from 'design';
import { ButtonBorder } from 'design';
import Table, { Cell } from 'design/DataTable';
import { renderLabelCell } from '../renderLabelCell';

export default function Container() {
const state = useDatabases();
Expand All @@ -38,7 +38,7 @@ function DatabaseList(props: State) {
{
key: 'labelsList',
headerText: 'Labels',
render: renderLabels,
render: renderLabelCell,
},
{
altKey: 'connect-btn',
Expand All @@ -51,17 +51,6 @@ function DatabaseList(props: State) {
);
}

const renderLabels = ({ labelsList }: types.Kube) => {
const labels = labelsList.map(l => `${l.name}:${l.value}`);
const $labels = labels.map(label => (
<Label mb="1" mr="1" key={label} kind="secondary">
{label}
</Label>
));

return <Cell>{$labels}</Cell>;
};

function renderConnectButton(uri: string, connect: (uri: string) => void) {
return (
<Cell align="right">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.
import React from 'react';
import { useKubes, State } from './useKubes';
import Table, { Cell } from 'design/DataTable';
import { Label, ButtonBorder } from 'design';
import * as types from 'teleterm/ui/services/clusters/types';
import { ButtonBorder } from 'design';
import { renderLabelCell } from '../renderLabelCell';

export default function Container() {
const state = useKubes();
Expand Down Expand Up @@ -70,14 +70,3 @@ export const renderConnectButtonCell = (
</Cell>
);
};

const renderLabelCell = ({ labelsList }: types.Kube) => {
const labels = labelsList.map(l => `${l.name}:${l.value}`);
const $labels = labels.map(label => (
<Label mb="1" mr="1" key={label} kind="secondary">
{label}
</Label>
));

return <Cell>{$labels}</Cell>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useServers, State } from './useServers';
import * as types from 'teleterm/ui/services/clusters/types';
import Table, { Cell } from 'design/DataTable';
import { ButtonBorder, Label } from 'design';
import { renderLabelCell } from '../renderLabelCell';

export default function Container() {
const state = useServers();
Expand Down Expand Up @@ -58,17 +59,6 @@ function ServerList(props: State) {
);
}

const renderLabelCell = ({ labelsList }: types.Server) => {
const labels = labelsList.map(l => `${l.name}:${l.value}`);
const $labels = labels.map(label => (
<Label mb="1" mr="1" key={label} kind="secondary">
{label}
</Label>
));

return <Cell>{$labels}</Cell>;
};

const renderConnectCell = (
serverUri: string,
connect: (serverUri: string) => void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function SideNav(props: Props) {
const $items = items.map((item, index) => {
return (
<ClusterNavButton
py={1}
p={1}
my={1}
title={item.title}
to={item.to}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { makeLabelTag } from 'teleport/components/formatters';
import { Cell } from 'design/DataTable';
import { Label as SingleLabel } from 'design';
import { Label } from 'teleport/types';

export function renderLabelCell<T extends { labelsList: Label[] }>(props: T) {
const labels = props.labelsList.map(makeLabelTag);
const $labels = labels.map(label => (
<SingleLabel mb="1" mr="1" key={label} kind="secondary">
{label}
</SingleLabel>
));

return <Cell>{$labels}</Cell>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export const Notfound = () => {

function renderState(state: ClustersServiceState) {
const appContext = new MockAppContext();
appContext.docsService.update = () => null;
appContext.workspacesService.getActiveWorkspaceDocumentService().update =
() => null;
appContext.clustersService.state = state;

const doc = {
Expand Down
Loading