Skip to content

Commit 92cfa6e

Browse files
committed
Indicate that pxl script editing has been disabled within CodeEditor
Signed-off-by: Dom Del Nano <ddelnano@gmail.com>
1 parent 4e1782c commit 92cfa6e

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/ui/src/components/code-editor/code-editor.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import type { MonacoEditorProps } from 'react-monaco-editor';
2424

2525
import { COMMON_THEME } from 'app/components/mui-theme';
2626
import { Spinner } from 'app/components/spinner/spinner';
27-
import { SCRIPT_MODIFICATION_DISABLED } from 'app/containers/constants';
2827
import { buildClass } from 'app/utils/build-class';
2928

3029
interface CodeEditorProps {
@@ -86,7 +85,7 @@ export class CodeEditor extends React.PureComponent<CodeEditorProps, CodeEditorS
8685
scrollBeyondLastColumn: 3, // Prevents hiding text behind the minimap or the scrollbar. Expands the scroll area.
8786
scrollBeyondLastLine: false,
8887
fontFamily: COMMON_THEME.typography.monospace.fontFamily,
89-
readOnly: this.props.isReadOnly === true || SCRIPT_MODIFICATION_DISABLED,
88+
readOnly: this.props.isReadOnly === true,
9089
},
9190
};
9291
this.onChange = this.onChange.bind(this);

src/ui/src/containers/editor/editor.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
} from 'app/components';
3232
import { usePluginList } from 'app/containers/admin/plugins/plugin-gql';
3333
import { SCRATCH_SCRIPT } from 'app/containers/App/scripts-context';
34+
import { SCRIPT_MODIFICATION_DISABLED } from 'app/containers/constants';
3435
import { getKeyMap } from 'app/containers/live/shortcuts';
3536
import { EditorContext } from 'app/context/editor-context';
3637
import { LayoutContext } from 'app/context/layout-context';
@@ -77,6 +78,8 @@ const useStyles = makeStyles((theme: Theme) => createStyles({
7778
},
7879
}), { name: 'Editor' });
7980

81+
const editorReadOnlyReason = 'Your cluster admin has disabled script modification';
82+
8083
const shortcutKeys = Object.values(getKeyMap()).map((keyBinding) => keyBinding.sequence);
8184

8285
const VisEditor = React.memo<{ visible: boolean }>(({ visible }) => {
@@ -110,6 +113,8 @@ const VisEditor = React.memo<{ visible: boolean }>(({ visible }) => {
110113
shortcutKeys={shortcutKeys}
111114
language='json'
112115
theme={EDITOR_THEME_MAP[theme.palette.mode]}
116+
readOnlyReason={SCRIPT_MODIFICATION_DISABLED ? editorReadOnlyReason : undefined}
117+
isReadOnly={SCRIPT_MODIFICATION_DISABLED}
113118
/>
114119
);
115120
});
@@ -147,6 +152,8 @@ const PxLEditor = React.memo<{ visible: boolean }>(({ visible }) => {
147152
shortcutKeys={shortcutKeys}
148153
language='python'
149154
theme={EDITOR_THEME_MAP[theme.palette.mode]}
155+
isReadOnly={SCRIPT_MODIFICATION_DISABLED}
156+
readOnlyReason={SCRIPT_MODIFICATION_DISABLED ? editorReadOnlyReason : undefined}
150157
/>
151158
);
152159
});

src/ui/src/pages/configure-data-export/data-export-detail.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ import { useHistory, useLocation } from 'react-router';
4242

4343
import { CodeEditor, EDITOR_THEME_MAP, StatusCell, StatusGroup, useSnackbar } from 'app/components';
4444
import { usePluginConfig } from 'app/containers/admin/plugins/plugin-gql';
45-
import { GQLClusterStatus, GQLEditableRetentionScript } from 'app/types/schema';
45+
import { SCRIPT_MODIFICATION_DISABLED } from 'app/containers/constants';
46+
import { GQLClusterStatus, GQLDetailedRetentionScript, GQLEditableRetentionScript } from 'app/types/schema';
4647
import { AutoSizerContext, withAutoSizerContext } from 'app/utils/autosizer';
4748
import { allowRetentionScriptName } from 'configurable/data-export';
4849

@@ -121,9 +122,21 @@ interface RetentionScriptEditorProps {
121122
initialValue: string;
122123
onChange: (value: string) => void;
123124
isReadOnly: boolean;
125+
readOnlyReason: string;
124126
}
127+
128+
const getReadOnlyReason = (script: GQLDetailedRetentionScript | null): string | undefined => {
129+
if (script?.isPreset) {
130+
return 'PxL for preset scripts cannot be edited';
131+
}
132+
if (SCRIPT_MODIFICATION_DISABLED) {
133+
return 'Editing retention scripts is disabled.';
134+
}
135+
return undefined;
136+
};
137+
125138
const RetentionScriptEditorInner = React.memo<RetentionScriptEditorProps>(({
126-
initialValue, onChange, isReadOnly = false,
139+
initialValue, onChange, isReadOnly = false, readOnlyReason,
127140
}) => {
128141
const { width, height } = React.useContext(AutoSizerContext);
129142
const theme = useTheme();
@@ -152,7 +165,7 @@ const RetentionScriptEditorInner = React.memo<RetentionScriptEditorProps>(({
152165
language='python'
153166
theme={EDITOR_THEME_MAP[theme.palette.mode]}
154167
isReadOnly={isReadOnly}
155-
readOnlyReason='PxL for preset scripts cannot be edited'
168+
readOnlyReason={readOnlyReason}
156169
/>
157170
</div>
158171
);
@@ -497,7 +510,8 @@ export const EditDataExportScript = React.memo<{ scriptId: string, isCreate: boo
497510
<RetentionScriptEditor
498511
initialValue={pendingValues.contents}
499512
onChange={(v) => setPendingField('contents', v)}
500-
isReadOnly={script?.isPreset}
513+
isReadOnly={script?.isPreset || SCRIPT_MODIFICATION_DISABLED}
514+
readOnlyReason={getReadOnlyReason(script)}
501515
/>
502516
</div>
503517
</Paper>

0 commit comments

Comments
 (0)