Skip to content

Commit

Permalink
Merge pull request #4020 from beyondessential/dev
Browse files Browse the repository at this point in the history
merge in latest dev for testing
  • Loading branch information
avaek authored Jul 6, 2022
2 parents 9eac74c + 4f93133 commit cdce529
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,26 @@ describe('measures', () => {
const display3 = getMeasureDisplayInfo({ questionC: 0.5 }, [optionsSpectrum]);
expect(display3).toHaveProperty('color', 'hsl(50, 100%, 50%)');
});

it('should support coloured radius', () => {
// A coloured radius will choose colour from a spectrum option, and pick radius size from a radius option
const questionAValue = 100;
const display = getMeasureDisplayInfo(
{
questionC: 0.5,
questionA: questionAValue,
},
[
{
...optionsSpectrum,
scaleType: 'performanceDesc',
},
{ ...optionsRadius, key: 'questionA' },
],
);
expect(display).toHaveProperty('color', 'hsl(50, 100%, 50%)');
expect(display).toHaveProperty('radius', questionAValue);
});
});

describe('popup', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/web-frontend/src/containers/mobile/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ export const DashboardComponent = ({

const filterItems = dashboards.map(({ dashboardName }) => ({
label: dashboardName,
id: dashboardName,
code: dashboardName,
value: dashboardName,
}));

const currentFilter = filterItems.find(item => item.id === currentDashboardName) || {
const currentFilter = filterItems.find(item => item.code === currentDashboardName) || {
label: 'General',
id: 'General',
code: 'General',
};

return (
Expand Down
6 changes: 1 addition & 5 deletions packages/web-frontend/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ export { isMobile, delayMobileTapCallback } from './mobile';
export { getCenterAndZoomForBounds } from './getCenterAndZoomForBounds';
export { getOrgUnitPhotoUrl } from './getOrgUnitPhotoUrl';
export { getMapUrl } from './getMapUrl';
export {
processMeasureInfo,
getSingleFormattedValue,
flattenNumericalMeasureData,
} from './measures';
export { processMeasureInfo, flattenNumericalMeasureData } from './measures';
export {
getMapOverlaysFromHierarchy,
checkHierarchyIncludesMapOverlayCodes,
Expand Down
94 changes: 0 additions & 94 deletions packages/web-frontend/src/utils/measures.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
} from '@tupaia/ui-components/lib/map';
import { VALUE_TYPES } from '../components/View/constants';
import { MAP_COLORS } from '../styles';
import { formatDataValue } from './formatters';
import { MARKER_TYPES, SCALE_TYPES } from '../constants';

export const MEASURE_TYPE_ICON = 'icon';
Expand Down Expand Up @@ -104,27 +103,6 @@ const getNullValueMapping = type => {
return baseMapping;
};

function getFormattedValue(value, type, valueInfo, scaleType, valueType, submissionDate) {
switch (type) {
case MEASURE_TYPE_SPECTRUM:
case MEASURE_TYPE_SHADED_SPECTRUM:
if (scaleType === SCALE_TYPES.TIME) {
return `last submission on ${submissionDate}`;
}
return formatDataValue(value, valueType);
case MEASURE_TYPE_RADIUS:
case MEASURE_TYPE_ICON:
case MEASURE_TYPE_COLOR:
case MEASURE_TYPE_SHADING:
if (scaleType === SCALE_TYPES.TIME) {
return `last submission on ${submissionDate}`;
}
return valueInfo.name || value;
default:
return value;
}
}

const getSpectrumScaleValues = (measureData, measureOption) => {
const { key, scaleType, startDate, endDate } = measureOption;

Expand Down Expand Up @@ -223,78 +201,6 @@ export function processMeasureInfo(response) {
};
}

function getValueInfo(value, valueMapping, hiddenValues = {}) {
if (!value && typeof value !== 'number' && valueMapping.null) {
// use 'no data' value
const nullValue = hiddenValues.null || hiddenValues[valueMapping.null.value];

return {
...valueMapping.null,
isHidden: nullValue,
};
}

const matchedValue = valueMapping[value];

if (!matchedValue) {
// use 'other' value
return {
...valueMapping.other,
isHidden: hiddenValues.other,
value,
};
}

return {
...matchedValue,
isHidden: hiddenValues[matchedValue.value],
};
}

export function getFormattedInfo(orgUnitData, measureOption) {
const { key, valueMapping, type, displayedValueKey, scaleType, valueType } = measureOption;

const value = orgUnitData[key];
const valueInfo = getValueInfo(value, valueMapping);

if (
displayedValueKey &&
(orgUnitData[displayedValueKey] || orgUnitData[displayedValueKey] === 0)
) {
return {
formattedValue: formatDataValue(
orgUnitData[displayedValueKey],
valueType,
orgUnitData.metadata,
),
valueInfo,
};
}

// note: dont use !value here, as 0 is a valid value.
if (value === null || value === undefined) {
return { formattedValue: valueInfo.name || 'No data', valueInfo };
}

return {
formattedValue: getFormattedValue(
value,
type,
valueInfo,
scaleType,
valueType,
orgUnitData.submissionDate,
),
valueInfo,
};
}

export function getSingleFormattedValue(orgUnitData, measureOptions) {
// For situations where we can only show one value, just show the value
// of the first measure.
return getFormattedInfo(orgUnitData, measureOptions[0]).formattedValue;
}

// Take a measureData array where the [key]: value is a number
// and filters NaN values (e.g. undefined).
export function flattenNumericalMeasureData(measureData, key) {
Expand Down

0 comments on commit cdce529

Please sign in to comment.