Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2506 - Updating react codemirror package that we use #3077

Merged
merged 12 commits into from
Dec 1, 2023
Merged
1,322 changes: 1,297 additions & 25 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kinto-admin",
"version": "2.1.0",
"version": "2.1.1",
"description": "Kinto Web Administration Console in React.js",
"scripts": {
"build": "rimraf build && cross-env NODE_ENV=production webpack --progress --config webpack.prod.js",
Expand Down Expand Up @@ -28,11 +28,12 @@
"@rjsf/core": "^5.13.2",
"@rjsf/validator-ajv8": "^5.13.2",
"@testing-library/react-hooks": "^8.0.1",
"@uiw/codemirror-extensions-langs": "^4.21.21",
"@uiw/react-codemirror": "^4.21.21",
"atob": "^2.0.3",
"bootstrap": "^4.6.2",
"bootstrap-icons": "^1.11.1",
"btoa": "^1.1.2",
"codemirror": "^5.39.2",
"diff": "^5.0.0",
"express": "^4.14.0",
"filesize": "^10.0.7",
Expand All @@ -44,7 +45,6 @@
"react-bootstrap": "^1.6.7",
"react-bootstrap-icons": "^1.10.3",
"react-bs-notifier": "^6.0.0",
"react-codemirror2": "^7.0.0",
"react-dom": "^17.0.2",
"react-redux": "^8.0.2",
"react-router": "^5.2.1",
Expand Down
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Provider } from "react-redux";

import { store, history } from "./store/configureStore";
import "bootstrap/dist/css/bootstrap.css";
import "codemirror/lib/codemirror.css";
// import "codemirror/lib/codemirror.css";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary anymore? Shall we just remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, missed that one.

import "../css/styles.css";
import { Layout } from "./components/Layout";

Expand Down
27 changes: 7 additions & 20 deletions src/components/JSONEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
import React from "react";
import { UnControlled as CodeMirror } from "react-codemirror2";
import "codemirror/mode/javascript/javascript";

const cmOptions = {
theme: "default",
height: "auto",
viewportMargin: Infinity,
mode: {
name: "javascript",
json: true,
statementIndent: 2,
},
lineNumbers: true,
lineWrapping: true,
indentWithTabs: false,
tabSize: 2,
};
import CodeMirror, { ViewUpdate } from "@uiw/react-codemirror";
import { langs } from "@uiw/codemirror-extensions-langs";

type Props = {
readonly: boolean;
Expand All @@ -30,7 +15,7 @@ export default function JSONEditor({
value,
onChange,
}: Props) {
const onCodeChange = (editor: Object, metadata: any, code: string) => {
const onCodeChange = (code: string, viewUpdate: ViewUpdate) => {
onChange(code);
};

Expand All @@ -39,9 +24,11 @@ export default function JSONEditor({
) : (
<CodeMirror
value={value}
autoCursor={false}
onChange={onCodeChange}
options={cmOptions}
height="auto"
style={{}}
extensions={[langs.json()]}
indentWithTab={true}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had indentWithTabs: false, with options like tabSize: 2,. Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that was my bad. I also had an empty style object in there because I wasn't sure if I was going to need to tweak things.

Switched indentWithTabs to false. Indentation size appears to be 2 by default so I didn't try to change it. But if we want to, it looks like we set that in extensions.

/>
);
}
81 changes: 51 additions & 30 deletions src/components/signoff/SimpleReview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,20 @@ export default function SimpleReview({
// get collection data
async function getRecords() {
if (destCid && destBid && sourceBid && sourceCid) {
const newRecords = await fetchRecords(sourceBid, sourceCid);
const oldRecords = await fetchRecords(destBid, destCid);
setRecords({ oldRecords, newRecords, loading: false });
try {
const newRecords = await fetchRecords(sourceBid, sourceCid);
const oldRecords = await fetchRecords(destBid, destCid);
setRecords({ oldRecords, newRecords, loading: false });
} catch (ex) {
if (ex.data?.code === 401) {
setRecords({
...records,
loading: false,
});
} else {
console.error(ex);
}
}
}
}
getRecords();
Expand All @@ -120,46 +131,35 @@ export default function SimpleReview({
);
}

let message = "";
if (!session.authenticated) {
message = "Not authenticated";
return (
<div className="simple-review-blocked-message list-page">
Not authenticated
</div>
);
} else if (
session.authenticating ||
session.busy ||
(records.loading && signoffSource && signoffDest)
) {
return <Spinner />;
} else if (!signoffSource || !signoffSource?.status) {
message = "This is not a collection that supports reviews.";
}

if (message) {
return (
<div className="simple-review-blocked-message list-page">{message}</div>
);
}

const handleRollback = (text: string) => {
rollbackChanges(text);
history.push(`/buckets/${bid}/collections/${cid}/records`);
};

return (
<div className="list-page">
<h1>
Review{" "}
<b>
{bid}/{cid}
</b>{" "}
Changes
</h1>
<CollectionTabs
bid={bid}
cid={cid}
selected="simple-review"
capabilities={capabilities || {}}
totalRecords={collection?.totalRecords || 0}
>
const SignoffContent = () => {
if (!signoffSource || !signoffSource?.status) {
return (
<div className="alert alert-warning">
This collection does not support reviews, or you do not have
permission to review.
</div>
);
}
return (
<>
{signoffSource.status !== "signed" && (
<SimpleReviewHeader {...signoffSource}>
<SimpleReviewButtons
Expand Down Expand Up @@ -190,6 +190,27 @@ export default function SimpleReview({
>
<Shuffle className="icon" /> Switch to Legacy Review UI
</button>
</>
);
};

return (
<div className="list-page">
<h1>
Review{" "}
<b>
{bid}/{cid}
</b>{" "}
Changes
</h1>
<CollectionTabs
bid={bid}
cid={cid}
selected="simple-review"
capabilities={capabilities || {}}
totalRecords={collection?.totalRecords || 0}
>
<SignoffContent />
</CollectionTabs>
</div>
);
Expand Down
Loading