Skip to content

Commit

Permalink
fix: terminalUpgrade tab (#8141)
Browse files Browse the repository at this point in the history
* feat: add back terminalUpgrade tab

* Update packages/app/src/app/components/Preview/DevTools/TerminalUpgrade/index.tsx

Co-authored-by: Filipe Lima <45261568+filipelima18@users.noreply.github.com>

* feat: Updated terminal_upgrade_screenshot.png

* fix: embeds

---------

Co-authored-by: Filipe Lima <45261568+filipelima18@users.noreply.github.com>
  • Loading branch information
alexnm and filipelima18 authored Oct 23, 2023
1 parent 6494ed0 commit 0f5c8c8
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface Props {
views: IViews;
disableLogging: boolean;
isOnEmbedPage: boolean;
isOnPrem: boolean;
}

export const DevToolTabs = ({
Expand All @@ -38,6 +39,7 @@ export const DevToolTabs = ({
disableLogging,
status,
isOnEmbedPage,
isOnPrem,
}: Props) => {
const currentPane = views[panes[currentPaneIndex].id];
const actions =
Expand All @@ -54,6 +56,7 @@ export const DevToolTabs = ({
<Tabs>
{panes
.filter(pane => (isOnEmbedPage ? !pane.hideOnEmbedPage : true))
.filter(pane => (isOnPrem ? !pane.hideOnEmbedPage : true))
.map((pane, i) => {
const active = !hidden && i === currentPaneIndex;
const view = views[pane.id];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import styled from 'styled-components';

export const StyledTitle = styled.div`
display: flex;
align-items: center;
font-weight: 600;
font-size: 1rem;
color: ${props =>
props.theme.light ? 'rgba(0, 0, 0, 0.4)' : 'rgba(255, 255, 255, 0.4)'};
width: 100%;
padding: 1rem;
border-bottom: 2px solid;
border-color: ${props =>
props.theme.light ? 'rgba(0, 0, 0, 0.3)' : 'rgba(255, 255, 255, 0.3)'};
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { Button, ThemeProvider, Text, Stack } from '@codesandbox/components';
import React from 'react';
import themeType from '@codesandbox/common/lib/theme';

import { withTheme } from 'styled-components';
import { useUpgradeFromV1ToV2 } from 'app/hooks/useUpgradeFromV1ToV2';
import { DevToolProps } from '..';
import { StyledTitle } from './elements';

type StyledProps = DevToolProps & {
theme: typeof themeType & { light: boolean };
};

export const TerminalUpgradeComponent: React.FC<StyledProps> = ({
hidden,
theme,
}) => {
const { perform, loading, canConvert } = useUpgradeFromV1ToV2('Terminal Tab');

if (hidden) {
return null;
}

return (
<ThemeProvider theme={theme.vscodeTheme}>
<Stack
direction="vertical"
css={{
width: '100%',
}}
>
<StyledTitle>Terminal</StyledTitle>
<Stack
direction="vertical"
css={{
padding: '1rem',
}}
gap={4}
>
<Text>
To use the terminal, you need to upgrade your Browser Sandbox into a
Cloud Sandbox.
</Text>
<Text>
Cloud Sandboxes are an improved coding experience that runs your code
in the cloud. They bring new languages, servers, databases,
a built-in AI assistant, and much more. See a preview below.
</Text>
<img alt="" src="/static/img/terminal_upgrade_screenshot.png" />
<Text>
{canConvert
? `Do you want to convert it into a Cloud Sandbox?`
: `Do you want to fork into a Cloud Sandbox?`}
</Text>
<Stack
direction="horizontal"
gap={4}
css={{
justifyContent: 'start',
}}
>
<Button
onClick={perform}
loading={loading}
css={{
width: 'inherit',
paddingLeft: '1rem',
paddingRight: '1rem',
}}
>
Yes, {canConvert ? 'convert' : 'fork and convert'}
</Button>
<Button
as="a"
variant="link"
style={{
width: 'inherit',
display: 'flex',
alignItems: 'center',
backgroundColor: 'transparent',
color: 'mutedForeground',
}}
target="_blank"
rel="noreferrer noopener"
href="https://codesandbox.io/docs/learn/sandboxes/overview?tab=cloud"
>
Learn more
</Button>
</Stack>
</Stack>
</Stack>
</ThemeProvider>
);
};

export const terminalUpgrade = {
id: 'codesandbox.terminalUpgrade',
title: 'Terminal',
Content: withTheme(TerminalUpgradeComponent),
actions: [],
};
7 changes: 3 additions & 4 deletions packages/app/src/app/components/Preview/DevTools/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,7 @@ export class DevTools extends React.PureComponent<Props, State> {
} = this.props;
const { hidden, height } = this.state;

// Filter out legacy panel that might be persisted
const panes = viewConfig.views.filter(
v => v.id !== 'codesandbox.terminalUpgrade'
);
const panes = viewConfig.views;

return (
<Container
Expand Down Expand Up @@ -544,6 +541,8 @@ export class DevTools extends React.PureComponent<Props, State> {
closeTab={this.props.closeTab}
disableLogging={disableLogging}
isOnEmbedPage={this.props.isOnEmbedPage}
// @ts-ignore
isOnPrem={window._env_.IS_ONPREM === 'true'}
/>

{!primary && (
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/app/pages/Sandbox/Editor/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import getTemplateDefinition from '@codesandbox/common/lib/templates';
import { BACKTICK } from '@codesandbox/common/lib/utils/keycodes';
import { VSCode as CodeEditor } from 'app/components/CodeEditor/VSCode';
import { DevTools } from 'app/components/Preview/DevTools';
import { terminalUpgrade } from 'app/components/Preview/DevTools/TerminalUpgrade';
import { useActions, useReaction, useEffects, useAppState } from 'app/overmind';
import useKey from 'react-use/lib/useKey';
import React, { useCallback, useEffect, useRef, useState } from 'react';
Expand Down Expand Up @@ -219,6 +220,7 @@ export const MainWorkspace: React.FC<{ theme: any }> = ({ theme }) => {
devToolsOpen={devToolsOpen}
addedViews={{
'codesandbox.browser': browserConfig,
'codesandbox.terminalUpgrade': terminalUpgrade,
}}
setDragging={dragging => {
if (dragging) {
Expand Down
Binary file modified packages/app/static/img/terminal_upgrade_screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion packages/common/src/templates/helpers/react-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ export class ReactTemplate extends Template {
getViews(): ViewConfig[] {
const REACT_VIEWS: ViewConfig[] = [
{
views: [{ id: 'codesandbox.browser' }, { id: 'codesandbox.tests' }],
views: [
{ id: 'codesandbox.browser' },
{ id: 'codesandbox.tests' },
{
id: 'codesandbox.terminalUpgrade',
hideOnEmbedPage: true,
hideOnPrem: true,
},
],
},
{
views: [
Expand Down
11 changes: 10 additions & 1 deletion packages/common/src/templates/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface ViewTab {
closeable?: boolean;
options?: any;
hideOnEmbedPage?: boolean;
hideOnPrem?: boolean;
}

export type ViewConfig = {
Expand All @@ -59,7 +60,15 @@ export type ViewConfig = {

const CLIENT_VIEWS: ViewConfig[] = [
{
views: [{ id: 'codesandbox.browser' }, { id: 'codesandbox.tests' }],
views: [
{ id: 'codesandbox.browser' },
{ id: 'codesandbox.tests' },
{
id: 'codesandbox.terminalUpgrade',
hideOnEmbedPage: true,
hideOnPrem: true,
},
],
},
{
views: [{ id: 'codesandbox.console' }, { id: 'codesandbox.problems' }],
Expand Down

0 comments on commit 0f5c8c8

Please sign in to comment.