diff --git a/otoroshi/javascript/src/components/window.js b/otoroshi/javascript/src/components/window.js index 0dc5280cd..2c9bdf135 100644 --- a/otoroshi/javascript/src/components/window.js +++ b/otoroshi/javascript/src/components/window.js @@ -1,4 +1,4 @@ -import React, { Component } from 'react'; +import React, { Component, useEffect, useRef } from 'react'; import ReactDOM from 'react-dom'; import isFunction from 'lodash/isFunction'; import isString from 'lodash/isString'; @@ -7,243 +7,214 @@ import { WizardFrame } from './wizardframe'; const KEY_NAME_ESC = 'Escape'; const KEY_EVENT_TYPE = 'keyup'; -const handleEscKey = (event, onClose) => { - if (event.key === KEY_NAME_ESC) { - onClose(); - } -}; +function EscapeModalListener({ close, children }) { -const handleClickOutside = (event, ref, onClose) => { - if (ref.current && !ref.current.contains(event.target)) { - onClose(); - } -}; + const ref = useRef() -class Alert extends Component { - constructor(props) { - super(props); - this.modalRef = React.createRef(); - } + const handleEscKey = (event, onClose) => { + if (event.key === KEY_NAME_ESC) { + onClose(); + } + }; + + const handleClickOutside = (event, ref, onClose) => { + if (ref.current && !ref.current.contains(event.target)) { + onClose(); + } + }; + + useEffect(() => { + document.addEventListener(KEY_EVENT_TYPE, (event) => handleEscKey(event, close), false); + document.addEventListener('mousedown', (event) => handleClickOutside(event, ref, close)); + + return () => { + document.removeEventListener(KEY_EVENT_TYPE, (event) => handleEscKey(event, close), false); + document.removeEventListener('mousedown', (event) => handleClickOutside(event, ref, close)); + } + }, []) + + return React.cloneElement(children, { ref }) +} +class Alert extends Component { componentDidMount() { - document.addEventListener(KEY_EVENT_TYPE, (event) => handleEscKey(event, this.props.close), false); - document.addEventListener('mousedown', (event) => handleClickOutside(event, this.modalRef, this.props.close)); this.okRef.focus(); } - componentWillUnmount() { - document.removeEventListener(KEY_EVENT_TYPE, (event) => handleEscKey(event, this.props.close), false); - document.removeEventListener('mousedown', (event) => handleClickOutside(event, this.modalRef, this.props.close)); - } - render() { const res = isFunction(this.props.message) - ? this.props.message(this.props.close) + ? this.props.message(this.props.close) : this.props.message; return (
{res}
} - {!isString(res) && !isFunction(res) && res} - {!isString(res) && isFunction(res) && res(this.props.close)} -{res}
} + {!isString(res) && !isFunction(res) && res} + {!isString(res) && isFunction(res) && res(this.props.close)} +{this.props.message}
-{this.props.message}
+{this.props.message}
- {!this.props.textarea && ( - (this.ref = r)} - onChange={(e) => this.setState({ text: e.target.value })} - /> - )} - {this.props.textarea && ( -{this.props.message}
+ {!this.props.textarea && ( + (this.ref = r)} + onChange={(e) => this.setState({ text: e.target.value })} + /> + )} + {this.props.textarea && ( +@@ -1907,11 +1907,10 @@ const GlobalPluginInformation = ({ plugin, open }) => { 'https://maif.github.io/otoroshi/manual/plugins/built-in-plugins.html'; const getNgPluginDocumentationUrl = () => { - return `https://maif.github.io/otoroshi/manual/next/built-in-plugins.html#${ - plugin.id.replace('cp:', '') + return `https://maif.github.io/otoroshi/manual/next/built-in-plugins.html#${plugin.id.replace('cp:', '') // .replace(/\./g, '-') // .toLowerCase() - }`; + }`; }; return ( diff --git a/otoroshi/javascript/src/pages/DraftsPage.js b/otoroshi/javascript/src/pages/DraftsPage.js new file mode 100644 index 000000000..95cf21568 --- /dev/null +++ b/otoroshi/javascript/src/pages/DraftsPage.js @@ -0,0 +1,50 @@ +import React, { Component } from 'react'; +import { nextClient } from '../services/BackOfficeServices'; +import { Table } from '../components/inputs'; + +export class DraftsPage extends Component { + columns = [ + { title: 'Name', filterId: 'name', content: (item) => item.name }, + { title: 'Description', filterId: 'description', content: (item) => item.description }, + { title: 'Kind', filterId: 'id', content: (item) => item['id'].split('_')[0] } + ]; + + componentDidMount() { + this.props.setTitle(`Drafts`); + } + + render() { + return ( +