-
Notifications
You must be signed in to change notification settings - Fork 526
Expand file tree
/
Copy pathWorkspace.tsx
More file actions
166 lines (157 loc) · 5.59 KB
/
Copy pathWorkspace.tsx
File metadata and controls
166 lines (157 loc) · 5.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import Alert from '@code-dot-org/component-library/alert';
import {useCodebridgeContext} from '@codebridge/codebridgeContext';
import ToggleFileBrowserButton from '@codebridge/components/ToggleFileBrowserButton';
import {Editor} from '@codebridge/Editor/Editor';
import {FileBrowser} from '@codebridge/FileBrowser/FileBrowser';
import {FileBrowserHeaderPopUpButton} from '@codebridge/FileBrowser/FileBrowserHeaderPopUpButton';
import {FileTabs} from '@codebridge/FileTabs/FileTabs';
import {Typography} from '@mui/material';
import classnames from 'classnames';
import React, {useRef} from 'react';
import {queryParams} from '@cdo/apps/code-studio/utils';
import codebridgeI18n from '@cdo/apps/codebridge/locale';
import {
START_SOURCES,
WIDGET2_SOURCES,
WARNING_BANNER_MESSAGES,
} from '@cdo/apps/lab2/constants';
import {getAppOptionsEditBlocks} from '@cdo/apps/lab2/projects/utils';
import {
isProjectTemplateLevel,
isPermanentlyReadOnlyWorkspace,
isTemporarilyReadOnlyWorkspace,
} from '@cdo/apps/lab2/redux/lab2ReduxSelectors';
import WorkspaceAlerts from '@cdo/apps/lab2/views/alerts/workspaceAlerts';
import PanelContainer from '@cdo/apps/lab2/views/components/PanelContainer';
import {WorkspaceHeader} from '@cdo/apps/lab2/views/components/WorkspaceHeader';
import {useAppSelector} from '@cdo/apps/util/reduxHooks';
import HeaderButtons from './HeaderButtons';
import moduleStyles from './workspace.module.scss';
interface WorkspaceProps {
className?: string;
style?: React.CSSProperties;
isWidgetView?: boolean;
hideHeaders?: boolean;
}
const Workspace: React.FunctionComponent<WorkspaceProps> = ({
style,
className,
isWidgetView,
hideHeaders,
}) => {
const {config} = useCodebridgeContext();
const isStartMode = getAppOptionsEditBlocks() === START_SOURCES;
const isWidget2SourcesMode = getAppOptionsEditBlocks() === WIDGET2_SOURCES;
const containerRef = useRef<HTMLDivElement>(null);
const projectTemplateLevel = useAppSelector(isProjectTemplateLevel);
const isPermanentlyReadOnly = useAppSelector(isPermanentlyReadOnlyWorkspace);
const isTemporarilyReadOnly = useAppSelector(isTemporarilyReadOnlyWorkspace);
const showLockedFilesBanner = useAppSelector(
state => state.codebridgeWorkspace.showLockedFilesBanner
);
const projectTooLarge = useAppSelector(
state => state.lab2Project.projectTooLarge
);
const showFileBrowser = useAppSelector(
state => state.codebridgeWorkspace.showFileBrowser
);
return (
<div style={style} className={className}>
<PanelContainer
id="editor-workspace"
hideHeaders={hideHeaders}
headerContent={<WorkspaceHeader.Content />}
rightHeaderContent={
<>
<WorkspaceHeader.TemplateIcon />
<HeaderButtons />
</>
}
className={moduleStyles.workspace}
headerClassName={moduleStyles.workspaceHeader}
>
{!hideHeaders && <WorkspaceAlerts inWorkspaceContainer />}
<div
className={classnames(moduleStyles.workspaceWorkarea, {
[moduleStyles.withFileBrowser]: showFileBrowser,
})}
>
<div
className={classnames(moduleStyles.workspaceToggleButtonContainer, {
[moduleStyles.withFileBrowser]: showFileBrowser,
})}
>
{showFileBrowser && (
<Typography
className={moduleStyles.fileBrowserHeaderText}
variant="body4"
component="h2"
>
{codebridgeI18n.filesHeader()}
</Typography>
)}
<div className={moduleStyles.fileBrowserHeaderButtons}>
{showFileBrowser && !isPermanentlyReadOnly && (
<FileBrowserHeaderPopUpButton
disabled={isTemporarilyReadOnly}
/>
)}
<ToggleFileBrowserButton />
</div>
</div>
<FileTabs />
{showFileBrowser && <FileBrowser />}
<div
className={classnames(moduleStyles.workplaceEditorWrapper, {
[moduleStyles.withFileBrowser]: showFileBrowser,
})}
ref={containerRef}
>
<Editor
langMapping={config.languageMapping}
editableFileTypes={config.editableFileTypes}
/>
</div>
<div className={moduleStyles.workspaceWarningArea}>
{showLockedFilesBanner && (
<Alert
text={WARNING_BANNER_MESSAGES.LOCK_FILES}
type={'info'}
className={moduleStyles.lockedFilesBanner}
/>
)}
{isStartMode && (
<Alert
text={
projectTemplateLevel
? WARNING_BANNER_MESSAGES.TEMPLATE
: WARNING_BANNER_MESSAGES.STANDARD
}
type={'warning'}
/>
)}
{isWidget2SourcesMode && (
<Alert
text={WARNING_BANNER_MESSAGES.EDITING_WIDGET2.replace(
'{widgetId}',
queryParams('widget2') as string
)}
type={'warning'}
/>
)}
{projectTooLarge && (
<Alert text={codebridgeI18n.projectTooLarge()} type={'danger'} />
)}
{isWidgetView && (
<Alert
text={codebridgeI18n.viewingWidgetView()}
type={'warning'}
/>
)}
</div>
</div>
</PanelContainer>
</div>
);
};
export default Workspace;