@codecademy/codebytes 0.3.2-alpha.556c03.0 → 0.4.1-alpha.80ebbb.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -1
- package/package.json +6 -2
- package/src/editor.tsx +4 -1
- package/src/helpers/index.ts +43 -0
- package/src/index.tsx +27 -14
- package/src/libs/eventTracking.ts +16 -0
- package/src/types.ts +15 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
### [0.
|
|
6
|
+
### [0.4.1-alpha.80ebbb.0](https://github.com/Codecademy/client-modules/compare/@codecademy/codebytes@0.4.0...@codecademy/codebytes@0.4.1-alpha.80ebbb.0) (2022-01-24)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @codecademy/codebytes
|
|
9
9
|
|
|
@@ -11,6 +11,15 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
## [0.4.0](https://github.com/Codecademy/client-modules/compare/@codecademy/codebytes@0.3.0...@codecademy/codebytes@0.4.0) (2022-01-21)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* **Codebytes:** move language selection component disc 354 ([#17](https://github.com/Codecademy/client-modules/issues/17)) ([040553d](https://github.com/Codecademy/client-modules/commit/040553dcc7867b6e331712365bcc19ea2df306d5))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
14
23
|
## [0.3.0](https://github.com/Codecademy/client-modules/compare/@codecademy/codebytes@0.2.0...@codecademy/codebytes@0.3.0) (2022-01-12)
|
|
15
24
|
|
|
16
25
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codecademy/codebytes",
|
|
3
3
|
"description": "Codebytes Code Editor",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.1-alpha.80ebbb.0",
|
|
5
5
|
"author": "Codecademy Engineering <dev@codecademy.com>",
|
|
6
6
|
"sideEffects": [
|
|
7
7
|
"**/*.css",
|
|
@@ -23,10 +23,13 @@
|
|
|
23
23
|
"@codecademy/gamut": "*",
|
|
24
24
|
"@codecademy/gamut-icons": "*",
|
|
25
25
|
"@codecademy/gamut-styles": "*",
|
|
26
|
+
"@codecademy/tracking": "0.18.0",
|
|
26
27
|
"@codecademy/variance": "*",
|
|
27
28
|
"@emotion/react": "^11.4.0",
|
|
28
29
|
"@emotion/styled": "^11.3.0",
|
|
29
30
|
"@monaco-editor/react": "4.3.1",
|
|
31
|
+
"js-base64": "^3.6.0",
|
|
32
|
+
"jsuri": "^1.3.1",
|
|
30
33
|
"monaco-editor": ">= 0.25.0 < 1",
|
|
31
34
|
"react-resize-observer": "1.1.1"
|
|
32
35
|
},
|
|
@@ -43,10 +46,11 @@
|
|
|
43
46
|
"@emotion/jest": "^11.3.0",
|
|
44
47
|
"@testing-library/dom": "^7.31.2",
|
|
45
48
|
"@testing-library/react": "^11.0.4",
|
|
49
|
+
"@types/jsuri": "^1.3.30",
|
|
46
50
|
"@types/loadable__component": "^5.13.2"
|
|
47
51
|
},
|
|
48
52
|
"publishConfig": {
|
|
49
53
|
"access": "public"
|
|
50
54
|
},
|
|
51
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "24c6606a667e1575e77836053ca73d46713d8e4c"
|
|
52
56
|
}
|
package/src/editor.tsx
CHANGED
|
@@ -12,6 +12,7 @@ import React, { useState } from 'react';
|
|
|
12
12
|
import { postSnippet } from './api';
|
|
13
13
|
import type { LanguageOption } from './consts';
|
|
14
14
|
import { Drawers } from './drawers';
|
|
15
|
+
import { trackClick } from './helpers';
|
|
15
16
|
import { SimpleMonacoEditor } from './MonacoEditor';
|
|
16
17
|
|
|
17
18
|
const Output = styled.pre<{ hasError: boolean }>`
|
|
@@ -47,8 +48,8 @@ export const Editor: React.FC<EditorProps> = ({
|
|
|
47
48
|
language,
|
|
48
49
|
text,
|
|
49
50
|
hideCopyButton,
|
|
50
|
-
onCopy,
|
|
51
51
|
onChange,
|
|
52
|
+
onCopy,
|
|
52
53
|
snippetsBaseUrl,
|
|
53
54
|
}) => {
|
|
54
55
|
const [output, setOutput] = useState('');
|
|
@@ -62,6 +63,7 @@ export const Editor: React.FC<EditorProps> = ({
|
|
|
62
63
|
.catch(() => console.error('Failed to copy'));
|
|
63
64
|
onCopy?.(text, language);
|
|
64
65
|
setIsCodeByteCopied(true);
|
|
66
|
+
trackClick('copy');
|
|
65
67
|
}
|
|
66
68
|
};
|
|
67
69
|
|
|
@@ -80,6 +82,7 @@ export const Editor: React.FC<EditorProps> = ({
|
|
|
80
82
|
};
|
|
81
83
|
setStatus('waiting');
|
|
82
84
|
setOutput('');
|
|
85
|
+
trackClick('run');
|
|
83
86
|
|
|
84
87
|
try {
|
|
85
88
|
const response = await postSnippet(data, snippetsBaseUrl);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import Uri from 'jsuri';
|
|
2
|
+
|
|
3
|
+
import { trackUserClick } from '../libs/eventTracking';
|
|
4
|
+
|
|
5
|
+
export type CodebyteOptions = {
|
|
6
|
+
clientName: string;
|
|
7
|
+
parentPage: string;
|
|
8
|
+
renderMode: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export enum CodebytesParams {
|
|
12
|
+
Language = 'lang',
|
|
13
|
+
Text = 'text',
|
|
14
|
+
CopyMode = 'copy-mode',
|
|
15
|
+
ClientName = 'client-name',
|
|
16
|
+
Page = 'page',
|
|
17
|
+
Mode = 'mode',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const getOptions = (): CodebyteOptions => {
|
|
21
|
+
const currentUri = new Uri(window.location.href);
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
clientName:
|
|
25
|
+
currentUri.getQueryParamValue(CodebytesParams.ClientName) || 'Unknown',
|
|
26
|
+
parentPage:
|
|
27
|
+
currentUri.getQueryParamValue(CodebytesParams.Page) || document.referrer,
|
|
28
|
+
renderMode: currentUri.getQueryParamValue(CodebytesParams.Mode) || '',
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const trackClick = (target: string) => {
|
|
33
|
+
const options = getOptions();
|
|
34
|
+
const page_name = options.renderMode
|
|
35
|
+
? `${options.clientName}_${options.renderMode}`
|
|
36
|
+
: options.clientName;
|
|
37
|
+
|
|
38
|
+
trackUserClick({
|
|
39
|
+
page_name,
|
|
40
|
+
context: options.parentPage,
|
|
41
|
+
target,
|
|
42
|
+
});
|
|
43
|
+
};
|
package/src/index.tsx
CHANGED
|
@@ -3,24 +3,14 @@ import { FaviconIcon } from '@codecademy/gamut-icons';
|
|
|
3
3
|
import { Background, states, system } from '@codecademy/gamut-styles';
|
|
4
4
|
import { StyleProps } from '@codecademy/variance';
|
|
5
5
|
import styled from '@emotion/styled';
|
|
6
|
-
import React, { useState } from 'react';
|
|
6
|
+
import React, { useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { helloWorld, LanguageOption } from './consts';
|
|
9
9
|
import { Editor } from './editor';
|
|
10
|
+
import { getOptions, trackClick } from './helpers';
|
|
10
11
|
import { LanguageSelection } from './languageSelection';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export interface CodeByteEditorProps {
|
|
15
|
-
text: string;
|
|
16
|
-
language: LanguageOption;
|
|
17
|
-
hideCopyButton: boolean;
|
|
18
|
-
onCopy?: CodebytesChangeHandler;
|
|
19
|
-
isIFrame?: boolean;
|
|
20
|
-
snippetsBaseUrl?: string;
|
|
21
|
-
onEdit?: CodebytesChangeHandler;
|
|
22
|
-
onLanguageChange?: CodebytesChangeHandler;
|
|
23
|
-
}
|
|
12
|
+
import { trackUserImpression } from './libs/eventTracking';
|
|
13
|
+
import { CodeByteEditorProps } from './types';
|
|
24
14
|
|
|
25
15
|
const editorStates = states({
|
|
26
16
|
isIFrame: { height: '100vh' },
|
|
@@ -55,6 +45,21 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
|
|
|
55
45
|
}) => {
|
|
56
46
|
const [text, setText] = useState<string>(initialText);
|
|
57
47
|
const [language, setLanguage] = useState<LanguageOption>(initialLanguage);
|
|
48
|
+
const [hasBeenEdited, setHasBeenEdited] = useState(false);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
const options = getOptions();
|
|
52
|
+
const page_name = options.renderMode
|
|
53
|
+
? `${options.clientName}_${options.renderMode}`
|
|
54
|
+
: options.clientName;
|
|
55
|
+
|
|
56
|
+
trackUserImpression({
|
|
57
|
+
page_name,
|
|
58
|
+
context: options.parentPage,
|
|
59
|
+
target: 'codebyte',
|
|
60
|
+
});
|
|
61
|
+
}, []);
|
|
62
|
+
|
|
58
63
|
return (
|
|
59
64
|
<EditorContainer bg="black" as="main" isIFrame={isIFrame}>
|
|
60
65
|
<Box borderBottom={1} borderColor="gray-900" py={4} pl={8}>
|
|
@@ -65,6 +70,7 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
|
|
|
65
70
|
target="_blank"
|
|
66
71
|
rel="noreferrer"
|
|
67
72
|
aria-label="visit codecademy.com"
|
|
73
|
+
onClick={() => trackClick('logo')}
|
|
68
74
|
/>
|
|
69
75
|
</Box>
|
|
70
76
|
{language ? (
|
|
@@ -75,6 +81,12 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
|
|
|
75
81
|
onChange={(newText: string) => {
|
|
76
82
|
setText(newText);
|
|
77
83
|
onEdit?.(newText, language);
|
|
84
|
+
|
|
85
|
+
const { renderMode } = getOptions();
|
|
86
|
+
if (!renderMode && hasBeenEdited === false) {
|
|
87
|
+
setHasBeenEdited(true);
|
|
88
|
+
trackClick('edit');
|
|
89
|
+
}
|
|
78
90
|
}}
|
|
79
91
|
snippetsBaseUrl={snippetsBaseUrl}
|
|
80
92
|
/>
|
|
@@ -85,6 +97,7 @@ export const CodeByteEditor: React.FC<CodeByteEditorProps> = ({
|
|
|
85
97
|
text || (newLanguage ? helloWorld[newLanguage] : '');
|
|
86
98
|
setLanguage(newLanguage);
|
|
87
99
|
setText(newText);
|
|
100
|
+
trackClick('lang_select');
|
|
88
101
|
onLanguageChange?.(newText, newLanguage);
|
|
89
102
|
}}
|
|
90
103
|
/>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createTracker } from '@codecademy/tracking';
|
|
2
|
+
|
|
3
|
+
const IS_DEV = process.env.NODE_ENV === 'development';
|
|
4
|
+
const API_BASE_URL =
|
|
5
|
+
process.env.GATSBY_MONOLITH_API_BASE || 'https://www.codecademy.com';
|
|
6
|
+
|
|
7
|
+
const tracker = createTracker({
|
|
8
|
+
apiBaseUrl: API_BASE_URL,
|
|
9
|
+
verbose: IS_DEV,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const {
|
|
13
|
+
click: trackUserClick,
|
|
14
|
+
visit: trackUserVisit,
|
|
15
|
+
impression: trackUserImpression,
|
|
16
|
+
} = tracker;
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { LanguageOption } from './consts';
|
|
2
|
+
|
|
3
|
+
interface CodebytesChangeHandler {
|
|
4
|
+
(text: string, language: LanguageOption): void;
|
|
5
|
+
}
|
|
6
|
+
export interface CodeByteEditorProps {
|
|
7
|
+
text: string;
|
|
8
|
+
language: LanguageOption;
|
|
9
|
+
hideCopyButton: boolean;
|
|
10
|
+
onCopy?: CodebytesChangeHandler;
|
|
11
|
+
isIFrame?: boolean;
|
|
12
|
+
snippetsBaseUrl?: string;
|
|
13
|
+
onEdit?: CodebytesChangeHandler;
|
|
14
|
+
onLanguageChange?: CodebytesChangeHandler;
|
|
15
|
+
}
|