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

merge in latest dev for testing #4020

Merged
merged 3 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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