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

disable edit lock while loading #15

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,8 @@
},
"workspaces": [
"packages/*"
]
],
"volta": {
"node": "16.20.2"
}
}
4 changes: 4 additions & 0 deletions packages/ove/cypress/e2e/editLocking.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ describe("editLocking", () => {
beforeEach(() => {
cy.visit("");
});

it("unlocking/locking should trigger the onChangeEditLock", () => {
cy.tgToggle("onChangeEditLock");
cy.get('span[icon="unlock"]').click();
cy.get('span[icon="unlock"]').trigger("mouseover");
cy.contains("Loading...");
cy.contains("onChangeEditLock callback triggered");
});

it("disabled edit lock tooltip should show forbiden message", () => {
cy.tgToggle("disableSetReadOnly");
cy.get('span[icon="unlock"]').trigger("mouseover");
Expand Down
1 change: 1 addition & 0 deletions packages/ove/demo/src/EditorDemo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,7 @@ clickOverrides: {
{...(this.state.onChangeEditLock && {
onChangeEditLock: () => {
window.toastr.success("onChangeEditLock callback triggered");
return new Promise((resolve) => setTimeout(resolve, 1000));
}
})}
{...(this.state.onSaveAs && {
Expand Down
5 changes: 4 additions & 1 deletion packages/ove/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"name": "@teselagen/ove",
"version": "0.3.7",
"main": "./src/index.js"
"main": "./src/index.js",
"volta": {
"node": "16.20.2"
}
}
2 changes: 0 additions & 2 deletions packages/ove/src/ToolBar/ToolbarItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ class ToolbarItem extends React.Component {
}
}



export default connectToEditor(({ toolBar = {} }, { toolName }) => ({
isOpen: toolBar.openItem === toolName
}))(ToolbarItem);
17 changes: 12 additions & 5 deletions packages/ove/src/ToolBar/editTool.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState } from "react";
import { Icon } from "@blueprintjs/core";
import ToolbarItem from "./ToolbarItem";
import { connectToEditor } from "../withEditorProps";
Expand All @@ -15,19 +15,26 @@ export default connectToEditor((editorState) => {
disableSetReadOnly,
onChangeEditLock
}) => {
const [isLoading, setIsLoading] = useState(false);
const readOnlyTooltip = ({ readOnly, disableSetReadOnly }) => {
if (disableSetReadOnly) {
if (isLoading) {
return "Loading...";
} else if (disableSetReadOnly) {
return "You do not have permission to edit locks on this sequence";
}
return readOnly ? "Click to enable editing" : "Click to disable editing";
};
return (
<ToolbarItem
{...{
disabled: disableSetReadOnly,
disabled: isLoading || disableSetReadOnly,
Icon: <Icon icon={readOnly ? "lock" : "unlock"} />,
onIconClick: () => {
if (onChangeEditLock) onChangeEditLock(!readOnly);
onIconClick: async () => {
if (onChangeEditLock) {
setIsLoading(true);
await onChangeEditLock(!readOnly);
setIsLoading(false);
}
toggleReadOnlyMode();
},
tooltip: readOnlyTooltip({ readOnly, disableSetReadOnly }),
Expand Down