Skip to content

Commit

Permalink
Merge pull request #210 from wri/chore/upgrade-dependencies
Browse files Browse the repository at this point in the history
Chore/upgrade dependencies
  • Loading branch information
tsubik authored May 28, 2024
2 parents 55758a9 + 15c05da commit a48f688
Show file tree
Hide file tree
Showing 18 changed files with 744 additions and 3,031 deletions.
3 changes: 0 additions & 3 deletions components/map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import isEmpty from 'lodash/isEmpty';
import ReactMapGL, { FlyToInterpolator } from 'react-map-gl';
import { fitBounds } from 'viewport-mercator-project';

import { easeCubic } from 'd3-ease';

const DEFAULT_VIEWPORT = {
zoom: 2,
latitude: 0,
Expand Down Expand Up @@ -415,7 +413,6 @@ class Map extends Component {
// getCursor={getCursor}

transitionInterpolator={new FlyToInterpolator()}
transitionEasing={easeCubic}
>
{loaded &&
!!this.map &&
Expand Down
31 changes: 4 additions & 27 deletions components/map/popup/templates/fmu/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,21 @@ import Link from 'next/link';
// Intl
import { injectIntl } from 'react-intl';

import { format } from 'd3-format';
import dayjs from 'dayjs';

class FMUTemplatePopup extends PureComponent {
static propTypes = {
layers: PropTypes.array.isRequired,
intl: PropTypes.object.isRequired
};

formatValue = (config, data) => {
const { column, format: format_str, prefix = '', suffix = '', type } = config;
const { column } = config;
let value = data[column] || '-';

switch (type) {
case 'date': {
if (value && format_str) {
value = dayjs(value).format(format_str);
}

break;
}

case 'number': {
if (value && format_str) {
value = format(format_str)(value);
}

break;
}

default: {
if (!['fmu_name', 'company_na'].includes(column)) {
value = this.props.intl.formatMessage({ id: data[column] || '-' });
}
}
if (!['fmu_name', 'company_na'].includes(column)) {
value = this.props.intl.formatMessage({ id: data[column] || '-' });
}

return `${prefix} ${value} ${suffix}`;
return value;
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ function DocumentsByOperator({ groupedByCategory, searchText, user, id, intl, ..
const fuse = new Fuse(documents, {
keys: ['title'],
threshold: 0.4,
minMatchCharLength: 2,
minMatchCharLength: 1,
ignoreLocation: true,
findAllMatches: true
});

const exactSearchResults = searchText.length > 2 ? documents.filter(exactSearch) : [];
const fuseSearchResults = fuse.search(searchText);
const fuseSearchResults = fuse.search(searchText).map(r => r.item);
return uniq([...exactSearchResults, ...fuseSearchResults]);
}

Expand Down
2 changes: 1 addition & 1 deletion components/operators/table-expanded-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const TableExpandedRow = ({ operator, fmuSearch, intl }) => {
distance: 100,
threshold: 0.15
});
fmus = fuse.search(fmuSearch);
fmus = fuse.search(fmuSearch).map(r => r.item);
}

return (
Expand Down
89 changes: 89 additions & 0 deletions components/ui/dropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React, { useState, useEffect, useRef, useCallback } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import useOutsideClick from 'hooks/use-outside-click';

const DropdownContent = (props) => {
const { children, className, ...dropdownContentProps } = props;
return (
<div {...dropdownContentProps} className={`dropdown__content ${className}`}>
{children}
</div>
);
}

const DropdownTrigger = (props) => {
const { children, className, ...dropdownTriggerProps } = props;

return (
<a {...dropdownTriggerProps} className={`dropdown__trigger ${className}`}>
{children}
</a>
);
}

const Dropdown = (props) => {
const { children, className, disabled } = props;
const [active, setActive] = useState(false);
const dropdownRef = useRef(null);

const onToggleClick = (event) => {
event.preventDefault();
if (active) {
setActive(false);
} else {
setActive(true);
}
};

useOutsideClick(dropdownRef, () => setActive(false));

const classList = classNames('dropdown', {
'dropdown--active': active,
'dropdown--disabled': disabled
}, className);

// stick callback on trigger element
const boundChildren = React.Children.map(children, child => {
if (child.type === DropdownTrigger) {
const originalOnClick = child.props.onClick;
child = React.cloneElement(child, {
onClick: (event) => {
if (!disabled) {
onToggleClick(event);
if (originalOnClick) {
originalOnClick.apply(child, arguments);
}
}
}
});
}
return child;
});

const cleanProps = { ...props };
delete cleanProps.active;

return (
<div {...cleanProps} ref={dropdownRef} className={classList}>
{boundChildren}
</div>
);
}

Dropdown.propTypes = {
disabled: PropTypes.bool,
active: PropTypes.bool,
children: PropTypes.node,
className: PropTypes.string,
style: PropTypes.object
};

Dropdown.defaultProps = {
className: ''
};

export { Dropdown, DropdownContent, DropdownTrigger };

export default Dropdown;
6 changes: 3 additions & 3 deletions components/ui/language-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import Link from 'next/link';
import { useRouter } from 'next/router';
import cx from 'classnames';

import Dropdown, {
import {
Dropdown,
DropdownTrigger,
DropdownContent,
} from 'react-simple-dropdown';

} from 'components/ui/dropdown';
import Icon from 'components/ui/icon';

import { LOCALES } from 'constants/locales';
Expand Down
20 changes: 15 additions & 5 deletions components/ui/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ import { EE } from 'services/modal';

class Modal extends React.Component {

onToogleModal = (e) => {
const { toggleModal } = this.props;
if (toggleModal) toggleModal(e.detail.opened, e.detail.opts);
}

onSetModalOptions = (e) => {
const { setModalOptions } = this.props;
if (setModalOptions) setModalOptions(e.detail.opts);
}

componentDidMount() {
const { toggleModal, setModalOptions } = this.props;
const { setModalOptions } = this.props;

EE.on('toggleModal', toggleModal);
EE.on('setModalOptions', setModalOptions);
EE.addEventListener('toggleModal', this.onToogleModal);
EE.addEventListener('setModalOptions', this.onSetModalOptions);

this.el.addEventListener('transitionend', () => {
if (!this.props.modal.opened) {
Expand All @@ -41,8 +51,8 @@ class Modal extends React.Component {
}

componentWillUnmount() {
EE.removeListener('toggleModal');
EE.removeListener('setModalOptions');
EE.removeEventListener('toggleModal', this.onToogleModal);
EE.removeEventListener('setModalOptions', this.onSetModalOptions);
}

getContent() {
Expand Down
6 changes: 3 additions & 3 deletions components/ui/navigation-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import PropTypes from 'prop-types';
import classnames from 'classnames';

import Link from 'next/link';
import Dropdown, {
import {
Dropdown,
DropdownTrigger,
DropdownContent,
} from 'react-simple-dropdown';

} from 'components/ui/dropdown';
import LanguageDropdown from 'components/ui/language-dropdown';

import { injectIntl } from 'react-intl';
Expand Down
2 changes: 1 addition & 1 deletion components/ui/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class Search extends React.Component {
this.setState({
index: 0,
value: searchText,
results: result.slice(0, 8),
results: result.map(r => r.item).slice(0, 8),
active: searchText !== ''
});
}
Expand Down
2 changes: 1 addition & 1 deletion components/ui/user-dropdown.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import PropTypes from 'prop-types';

import Dropdown, { DropdownTrigger, DropdownContent } from 'react-simple-dropdown';
import { injectIntl } from 'react-intl';

import { connect } from 'react-redux';
import { logout } from 'modules/user';

import modal from 'services/modal';

import { Dropdown, DropdownTrigger, DropdownContent } from 'components/ui/dropdown';
import UserMenuList from 'components/ui/user-menu-list';
import Login from 'components/ui/login';
import Icon from 'components/ui/icon';
Expand Down
20 changes: 20 additions & 0 deletions hooks/use-outside-click.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useEffect, useCallback } from 'react';

export default function useOutsideClick(element, action) {
if (typeof action !== 'function') throw new Error('useOutsideClick expects action to be function');

const handleClickOutside = useCallback((event) => {
if (!element.current) return;
if (!element.current.contains(event.target)) action();
}, [element, action]);

useEffect(() => {
document.addEventListener('mousedown', handleClickOutside);
document.addEventListener('touchStart', handleClickOutside);

return () => {
document.removeEventListener('mousedown', handleClickOutside);
document.removeEventListener('touchstart', handleClickOutside);
};
}, [handleClickOutside]);
}
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
require('dotenv').load();
require('dotenv').config();

const express = require('express');
const cookieSession = require('cookie-session');
Expand Down
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { withSentryConfig } = require('@sentry/nextjs');

require('dotenv').load();
require('dotenv').config();

const config = {
env: {
Expand Down
47 changes: 20 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,30 @@
"dependencies": {
"@sentry/nextjs": "^7.51.2",
"@turf/bbox": "^6.5.0",
"autoprefixer": "^10.4.14",
"body-parser": "^1.20.2",
"classnames": "^2.3.2",
"classnames": "^2.5.1",
"cookie-parser": "^1.4.6",
"cookie-session": "^2.0.0-beta.2",
"d3-ease": "^1.0.6",
"d3-format": "^1.4.3",
"date-fns": "^2.30.0",
"dayjs": "^1.11.9",
"cookie-session": "^2.1.0",
"date-fns": "^3.6.0",
"dayjs": "^1.11.11",
"deck.gl": "7.3.6",
"dotenv": "^4.0.0",
"eventemitter3": "^2.0.3",
"express": "^4.14.0",
"foundation-sites": "^6.3.1",
"fuse.js": "^3.0.5",
"globalthis": "^1.0.3",
"html-react-parser": "^3.0.16",
"jsona": "^1.0.9",
"layer-manager": "3.0.9",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"foundation-sites": "^6.8.1",
"fuse.js": "^7.0.0",
"globalthis": "^1.0.4",
"html-react-parser": "^5.1.10",
"jsona": "^1.12.1",
"layer-manager": "3.0.11",
"lodash": "4.17.21",
"luma.gl": "7.3.2",
"mapbox-gl": "^1.8.1",
"moveto": "^1.8.1",
"next": "12",
"next-redux-wrapper": "^4.0.1",
"normalize.css": "^8.0.1",
"postcss-easy-import": "^4.0.0",
"prop-types": "^15.8.1",
"query-string": "6",
"rc-tooltip": "6",
"rc-tooltip": "6.2.0",
"react": "17",
"react-datepicker": "^4.11.0",
"react-dom": "17",
Expand All @@ -46,14 +40,13 @@
"react-geosuggest": "^2.7.0",
"react-intl": "^5",
"react-map-gl": "^5.2.1",
"react-redux": "^4.4.6",
"react-redux": "^7",
"react-redux-toastr": "^7.6.4",
"react-select": "^5.7.3",
"react-simple-dropdown": "^3.2.0",
"react-select": "^5.8.0",
"react-table": "^6.2.0",
"react-truncate": "^2.4.0",
"recharts": "^2.12.4",
"redux": "^3.6.0",
"recharts": "^2.12.7",
"redux": "^4",
"redux-thunk": "^2.1.0",
"reselect": "^4.1.8",
"slugify": "^1.4.0",
Expand All @@ -62,12 +55,12 @@
},
"devDependencies": {
"@next/bundle-analyzer": "^13.4.5",
"autoprefixer": "^10.4.19",
"eslint": "^8",
"eslint-config-next": "12.x",
"eslint-config-prettier": "^8.4.0",
"extract-text-webpack-plugin": "^2.1.0",
"sass": "^1.54.4",
"xo": "^0.17.1"
"postcss-easy-import": "^4.0.0",
"sass": "^1.54.4"
},
"scripts": {
"dev": "NODE_ENV=development node index.js",
Expand Down
Loading

0 comments on commit a48f688

Please sign in to comment.