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

MATRIX-5759 integration with others property react sdk #5

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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
111 changes: 104 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
"ts-loader": "^9.4.2",
"typescript": "^4.1.5",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
"webpack-cli": "^5.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"dependencies": {
"matrix-requirements-api": "^1.0.19",
"matrix-requirements-api": "^1.0.20",
"matrixrequirements-type-declarations": "^1.0.4"
}
}
77 changes: 0 additions & 77 deletions src/BPP/Control.ts

This file was deleted.

61 changes: 61 additions & 0 deletions src/BPP/Control/Control.tsx
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();
}
}
}
26 changes: 26 additions & 0 deletions src/BPP/Control/ControlComponent.tsx
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) => {
Copy link

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)

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>
</>
}
Loading