Skip to content

Commit

Permalink
Merge pull request #228 from wri/chore/performance
Browse files Browse the repository at this point in the history
Chore/performance
  • Loading branch information
tsubik authored Dec 14, 2024
2 parents 6e87824 + 8805207 commit c99e582
Show file tree
Hide file tree
Showing 191 changed files with 4,650 additions and 3,532 deletions.
20 changes: 13 additions & 7 deletions .env.default
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,30 @@ GFW_API_KEY=
MAPBOX_API_KEY=
DOCUMENTS_MINDATE=

// Transifex token
# Transifex token
TX_TOKEN=

// Sentry DSN
# Sentry DSN
SENTRY_DSN=
SENTRY_ORG=
SENTRY_PROJECT=
SENTRY_AUTH_TOKEN=
// for development env to disable pushing release to sentry
# for development env to disable pushing release to sentry
SENTRY_DISABLE_RELEASE=

// Osano Cookie Consent Manager
# Osano Cookie Consent Manager
OSANO_ID=

// Hotjar - you can disable for e2e or development in prod mode
# Hotjar - you can disable for e2e or development in prod mode
# DISABLE_HOTJAR=true

// Features
# Critical CSS
CRITICAL_CSS=true

# Features
FEATURE_COUNTRY_PAGES=false
// map page should be enabled only in dev environment
# map page should be enabled only in dev environment
FEATURE_MAP_PAGE=true

# Next
NEXT_TELEMETRY_DISABLED=1
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ static/tiles

# Sentry
.sentryclirc

# compiled languages
lang/compiled
9 changes: 5 additions & 4 deletions components/countries-detail/documentation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useRouter } from 'next/router';

// Utils
import { HELPERS_DOC } from 'utils/documentation';
Expand All @@ -8,15 +9,16 @@ import { HELPERS_DOC } from 'utils/documentation';
import DocumentsByCountry from 'components/countries-detail/documentation/documents-by-country';
import Html from 'components/html';

