Skip to content

Commit

Permalink
DEP Upgrade frontend build stack
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Jan 25, 2023
1 parent cd1e5dd commit a650d89
Show file tree
Hide file tree
Showing 20 changed files with 5,400 additions and 9,640 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10
18
6 changes: 6 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}
2 changes: 1 addition & 1 deletion client/dist/js/bundle-admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/styles/bundle-admin.css

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

2 changes: 1 addition & 1 deletion client/dist/styles/bundle.css

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

23 changes: 6 additions & 17 deletions client/src/components/CKANExampleApp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global document, window */
import React, { Component } from 'react';
import { BrowserRouter, Route, Redirect } from 'react-router-dom';
import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
import fetch from 'isomorphic-fetch';
import CKANRegistryDisplay from 'components/CKANRegistryDisplay';
import CKANRegistryDetailView from 'components/CKANRegistryDetailView';
Expand Down Expand Up @@ -64,22 +64,11 @@ class CKANExampleApp extends Component {

return (
<div className="ckan-registry__content">
<Route
path={basePath}
exact
render={props => <CKANRegistryDisplay {...props} {...passProps} />}
/>

<Route
path={`${basePath}/view/:item`}
render={props => <CKANRegistryDetailView {...props} {...passProps} />}
/>

<Route
path={`${basePath}/view`}
exact
render={() => <Redirect to={basePath} />}
/>
<Routes>
<Route path={basePath} element={<CKANRegistryDisplay {...passProps} />} />
<Route path={`${basePath}/view/:item`} element={<CKANRegistryDetailView {...passProps} />} />
<Route path={`${basePath}/view`} element={<Navigate to={basePath} replace />} />
</Routes>
</div>
);
}
Expand Down
60 changes: 24 additions & 36 deletions client/src/components/CKANRegistryDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import Griddle, { ColumnDefinition, RowDefinition, selectors, connect } from 'gr
import { withHandlers } from 'recompose';
import { compose } from 'redux';
import classnames from 'classnames';
import CKANApi from 'lib/CKANApi';
import { Row, Col } from 'reactstrap';
import CKANRegistryFilterContainer from 'components/CKANRegistryFilterContainer';
import CKANApi from 'lib/CKANApi';
import Query from 'lib/CKANApi/DataStore/Query';
import { Redirect } from 'react-router-dom';
import withGriddleLayout from 'lib/withGriddleLayout';
import { Navigate } from 'react-router-dom';
import 'url-search-params-polyfill';

