From 0423890089c96ae2f1c73e70241d8be9eca137c0 Mon Sep 17 00:00:00 2001
From: Johan Adami <4760722+jadami10@users.noreply.github.com>
Date: Mon, 6 Dec 2021 18:25:05 -0500
Subject: [PATCH] add option to wrap lines in custom code mirror (#7857)
---
.../app/components/CustomCodemirror.tsx | 56 +++++++++++++------
.../resources/app/pages/ZookeeperPage.tsx | 4 +-
2 files changed, 42 insertions(+), 18 deletions(-)
diff --git a/pinot-controller/src/main/resources/app/components/CustomCodemirror.tsx b/pinot-controller/src/main/resources/app/components/CustomCodemirror.tsx
index 07c8b5993c81..65fda0b09c46 100644
--- a/pinot-controller/src/main/resources/app/components/CustomCodemirror.tsx
+++ b/pinot-controller/src/main/resources/app/components/CustomCodemirror.tsx
@@ -18,7 +18,7 @@
* under the License.
*/
-import React, { } from 'react';
+import React, { useState } from 'react';
import { UnControlled as CodeMirror } from 'react-codemirror2';
import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/material.css';
@@ -26,7 +26,7 @@ import 'codemirror/addon/lint/lint.css';
import 'codemirror/mode/javascript/javascript';
import 'codemirror/addon/lint/lint';
import 'codemirror/addon/lint/json-lint';
-import { makeStyles } from '@material-ui/core';
+import {FormControlLabel, FormGroup, makeStyles, Switch} from '@material-ui/core';
import clsx from 'clsx';
declare global {
@@ -41,18 +41,38 @@ type Props = {
data: Object,
isEditable?: Object,
returnCodemirrorValue?: Function,
- customClass?: string
+ customClass?: string,
+ showLineWrapToggle? : boolean,
};
const useStyles = makeStyles((theme) => ({
codeMirror: {
'& .CodeMirror': { height: 600, border: '1px solid #BDCCD9', fontSize: '13px' },
- }
+ },
+ switch: {
+ '& .MuiFormControlLabel-root': { marginLeft: '0px'},
+ },
}));
-const CustomCodemirror = ({data, isEditable, returnCodemirrorValue, customClass = ''}: Props) => {
+
+const CustomCodemirror = ({data, isEditable, returnCodemirrorValue, customClass = '', showLineWrapToggle=false}: Props) => {
const classes = useStyles();
+ const [isWrappedToggled, setWrappedToggled] = useState(false);
+ const wrapToggle = (
+
+ )
+ const wrapToggleGroup = (
+
+ setWrappedToggled(checked)}
+ />
+
+ )
+
const jsonoptions = {
lineNumbers: true,
mode: 'application/json',
@@ -60,20 +80,24 @@ const CustomCodemirror = ({data, isEditable, returnCodemirrorValue, customClass
gutters: ['CodeMirror-lint-markers'],
lint: isEditable || false,
theme: 'default',
- readOnly: !isEditable
+ readOnly: !isEditable,
+ lineWrapping: isWrappedToggled,
};
return (
- {
- returnCodemirrorValue && returnCodemirrorValue(value);
- }}
- />
+ <>
+ {showLineWrapToggle && wrapToggleGroup}
+ {
+ returnCodemirrorValue && returnCodemirrorValue(value);
+ }}
+ />
+ >
);
};
-export default CustomCodemirror;
\ No newline at end of file
+export default CustomCodemirror;
diff --git a/pinot-controller/src/main/resources/app/pages/ZookeeperPage.tsx b/pinot-controller/src/main/resources/app/pages/ZookeeperPage.tsx
index abaf4a213693..8a44de697dcd 100644
--- a/pinot-controller/src/main/resources/app/pages/ZookeeperPage.tsx
+++ b/pinot-controller/src/main/resources/app/pages/ZookeeperPage.tsx
@@ -193,13 +193,13 @@ const ZookeeperPage = () => {
>
{lastRefresh && renderLastRefresh()}
-
+
{lastRefresh && renderLastRefresh()}
-
+