Skip to content

Commit

Permalink
Remove deprecated theme setting
Browse files Browse the repository at this point in the history
  • Loading branch information
avatus committed May 16, 2024
1 parent 2553260 commit dcbb211
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 125 deletions.
1 change: 0 additions & 1 deletion web/packages/design/src/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ import lightTheme from './themes/lightTheme';
import bblpTheme from './themes/bblpTheme';

export { darkTheme, lightTheme, bblpTheme };
export type { DeprecatedThemeOption } from './types';
19 changes: 0 additions & 19 deletions web/packages/design/src/theme/types.ts

This file was deleted.

46 changes: 1 addition & 45 deletions web/packages/teleport/src/User/UserContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { setupServer } from 'msw/node';
import { rest } from 'msw';
import { MemoryRouter } from 'react-router';

import { render, screen, waitFor } from '@testing-library/react';
import { render, screen } from '@testing-library/react';

import '@testing-library/jest-dom';

Expand Down Expand Up @@ -73,34 +73,6 @@ describe('user context - success state', () => {

expect(theme).toBeInTheDocument();
});

it('should migrate the previous theme setting from local storage', async () => {
let updateBody: { theme?: Theme } = {};

server.use(
rest.put(cfg.api.userPreferencesPath, async (req, res, ctx) => {
updateBody = await req.json();

return res(ctx.status(200), ctx.json({}));
})
);

localStorage.setItem(KeysEnum.THEME, 'dark');

render(
<MemoryRouter>
<UserContextProvider>
<ThemeName />
</UserContextProvider>
</MemoryRouter>
);

await waitFor(() => expect(updateBody.theme).toEqual(Theme.DARK));

const theme = await screen.findByText(/theme: dark/i);

expect(theme).toBeInTheDocument();
});
});

describe('user context - error state', () => {
Expand Down Expand Up @@ -129,22 +101,6 @@ describe('user context - error state', () => {
expect(theme).toBeInTheDocument();
});

it('should render with the theme from the previous local storage setting', async () => {
localStorage.setItem(KeysEnum.THEME, 'dark');

render(
<MemoryRouter>
<UserContextProvider>
<ThemeName />
</UserContextProvider>
</MemoryRouter>
);

const theme = await screen.findByText(/theme: dark/i);

expect(theme).toBeInTheDocument();
});

it('should render with the settings from local storage', async () => {
localStorage.setItem(
KeysEnum.USER_PREFERENCES,
Expand Down
28 changes: 0 additions & 28 deletions web/packages/teleport/src/User/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,13 @@ import { UserPreferences } from 'gen-proto-ts/teleport/userpreferences/v1/userpr

import { ClusterUserPreferences } from 'gen-proto-ts/teleport/userpreferences/v1/cluster_preferences_pb';

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

import { StyledIndicator } from 'teleport/Main';

import * as service from 'teleport/services/userPreferences';
import cfg from 'teleport/config';

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

import { deprecatedThemeToThemePreference } from 'teleport/services/userPreferences/types';

import { makeDefaultUserPreferences } from 'teleport/services/userPreferences/userPreferences';

export interface UserContextValue {
Expand Down Expand Up @@ -108,28 +104,11 @@ export function UserContextProvider(props: PropsWithChildren<unknown>) {

async function loadUserPreferences() {
const storedPreferences = storageService.getUserPreferences();
const theme = storageService.getDeprecatedThemePreference();

try {
const preferences = await service.getUserPreferences();
clusterPreferences.current[cfg.proxyCluster] =
preferences.clusterPreferences;
if (!storedPreferences) {
// there are no mirrored user preferences in local storage so this is the first time
// the user has requested their preferences in this browser session

// if there is a legacy theme preference, update the preferences with it and remove it
if (theme) {
preferences.theme = deprecatedThemeToThemePreference(theme);

if (preferences.theme !== Theme.LIGHT) {
// the light theme is the default, so only update the backend if it is not light
updatePreferences(preferences);
}

storageService.clearDeprecatedThemePreference();
}
}

setPreferences(preferences);
storageService.setUserPreferences(preferences);
Expand All @@ -139,13 +118,6 @@ export function UserContextProvider(props: PropsWithChildren<unknown>) {

return;
}

if (theme) {
setPreferences({
...preferences,
theme: deprecatedThemeToThemePreference(theme),
});
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { DeprecatedThemeOption } from 'design/theme/types';

import { UserPreferences } from 'gen-proto-ts/teleport/userpreferences/v1/userpreferences_pb';

import { Theme } from 'gen-proto-ts/teleport/userpreferences/v1/theme_pb';
Expand Down Expand Up @@ -177,11 +175,6 @@ export const storageService = {
return userPreferences.theme;
}

const theme = this.getDeprecatedThemePreference();
if (theme) {
return theme === 'light' ? Theme.LIGHT : Theme.DARK;
}

const prefersDark =
window.matchMedia &&
window.matchMedia('(prefers-color-scheme: dark)').matches;
Expand All @@ -205,16 +198,6 @@ export const storageService = {
};
},

// DELETE IN 15 (ryan)
getDeprecatedThemePreference(): DeprecatedThemeOption {
return window.localStorage.getItem(KeysEnum.THEME) as DeprecatedThemeOption;
},

// TODO(ryan): remove in v15
clearDeprecatedThemePreference() {
window.localStorage.removeItem(KeysEnum.THEME);
},

arePinnedResourcesDisabled(): boolean {
return (
window.localStorage.getItem(KeysEnum.PINNED_RESOURCES_NOT_SUPPORTED) ===
Expand Down
15 changes: 0 additions & 15 deletions web/packages/teleport/src/services/userPreferences/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { DeprecatedThemeOption } from 'design/theme';

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

export type MarketingParams = {
campaign: string;
source: string;
medium: string;
intent: string;
};

export function deprecatedThemeToThemePreference(
theme: DeprecatedThemeOption
): Theme {
switch (theme) {
case 'light':
return Theme.LIGHT;
case 'dark':
return Theme.DARK;
}
}

0 comments on commit dcbb211

Please sign in to comment.