function OperatorsDetailDocumentation ({ countryDocumentation, vpaOverview, url }) {
function OperatorsDetailDocumentation ({ countryDocumentation, vpaOverview }) {
const router = useRouter();
const groupedByType = HELPERS_DOC.getGroupedByType(countryDocumentation);

return (
<div>
<div className="c-section">
<div className="l-container">
{vpaOverview && <Html html={vpaOverview} className="georgia" /> }
<DocumentsByCountry data={groupedByType['gov-documents']} id={url.query.id} />
<DocumentsByCountry data={groupedByType['gov-documents']} id={router.query.id} />
</div>
</div>
</div>
Expand All @@ -25,8 +27,7 @@ function OperatorsDetailDocumentation ({ countryDocumentation, vpaOverview, url

OperatorsDetailDocumentation.propTypes = {
countryDocumentation: PropTypes.array,
vpaOverview: PropTypes.string,
url: PropTypes.object,
vpaOverview: PropTypes.string
};

export default OperatorsDetailDocumentation;
2 changes: 2 additions & 0 deletions components/database/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ function DatabaseTable({
target="_blank"
rel="noopener noreferrer"
className="report-item"
aria-label="Download document"
>
<Icon className="" name="icon-file-empty" />
</a>
Expand Down Expand Up @@ -213,6 +214,7 @@ function DatabaseTable({
target="_blank"
rel="noopener noreferrer"
className="evidence-item"
aria-label="Download evidence document"
>
<Icon className="" name="icon-file-empty" />
</a>
Expand Down
2 changes: 1 addition & 1 deletion components/form/CheckboxGroup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import isEqual from 'lodash/isEqual';
import isEqual from 'react-fast-compare';
import { injectIntl } from 'react-intl';

import Checkbox from './Checkbox';
Expand Down
3 changes: 2 additions & 1 deletion components/form/File.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import omit from 'lodash/omit';

import { omit } from 'utils/general';

// Intl
import { injectIntl } from 'react-intl';
Expand Down
2 changes: 1 addition & 1 deletion components/form/FmusCheckboxGroup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import isEqual from 'lodash/isEqual';
import isEqual from 'react-fast-compare';
import { injectIntl } from 'react-intl';

// Utils
Expand Down
9 changes: 3 additions & 6 deletions components/form/FormElement.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import isEqual from 'lodash/isEqual';
import pick from 'lodash/pick';
import isEqual from 'react-fast-compare';

import Validator from './Validator';

Expand Down Expand Up @@ -30,10 +29,8 @@ class FormElement extends React.Component {
}

componentDidUpdate(prevProps) {
const prevPropsParsed = pick(prevProps, ['properties', 'validations']);
const currentPropsParsed = pick(this.props, ['properties', 'validations']);

if (!isEqual(prevPropsParsed, currentPropsParsed)) {
if (!isEqual(prevProps.properties, this.props.properties) ||
!isEqual(prevProps.validations, this.props.validations)) {
this.triggerValidate();
}

Expand Down
2 changes: 1 addition & 1 deletion components/form/Validator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isEmpty from "lodash/isEmpty";
import { isEmpty } from "utils/general";

class Validator {
constructor(intl) {
Expand Down
13 changes: 7 additions & 6 deletions components/help/faqs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import Spinner from 'components/ui/spinner';
import Html from 'components/html';
import { withRouter } from 'next/router';

// Intl
import { injectIntl } from 'react-intl';
Expand All @@ -19,17 +20,17 @@ class HelpFaqs extends React.Component {
easing: 'easeOutQuart'
});

if (this.props.url.query.article) {
if (this.props.router.query.article) {
setTimeout(() => {
this.triggerScrollTo(`#${this.props.url.query.article}`);
this.triggerScrollTo(`#${this.props.router.query.article}`);
}, 250);
}
}

componentDidUpdate() {
if (this.props.url.query.article) {
if (this.props.router.query.article) {
setTimeout(() => {
this.triggerScrollTo(`#${this.props.url.query.article}`);
this.triggerScrollTo(`#${this.props.router.query.article}`);
}, 250);
}
}
Expand Down Expand Up @@ -98,8 +99,8 @@ class HelpFaqs extends React.Component {

HelpFaqs.propTypes = {
intl: PropTypes.object.isRequired,
url: PropTypes.object.isRequired,
router: PropTypes.object.isRequired,
faqs: PropTypes.object
};

export default injectIntl(HelpFaqs);
export default injectIntl(withRouter(HelpFaqs));
13 changes: 7 additions & 6 deletions components/help/how-otp-works.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import Spinner from 'components/ui/spinner';
import Html from 'components/html';
import { withRouter } from 'next/router';

// Intl
import { injectIntl } from 'react-intl';
Expand All @@ -19,17 +20,17 @@ class HelpHowOTPWorks extends React.Component {
easing: 'easeOutQuart'
});

if (this.props.url.query.article) {
if (this.props.router.query.article) {
setTimeout(() => {
this.triggerScrollTo(`#${this.props.url.query.article}`);
this.triggerScrollTo(`#${this.props.router.query.article}`);
}, 250);
}
}

componentDidUpdate() {
if (this.props.url.query.article) {
if (this.props.router.query.article) {
setTimeout(() => {
this.triggerScrollTo(`#${this.props.url.query.article}`);
this.triggerScrollTo(`#${this.props.router.query.article}`);
}, 250);
}
}
Expand Down Expand Up @@ -98,8 +99,8 @@ class HelpHowOTPWorks extends React.Component {

HelpHowOTPWorks.propTypes = {
intl: PropTypes.object.isRequired,
url: PropTypes.object.isRequired,
router: PropTypes.object.isRequired,
howtos: PropTypes.object
};

export default injectIntl(HelpHowOTPWorks);
export default injectIntl(withRouter(HelpHowOTPWorks));
13 changes: 7 additions & 6 deletions components/help/legislation-and-regulations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import Spinner from 'components/ui/spinner';
import Html from 'components/html';
import { withRouter } from 'next/router';

// Intl
import { injectIntl } from 'react-intl';
Expand All @@ -19,17 +20,17 @@ class HelpTools extends React.Component {
easing: 'easeOutQuart'
});

if (this.props.url.query.article) {
if (this.props.router.query.article) {
setTimeout(() => {
this.triggerScrollTo(`#${this.props.url.query.article}`);
this.triggerScrollTo(`#${this.props.router.query.article}`);
}, 250);
}
}

componentDidUpdate() {
if (this.props.url.query.article) {
if (this.props.router.query.article) {
setTimeout(() => {
this.triggerScrollTo(`#${this.props.url.query.article}`);
this.triggerScrollTo(`#${this.props.router.query.article}`);
}, 250);
}
}
Expand Down Expand Up @@ -98,8 +99,8 @@ class HelpTools extends React.Component {

HelpTools.propTypes = {
intl: PropTypes.object.isRequired,
url: PropTypes.object.isRequired,
router: PropTypes.object.isRequired,
tools: PropTypes.object
};

export default injectIntl(HelpTools);
export default injectIntl(withRouter(HelpTools));
1 change: 1 addition & 0 deletions components/help/overview/gallery-1.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function Gallery1(props) {
description={tutorial.description}
link={{
label: props.intl.formatMessage({ id: 'Read more' }),
"aria-label": tutorial.name,
href: `/help/how-otp-works?article=tutorial-article-${tutorial.id}`
}}
/>
Expand Down
1 change: 1 addition & 0 deletions components/help/overview/gallery-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function Gallery2(props) {
description={tutorial.description}
link={{
label: props.intl.formatMessage({ id: 'Read more' }),
"aria-label": tutorial.name,
href: `/help/legislation-and-regulations?article=tutorial-article-${tutorial.id}`
}}
/>
Expand Down
1 change: 1 addition & 0 deletions components/help/overview/gallery-3.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function Gallery3(props) {
description={faq.answer}
link={{
label: props.intl.formatMessage({ id: 'Read more' }),
"aria-label": faq.question,
href: `/help/faqs?article=faq-article-${faq.id}`
}}
/>
Expand Down
1 change: 1 addition & 0 deletions components/help/overview/gallery-4.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ function Gallery1(props) {
description={tutorial.description}
link={{
label: props.intl.formatMessage({ id: 'Read more' }),
"aria-label": tutorial.name,
href: `/help/tutorials?article=tutorial-article-${tutorial.id}`
}}
/>
Expand Down
13 changes: 7 additions & 6 deletions components/help/tutorials.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import Spinner from 'components/ui/spinner';
import Html from 'components/html';
import { withRouter } from 'next/router';

// Intl
import { injectIntl } from 'react-intl';
Expand All @@ -19,17 +20,17 @@ class HelpTutorials extends React.Component {
easing: 'easeOutQuart'
});

if (this.props.url.query.article) {
if (this.props.router.query.article) {
setTimeout(() => {
this.triggerScrollTo(`#${this.props.url.query.article}`);
this.triggerScrollTo(`#${this.props.router.query.article}`);
}, 250);
}
}

componentDidUpdate() {
if (this.props.url.query.article) {
if (this.props.router.query.article) {
setTimeout(() => {
this.triggerScrollTo(`#${this.props.url.query.article}`);
this.triggerScrollTo(`#${this.props.router.query.article}`);
}, 250);
}
}
Expand Down Expand Up @@ -98,8 +99,8 @@ class HelpTutorials extends React.Component {

HelpTutorials.propTypes = {
intl: PropTypes.object.isRequired,
url: PropTypes.object.isRequired,
router: PropTypes.object.isRequired,
tutorials: PropTypes.object
};

export default injectIntl(HelpTutorials);
export default injectIntl(withRouter(HelpTutorials));
11 changes: 10 additions & 1 deletion components/html/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ function linkifyProcess(content) {
function preprocess(text, linkify, placeholders) {
let processedText = text;
if (linkify) processedText = linkifyProcess(processedText);
// TODO: react does not allow wrong html structure (p inside p, table inside p etc.)
// remove <p> tags from placeholders
if (placeholders) {
Object.keys(placeholders).forEach((key) => {
processedText = processedText.replace(`{${key}}`, placeholders[key]);
processedText = processedText.replace(`<p>{${key}}</p>`, `{${key}}`);
});
}

Expand All @@ -27,6 +29,13 @@ const HTML = ({ html, linkify, placeholders, className }) => (
preprocess(html, linkify, placeholders) || '',
{
replace: (node) => {
// TODO: works only for placeholders as separate text nodes
if (node.type === 'text' && placeholders) {
const key = Object.keys(placeholders).find((key) => node.data.trim() === `{${key}}`);

if (key) return placeholders[key];
}

if (node.name === 'a') {
return (
<a
Expand Down
Loading

0 comments on commit c99e582

Please sign in to comment.