-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3081:Add template with readonly blocks to reportText
This makes sure that when creating a report, the reportText field contains a template text. Some of the heading blocks in the template are readonly and can't be removed. Note: it only works now on add, after save, on edit, the headings are no longer readonly (still to be implemented).
- Loading branch information
1 parent
73f5e0b
commit 06a38fc
Showing
4 changed files
with
61 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
client/src/components/editor/plugins/readonlyBlockPlugin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const preventHandleOnReadonly = editorState => { | ||
const selectionState = editorState.getSelection() | ||
const anchorKey = selectionState.getAnchorKey() | ||
const contentState = editorState.getCurrentContent() | ||
const currentContentBlock = contentState.getBlockForKey(anchorKey) | ||
const currentContentBlockData = currentContentBlock.getData().toObject() | ||
if (currentContentBlockData.mandatory) { | ||
return "handled" | ||
} | ||
return "not-handled" | ||
} | ||
|
||
const createReadonlyBlockPlugin = config => { | ||
const handleKeyCommand = (command, editorState) => { | ||
return preventHandleOnReadonly(editorState) | ||
} | ||
const handleBeforeInput = (chars, editorState) => { | ||
return preventHandleOnReadonly(editorState) | ||
} | ||
return { | ||
handleKeyCommand: handleKeyCommand, | ||
handleBeforeInput: handleBeforeInput | ||
} | ||
} | ||
|
||
export default createReadonlyBlockPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters