forked from MatrixRequirements/matrix-ui-plugin-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
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
MATRIX-5759 integration with others property react sdk #5
Merged
francoischasseur
merged 7 commits into
main
from
MATRIX-5759-integration-with-others-property-react-sdk
Jul 12, 2023
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
56d3ab9
WIP for Control and DashboardPage
francoischasseur 1b96dbe
Fixing control
francoischasseur 260d227
Adding server Settings page
francoischasseur c72b31b
Adding server Settings page
francoischasseur 5c0bec3
Integrating React into plugins
francoischasseur b3cb63e
Better logic
francoischasseur f96cd9c
Moving IControlProp to control file + fix tsConfig wildcards (PR review)
francoischasseur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,61 @@ | ||
/// <reference types="matrixrequirements-type-declarations" /> | ||
/// <reference types="matrix-requirements-api" /> | ||
import {IPluginFieldOptions, IPluginFieldParameter, IPluginFieldValue, IPluginPrintParams} from "../Interfaces"; | ||
import * as React from "react"; | ||
import {FieldHandler} from "./FieldHandler"; | ||
import * as ReactDOM from "react-dom"; | ||
import {ControlComponent} from "./ControlComponent"; | ||
|
||
|
||
export class Control extends matrixApi.ControlCore<IPluginFieldOptions, FieldHandler> { | ||
|
||
|
||
/** default configuration of control */ | ||
protected controlConfig: IPluginFieldParameter = { | ||
options: {} | ||
}; | ||
|
||
/** method to call to initialize the editor, e.g. to attach handlers to checkboxes etc */ | ||
initEditor() { | ||
let that = this; | ||
} | ||
|
||
/** this method is called by the UI to retrieve the string to be saved in the database */ | ||
getValue(): string { | ||
return this.fieldHandler.getData(); | ||
} | ||
|
||
/** interactive radio control */ | ||
protected renderEditor(fieldId: string, value: IPluginFieldValue, options: IPluginFieldOptions) { | ||
this.fieldHandler.setValue(value); | ||
let container = document.createElement("div"); | ||
ReactDOM.render(<ControlComponent print={false} valueChanged={(data) => { | ||
this.handleValueChange(data) | ||
}} | ||
value={value}/>, container) | ||
return $(container); | ||
} | ||
|
||
/** readonly printing for custom section, tooltip, zen or user without right to edit */ | ||
protected renderPrint(fieldId: string, value: IPluginFieldValue, options: IPluginFieldOptions, params: IPluginPrintParams) { | ||
this.fieldHandler.setValue(value); | ||
let container = document.createElement("div"); | ||
ReactDOM.render(<ControlComponent print={true} value={value} valueChanged={(data) => { | ||
}}/>, container) | ||
return $(container); | ||
} | ||
|
||
/** this method compares the to value of the control to another previous value */ | ||
protected isSame(a: IPluginFieldValue, b: IPluginFieldValue) { | ||
return JSON.stringify(a) === JSON.stringify(b); | ||
} | ||
|
||
private handleValueChange(data: IPluginFieldValue) { | ||
this.fieldHandler.setValue(data) | ||
this.hasChanged(); | ||
if (this && this.settings && this.settings.valueChanged) { | ||
// Call hook to notify the form that the value has changed. | ||
this.settings.valueChanged(); | ||
} | ||
} | ||
} |
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 @@ | ||
/** | ||
* This implements a field which can be added to a category to be displayed when editing an item. | ||
* | ||
* These fields can be printed in using the custom print sections. | ||
* | ||
*/ | ||
import * as React from "react"; | ||
import {IControlProp} from "../Interfaces"; | ||
|
||
|
||
export const ControlComponent = (props: IControlProp) => { | ||
const [value, setValue] = React.useState(props.value); | ||
const handleChange = (val: string) => { | ||
setValue({value: val}); | ||
props.valueChanged({value: val}); | ||
} | ||
if (props.print) { | ||
return <div>{value?.value}</div> | ||
} | ||
return <> | ||
<div> | ||
<span> <input autoComplete="off" className="lineInput form-control" value={value?.value} | ||
onChange={(event) => handleChange(event.target.value)}/> </span> | ||
</div> | ||
</> | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put the type definition (IControlProp) in the react control file so you can use it as documentation (and also they are typically not shared)