Skip to content

Commit

Permalink
Too much log in console prevent to detect real errors (#449)
Browse files Browse the repository at this point in the history
* React intl under control and some small adaptations
* Base on warning fix some translations and subscription cancellation
  • Loading branch information
richard-julien authored and Samuel Hassine committed Jan 27, 2020
1 parent f39c32f commit f31aa0c
Show file tree
Hide file tree
Showing 8 changed files with 785 additions and 760 deletions.
2 changes: 1 addition & 1 deletion opencti-platform/opencti-front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"fs-extra": "^8.1.0",
"prettier": "^1.19.1",
"react-app-rewired": "^2.1.5",
"react-scripts": "^3.3.0",
"react-scripts": "3.2.0",
"relay-compiler": "^7.1.0",
"relay-devtools": "^1.4.0"
},
Expand Down
46 changes: 25 additions & 21 deletions opencti-platform/opencti-front/src/components/AppIntlProvider.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { Component } from 'react';
import React from 'react';
import * as PropTypes from 'prop-types';
import { IntlProvider } from 'react-intl';
import MomentUtils from '@date-io/moment';
Expand All @@ -11,33 +11,37 @@ import { pathOr } from 'ramda';
import locale from '../utils/BrowserLanguage';
import i18n from '../utils/Localization';

class AppIntlProvider extends Component {
render() {
const { children } = this.props;
const platformLanguage = pathOr(
null,
['settings', 'platform_language'],
this.props,
);
const userLanguage = pathOr(null, ['me', 'language'], this.props);
const platformLang = platformLanguage !== null && platformLanguage !== 'auto'
? this.props.settings.platform_language
: locale;
const lang = userLanguage !== null && userLanguage !== 'auto'
? this.props.me.language
: platformLang;
return (
<IntlProvider locale={lang} key={lang} messages={i18n.messages[lang]}>
const AppIntlProvider = (props) => {
const { children } = props;
const intlError = (error) => {
const matchingLocale = /for locale: "([a-z]+)"/gm;
const regMatch = matchingLocale.exec(error);
const currentLocale = regMatch !== null ? regMatch[1] : null;
if (currentLocale && currentLocale !== 'en') console.error(error);
};
const platformLanguage = pathOr(
null,
['settings', 'platform_language'],
props,
);
const userLanguage = pathOr(null, ['me', 'language'], props);
const platformLang = platformLanguage !== null && platformLanguage !== 'auto'
? props.settings.platform_language
: locale;
const lang = userLanguage !== null && userLanguage !== 'auto'
? props.me.language
: platformLang;
return (
<IntlProvider locale={lang} onError={intlError} key={lang} messages={i18n.messages[lang]}>
<MuiPickersUtilsProvider
utils={MomentUtils}
locale={lang}
moment={moment}>
{children}
</MuiPickersUtilsProvider>
</IntlProvider>
);
}
}
);
};

AppIntlProvider.propTypes = {
children: PropTypes.node,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ class ConnectorsStatusComponent extends Component {
});
}

componentWillUnmount() {
this.subscription.unsubscribe();
}

handleResetState(connectorId) {
commitMutation({
mutation: connectorsStatusResetStateMutation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class WorkersStatusComponent extends Component {
});
}

componentWillUnmount() {
this.subscription.unsubscribe();
}

render() {
const {
classes, t, n, data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class ImportComponent extends Component {
});
}

componentWillUnmount() {
this.subscription.unsubscribe();
}

render() {
const {
classes,
Expand Down
2 changes: 1 addition & 1 deletion opencti-platform/opencti-front/src/relay/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ QueryRenderer.propTypes = {
managedErrorTypes: PropTypes.array,
variables: PropTypes.object,
render: PropTypes.func,
query: PropTypes.func,
query: PropTypes.object,
};

// Relay functions
Expand Down
9 changes: 9 additions & 0 deletions opencti-platform/opencti-front/src/utils/Localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ const i18n = {
'Vous devez être authentifié pour faire cette action.',
'You are not allowed to do this.':
"Vous n'ête pas autorisés à faire cette action.",
// Dependencies
Grakn: 'Grakn',
Elasticsearch: 'Elasticsearch',
RabbitMQ: 'RabbitMQ',
Redis: 'Redis',
MinIO: 'MinIO',
// Interface
Search: 'Rechercher',
'Search for a threat...': 'Rechercher une menace...',
Expand Down Expand Up @@ -215,8 +221,11 @@ const i18n = {
'No connectors are enabled on this platform.':
"Aucun connecteur n'est actif sur cette plateforme",
'Enabled import connectors': "Connecteurs d'import activés",
'No enrichment connectors on this platform': "Aucun connecteur d'enrichissement sur cette plateforme",
'Enrichment connectors': "Connecteurs d'enrichissement",
'Registered connectors': 'Connecteurs enregistrés',
Scope: 'Périmètre',
Modified: 'Modifié',
'No import connectors on this platform':
"Aucun connecteur d'import sur cette plateforme",
'No connectors for this type of observable':
Expand Down
Loading

0 comments on commit f31aa0c

Please sign in to comment.