Skip to content

feat: exprimental option to open sandboxes in v2 #8166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ AMPLITUDE_API_KEY=a205ed9b06a7baf5a594bdd30293aa80
SENTRY_DSN=https://[email protected]/2071895
IS_ONPREM=false
USE_STATIC_PREVIEW=false
PREVIEW_DOMAIN=csb.app
PREVIEW_DOMAIN=csb.app
ROWS_API_KEY=""
17 changes: 14 additions & 3 deletions packages/app/src/app/components/CreateSandbox/CreateSandbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import track from '@codesandbox/common/lib/utils/analytics';
import { sandboxUrl } from '@codesandbox/common/lib/utils/url-generator';

import { useCreateCheckout } from 'app/hooks';
import { useGlobalPersistedState } from 'app/hooks/usePersistedState';
import {
Container,
Tab,
Expand All @@ -39,6 +40,7 @@ import { GithubRepoToImport } from './Import/types';
import { ImportInfo } from './Import/ImportInfo';
import { FromRepo } from './Import/FromRepo';
import { ImportSandbox } from './ImportSandbox';
import { ExperimentalBetaEditor } from './ExperimentalBetaEditor';

export const COLUMN_MEDIA_THRESHOLD = 1600;

Expand Down Expand Up @@ -187,6 +189,11 @@ export const CreateSandbox: React.FC<CreateSandboxProps> = ({
});
};

const [hasBetaEditorExperiment] = useGlobalPersistedState(
'BETA_SANDBOX_EDITOR',
false
);

const createFromTemplate = (
template: TemplateFragment,
{ name }: CreateSandboxParams
Expand All @@ -196,6 +203,7 @@ export const CreateSandbox: React.FC<CreateSandboxProps> = ({
actions.editor.forkExternalSandbox({
sandboxId: sandbox.id,
openInNewWindow: false,
hasBetaEditorExperiment,
body: {
alias: name,
collectionId,
Expand All @@ -215,7 +223,7 @@ export const CreateSandbox: React.FC<CreateSandboxProps> = ({

const openTemplate = (template: TemplateFragment) => {
const { sandbox } = template;
const url = sandboxUrl(sandbox);
const url = sandboxUrl(sandbox, hasBetaEditorExperiment);
window.open(url, '_blank');
};

Expand Down Expand Up @@ -449,7 +457,7 @@ export const CreateSandbox: React.FC<CreateSandboxProps> = ({
officialTemplates={officialTemplates}
/>
) : (
<>
<Stack direction="vertical" gap={2}>
<Panel tab={tabState} id="quickstart">
<TemplateCategoryList
canCheckout={canCheckout}
Expand Down Expand Up @@ -666,7 +674,10 @@ export const CreateSandbox: React.FC<CreateSandboxProps> = ({
</Panel>
))
: null}
</>
{tabState.selectedId === 'quickstart' && (
<ExperimentalBetaEditor />
)}
</Stack>
))}

{viewState === 'fromTemplate' ? (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';
import {
Badge,
MessageStripe,
Stack,
Text,
Switch,
} from '@codesandbox/components';
import { useGlobalPersistedState } from 'app/hooks/usePersistedState';
import { useActions } from 'app/overmind';
import track from '@codesandbox/common/lib/utils/analytics';
import { UnstyledButtonLink } from './elements';

export const ExperimentalBetaEditor = () => {
const actions = useActions();
const [betaSandboxEditor, setBetaSandboxEditor] = useGlobalPersistedState(
'BETA_SANDBOX_EDITOR',
false
);

if (betaSandboxEditor) {
return (
<Stack justify="center" padding={2}>
<Text size={3}>
Open{' '}
<UnstyledButtonLink
onClick={() => {
actions.modals.newSandboxModal.close();
actions.preferences.openPreferencesModal('experiments');
}}
>
Preferences
</UnstyledButtonLink>{' '}
to disable the new sandbox editor
</Text>
</Stack>
);
}

return (
<MessageStripe variant="primary">
<Stack direction="horizontal" justify="space-between" align="center">
<Stack direction="horizontal" align="center" gap={1}>
<Badge icon="sandbox" variant="highlight">
Beta
</Badge>
<Text weight="500">Try the new sandbox editor.</Text>
<Text>For a faster and more stable prototyping experience.</Text>
</Stack>
<Switch
onChange={() => {
setBetaSandboxEditor(true);
track('Enable new sandbox editor - Create modal');
}}
/>
</Stack>
</MessageStripe>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, { useEffect } from 'react';
import { connectInfiniteHits } from 'react-instantsearch-dom';
import { InfiniteHitsProvided } from 'react-instantsearch-core';
import { AlgoliaSandboxHit } from '@codesandbox/common/lib/types/algolia';
import { isServer } from '@codesandbox/common/lib/templates/helpers/is-server';
import type { TemplateType } from '@codesandbox/common/lib/templates';
import { TemplateFragment } from 'app/graphql/types';
import { TemplateGrid } from '../elements';
import { TemplateCard } from '../TemplateCard';
Expand Down Expand Up @@ -60,6 +62,7 @@ const Results = (props: ResultsProps) => {
template: hit.template,
},
team: hit.team,
isSse: isServer(hit.template as TemplateType),
},
}));

Expand Down
14 changes: 13 additions & 1 deletion packages/app/src/app/components/CreateSandbox/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Tab as BaseTab, TabList, TabPanel } from 'reakit/Tab';
import { Select } from '@codesandbox/components';

export const Container = styled.div`
height: 500px;
height: 530px;
overflow: hidden;
border-radius: 4px;
background-color: #151515;
Expand Down Expand Up @@ -158,3 +158,15 @@ export const StyledSelect = styled(Select)`
color: #e5e5e5;
}
`;

export const UnstyledButtonLink = styled.button`
appearance: none;
padding: 0;
background: transparent;
color: inherit;
border: none;
font-size: inherit;
font-family: inherit;
text-decoration: underline;
cursor: pointer;
`;
1 change: 1 addition & 0 deletions packages/app/src/app/components/CreateSandbox/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const TEMPLATE_FRAGMENT = gql`
insertedAt
updatedAt
isV2
isSse

team {
name
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/app/components/CreateSandbox/utils/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { TemplateType } from '@codesandbox/common/lib/templates';
import { isServer } from '@codesandbox/common/lib/templates/helpers/is-server';
import { TemplateInfo } from '../types';

interface IExploreTemplate {
Expand Down Expand Up @@ -61,6 +62,7 @@ const mapAPIResponseToTemplateInfo = (
name: 'CodeSandbox',
},
isV2: sandbox.v2,
isSse: isServer(sandbox.environment),
git: sandbox.git && {
id: sandbox.git.id,
username: sandbox.git.username,
Expand Down
Loading