Skip to content

Commit

Permalink
Move Teleport Connect over to Vite (#36921)
Browse files Browse the repository at this point in the history
* Move Teleport connect over to Vite

* Clean up the Electron Vite config

* Add mts to prettier/eslint

* Add license headers

* Dedupe @babel scope

* Remove console.log from mainProcess

* Set suggestedReviewers on CreateAccessRequestRequest

* Remove unneeded code added from strict null checks

* Move out dir to build/app

On masted it's build/app/dist.

We don't want to use build directly, as the app is being packaged in
build/release.

* Move Node-only deps to dependencies

https://electron-vite.org/guide/dev#dependencies-vs-devdependencies

cross-env has been removed since it's not needed at all.

* Remove eval warning suppression

* Fix default path of tsh

* Rename dev-term to start-term-skip-native-deps

* Use correct `oneofKind` value for `ptyEventOneOfIsStartError`

* Undo strict null check changes

* Correctly construct env vars struct for shell

Based on https://stackoverflow.com/a/66989401

* Allow reloading renderer app

* Move JSDoc for TshdEventContextBridgeService to correct position

* Remove outdated comment about type casting in tshdEvents/index.ts

* Drop type cast for error.cause['message']

* Ignore teleterm's build dir in .eslintignore

**/dist/** has been removed from ignorePatterns because it's no longer
necessary, neither Web UI nor Connect build in a dir matching this pattern.

* Define NODE_ENV for main and renderer

* Define only NODE_ENV, not whole process.env

Otherwise process.env in the main process is always replaced with an
object containing just NODE_ENV.

We need process.env to be properly populated since it's then used when
spawning tsh daemon and other processes.

Using define like this guarantees that only callsites using
process.env.NODE_ENV directly will be affected.

* Add support for the cluster preferences backend mismatch from the gRPC UserPreferences object

* Return resourceIds from preferences, convert preferences before updating

* Future proof all of the clusterPreferences object getting converted correctly

* Fix cluster preferences for leaf clusters

* Use correct `AssistViewMode` enum, remove the old one and unused interface

* Lint fix

* Add back in JS protobuf stuff, it can be removed in a later PR

* Remove `List` from property

* Add license header

* Remove console.logs

---------

Co-authored-by: Rafał Cieślak <[email protected]>
Co-authored-by: Grzegorz Zdunek <[email protected]>
  • Loading branch information
3 people authored Jan 26, 2024
1 parent 8360fc5 commit 200553c
Show file tree
Hide file tree
Showing 108 changed files with 3,663 additions and 4,384 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

# Ignore WASM generated files:
web/packages/teleport/src/ironrdp/pkg

web/packages/teleterm/build
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"start-teleport-e": "yarn workspace @gravitational/teleport.e start",
"build-term": "yarn workspace @gravitational/teleterm build",
"start-term": "yarn workspace @gravitational/teleterm start",
"start-term-skip-native-deps": "yarn workspace @gravitational/teleterm start-skip-native-deps",
"package-term": "yarn workspace @gravitational/teleterm package",
"storybook": "start-storybook -p 9002 -c web/.storybook -s web/.storybook/public",
"storybook-smoke-test": "yarn storybook --ci --smoke-test",
Expand All @@ -18,10 +19,10 @@
"test-update-snapshot": "yarn test -- --updateSnapshot",
"tdd": "jest --watch",
"lint": "yarn prettier-check && yarn eslint",
"eslint": "eslint --quiet '+(e|web)/**/*.{ts,tsx,js,jsx}'",
"eslint": "eslint --quiet '+(e|web)/**/*.{ts,tsx,js,jsx,mts}'",
"type-check": "NODE_OPTIONS='--max-old-space-size=4096' tsc --noEmit",
"prettier-check": "yarn prettier --check '+(e|web)/**/*.{ts,tsx,js,jsx}'",
"prettier-write": "yarn prettier --write --loglevel silent '+(e|web)/**/*.{ts,tsx,js,jsx}'",
"prettier-check": "yarn prettier --check '+(e|web)/**/*.{ts,tsx,js,jsx,mts}'",
"prettier-write": "yarn prettier --write --loglevel silent '+(e|web)/**/*.{ts,tsx,js,jsx,mts}'",
"process-icons": "node web/packages/design/src/Icon/script/script.js & yarn prettier --loglevel silent --write 'web/packages/design/src/Icon/Icons/*.tsx'",
"nop": "exit 0"
},
Expand Down
39 changes: 39 additions & 0 deletions web/packages/build/vite/csp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Teleport
* Copyright (C) 2023 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import type { Plugin } from 'vite';

