@@ -32,13 +32,6 @@ export default class Navigation extends Component {
);
}
- config(isInitialized, context) {
- // Since this component is 'above' the content of the page (that is, it is a
- // part of the global UI that persists between routes), we will flag the DOM
- // to be retained across route changes.
- context.retain = true;
- }
-
/**
* Get the back button.
*
@@ -54,7 +47,6 @@ export default class Navigation extends Component {
href: history.backUrl(),
icon: 'fas fa-chevron-left',
title: previous.title,
- config: () => {},
onclick: (e) => {
if (e.shiftKey || e.ctrlKey || e.metaKey || e.which === 2) return;
e.preventDefault();
@@ -88,7 +80,7 @@ export default class Navigation extends Component {
* @protected
*/
getDrawerButton() {
- if (!this.props.drawer) return '';
+ if (!this.attrs.drawer) return '';
const { drawer } = app;
const user = app.session.user;
diff --git a/js/src/common/components/Page.js b/js/src/common/components/Page.js
index fa13c8c20..917aad5af 100644
--- a/js/src/common/components/Page.js
+++ b/js/src/common/components/Page.js
@@ -7,10 +7,14 @@ import PageState from '../states/PageState';
* @abstract
*/
export default class Page extends Component {
- init() {
+ oninit(vnode) {
+ super.oninit(vnode);
+
app.previous = app.current;
app.current = new PageState(this.constructor);
+ this.onNewRoute();
+
app.drawer.hide();
app.modal.close();
@@ -22,13 +26,27 @@ export default class Page extends Component {
this.bodyClass = '';
}
- config(isInitialized, context) {
- if (isInitialized) return;
+ /**
+ * A collections of actions to run when the route changes.
+ * This is extracted here, and not hardcoded in oninit, as oninit is not called
+ * when a different route is handled by the same component, but we still need to
+ * adjust the current route name.
+ */
+ onNewRoute() {
+ app.current.set('routeName', this.attrs.routeName);
+ }
+
+ oncreate(vnode) {
+ super.oncreate(vnode);
if (this.bodyClass) {
$('#app').addClass(this.bodyClass);
+ }
+ }
- context.onunload = () => $('#app').removeClass(this.bodyClass);
+ onremove() {
+ if (this.bodyClass) {
+ $('#app').removeClass(this.bodyClass);
}
}
}
diff --git a/js/src/common/components/Placeholder.js b/js/src/common/components/Placeholder.js
index 28673a08c..a5d556351 100644
--- a/js/src/common/components/Placeholder.js
+++ b/js/src/common/components/Placeholder.js
@@ -4,7 +4,7 @@ import Component from '../Component';
* The `Placeholder` component displays a muted text with some call to action,
* usually used as an empty state.
*
- * ### Props
+ * ### Attrs
*
* - `text`
*/
@@ -12,7 +12,7 @@ export default class Placeholder extends Component {
view() {
return (
);
}
diff --git a/js/src/common/components/RequestErrorModal.js b/js/src/common/components/RequestErrorModal.js
index af460e91e..297f2a462 100644
--- a/js/src/common/components/RequestErrorModal.js
+++ b/js/src/common/components/RequestErrorModal.js
@@ -6,11 +6,11 @@ export default class RequestErrorModal extends Modal {
}
title() {
- return this.props.error.xhr ? `${this.props.error.xhr.status} ${this.props.error.xhr.statusText}` : '';
+ return this.attrs.error.xhr ? `${this.attrs.error.xhr.status} ${this.attrs.error.xhr.statusText}` : '';
}
content() {
- const { error, formattedError } = this.props;
+ const { error, formattedError } = this.attrs;
let responseText;
@@ -31,7 +31,7 @@ export default class RequestErrorModal extends Modal {
return (
- {this.props.error.options.method} {this.props.error.options.url}
+ {this.attrs.error.options.method} {this.attrs.error.options.url}
{responseText}
diff --git a/js/src/common/components/Select.js b/js/src/common/components/Select.js
index fee8c1a96..d4cfab4fa 100644
--- a/js/src/common/components/Select.js
+++ b/js/src/common/components/Select.js
@@ -1,9 +1,10 @@
import Component from '../Component';
import icon from '../helpers/icon';
+import withAttr from '../utils/withAttr';
/**
* The `Select` component displays a