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

Remove legacy contextTypes #4997

Merged
merged 9 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 17 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ const tsRules = Object.assign({}, jsRules, {
'comma-dangle': 'off',
'comma-spacing': 'off',
'func-call-spacing': 'off',
'no-duplicate-imports': [1, {includeExports: true}],
// The 'import' plugin supports separately importing types
// (@typescript-eslint/no-duplicate-imports is deprecated)
'import/no-duplicates': 1,
// Turn off ESLint's version of this rule when in TypeScript
'no-duplicate-imports': 'off',
'no-nonoctal-decimal-escape': 'off',
// It is recommended that this check is disabled for TS files, see:
// https://typescript-eslint.io/docs/linting/troubleshooting/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
Expand Down Expand Up @@ -213,7 +217,18 @@ module.exports = {
{
files: ['**/*.ts', '**/*.tsx'],
parser: '@typescript-eslint/parser',
plugins: ['react', '@typescript-eslint'],
plugins: [
'react',
'@typescript-eslint',
// For import/no-duplicates
// Could do more with it.
'import',
],
settings: {
'import/resolver': {
typescript: true,
},
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parserOptions: {
project: ['./tsconfig.json'],
Expand Down
3 changes: 0 additions & 3 deletions jsapp/js/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
*/

import React from 'react';
import PropTypes from 'prop-types';
import DocumentTitle from 'react-document-title';
import {Outlet} from 'react-router-dom';
import reactMixin from 'react-mixin';
import Reflux from 'reflux';
import {stores} from 'js/stores';
import 'js/surveyCompanionStore'; // importing it so it exists
import {} from 'js/bemComponents'; // importing it so it exists
import bem from 'js/bem';
Expand Down Expand Up @@ -147,7 +145,6 @@ class App extends React.Component {
}
}

App.contextTypes = {router: PropTypes.object};

reactMixin(App.prototype, Reflux.connect(pageState, 'pageState'));
reactMixin(App.prototype, mixins.contextRouter);
Expand Down
5 changes: 0 additions & 5 deletions jsapp/js/components/RESTServices/RESTServiceLogs.es6
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import PropTypes from 'prop-types';
import autoBind from 'react-autobind';
import reactMixin from 'react-mixin';
import Reflux from 'reflux';
Expand Down Expand Up @@ -368,7 +367,3 @@ export default class RESTServiceLogs extends React.Component {

reactMixin(RESTServiceLogs.prototype, Reflux.ListenerMixin);
reactMixin(RESTServiceLogs.prototype, mixins.contextRouter);

RESTServiceLogs.contextTypes = {
router: PropTypes.object
};
9 changes: 0 additions & 9 deletions jsapp/js/components/drawer.es6
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, {lazy, Suspense} from 'react';
import PropTypes from 'prop-types';
import reactMixin from 'react-mixin';
import autoBind from 'react-autobind';
import {observer} from 'mobx-react';
Expand Down Expand Up @@ -90,10 +89,6 @@ const FormSidebar = observer(
}
);

FormSidebar.contextTypes = {
router: PropTypes.object,
};

reactMixin(FormSidebar.prototype, searches.common);
reactMixin(FormSidebar.prototype, mixins.droppable);

Expand Down Expand Up @@ -217,8 +212,4 @@ reactMixin(Drawer.prototype, searches.common);
reactMixin(Drawer.prototype, mixins.droppable);
reactMixin(Drawer.prototype, mixins.contextRouter);

Drawer.contextTypes = {
router: PropTypes.object,
};

export default withRouter(Drawer);
4 changes: 0 additions & 4 deletions jsapp/js/components/formEditors.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React from 'react';
import PropTypes from 'prop-types';
import reactMixin from 'react-mixin';
import autoBind from 'react-autobind';
import Reflux from 'reflux';
import editableFormMixin from '../editorMixins/editableForm';
import {update_states} from 'js/constants';
import {ROUTES} from 'js/router/routerConstants';
import mixins from '../mixins';
import {withRouter} from 'js/router/legacy';

/**
Expand All @@ -29,7 +27,6 @@ export class FormPage extends React.Component {
}
reactMixin(FormPage.prototype, Reflux.ListenerMixin);
reactMixin(FormPage.prototype, editableFormMixin);
FormPage.contextTypes = {router: PropTypes.object};

class LibraryAssetEditorComponent extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -69,6 +66,5 @@ class LibraryAssetEditorComponent extends React.Component {
}
reactMixin(LibraryAssetEditorComponent.prototype, Reflux.ListenerMixin);
reactMixin(LibraryAssetEditorComponent.prototype, editableFormMixin);
LibraryAssetEditorComponent.contextTypes = {router: PropTypes.object};

export const LibraryAssetEditor = withRouter(LibraryAssetEditorComponent);
5 changes: 0 additions & 5 deletions jsapp/js/components/formLanding.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import PropTypes from 'prop-types';
import reactMixin from 'react-mixin';
import autoBind from 'react-autobind';
import Reflux from 'reflux';
Expand Down Expand Up @@ -813,8 +812,4 @@ class FormLanding extends React.Component {
reactMixin(FormLanding.prototype, mixins.dmix);
reactMixin(FormLanding.prototype, Reflux.ListenerMixin);

FormLanding.contextTypes = {
router: PropTypes.object,
};

export default withRouter(FormLanding);
6 changes: 0 additions & 6 deletions jsapp/js/components/formSubScreens.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, {Suspense} from 'react';
import PropTypes from 'prop-types';
import reactMixin from 'react-mixin';
import autoBind from 'react-autobind';
import {actions} from '../actions';
Expand All @@ -15,7 +14,6 @@ import RESTServices from './RESTServices';
import LoadingSpinner from 'js/components/common/loadingSpinner';
import {ROUTES} from 'js/router/routerConstants';
import {withRouter} from 'js/router/legacy';
import sessionStore from 'js/stores/session';
import TransferProjects from 'js/components/permissions/transferProjects/transferProjects.component';

const ConnectProjects = React.lazy(() =>
Expand Down Expand Up @@ -166,8 +164,4 @@ export class FormSubScreens extends React.Component {
reactMixin(FormSubScreens.prototype, mixins.dmix);
reactMixin(FormSubScreens.prototype, mixins.contextRouter);

FormSubScreens.contextTypes = {
router: PropTypes.object,
};

export default withRouter(FormSubScreens);
5 changes: 0 additions & 5 deletions jsapp/js/components/formViewSideTabs.es6
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import PropTypes from 'prop-types';
import reactMixin from 'react-mixin';
import autoBind from 'react-autobind';
import Reflux from 'reflux';
Expand Down Expand Up @@ -207,8 +206,4 @@ class FormViewSideTabs extends Reflux.Component {
reactMixin(FormViewSideTabs.prototype, Reflux.ListenerMixin);
reactMixin(FormViewSideTabs.prototype, mixins.contextRouter);

FormViewSideTabs.contextTypes = {
router: PropTypes.object,
};

export default withRouter(FormViewSideTabs);
2 changes: 0 additions & 2 deletions jsapp/js/components/modalForms/libraryAssetForm.es6
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Reflux from 'reflux';
import clonedeep from 'lodash.clonedeep';
import KoboTagsInput from 'js/components/common/koboTagsInput';
import WrappedSelect from 'js/components/common/wrappedSelect';
import PropTypes from 'prop-types';
import TextBox from 'js/components/common/textBox';
import bem from 'js/bem';
import LoadingSpinner from 'js/components/common/loadingSpinner';
Expand Down Expand Up @@ -294,5 +293,4 @@ export class LibraryAssetFormComponent extends React.Component {
reactMixin(LibraryAssetFormComponent.prototype, Reflux.ListenerMixin);
reactMixin(LibraryAssetFormComponent.prototype, mixins.contextRouter);

LibraryAssetFormComponent.contextTypes = {router: PropTypes.object};
export const LibraryAssetForm = withRouter(LibraryAssetFormComponent);
5 changes: 0 additions & 5 deletions jsapp/js/components/modalForms/libraryNewItemForm.es6
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import reactMixin from 'react-mixin';
import autoBind from 'react-autobind';
import Reflux from 'reflux';
import PropTypes from 'prop-types';
import bem from 'js/bem';
import LoadingSpinner from 'js/components/common/loadingSpinner';
import sessionStore from 'js/stores/session';
Expand Down Expand Up @@ -106,8 +105,4 @@ class LibraryNewItemForm extends React.Component {
reactMixin(LibraryNewItemForm.prototype, Reflux.ListenerMixin);
reactMixin(LibraryNewItemForm.prototype, mixins.contextRouter);

LibraryNewItemForm.contextTypes = {
router: PropTypes.object
};

export default withRouter(LibraryNewItemForm);
11 changes: 4 additions & 7 deletions jsapp/js/components/modalForms/projectSettings.es6
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import PropTypes from 'prop-types';
import reactMixin from 'react-mixin';
import autoBind from 'react-autobind';
import {when} from 'mobx';
Expand Down Expand Up @@ -355,10 +354,10 @@ class ProjectSettings extends React.Component {
let targetUid;
if (this.state.formAsset) {
targetUid = this.state.formAsset.uid;
} else if (this.context.router && this.context.router.params.assetid) {
targetUid = this.context.router.params.assetid;
} else if (this.context.router && this.context.router.params.uid) {
targetUid = this.context.router.params.uid;
} else if (this.props.router.params.assetid) {
targetUid = this.props.router.params.assetid;
} else if (this.props.router.params.uid) {
targetUid = this.props.router.params.uid;
}

if (!targetUid) {
Expand Down Expand Up @@ -1131,6 +1130,4 @@ reactMixin(ProjectSettings.prototype, mixins.droppable);
// NOTE: dmix mixin is causing a full asset load after component mounts
reactMixin(ProjectSettings.prototype, mixins.dmix);

ProjectSettings.contextTypes = {router: PropTypes.object};

export default withRouter(ProjectSettings);
5 changes: 3 additions & 2 deletions jsapp/js/formbuild/renderInBackbone.es6
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import {createRoot} from 'react-dom/client';
import KoboMatrix from './containers/KoboMatrix';
import { fromJS } from 'immutable';

Expand Down Expand Up @@ -45,5 +45,6 @@ class KoboMatrixRow {

export function renderKobomatrix (view, el) {
let model = new KoboMatrixRow(view.model);
ReactDOM.render(<KoboMatrix model={model} />, el.get(0));
const root = createRoot(el.get(0));
root.render(<KoboMatrix model={model} />);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@

*/
import React from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import cx from 'classnames';
import type { Argument as ClassnamesArgument } from 'classnames'

const reactCreateBemElement = function(base, el='div'){
const reactCreateBemElement = function(base: string, el='div'){
let elUnwrap;
if (el.match) {
elUnwrap = el.match(/\<(\w+)\s?\/?\>/);
Expand All @@ -49,8 +49,15 @@ const reactCreateBemElement = function(base, el='div'){
}
}

let reduceModify = function (s, modifier){
if (Object.prototype.toString.call(modifier) === '[object Object]') {
const reduceModify = function (
s: {[key: string]: boolean},
modifier:
{[key: string]: boolean}
| string[]
| string
| undefined
){
if (typeof modifier === 'object' && !Array.isArray(modifier)) {
Object.keys(modifier).forEach(function(key){
if (modifier[key]) {
s[`${base}--${key}`] = true;
Expand All @@ -62,38 +69,41 @@ const reactCreateBemElement = function(base, el='div'){
return s;
};

class c extends React.Component {
render () {

class c extends React.Component<{
m?: string[] | string;
className: string;
classNames: ClassnamesArgument;
}> {
render() {
const props = Object.assign({}, this.props);

// allows modifiers to be a string, an array, or undefined (ignored)
let modifier = [].concat(props.m)
const modifier = ([] as Array<string | undefined>).concat(props.m)
.reduce(reduceModify, {});
delete props.m;

// builds the bem classNames, and allows additional classNames
// to be specified in an object (props.classNames) or normal string
props.className = classNames(base,
modifier,
props.classNames,
props.className);
delete props.classNames;
const className = cx(base,
modifier,
props.classNames,
props.className);

return React.createElement(el, props);
// Omitting m and classNames from new Props
// via "Tricky Destructuring Assignment" (https://stackoverflow.com/a/33053362)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const {m, classNames, ...newProps} = props;
return React.createElement(el, {...newProps, className});
}
};
c.propTypes = {
m: PropTypes.any,
className: PropTypes.string,
classNames: PropTypes.any,
};
c.displayName = `BEM.${base}`;
static displayName = `BEM.${base}`;
}

return c;
};

export function bemComponents (obj) {
export function bemComponents (obj: {[key: string]: ([string, string?] | string)}) {
let keys = Object.keys(obj);
return Object.freeze(keys.reduce(function(hsh, key){
return Object.freeze(keys.reduce(function(hsh: any, key){
let val = obj[key];
if (val instanceof Array) {
hsh[key] = reactCreateBemElement.apply(null, val);
Expand Down
5 changes: 0 additions & 5 deletions jsapp/js/lists/sidebarForms.es6
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import PropTypes from 'prop-types';
import reactMixin from 'react-mixin';
import autoBind from 'react-autobind';
import {Link} from 'react-router-dom';
Expand Down Expand Up @@ -149,10 +148,6 @@ class SidebarFormsList extends Reflux.Component {
}
}

SidebarFormsList.contextTypes = {
router: PropTypes.object,
};

reactMixin(SidebarFormsList.prototype, searches.common);
reactMixin(SidebarFormsList.prototype, Reflux.ListenerMixin);
reactMixin(SidebarFormsList.prototype, mixins.contextRouter);
Expand Down
Loading
Loading