export function cspPlugin(csp: string): Plugin {
return {
name: 'teleport-connect-html-plugin',
transformIndexHtml(html) {
return {
html,
tags: [
{
tag: 'meta',
attrs: {
'http-equiv': 'Content-Security-Policy',
content: csp,
},
},
],
};
},
};
}
1 change: 1 addition & 0 deletions web/packages/build/webpack/webpack.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ function createDefaultConfig() {
design: path.join(__dirname, '/../../design/src'),
shared: path.join(__dirname, '/../../shared'),
'gen-proto-js': path.join(__dirname, '/../../../../gen/proto/js'),
'gen-proto-ts': path.join(__dirname, '/../../../../gen/proto/ts'),
},

/*
Expand Down
9 changes: 5 additions & 4 deletions web/packages/design/src/ThemeProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@ import {

import { KeysEnum, storageService } from 'teleport/services/storageService';

import { ThemePreference } from 'teleport/services/userPreferences/types';
import cfg from 'teleport/config';

import { Theme } from 'gen-proto-ts/teleport/userpreferences/v1/theme_pb';

import { darkTheme, lightTheme, bblpTheme } from '../theme';

import { GlobalStyle } from './globals';

function themePreferenceToTheme(themePreference: ThemePreference) {
return themePreference === ThemePreference.Light ? lightTheme : darkTheme;
function themePreferenceToTheme(themePreference: Theme) {
return themePreference === Theme.LIGHT ? lightTheme : darkTheme;
}

const ThemeProvider = props => {
const [themePreference, setThemePreference] = useState<ThemePreference>(
const [themePreference, setThemePreference] = useState<Theme>(
storageService.getThemePreference()
);

Expand Down
17 changes: 7 additions & 10 deletions web/packages/shared/components/UnifiedResources/FilterPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import {
ArrowsOut,
} from 'design/Icon';

import { ViewMode } from 'shared/services/unifiedResourcePreferences';
import { ViewMode } from 'gen-proto-ts/teleport/userpreferences/v1/unified_resource_preferences_pb';

import { HoverTooltip } from 'shared/components/ToolTip';

import { FilterKind } from './UnifiedResources';
Expand Down Expand Up @@ -132,7 +133,7 @@ export function FilterPanel({
<Flex mr={1}>{BulkActions}</Flex>
{!hideViewModeOptions && (
<>
{currentViewMode === ViewMode.VIEW_MODE_LIST && (
{currentViewMode === ViewMode.LIST && (
<ButtonBorder
size="small"
css={`
Expand Down Expand Up @@ -468,10 +469,8 @@ function ViewModeSwitch({
return (
<ViewModeSwitchContainer>
<ViewModeSwitchButton
className={
currentViewMode === ViewMode.VIEW_MODE_CARD ? 'selected' : ''
}
onClick={() => setCurrentViewMode(ViewMode.VIEW_MODE_CARD)}
className={currentViewMode === ViewMode.CARD ? 'selected' : ''}
onClick={() => setCurrentViewMode(ViewMode.CARD)}
css={`
border-right: 1px solid
${props => props.theme.colors.spotBackground[2]};
Expand All @@ -482,10 +481,8 @@ function ViewModeSwitch({
<SquaresFour size="small" color="text.main" />
</ViewModeSwitchButton>
<ViewModeSwitchButton
className={
currentViewMode === ViewMode.VIEW_MODE_LIST ? 'selected' : ''
}
onClick={() => setCurrentViewMode(ViewMode.VIEW_MODE_LIST)}
className={currentViewMode === ViewMode.LIST ? 'selected' : ''}
onClick={() => setCurrentViewMode(ViewMode.LIST)}
css={`
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import { UrlResourcesParams } from 'teleport/config';
import { ResourcesResponse } from 'teleport/services/agents';

import {
UnifiedResourcePreferences,
DefaultTab,
ViewMode,
LabelsViewMode,
} from 'shared/services/unifiedResourcePreferences';
UnifiedResourcePreferences,
ViewMode,
} from 'gen-proto-ts/teleport/userpreferences/v1/unified_resource_preferences_pb';

import { makeErrorAttempt, makeProcessingAttempt } from 'shared/hooks/useAsync';

Expand Down Expand Up @@ -97,9 +97,9 @@ const story = ({
};
return () => {
const [userPrefs, setUserPrefs] = useState<UnifiedResourcePreferences>({
defaultTab: DefaultTab.DEFAULT_TAB_ALL,
viewMode: ViewMode.VIEW_MODE_CARD,
labelsViewMode: LabelsViewMode.LABELS_VIEW_MODE_COLLAPSED,
defaultTab: DefaultTab.ALL,
viewMode: ViewMode.CARD,
labelsViewMode: LabelsViewMode.COLLAPSED,
});
const { fetch, attempt, resources } = useUnifiedResourcesFetch({
fetchFunc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ import { ResourcesResponse } from 'teleport/services/agents';

import {
DefaultTab,
ViewMode,
UnifiedResourcePreferences,
LabelsViewMode,
} from 'shared/services/unifiedResourcePreferences';
UnifiedResourcePreferences,
ViewMode,
} from 'gen-proto-ts/teleport/userpreferences/v1/unified_resource_preferences_pb';

import { HoverTooltip } from 'shared/components/ToolTip';
import {
makeEmptyAttempt,
Expand Down Expand Up @@ -90,11 +91,11 @@ export const PINNING_NOT_SUPPORTED_MESSAGE =
const tabs: { label: string; value: DefaultTab }[] = [
{
label: 'All Resources',
value: DefaultTab.DEFAULT_TAB_ALL,
value: DefaultTab.ALL,
},
{
label: 'Pinned Resources',
value: DefaultTab.DEFAULT_TAB_PINNED,
value: DefaultTab.PINNED,
},
];

Expand Down Expand Up @@ -304,7 +305,7 @@ export function UnifiedResources(props: UnifiedResourcesProps) {
};

const selectTab = (value: DefaultTab) => {
const pinnedOnly = value === DefaultTab.DEFAULT_TAB_PINNED;
const pinnedOnly = value === DefaultTab.PINNED;
setParams({
...params,
pinnedOnly,
Expand Down Expand Up @@ -366,8 +367,7 @@ export function UnifiedResources(props: UnifiedResourcesProps) {
};

const expandAllLabels =
unifiedResourcePreferences.labelsViewMode ===
LabelsViewMode.LABELS_VIEW_MODE_EXPANDED;
unifiedResourcePreferences.labelsViewMode === LabelsViewMode.EXPANDED;

useEffect(() => {
const resizeObserver = new ResizeObserver(entries => {
Expand All @@ -386,8 +386,7 @@ export function UnifiedResources(props: UnifiedResourcesProps) {
}, []);

const ViewComponent =
unifiedResourcePreferences.viewMode === ViewMode.VIEW_MODE_CARD ||
forceCardView
unifiedResourcePreferences.viewMode === ViewMode.CARD || forceCardView
? CardsView
: ListView;

Expand Down Expand Up @@ -448,9 +447,7 @@ export function UnifiedResources(props: UnifiedResourcesProps) {
ClusterDropdown={ClusterDropdown}
setExpandAllLabels={expandAllLabels => {
setLabelsViewMode(
expandAllLabels
? LabelsViewMode.LABELS_VIEW_MODE_EXPANDED
: LabelsViewMode.LABELS_VIEW_MODE_COLLAPSED
expandAllLabels ? LabelsViewMode.EXPANDED : LabelsViewMode.COLLAPSED
);
}}
hideViewModeOptions={forceCardView}
Expand Down Expand Up @@ -498,14 +495,14 @@ export function UnifiedResources(props: UnifiedResourcesProps) {
key={tab.value}
onClick={() => selectTab(tab.value)}
disabled={
tab.value === DefaultTab.DEFAULT_TAB_PINNED &&
tab.value === DefaultTab.PINNED &&
pinning.kind === 'not-supported'
}
title={tab.label}
isSelected={
params.pinnedOnly
? tab.value === DefaultTab.DEFAULT_TAB_PINNED
: tab.value === DefaultTab.DEFAULT_TAB_ALL
? tab.value === DefaultTab.PINNED
: tab.value === DefaultTab.ALL
}
/>
))}
Expand Down
56 changes: 0 additions & 56 deletions web/packages/shared/services/unifiedResourcePreferences.ts

This file was deleted.

Loading

0 comments on commit 200553c

Please sign in to comment.