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

Money range fixes #98

Merged
merged 4 commits into from
Mar 27, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@ const toggleTable = (value, valueIdx, conceptIdx, tableIdx, isExcluded) => {
];
};

const setFilterValue = (value, valueIdx, conceptIdx, tableIdx, filterIdx, filterValue) => {
const setFilterValue = (
value,
valueIdx,
conceptIdx,
tableIdx,
filterIdx,
filterValue,
formattedFilterValue
) => {
const concepts = value[valueIdx].concepts;
const tables = concepts[conceptIdx].tables;
const filters = tables[tableIdx].filters;
Expand All @@ -123,7 +131,8 @@ const setFilterValue = (value, valueIdx, conceptIdx, tableIdx, filterIdx, filter
...filters.slice(0, filterIdx),
{
...filters[filterIdx],
value: filterValue
value: filterValue,
formattedValue: formattedFilterValue,
},
...filters.slice(filterIdx + 1),
]
Expand Down Expand Up @@ -164,7 +173,8 @@ const switchFilterMode = (value, valueIdx, conceptIdx, tableIdx, filterIdx, mode
{
...filters[filterIdx],
mode: mode,
value: null
value: null,
formattedValue: null,
},
...filters.slice(filterIdx + 1),
]
Expand Down Expand Up @@ -279,15 +289,23 @@ export const FormConceptGroup = (props: PropsType) => (
toggleTable(props.input.value, valueIdx, conceptIdx, tableIdx, isExcluded)
)
}
onSetFilterValue={(valueIdx, conceptIdx, tableIdx, filterIdx, filterValue) =>
onSetFilterValue={(
valueIdx,
conceptIdx,
tableIdx,
filterIdx,
filterValue,
formattedFilterValue
) =>
props.input.onChange(
setFilterValue(
props.input.value,
valueIdx,
conceptIdx,
tableIdx,
filterIdx,
filterValue
filterValue,
formattedFilterValue
)
)
}
Expand Down
5 changes: 1 addition & 4 deletions frontend/lib/js/form-components/ClearableInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ const ClearableInput = (props: PropsType) => {
type={props.inputType}
onValueChange={(values: NumberFormatValueType) => {
const { formattedValue, floatValue } = values;
props.onChange({
formattedValue,
raw: floatValue * (T.translate('moneyRange.factor') || 1)
});
props.onChange(floatValue * (T.translate('moneyRange.factor') || 1), formattedValue);
}}
value={props.formattedValue}
{...props.inputProps}
Expand Down
36 changes: 25 additions & 11 deletions frontend/lib/js/form-components/InputRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ const InputRange = (props: PropsType) => {

const factor = T.translate('moneyRange.factor') || 1;
const minFormattedValue =
(formattedValue && formattedValue.min) || (parseInt(minValue) / factor) || '';
(formattedValue && formattedValue.min) || (parseInt(minValue) / factor) || null;
const maxFormattedValue =
(formattedValue && formattedValue.max) || (parseInt(maxValue) / factor) || '';
(formattedValue && formattedValue.max) || (parseInt(maxValue) / factor) || null;
const exactFormattedValue =
(formattedValue && formattedValue.exact) || (parseInt(exactValue) / factor) || '';
(formattedValue && formattedValue.exact) || (parseInt(exactValue) / factor) || null;

const isRangeMode = props.mode === 'range';
const inputProps = {
Expand All @@ -61,16 +61,30 @@ const InputRange = (props: PropsType) => {
max: (props.limits && props.limits.max) || null,
};

const onChangeValue = (type, newValue) => {
const onChangeValue = (type, newValue, newFormattedValue) => {
const { value } = props.input;
const { formattedValue, raw } = newValue;
const nextValue = raw || null;
const nextValue = newValue || null;
const nextFormattedValue = newFormattedValue || null;

if (type === 'exact')
// SET ENTIRE VALUE TO NULL IF POSSIBLE
if (nextValue === null)
props.input.onChange(null, null);
else
props.input.onChange({
exact: nextValue
}, {
exact: nextFormattedValue
});
else if (type === 'min' || type === 'max')
if (
nextValue === null && (
(value && value.min == null && type === 'max') ||
(value && value.max == null && type === 'min')
)
)
props.input.onChange(null, null);
else
props.input.onChange({
min: value ? value.min : null,
max: value ? value.max : null,
Expand All @@ -79,10 +93,10 @@ const InputRange = (props: PropsType) => {
{
min: props.input.formattedValue ? props.input.formattedValue.min : null,
max: props.input.formattedValue ? props.input.formattedValue.max : null,
[type]: formattedValue
[type]: nextFormattedValue
});
else
props.input.onChange(null);
props.input.onChange(null, null);
};

return (
Expand Down Expand Up @@ -120,7 +134,7 @@ const InputRange = (props: PropsType) => {
input={{
value: exactValue,
formattedValue: exactFormattedValue,
onChange: (value) => onChangeValue('exact', value)
onChange: (value, formattedValue) => onChangeValue('exact', value, formattedValue)
}}
inputProps={inputProps}
/>
Expand All @@ -139,7 +153,7 @@ const InputRange = (props: PropsType) => {
input={{
value: minValue,
formattedValue: minFormattedValue,
onChange: value => onChangeValue('min', value),
onChange: (value, formattedValue) => onChangeValue('min', value, formattedValue),
}}
inputProps={inputProps}
/>
Expand All @@ -153,7 +167,7 @@ const InputRange = (props: PropsType) => {
input={{
value: maxValue,
formattedValue: maxFormattedValue,
onChange: value => onChangeValue('max', value),
onChange: (value, formattedValue) => onChangeValue('max', value, formattedValue),
}}
inputProps={inputProps}
/>
Expand Down
3 changes: 2 additions & 1 deletion frontend/lib/js/model/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const resetAllFiltersInTables = (tables: TableType[]) => {
const filters = table.filters
? table.filters.map((filter) => ({
...filter,
value: filter.defaultValue
value: filter.defaultValue,
formattedValue: undefined
}))
: null;

Expand Down
1 change: 1 addition & 0 deletions frontend/lib/js/query-node-editor/ParameterTableFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const ParameterTableFilters = (props: PropsType) => (
onChange: (value, formattedValue) =>
props.onSetFilterValue(filterIdx, value, formattedValue),
}}
unit={filter.unit}
label={filter.label}
mode={filter.mode || 'range'}
disabled={!!props.excludeTable}
Expand Down
3 changes: 2 additions & 1 deletion frontend/lib/js/standard-query-editor/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ const switchNodeFilterMode = (state, action) => {

return setNodeFilterProperties(state, action, {
mode,
value: null
value: null,
formattedValue: null,
});
};

Expand Down