Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 Post-Migration Code Cleanup #1124

Merged
merged 38 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
31d472e
unify function declarations: `const` vs `function`
JGreenlee Jan 26, 2024
adc6620
use 'const' and 'let' instead of 'var'
JGreenlee Jan 26, 2024
0a8ed76
cleanup all console/log statements
JGreenlee Jan 26, 2024
03fc69a
Merge branch 'master' of https://github.com/e-mission/e-mission-phone…
JGreenlee Feb 12, 2024
a26d039
use PascalCase for all type defs
JGreenlee Feb 12, 2024
069a72e
use LocalDt in MetricsTypes
JGreenlee Feb 12, 2024
633db15
use 'i18n.resolvedLanguage', not 'language'
JGreenlee Feb 12, 2024
125d009
LabelTab: guard clause for pipelineRange, both start_ts and end_ts
JGreenlee Feb 12, 2024
2453e9a
use Boolean() instead of !!
JGreenlee Feb 12, 2024
c483322
use AppConfig type def on the useAppConfig hook and in inputMatcher
JGreenlee Feb 12, 2024
a4eb833
remove 'ch' unit from MetricsDateSelect
JGreenlee Feb 12, 2024
260f213
bump 'react-native-paper' to ^5.11.0
JGreenlee Feb 9, 2024
1ed9e57
use the new Icon component from RN Paper 5.11
JGreenlee Feb 13, 2024
a717560
in useAppConfig, check config contents safely
JGreenlee Feb 13, 2024
ed49146
AddedNotesList: adjust UI
JGreenlee Feb 13, 2024
b076910
EnketoModal: allow appConfig to be initially null
JGreenlee Feb 13, 2024
8101388
use theme colors for logout button
JGreenlee Feb 13, 2024
8047221
fix OverallTripDescriptives not showing for multimodal unlabeled trips
JGreenlee Feb 13, 2024
72608de
make <NavBar> a reusable component
JGreenlee Feb 13, 2024
09a0408
aria: make NavBar + NavBarButton taller
JGreenlee Feb 13, 2024
d647f33
add AlertManager for global alerts
JGreenlee Feb 15, 2024
76f4d5d
remove weird comma
JGreenlee Feb 15, 2024
c6a9777
move AlertBar to /components
JGreenlee Feb 15, 2024
9592107
revert "remove weird comma"
JGreenlee Feb 15, 2024
b573e06
make push notifications warning an AlertBar
JGreenlee Feb 16, 2024
524eb71
make Log Out button a NavBarButton; tweak NavBarButton
JGreenlee Feb 16, 2024
5f8bb77
explanation comment in dynamicStyleSheet.d.ts
JGreenlee Feb 19, 2024
f9c3c57
AddedNotesList: safer guard clauses in deleteEntry
JGreenlee Feb 20, 2024
9178685
aria: use 'touch' style for Enketo forms
JGreenlee Feb 20, 2024
9174545
fix inputMatcher logging test
JGreenlee Feb 21, 2024
2bf2e3e
fix uploadService arrow functions 'this'
JGreenlee Feb 21, 2024
0ce1e7d
add "inverse" colors to appTheme for AlertBars
JGreenlee Feb 21, 2024
658f00f
finish adding typings for LabelTabContext
JGreenlee Feb 21, 2024
0e50c8b
simplify alert creation in ProfileSettings
JGreenlee Feb 21, 2024
2796702
SettingRow: remove unused variable 'descriptionText'
JGreenlee Feb 21, 2024
b62861e
use blue instead of orange for enketo surveys
JGreenlee Feb 28, 2024
9062055
UI touch up on the EnketoModal footer
JGreenlee Feb 28, 2024
14f72de
Merge branch 'master' into code-cleanup-jan2024
JGreenlee Mar 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.cordovabuild.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
"react-chartjs-2": "^5.2.0",
"react-dom": "^18.2.*",
"react-i18next": "^13.5.0",
"react-native-paper": "^5.8.0",
"react-native-paper": "^5.11.0",
"react-native-paper-dates": "^0.18.12",
"react-native-safe-area-context": "^4.6.3",
"react-native-screens": "^3.22.0",
Expand Down
2 changes: 1 addition & 1 deletion package.serve.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"react-chartjs-2": "^5.2.0",
"react-dom": "^18.2.*",
"react-i18next": "^13.5.0",
"react-native-paper": "^5.8.0",
"react-native-paper": "^5.11.0",
"react-native-paper-dates": "^0.18.12",
"react-native-safe-area-context": "^4.6.3",
"react-native-screens": "^3.22.0",
Expand Down
2 changes: 1 addition & 1 deletion www/__mocks__/fileSystemMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const mockFileSystem = () => {
onerror: (e: any) => void;
write: (obj: Blob) => void;
};
window['resolveLocalFileSystemURL'] = function (parentDir, handleFS) {
window['resolveLocalFileSystemURL'] = (parentDir, handleFS) => {
const fs = {
filesystem: {
root: {
Expand Down
14 changes: 4 additions & 10 deletions www/__mocks__/pushNotificationMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@ export const mockPushNotification = () => {
};
};

export const clearNotifMock = function () {
export function clearNotifMock() {
notifSettings = {};
onList = {};
called = null;
};

export const getOnList = function () {
return onList;
};

export const getCalled = function () {
return called;
};
}
export const getOnList = () => onList;
export const getCalled = () => called;
7 changes: 5 additions & 2 deletions www/__tests__/inputMatcher.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mockBEMUserCache } from '../__mocks__/cordovaMocks';
import { mockLogger } from '../__mocks__/globalMocks';
import { unprocessedLabels, updateLocalUnprocessedInputs } from '../js/diary/timelineHelper';
import * as logger from '../js/plugin/logger';
import { EnketoUserInputEntry } from '../js/survey/enketo/enketoHelper';
import {
fmtTs,
Expand Down Expand Up @@ -148,11 +149,13 @@ describe('input-matcher', () => {
});

it('tests getNotDeletedCandidates called with 0 candidates', () => {
jest.spyOn(console, 'log');
jest.spyOn(logger, 'logDebug');
const candidates = getNotDeletedCandidates([]);

// check if the log printed collectly with
expect(console.log).toHaveBeenCalledWith('getNotDeletedCandidates called with 0 candidates');
expect(logger.logDebug).toHaveBeenCalledWith(
'getNotDeletedCandidates called with 0 candidates',
);
expect(candidates).toStrictEqual([]);
});

Expand Down
6 changes: 6 additions & 0 deletions www/css/style.css → www/css/style.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* This file is in Sassy CSS (SCSS) because Enketo uses SCSS and we want to extend on their styles.
Webpack will just compile this to plain CSS anyway */

@import 'leaflet/dist/leaflet.css';

html {
Expand All @@ -7,6 +10,9 @@ html {
/* Scoped styles for Enketo */
/* if we don't contain them here, they will leak into the rest of the app */
.enketo-plugin {
// Enketo's default theme uses orange; we can override with our own blue
$primary: #0080b9; // matches 'primary' in appTheme.ts
$brand-primary-color: darken($primary, 5%); // make it a bit darker for legibility in Enketo UI
@import 'enketo-core/src/sass/formhub/formhub.scss';
flex: 1;
.question.non-select {
Expand Down
2 changes: 1 addition & 1 deletion www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { createRoot } from 'react-dom/client';
import { Provider as PaperProvider } from 'react-native-paper';

import './css/style.css';
import './css/style.scss';
import 'chartjs-adapter-luxon';

import initializedI18next from './js/i18nextInit';
Expand Down
4 changes: 2 additions & 2 deletions www/js/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { initStoreDeviceSettings } from './splash/storeDeviceSettings';
import { initRemoteNotifyHandler } from './splash/remoteNotifyHandler';
import { withErrorBoundary } from './plugin/ErrorBoundary';
import { initCustomDatasetHelper } from './metrics/customMetricsHelper';
import AlertBar from './components/AlertBar';

const defaultRoutes = (t) => [
{
Expand Down Expand Up @@ -95,8 +96,6 @@ const App = () => {
setPermissionsPopupVis,
};

console.debug('onboardingState in App', onboardingState);

let appContent;
if (onboardingState == null) {
// if onboarding state is not yet determined, show a loading spinner
Expand Down Expand Up @@ -133,6 +132,7 @@ const App = () => {
<AppStatusModal permitVis={permissionsPopupVis} setPermitVis={setPermissionsPopupVis} />
)}
</AppContext.Provider>
<AlertBar />
</>
);
};
Expand Down
8 changes: 6 additions & 2 deletions www/js/appTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const AppTheme = {
surfaceVariant: '#e0f0ff', // lch(94% 50 250) - background of DataTable
surfaceDisabled: '#c7e0f7', // lch(88% 15 250)
onSurfaceDisabled: '#3a4955', // lch(30% 10 250)
// "inverse" colors - used for SnackBars / AlertBars
inversePrimary: '#90ceff', // lch(80% 35 250) - SnackBar colored text
inverseSurface: '#2e3133', // lch(20% 2 250) - SnackBar background
inverseOnSurface: '#edf1f6', // lch(95% 3 250) - SnackBar text
elevation: {
level0: 'transparent',
level1: '#fafdff', // lch(99% 30 250)
Expand Down Expand Up @@ -85,7 +89,7 @@ const flavorOverrides = {

/* This function is used to retrieve the theme for a given flavor.
If no valid flavor is specified, it returns the default theme. */
export const getTheme = (flavor?: keyof typeof flavorOverrides) => {
export function getTheme(flavor?: keyof typeof flavorOverrides) {
if (!flavor || !flavorOverrides[flavor]) return AppTheme;
const typeStyle = flavorOverrides[flavor];
const scopedElevation = { ...AppTheme.colors.elevation, ...typeStyle?.colors?.elevation };
Expand All @@ -94,4 +98,4 @@ export const getTheme = (flavor?: keyof typeof flavorOverrides) => {
...{ ...typeStyle.colors, elevation: scopedElevation },
};
return { ...AppTheme, colors: scopedColors };
};
}
20 changes: 10 additions & 10 deletions www/js/appstatus/PermissionsControls.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
//component to view and manage permission settings
import React, { useContext, useState } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import { StyleSheet, ScrollView, View } from 'react-native';
import { Button, Text } from 'react-native-paper';
import { useTranslation } from 'react-i18next';
import PermissionItem from './PermissionItem';
import { refreshAllChecks } from '../usePermissionStatus';
import ExplainPermissions from './ExplainPermissions';
import AlertBar from '../control/AlertBar';
import { AlertManager } from '../components/AlertBar';
import { AppContext } from '../App';

const PermissionsControls = ({ onAccept }) => {
const { t } = useTranslation();
const [explainVis, setExplainVis] = useState<boolean>(false);
const { permissionStatus } = useContext(AppContext);
const { checkList, overallStatus, error, errorVis, setErrorVis, explanationList } =
permissionStatus;
const { checkList, overallStatus, error, explanationList } = permissionStatus;

useEffect(() => {
if (!error) return;
AlertManager.addMessage({
text: error,
});
}, [error]);

return (
<>
Expand All @@ -36,12 +42,6 @@ const PermissionsControls = ({ onAccept }) => {
{t('control.button-accept')}
</Button>
</View>

<AlertBar
visible={errorVis}
setVisible={setErrorVis}
messageKey={'Error '}
messageAddition={error}></AlertBar>
</>
);
};
Expand Down
59 changes: 59 additions & 0 deletions www/js/components/AlertBar.tsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not going to hold up the release for this, but it looks like we need to add some additional tests for this functionality. For example, there is no test for setListener or addMessage (or that is what `codecov tells me)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* Provides a global context for alerts to show as SnackBars ('toasts') at the bottom of the screen.
Alerts can be added to the queue from anywhere by calling AlertManager.addMessage. */

import React, { useState, useEffect } from 'react';
import { Snackbar } from 'react-native-paper';
import { Modal } from 'react-native';
import { useTranslation } from 'react-i18next';
import { ParseKeys } from 'i18next';

type AlertMessage = {
msgKey?: ParseKeys<'translation'>;
text?: string;
duration?: number;
};

// public static AlertManager that can add messages from a global context
export class AlertManager {
private static listener?: (msg: AlertMessage) => void;
static setListener(listener?: (msg: AlertMessage) => void) {
AlertManager.listener = listener;

Check warning on line 20 in www/js/components/AlertBar.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/components/AlertBar.tsx#L19-L20

Added lines #L19 - L20 were not covered by tests
}
static addMessage(msg: AlertMessage) {
AlertManager.listener?.(msg);

Check warning on line 23 in www/js/components/AlertBar.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/components/AlertBar.tsx#L22-L23

Added lines #L22 - L23 were not covered by tests
}
}

const AlertBar = () => {
const { t } = useTranslation();
const [messages, setMessages] = useState<AlertMessage[]>([]);
const onDismissSnackBar = () => setMessages(messages.slice(1));

Check warning on line 30 in www/js/components/AlertBar.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/components/AlertBar.tsx#L28-L30

Added lines #L28 - L30 were not covered by tests

// on init, attach a listener to AlertManager so messages can be added from a global context
useEffect(() => {
AlertManager.setListener((msg) => {
setMessages([...messages, msg]);

Check warning on line 35 in www/js/components/AlertBar.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/components/AlertBar.tsx#L33-L35

Added lines #L33 - L35 were not covered by tests
});
return () => AlertManager.setListener(undefined);

Check warning on line 37 in www/js/components/AlertBar.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/components/AlertBar.tsx#L37

Added line #L37 was not covered by tests
}, []);

if (!messages.length) return null;
const { msgKey, text } = messages[0];
const alertText = [msgKey && t(msgKey), text].filter((x) => x).join(' ');
return (

Check warning on line 43 in www/js/components/AlertBar.tsx

View check run for this annotation

Codecov / codecov/patch

www/js/components/AlertBar.tsx#L40-L43

Added lines #L40 - L43 were not covered by tests
<Modal visible={true} onDismiss={onDismissSnackBar} transparent={true}>
<Snackbar
visible={true}
onDismiss={onDismissSnackBar}
duration={messages[0].duration}
action={{
label: t('join.close'),
onPress: onDismissSnackBar,
}}>
{alertText}
</Snackbar>
</Modal>
);
};

export default AlertBar;
12 changes: 5 additions & 7 deletions www/js/components/DiaryButton.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';
import { StyleSheet } from 'react-native';
import { Button, ButtonProps, useTheme } from 'react-native-paper';
import { Button, ButtonProps, Icon, useTheme } from 'react-native-paper';
import color from 'color';
import { Icon } from './Icon';

type Props = ButtonProps & { fillColor?: string; borderColor?: string };
const DiaryButton = ({ children, fillColor, borderColor, icon, ...rest }: Props) => {
Expand All @@ -19,7 +18,7 @@ const DiaryButton = ({ children, fillColor, borderColor, icon, ...rest }: Props)
contentStyle={s.buttonContent}
{...rest}>
<>
{icon && <Icon icon={icon} iconColor={textColor} size={18} style={s.icon} />}
{icon && <Icon source={icon} color={textColor} size={18} />}
{children}
</>
</Button>
Expand All @@ -39,15 +38,14 @@ const s = StyleSheet.create({
height: 25,
},
label: {
display: 'flex',
alignItems: 'center',
marginHorizontal: 5,
marginVertical: 0,
fontSize: 13,
fontWeight: '500',
whiteSpace: 'nowrap',
},
icon: {
marginRight: 4,
verticalAlign: 'middle',
gap: 4,
},
});

Expand Down
31 changes: 0 additions & 31 deletions www/js/components/Icon.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions www/js/components/LeafletView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ const LeafletView = ({ geojson, opts, downscaleTiles, cacheHtml, ...otherProps }
const startIcon = L.divIcon({ className: 'leaflet-div-icon-start', iconSize: [18, 18] });
const stopIcon = L.divIcon({ className: 'leaflet-div-icon-stop', iconSize: [18, 18] });

const pointToLayer = (feature, latlng) => {
function pointToLayer(feature, latlng) {
switch (feature.properties.feature_type) {
case 'start_place':
return L.marker(latlng, { icon: startIcon });
Expand All @@ -175,6 +175,6 @@ const pointToLayer = (feature, latlng) => {
alert('Found unknown type in feature' + feature);
return L.marker(latlng);
}
};
}

export default LeafletView;
Loading
Loading