class CKANRegistryDisplay extends Component {
Expand All @@ -28,6 +28,8 @@ class CKANRegistryDisplay extends Component {
this.handleGetPage = this.handleGetPage.bind(this);
this.handleFilter = this.handleFilter.bind(this);
this.handleSort = this.handleSort.bind(this);

this.griddleLayoutHOC = withGriddleLayout(this.props, this.handleFilter, this.state.filterValues);
}

componentDidMount() {
Expand All @@ -50,14 +52,30 @@ class CKANRegistryDisplay extends Component {
*/
componentDidUpdate(prevProps, prevState) {
const pageChanged = prevState.currentPage !== this.state.currentPage;
const filterValuesChanged = JSON.stringify(prevState.filterValues) !== JSON.stringify(this.state.filterValues);

if (
pageChanged
|| filterValuesChanged
|| JSON.stringify(prevState.sort) !== JSON.stringify(this.state.sort)
|| JSON.stringify(prevState.filterValues) !== JSON.stringify(this.state.filterValues)
) {
this.loadData();
}

let needsNewHoc = filterValuesChanged;
if (!needsNewHoc) {
// eslint-disable-next-line no-restricted-syntax
for (const key of Object.keys(CKANRegistryFilterContainer.propTypes)) {
if (prevProps[key] !== this.props[key]) {
needsNewHoc = true;
break;
}
}
}

if (needsNewHoc) {
this.griddleLayoutHOC = withGriddleLayout(this.props, this.handleFilter, this.state.filterValues);
}
}

/**
Expand Down Expand Up @@ -96,7 +114,7 @@ class CKANRegistryDisplay extends Component {
onSort: newSort => { this.handleSort(newSort); },
},
components: {
Layout: this.getGriddleLayoutHOC(),
Layout: this.griddleLayoutHOC,
RowEnhancer: compose(
EnhanceWithRowData,
withHandlers({
Expand All @@ -113,36 +131,6 @@ class CKANRegistryDisplay extends Component {
};
}

/**
* Get an HOC that is used to render the layout of the Griddle components
*
* @return {function({Table: *, Pagination: *, Filter: *}): *}
*/
getGriddleLayoutHOC() {
const { filterValues } = this.state;
return ({ Table, Pagination }) => (
<Row>
<Col md={3} lg={2} className="ckan-registry__filters">
<CKANRegistryFilterContainer
{...this.props}
onFilter={this.handleFilter}
allColumns={this.getVisibleFields()}
defaultValues={filterValues}
/>
</Col>
<Col md={9} lg={10} className="ckan-registry__loading-container">
<div className="ckan-registry__loading">
{ window.i18n._t('CKANRegistryDisplay.LOADING', 'Loading...') }
</div>
</Col>
<Col md={9} lg={10} className="ckan-registry__table">
{ <Table /> }
{ <Pagination /> }
</Col>
</Row>
);
}

/**
* Get some default state values that require a bit of pre-processing
*
Expand Down Expand Up @@ -615,7 +603,7 @@ class CKANRegistryDisplay extends Component {

// Send the user off to the right detail view if they've clicked on a row
if (selectedRow !== null) {
return <Redirect to={`${basePath}/view/${selectedRow}`} />;
return <Navigate to={`${basePath}/view/${selectedRow}`} replace />;
}

const invalidConfig = !this.hasValidConfig();
Expand Down
3 changes: 3 additions & 0 deletions client/src/components/CKANRegistryFilterContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class CKANRegistryFilterContainer extends Component {

CKANRegistryFilterContainer.propTypes = {
onFilter: PropTypes.func.isRequired,
defaultValues: PropTypes.oneOf([PropTypes.array, PropTypes.object]),
spec: PropTypes.object,
filters: PropTypes.array,
};

export default CKANRegistryFilterContainer;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* global jest */
jest.mock('lib/CKANApi');

import { setImmediate } from 'core-js';
import React from 'react';
import {
Component as CKANPresentedOptions,
Expand Down
7 changes: 3 additions & 4 deletions client/src/components/tests/CKANRegistryDisplay-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Adapter from 'enzyme-adapter-react-16';
import CKANRegistryDisplay from '../CKANRegistryDisplay';
import i18n from 'i18n';
import Query from 'lib/CKANApi/DataStore/Query';
import { Redirect } from 'react-router-dom';
import { Navigate } from 'react-router-dom';

Enzyme.configure({ adapter: new Adapter() });

Expand Down Expand Up @@ -677,7 +677,6 @@ describe('CKANRegistryDisplay', () => {
const historyMock = { push: jest.fn() };
const wrapper = shallow(
<CKANRegistryDisplay

fields={testFields}
filters={[
{ id: 1, allColumns: false, columns: [{ target: 'foo' }] },
Expand Down Expand Up @@ -713,14 +712,14 @@ describe('CKANRegistryDisplay', () => {
expect(wrapper.html()).toContain('There are no columns');
});

it('returns a Redirect when switching pages', () => {
it('returns a Navigate when switching pages', () => {
const wrapper = shallow(
<CKANRegistryDisplay spec={{ identifier: 'something' }} />,
{ disableLifecycleMethods: true }
);

wrapper.setState({ selectedRow: 123 });
expect(wrapper.find(Redirect).length).toBe(1);
expect(wrapper.find(Navigate).length).toBe(1);
});
});

Expand Down
4 changes: 2 additions & 2 deletions client/src/legacy/CKANExampleApp-loader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global window */
import React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import CKANExampleApp from 'components/CKANExampleApp';

window.document.addEventListener('DOMContentLoaded', () => {
Expand All @@ -13,6 +13,6 @@ window.document.addEventListener('DOMContentLoaded', () => {
}
element.classList.add('loaded');

ReactDOM.render(<CKANExampleApp />, element);
createRoot(element).render(<CKANExampleApp />);
});
});
19 changes: 13 additions & 6 deletions client/src/legacy/CKANPresentedOptionsField-entwine.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import jQuery from 'jquery';
import React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import { loadComponent } from 'lib/Injector';

jQuery.entwine('ss', ($) => {
$('.ckan-presented-options__container').entwine({
FieldIDs: [],
Mounted: false,
ReactRoot: null,

renderComponent(value = null) {
const context = {};
Expand All @@ -22,10 +23,12 @@ jQuery.entwine('ss', ($) => {
...forwardedProps,
};

ReactDOM.render(
<PresentedOptionsComponent {...props} />,
this[0]
);
let root = this.getReactRoot();
if (!root) {
root = createRoot(this[0]);
this.setReactRoot(root);
}
root.render(<PresentedOptionsComponent {...props} />);

this.setMounted(true);
},
Expand Down Expand Up @@ -54,7 +57,11 @@ jQuery.entwine('ss', ($) => {
},

onunmatch() {
ReactDOM.unmountComponentAtNode(this[0]);
const root = this.getReactRoot();
if (root) {
root.unmount();
this.setReactRoot(null);
}
this.setMounted(false);
}
});
Expand Down
20 changes: 14 additions & 6 deletions client/src/legacy/CKANResourceLocatorField-entwine.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import jQuery from 'jquery';
import React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import { loadComponent } from 'lib/Injector';

jQuery.entwine('ss', ($) => {
$('.js-injector-boot .ckan-resource-locator__container').entwine({
ReactRoot: null,

onmatch() {
const context = {};
const CKANResourceLocatorField = loadComponent('CKANResourceLocatorField', context);
Expand All @@ -19,14 +21,20 @@ jQuery.entwine('ss', ($) => {
value: value ? JSON.parse(value) : undefined,
};

ReactDOM.render(
<CKANResourceLocatorField {...props} />,
this[0]
);
let root = this.getReactRoot();
if (!root) {
root = createRoot(this[0]);
this.setReactRoot(root);
}
root.render(<CKANResourceLocatorField {...props} />);
},

onunmatch() {
ReactDOM.unmountComponentAtNode(this[0]);
const root = this.getReactRoot();
if (root) {
root.unmount();
this.setReactRoot(null);
}
},
});
});
Loading

0 comments on commit a650d89

Please sign in to comment.