1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

RFC: sort keys rule and initial changes (#15534)

This commit is contained in:
Brad Decker 2022-08-15 12:41:29 -05:00 committed by GitHub
parent 9cf358a82a
commit 74d48df235
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 50 deletions

View File

@ -344,5 +344,11 @@ module.exports = {
sourceType: 'script', sourceType: 'script',
}, },
}, },
{
files: ['ui/pages/settings/*.js'],
rules: {
'sort-keys': ['error', 'asc', { natural: true }],
},
},
], ],
}; };

View File

@ -45,20 +45,20 @@ import SettingsSearchList from './settings-search-list';
class SettingsPage extends PureComponent { class SettingsPage extends PureComponent {
static propTypes = { static propTypes = {
addNewNetwork: PropTypes.bool,
addressName: PropTypes.string, addressName: PropTypes.string,
backRoute: PropTypes.string, backRoute: PropTypes.string,
breadCrumbTextKey: PropTypes.string,
conversionDate: PropTypes.number,
currentPath: PropTypes.string, currentPath: PropTypes.string,
history: PropTypes.object, history: PropTypes.object,
initialBreadCrumbKey: PropTypes.string,
initialBreadCrumbRoute: PropTypes.string,
isAddressEntryPage: PropTypes.bool, isAddressEntryPage: PropTypes.bool,
isPopup: PropTypes.bool, isPopup: PropTypes.bool,
isSnapViewPage: PropTypes.bool, isSnapViewPage: PropTypes.bool,
pathnameI18nKey: PropTypes.string,
initialBreadCrumbRoute: PropTypes.string,
breadCrumbTextKey: PropTypes.string,
initialBreadCrumbKey: PropTypes.string,
mostRecentOverviewPage: PropTypes.string.isRequired, mostRecentOverviewPage: PropTypes.string.isRequired,
addNewNetwork: PropTypes.bool, pathnameI18nKey: PropTypes.string,
conversionDate: PropTypes.number,
}; };
static contextTypes = { static contextTypes = {
@ -66,9 +66,9 @@ class SettingsPage extends PureComponent {
}; };
state = { state = {
isSearchList: false,
lastFetchedConversionDate: null, lastFetchedConversionDate: null,
searchResults: [], searchResults: [],
isSearchList: false,
searchText: '', searchText: '',
}; };
@ -91,8 +91,8 @@ class SettingsPage extends PureComponent {
const { history } = this.props; const { history } = this.props;
history.push(setting.route); history.push(setting.route);
this.setState({ this.setState({
searchResults: '',
isSearchList: '', isSearchList: '',
searchResults: '',
}); });
} }
@ -142,8 +142,8 @@ class SettingsPage extends PureComponent {
<SettingsSearch <SettingsSearch
onSearch={({ searchQuery = '', results = [] }) => { onSearch={({ searchQuery = '', results = [] }) => {
this.setState({ this.setState({
searchResults: results,
isSearchList: searchQuery !== '', isSearchList: searchQuery !== '',
searchResults: results,
searchText: searchQuery, searchText: searchQuery,
}); });
}} }}
@ -255,55 +255,55 @@ class SettingsPage extends PureComponent {
<TabBar <TabBar
tabs={[ tabs={[
{ {
icon: <i className="fa fa-cog" />,
content: t('general'), content: t('general'),
icon: <i className="fa fa-cog" />,
key: GENERAL_ROUTE, key: GENERAL_ROUTE,
}, },
{ {
icon: <i className="fas fa-sliders-h" />,
content: t('advanced'), content: t('advanced'),
icon: <i className="fas fa-sliders-h" />,
key: ADVANCED_ROUTE, key: ADVANCED_ROUTE,
}, },
{ {
icon: <i className="fa fa-address-book" />,
content: t('contacts'), content: t('contacts'),
icon: <i className="fa fa-address-book" />,
key: CONTACT_LIST_ROUTE, key: CONTACT_LIST_ROUTE,
}, },
///: BEGIN:ONLY_INCLUDE_IN(flask) ///: BEGIN:ONLY_INCLUDE_IN(flask)
{ {
content: t('snaps'),
icon: ( icon: (
<i <i
className="fa fa-flask" className="fa fa-flask"
title={t('snapsSettingsDescription')} title={t('snapsSettingsDescription')}
/> />
), ),
content: t('snaps'),
key: SNAPS_LIST_ROUTE, key: SNAPS_LIST_ROUTE,
}, },
///: END:ONLY_INCLUDE_IN ///: END:ONLY_INCLUDE_IN
{ {
icon: <i className="fa fa-lock" />,
content: t('securityAndPrivacy'), content: t('securityAndPrivacy'),
icon: <i className="fa fa-lock" />,
key: SECURITY_ROUTE, key: SECURITY_ROUTE,
}, },
{ {
icon: <i className="fa fa-bell" />,
content: t('alerts'), content: t('alerts'),
icon: <i className="fa fa-bell" />,
key: ALERTS_ROUTE, key: ALERTS_ROUTE,
}, },
{ {
icon: <i className="fa fa-plug" />,
content: t('networks'), content: t('networks'),
icon: <i className="fa fa-plug" />,
key: NETWORKS_ROUTE, key: NETWORKS_ROUTE,
}, },
{ {
icon: <i className="fa fa-flask" />,
content: t('experimental'), content: t('experimental'),
icon: <i className="fa fa-flask" />,
key: EXPERIMENTAL_ROUTE, key: EXPERIMENTAL_ROUTE,
}, },
{ {
icon: <i className="fa fa-info-circle" />,
content: t('about'), content: t('about'),
icon: <i className="fa fa-info-circle" />,
key: ABOUT_US_ROUTE, key: ABOUT_US_ROUTE,
}, },
]} ]}
@ -311,7 +311,7 @@ class SettingsPage extends PureComponent {
if (key === GENERAL_ROUTE && currentPath === SETTINGS_ROUTE) { if (key === GENERAL_ROUTE && currentPath === SETTINGS_ROUTE) {
return true; return true;
} }
return matchPath(currentPath, { path: key, exact: true }); return matchPath(currentPath, { exact: true, path: key });
}} }}
onSelect={(key) => history.push(key)} onSelect={(key) => history.push(key)}
/> />

View File

@ -10,18 +10,18 @@ describe('SettingsPage', () => {
let wrapper; let wrapper;
const props = { const props = {
isAddressEntryPage: false, addNewNetwork: false,
addressName: '',
backRoute: '/', backRoute: '/',
conversionDate: Date.now(),
currentPath: '/settings', currentPath: '/settings',
initialBreadCrumbKey: undefined,
initialBreadCrumbRoute: undefined,
isAddressEntryPage: false,
isPopup: false,
location: '/settings', location: '/settings',
mostRecentOverviewPage: '', mostRecentOverviewPage: '',
isPopup: false,
pathnameI18nKey: undefined, pathnameI18nKey: undefined,
addressName: '',
initialBreadCrumbRoute: undefined,
initialBreadCrumbKey: undefined,
addNewNetwork: false,
conversionDate: Date.now(),
}; };
beforeEach(() => { beforeEach(() => {

View File

@ -33,21 +33,21 @@ import Settings from './settings.component';
const ROUTES_TO_I18N_KEYS = { const ROUTES_TO_I18N_KEYS = {
[ABOUT_US_ROUTE]: 'about', [ABOUT_US_ROUTE]: 'about',
[ADD_NETWORK_ROUTE]: 'networks',
[ADD_POPULAR_CUSTOM_NETWORK]: 'addNetwork',
[ADVANCED_ROUTE]: 'advanced', [ADVANCED_ROUTE]: 'advanced',
[ALERTS_ROUTE]: 'alerts', [ALERTS_ROUTE]: 'alerts',
[GENERAL_ROUTE]: 'general',
[CONTACT_ADD_ROUTE]: 'newContact', [CONTACT_ADD_ROUTE]: 'newContact',
[CONTACT_EDIT_ROUTE]: 'editContact', [CONTACT_EDIT_ROUTE]: 'editContact',
[CONTACT_LIST_ROUTE]: 'contacts', [CONTACT_LIST_ROUTE]: 'contacts',
[CONTACT_VIEW_ROUTE]: 'viewContact',
[EXPERIMENTAL_ROUTE]: 'experimental',
[GENERAL_ROUTE]: 'general',
[NETWORKS_FORM_ROUTE]: 'networks',
[NETWORKS_ROUTE]: 'networks',
[SECURITY_ROUTE]: 'securityAndPrivacy',
[SNAPS_LIST_ROUTE]: 'snaps', [SNAPS_LIST_ROUTE]: 'snaps',
[SNAPS_VIEW_ROUTE]: 'snaps', [SNAPS_VIEW_ROUTE]: 'snaps',
[CONTACT_VIEW_ROUTE]: 'viewContact',
[NETWORKS_ROUTE]: 'networks',
[NETWORKS_FORM_ROUTE]: 'networks',
[ADD_NETWORK_ROUTE]: 'networks',
[SECURITY_ROUTE]: 'securityAndPrivacy',
[EXPERIMENTAL_ROUTE]: 'experimental',
[ADD_POPULAR_CUSTOM_NETWORK]: 'addNetwork',
}; };
const mapStateToProps = (state, ownProps) => { const mapStateToProps = (state, ownProps) => {
@ -98,18 +98,18 @@ const mapStateToProps = (state, ownProps) => {
); );
return { return {
isAddressEntryPage,
backRoute,
currentPath: pathname,
isPopup,
pathnameI18nKey,
addressName,
initialBreadCrumbRoute,
initialBreadCrumbKey,
mostRecentOverviewPage: getMostRecentOverviewPage(state),
addNewNetwork, addNewNetwork,
addressName,
backRoute,
conversionDate, conversionDate,
currentPath: pathname,
initialBreadCrumbKey,
initialBreadCrumbRoute,
isAddressEntryPage,
isPopup,
isSnapViewPage, isSnapViewPage,
mostRecentOverviewPage: getMostRecentOverviewPage(state),
pathnameI18nKey,
}; };
}; };

View File

@ -21,8 +21,6 @@ import {
import SettingsPage from './settings.component'; import SettingsPage from './settings.component';
export default { export default {
title: 'Pages/SettingsPage',
id: __filename,
decorators: [ decorators: [
(story) => ( (story) => (
<MemoryRouter initialEntries={['/settings/general']}> <MemoryRouter initialEntries={['/settings/general']}>
@ -30,22 +28,24 @@ export default {
</MemoryRouter> </MemoryRouter>
), ),
], ],
id: __filename,
title: 'Pages/SettingsPage',
}; };
const ROUTES_TO_I18N_KEYS = { const ROUTES_TO_I18N_KEYS = {
[ABOUT_US_ROUTE]: 'about', [ABOUT_US_ROUTE]: 'about',
[ADVANCED_ROUTE]: 'advanced', [ADVANCED_ROUTE]: 'advanced',
[ALERTS_ROUTE]: 'alerts', [ALERTS_ROUTE]: 'alerts',
[GENERAL_ROUTE]: 'general',
[CONTACT_ADD_ROUTE]: 'newContact', [CONTACT_ADD_ROUTE]: 'newContact',
[CONTACT_EDIT_ROUTE]: 'editContact', [CONTACT_EDIT_ROUTE]: 'editContact',
[CONTACT_LIST_ROUTE]: 'contacts', [CONTACT_LIST_ROUTE]: 'contacts',
[CONTACT_VIEW_ROUTE]: 'viewContact',
[GENERAL_ROUTE]: 'general',
[NETWORKS_FORM_ROUTE]: 'networks',
[NETWORKS_ROUTE]: 'networks',
[SECURITY_ROUTE]: 'securityAndPrivacy',
[SNAPS_LIST_ROUTE]: 'snaps', [SNAPS_LIST_ROUTE]: 'snaps',
[SNAPS_VIEW_ROUTE]: 'snaps', [SNAPS_VIEW_ROUTE]: 'snaps',
[CONTACT_VIEW_ROUTE]: 'viewContact',
[NETWORKS_ROUTE]: 'networks',
[NETWORKS_FORM_ROUTE]: 'networks',
[SECURITY_ROUTE]: 'securityAndPrivacy',
}; };
global.platform = { global.platform = {