Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import compiler from 'mson/lib/compiler';
import * as components from './components';
import globals from 'mson/lib/globals';
import uiComponents from '../components';
import FieldEditorForm from 'mson/lib/form/field-editor-form';
import FieldEditorFormUI from '../field-editor-form';
import FormEditor from 'mson/lib/form/form-editor';
import FormEditorUI from '../form-editor';
import FormBuilder from 'mson/lib/form/form-builder';
// Set the site key when using the ReCAPTCHAField
globals.set({ reCAPTCHASiteKey: '6LdIbGMUAAAAAJnipR9t-SnWzCbn0ZX2myXBIauh' });
// Register optional core components
compiler.registerComponent('FieldEditorForm', FieldEditorForm);
uiComponents.FieldEditorForm = FieldEditorFormUI;
compiler.registerComponent('FormEditor', FormEditor);
uiComponents.FormEditor = FormEditorUI;
compiler.registerComponent('FormBuilder', FormBuilder);
// Register all the components
for (let name in components) {
let component = components[name];
compiler.registerComponent(component.name, component);
}
// Instantiate the app
const app = compiler.newComponent({
componentDidUpdate(prevProps) {
const snackbarMessage = globals.get('snackbarMessage');
if (snackbarMessage) {
this.displaySnackbar(snackbarMessage);
globals.set({ snackbarMessage: null });
}
if (
this.props.redirectPath &&
this.props.redirectPath !== prevProps.redirectPath
) {
this.redirect(this.props.redirectPath);
}
if (this.props.path !== prevProps.path) {
this.navigateTo(this.props.path);
}
if (this.props.confirmation !== prevProps.confirmation) {
// Show the popup if any of the confirmation info has changed
this.setState({ confirmationOpen: true });
redirect(path) {
const { history } = this.props;
// Clear the redirectPath so that back-to-back redirects to the same route are considered
// unique, e.g. if / routes to /somepage and then the user hits back.
globals.set({ redirectPath: null });
history.push(path);
}
(!parentItem || this.requireAccess(parentItem.roles))
) {
if (isAction) {
// Execute the actions
await menuItem.content.run();
} else {
// Instantiate form
// this.component = compiler.newComponent(menuItem.content.component);
this.component = menuItem.content;
// Emit a load event so that the component can load any initial data, etc...
this.component.emitLoad();
const { canArchive, canSearch } = this.canArchive();
globals.set({ searchString: null });
// Set showArchived to false whenever we change the route
this.setState({
menuItem,
showArchived: false,
showArchivedToggle: canArchive,
searchStringInput: '',
showSearch: canSearch
});
}
}
} else {
this.component = null;
}
}
};
emitLoggedOut() {
globals.set({ redirectAfterLogin: this.props.location.pathname });
this.props.component.emitLoggedOut();
}