From d41c6663afb076caab514e1c4cdaa74bfbaa63cb Mon Sep 17 00:00:00 2001 From: Mauko Quiroga Date: Sun, 11 Dec 2022 05:28:01 +0100 Subject: [PATCH] Adapt components --- src/components/app.jsx | 10 ++++----- src/components/entity.jsx | 2 +- src/components/formula.jsx | 4 ++-- src/components/pages/country-model-item.jsx | 4 ++-- src/components/pages/home.jsx | 4 ++-- src/components/pages/searchbar.jsx | 2 +- src/components/parameter.jsx | 4 ++-- src/components/scale.jsx | 2 +- src/components/variable.jsx | 4 ++-- src/utils/periods.ts | 24 --------------------- 10 files changed, 18 insertions(+), 42 deletions(-) delete mode 100644 src/utils/periods.ts diff --git a/src/components/app.jsx b/src/components/app.jsx index 85c956bc..077953c4 100644 --- a/src/components/app.jsx +++ b/src/components/app.jsx @@ -1,11 +1,11 @@ import DocumentTitle from 'react-document-title' import React from 'react' import PropTypes from 'prop-types' -import {locationShape, Link} from 'react-router' +import {Link} from 'react-router-dom' import {FormattedMessage, injectIntl, intlShape} from 'react-intl' -import { entityShape, parameterShape, variableShape } from '../openfisca-proptypes' -import {findCountryModelItems} from '../search' +import { entityShape, locationShape, parameterShape, variableShape } from '../utils/proptypes' +import search from '../utils/search' class App extends React.Component { static childContextTypes = { @@ -31,7 +31,7 @@ class App extends React.Component { this.state = { searchQuery, - searchResults: findCountryModelItems(entities, parameters, variables, searchQuery), + searchResults: search.findCountryModelItems(entities, parameters, variables, searchQuery), } } @@ -43,7 +43,7 @@ class App extends React.Component { setSearchQuery: searchQuery => { this.setState({ searchQuery, - searchResults: findCountryModelItems(entities, parameters, variables, searchQuery), + searchResults: search.findCountryModelItems(entities, parameters, variables, searchQuery), }) }, } diff --git a/src/components/entity.jsx b/src/components/entity.jsx index fc64a25b..abd9a449 100644 --- a/src/components/entity.jsx +++ b/src/components/entity.jsx @@ -4,7 +4,7 @@ import React from 'react' import PropTypes from 'prop-types' import config from '../config' -import { entityShape } from '../openfisca-proptypes' +import { entityShape } from '../utils/proptypes' class Entity extends React.Component { diff --git a/src/components/formula.jsx b/src/components/formula.jsx index 5cf5ded0..20670c4f 100644 --- a/src/components/formula.jsx +++ b/src/components/formula.jsx @@ -1,7 +1,7 @@ import React from 'react' import PropTypes from 'prop-types' -import { parameterShape, variableShape } from '../openfisca-proptypes' -import { Link } from 'react-router' +import { parameterShape, variableShape } from '../utils/proptypes' +import { Link } from 'react-router-dom' import { FormattedMessage, FormattedDate } from 'react-intl' import { flatten, pipe, map, is } from 'ramda' import Highlight from 'react-highlight/lib/optimized' diff --git a/src/components/pages/country-model-item.jsx b/src/components/pages/country-model-item.jsx index 3be4568a..5afc634d 100644 --- a/src/components/pages/country-model-item.jsx +++ b/src/components/pages/country-model-item.jsx @@ -1,9 +1,9 @@ import React from 'react' import PropTypes from 'prop-types' -import { Link, locationShape, routerShape } from 'react-router' +import { Link } from 'react-router-dom' import { FormattedMessage } from 'react-intl' -import { entityShape, parameterShape, variableShape } from '../../openfisca-proptypes' +import { entityShape, locationShape, parameterShape, routerShape, variableShape } from '../../utils/proptypes' import Entity from '../entity' import Parameter from '../parameter' import Variable from '../variable' diff --git a/src/components/pages/home.jsx b/src/components/pages/home.jsx index b9f3b679..aa45d2e1 100644 --- a/src/components/pages/home.jsx +++ b/src/components/pages/home.jsx @@ -1,11 +1,11 @@ import {isEmpty} from 'ramda' import React from 'react' import PropTypes from 'prop-types' -import {Link, locationShape, routerShape} from 'react-router' +import {Link} from 'react-router-dom' import {FormattedMessage, injectIntl, intlShape} from 'react-intl' import DocumentTitle from 'react-document-title' -import { entityShape, parameterShape, variableShape } from '../../openfisca-proptypes' +import { entityShape, locationShape, parameterShape, routerShape, variableShape } from '../../utils/proptypes' import List from '../list' import config from '../../config' import SearchBar from './searchbar' diff --git a/src/components/pages/searchbar.jsx b/src/components/pages/searchbar.jsx index ab437eec..dcf65ab3 100644 --- a/src/components/pages/searchbar.jsx +++ b/src/components/pages/searchbar.jsx @@ -1,7 +1,7 @@ -import { routerShape } from 'react-router' import React from 'react' import {FormattedMessage, injectIntl, intlShape} from 'react-intl' +import { routerShape } from '../../utils/proptypes' import { searchInputId } from './home' class SearchBar extends React.Component { diff --git a/src/components/parameter.jsx b/src/components/parameter.jsx index 97e53075..805ce7fb 100644 --- a/src/components/parameter.jsx +++ b/src/components/parameter.jsx @@ -4,9 +4,9 @@ import React from 'react' import PropTypes from 'prop-types' import config from '../config' -import { parameterShape } from '../openfisca-proptypes' +import { parameterShape } from '../utils/proptypes' import Scale from './scale' -import getDayBefore from '../periods' +import getDayBefore from '../utils/periods' class Parameter extends React.Component { static propTypes = { diff --git a/src/components/scale.jsx b/src/components/scale.jsx index 9953c6f3..c14d57f6 100644 --- a/src/components/scale.jsx +++ b/src/components/scale.jsx @@ -1,7 +1,7 @@ import React from 'react' import { FormattedMessage, FormattedDate, FormattedNumber } from 'react-intl' -import { parameterShape } from '../openfisca-proptypes' +import { parameterShape } from '../utils/proptypes' class Scale extends React.Component { diff --git a/src/components/variable.jsx b/src/components/variable.jsx index 20519fd4..a541235c 100644 --- a/src/components/variable.jsx +++ b/src/components/variable.jsx @@ -5,9 +5,9 @@ import PropTypes from 'prop-types' import { keys } from 'ramda' import config from '../config' -import { parameterShape, variableShape } from '../openfisca-proptypes' +import { parameterShape, variableShape } from '../utils/proptypes' import Formula from './formula' -import getDayBefore from '../periods' +import getDayBefore from '../utils/periods' class Variable extends React.Component { //Variable properties include other objects for Formula code highlight. diff --git a/src/utils/periods.ts b/src/utils/periods.ts deleted file mode 100644 index a5b19693..00000000 --- a/src/utils/periods.ts +++ /dev/null @@ -1,24 +0,0 @@ -const LENGTH = 'YYYY-MM-DD'.length -const ONE_DAY = 86400000 // in ms - -/** - * Returns the date that occurred one day before the input date. - * - * @param {string} day - The input date as a string in the 'YYYY-MM-DD' format. - * @returns {string} The date that occurred one day before the input date. - * @throws {Error} If the input date is not a valid date. - */ -const getDayBefore = (day: string): string => { - const date = new Date(day) - - if (!Number.isFinite(date)) { - throw new Error(`${day} is not a valid date`) - } - - const dayBefore = new Date(date - ONE_DAY) - - return dayBefore.toISOString().slice(0, LENGTH) -} - - -export default getDayBefore