Skip to content

Commit

Permalink
chore: cleanup and code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaclennan committed Sep 10, 2020
1 parent 2e25a4a commit e3d55c0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"ky": "^0.23.0",
"lodash": "^4.17.19",
"mapeo-offline-map": "^2.0.0",
"mapeo-schema": "^2.0.1",
"mapeo-schema": "^2.0.2",
"nodejs-mobile-react-native": "^0.6.1",
"patch-package": "^6.2.2",
"path": "^0.12.7",
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/screens/Observation/ObservationView.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const ObservationView = ({
onPressDelete,
}: ODVProps) => {
const intl = useIntl();
const { formatMessage: t, formatDate } = intl;
const { formatMessage: t } = intl;
const deviceId = useDeviceId();
const isMine = deviceId === observation.value.deviceId;
const { lat, lon, attachments } = observation.value;
Expand Down
21 changes: 20 additions & 1 deletion src/frontend/sharedComponents/FormattedData.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ export const FormattedCoords = ({ lat, lon }: { lat: number, lon: number }) => {
return <>{formatCoords({ lon, lat })}</>;
};

// Render the translated value of a translatable Field property (one of
// `label`, `placeholder` or `helperText`). `label` will always render
// something: if it is undefined or an empty string, then it will use the field
// key as the label. `placeholder` and `helperText` will render to null if they
// are not defined.
export const FormattedFieldProp = ({
field,
propName,
}: {
field: Field,
propName: "label" | "placeholder",
propName: "label" | "placeholder" | "helperText",
}) => {
const { formatMessage: t } = useIntl();
const fieldKey = Array.isArray(field.key) ? field.key[0] : field.key;
Expand All @@ -55,6 +60,14 @@ export const FormattedFieldProp = ({
return <>{value}</>;
};

// Render a field value as a string. If the value is an array, convert to string
// and join with `, `. If the field is a select_one or select_multiple field,
// then use `field.option.label` to display the value, if a label is defined.
// Translate the field value if a translation is defined.
//
// TODO: Consider an API like
// https://formatjs.io/docs/react-intl/components#formatteddateparts to enable
// formatting of individual items in an array value.
export const FormattedFieldValue = ({
value,
field,
Expand All @@ -80,6 +93,8 @@ export const FormattedFieldValue = ({
return <>{formattedValue || t(m.noAnswer)}</>;
};

// Format the created_at date of an observation as either a datetime, or a
// relative datetime (e.g. "3 minutes ago")
export const FormattedObservationDate = ({
observation,
variant,
Expand All @@ -98,6 +113,8 @@ export const FormattedObservationDate = ({
}
};

// Format the translated preset name, with a fallback to "Observation" if no
// preset is defined
export const FormattedPresetName = ({
preset,
}: {|
Expand All @@ -111,6 +128,8 @@ export const FormattedPresetName = ({
return <>{name}</>;
};

// TODO: Better hangling of boolean and null values (we don't create these
// anywhere yet)
function getValueLabel(
value: null | boolean | number | string,
field: Field
Expand Down

0 comments on commit e3d55c0

Please sign in to comment.