Skip to content

Commit 389ddfa

Browse files
alexnmdanilowoz
andauthored
feat: exprimental option to open sandboxes in v2 (#8166)
* feat: add experimental beta sandbox flag * feat: storage with subscription * fix: update all sandbox urls * feat: add data request to rows * feat: Update CreateSandbox and BetaEditor components Update CreateSandbox and BetaEditor components with new features and improvements. * keep the v1 link for sse * ROWS_KEY in env * style: Ignore TypeScript error * rows integration only in prod * feat: Added isSse property to queries and router Added isSse property to queries.ts and router.ts files * fix: ensure sse flag for all templates * fix: v2 links open without history.push * fix: undo changes in areas where v2 links are not done * feat: Rename experiments to Preferences Rename the 'experiments' component to 'Preferences' --------- Co-authored-by: Danilo Woznica <[email protected]>
1 parent 6b0d1a6 commit 389ddfa

File tree

31 files changed

+486
-73
lines changed

31 files changed

+486
-73
lines changed

.env

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ AMPLITUDE_API_KEY=a205ed9b06a7baf5a594bdd30293aa80
22
SENTRY_DSN=https://[email protected]/2071895
33
IS_ONPREM=false
44
USE_STATIC_PREVIEW=false
5-
PREVIEW_DOMAIN=csb.app
5+
PREVIEW_DOMAIN=csb.app
6+
ROWS_API_KEY=""

packages/app/src/app/components/CreateSandbox/CreateSandbox.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import track from '@codesandbox/common/lib/utils/analytics';
1616
import { sandboxUrl } from '@codesandbox/common/lib/utils/url-generator';
1717

1818
import { useCreateCheckout } from 'app/hooks';
19+
import { useGlobalPersistedState } from 'app/hooks/usePersistedState';
1920
import {
2021
Container,
2122
Tab,
@@ -39,6 +40,7 @@ import { GithubRepoToImport } from './Import/types';
3940
import { ImportInfo } from './Import/ImportInfo';
4041
import { FromRepo } from './Import/FromRepo';
4142
import { ImportSandbox } from './ImportSandbox';
43+
import { ExperimentalBetaEditor } from './ExperimentalBetaEditor';
4244

4345
export const COLUMN_MEDIA_THRESHOLD = 1600;
4446

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

192+
const [hasBetaEditorExperiment] = useGlobalPersistedState(
193+
'BETA_SANDBOX_EDITOR',
194+
false
195+
);
196+
190197
const createFromTemplate = (
191198
template: TemplateFragment,
192199
{ name }: CreateSandboxParams
@@ -196,6 +203,7 @@ export const CreateSandbox: React.FC<CreateSandboxProps> = ({
196203
actions.editor.forkExternalSandbox({
197204
sandboxId: sandbox.id,
198205
openInNewWindow: false,
206+
hasBetaEditorExperiment,
199207
body: {
200208
alias: name,
201209
collectionId,
@@ -215,7 +223,7 @@ export const CreateSandbox: React.FC<CreateSandboxProps> = ({
215223

216224
const openTemplate = (template: TemplateFragment) => {
217225
const { sandbox } = template;
218-
const url = sandboxUrl(sandbox);
226+
const url = sandboxUrl(sandbox, hasBetaEditorExperiment);
219227
window.open(url, '_blank');
220228
};
221229

@@ -449,7 +457,7 @@ export const CreateSandbox: React.FC<CreateSandboxProps> = ({
449457
officialTemplates={officialTemplates}
450458
/>
451459
) : (
452-
<>
460+
<Stack direction="vertical" gap={2}>
453461
<Panel tab={tabState} id="quickstart">
454462
<TemplateCategoryList
455463
canCheckout={canCheckout}
@@ -666,7 +674,10 @@ export const CreateSandbox: React.FC<CreateSandboxProps> = ({
666674
</Panel>
667675
))
668676
: null}
669-
</>
677+
{tabState.selectedId === 'quickstart' && (
678+
<ExperimentalBetaEditor />
679+
)}
680+
</Stack>
670681
))}
671682

672683
{viewState === 'fromTemplate' ? (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import React from 'react';
2+
import {
3+
Badge,
4+
MessageStripe,
5+
Stack,
6+
Text,
7+
Switch,
8+
} from '@codesandbox/components';
9+
import { useGlobalPersistedState } from 'app/hooks/usePersistedState';
10+
import { useActions } from 'app/overmind';
11+
import track from '@codesandbox/common/lib/utils/analytics';
12+
import { UnstyledButtonLink } from './elements';
13+
14+
export const ExperimentalBetaEditor = () => {
15+
const actions = useActions();
16+
const [betaSandboxEditor, setBetaSandboxEditor] = useGlobalPersistedState(
17+
'BETA_SANDBOX_EDITOR',
18+
false
19+
);
20+
21+
if (betaSandboxEditor) {
22+
return (
23+
<Stack justify="center" padding={2}>
24+
<Text size={3}>
25+
Open{' '}
26+
<UnstyledButtonLink
27+
onClick={() => {
28+
actions.modals.newSandboxModal.close();
29+
actions.preferences.openPreferencesModal('experiments');
30+
}}
31+
>
32+
Preferences
33+
</UnstyledButtonLink>{' '}
34+
to disable the new sandbox editor
35+
</Text>
36+
</Stack>
37+
);
38+
}
39+
40+
return (
41+
<MessageStripe variant="primary">
42+
<Stack direction="horizontal" justify="space-between" align="center">
43+
<Stack direction="horizontal" align="center" gap={1}>
44+
<Badge icon="sandbox" variant="highlight">
45+
Beta
46+
</Badge>
47+
<Text weight="500">Try the new sandbox editor.</Text>
48+
<Text>For a faster and more stable prototyping experience.</Text>
49+
</Stack>
50+
<Switch
51+
onChange={() => {
52+
setBetaSandboxEditor(true);
53+
track('Enable new sandbox editor - Create modal');
54+
}}
55+
/>
56+
</Stack>
57+
</MessageStripe>
58+
);
59+
};

packages/app/src/app/components/CreateSandbox/SearchResults/SearchResultList.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, { useEffect } from 'react';
22
import { connectInfiniteHits } from 'react-instantsearch-dom';
33
import { InfiniteHitsProvided } from 'react-instantsearch-core';
44
import { AlgoliaSandboxHit } from '@codesandbox/common/lib/types/algolia';
5+
import { isServer } from '@codesandbox/common/lib/templates/helpers/is-server';
6+
import type { TemplateType } from '@codesandbox/common/lib/templates';
57
import { TemplateFragment } from 'app/graphql/types';
68
import { TemplateGrid } from '../elements';
79
import { TemplateCard } from '../TemplateCard';
@@ -60,6 +62,7 @@ const Results = (props: ResultsProps) => {
6062
template: hit.template,
6163
},
6264
team: hit.team,
65+
isSse: isServer(hit.template as TemplateType),
6366
},
6467
}));
6568

packages/app/src/app/components/CreateSandbox/elements.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Tab as BaseTab, TabList, TabPanel } from 'reakit/Tab';
33
import { Select } from '@codesandbox/components';
44

55
export const Container = styled.div`
6-
height: 500px;
6+
height: 530px;
77
overflow: hidden;
88
border-radius: 4px;
99
background-color: #151515;
@@ -158,3 +158,15 @@ export const StyledSelect = styled(Select)`
158158
color: #e5e5e5;
159159
}
160160
`;
161+
162+
export const UnstyledButtonLink = styled.button`
163+
appearance: none;
164+
padding: 0;
165+
background: transparent;
166+
color: inherit;
167+
border: none;
168+
font-size: inherit;
169+
font-family: inherit;
170+
text-decoration: underline;
171+
cursor: pointer;
172+
`;

packages/app/src/app/components/CreateSandbox/queries.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const TEMPLATE_FRAGMENT = gql`
1414
insertedAt
1515
updatedAt
1616
isV2
17+
isSse
1718
1819
team {
1920
name

packages/app/src/app/components/CreateSandbox/utils/api.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TemplateType } from '@codesandbox/common/lib/templates';
2+
import { isServer } from '@codesandbox/common/lib/templates/helpers/is-server';
23
import { TemplateInfo } from '../types';
34

45
interface IExploreTemplate {
@@ -61,6 +62,7 @@ const mapAPIResponseToTemplateInfo = (
6162
name: 'CodeSandbox',
6263
},
6364
isV2: sandbox.v2,
65+
isSse: isServer(sandbox.environment),
6466
git: sandbox.git && {
6567
id: sandbox.git.id,
6668
username: sandbox.git.username,

0 commit comments

Comments
 (0)