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

Select filter with default value #42

Merged
merged 5 commits into from
Feb 4, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions frontend/app/api/concepts.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"label": "Picture Format",
"type": "SELECT",
"description": "The original picture format",
"defaultValue": "hdtv",
"options": [
{
"value": "sdtv",
Expand Down
8 changes: 8 additions & 0 deletions frontend/lib/js/category-trees/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ export const loadTrees = (datasetId: DatasetIdType) => {
r => {
dispatch(loadTreesSuccess(r));

// Assign default select filter values
Object.values(r.concepts).forEach(concept => concept.tables.forEach(table =>
table.filters.forEach(filter => {
if (filter.defaultValue)
filter.value = filter.defaultValue;
})
));

// In the future: Data could be cached, version could be checked and
// further data only loaded when necessary
if (r.version > -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const findActiveFilters = (concept) => (
concept.tables.some(table =>
table.exclude || (table.filters && table.filters.some(filter =>
// multi select filters create an array that is not nulled when empty
filter.value && Object.keys(filter.value).length > 0
filter.value && filter.value !== filter.defaultValue && Object.keys(filter.value).length > 0
))
)
);
Expand Down
1 change: 1 addition & 0 deletions frontend/lib/js/form-components/InputSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const InputSelect = (props: PropsType) => {
? props.input.onChange(field.value)
: props.input.onChange(null)
}
clearable={props.input.clearable}
disabled={!!props.disabled}
placeholder={T.translate('reactSelect.placeholder')}
backspaceToRemoveMessage={T.translate('reactSelect.backspaceToRemove')}
Expand Down
1 change: 1 addition & 0 deletions frontend/lib/js/query-node-modal/ParameterTableFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const ParameterTableFilters = (props: PropsType) => (
return (
<InputSelect
input={{
clearable: filter.value !== filter.defaultValue,
value: filter.value,
onChange: (value) => props.onSetFilterValue(filterIdx, value),
}}
Expand Down
15 changes: 9 additions & 6 deletions frontend/lib/js/standard-query-editor/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const setElementProperties = (node, andIdx, orIdx, properties) => {
};

return setGroupProperties(node, andIdx, groupProperties);
}
};

const setAllElementsProperties = (node, properties) => {
return node.map(group => ({
Expand All @@ -120,11 +120,11 @@ const setAllElementsProperties = (node, properties) => {
...properties
}))
}));
}
};

const nodeHasActiveFilters = (node, tables = node.tables) => {
return node.excludeTimestamps || nodeHasActiveTableFilters(tables);
}
};

const dropAndNode = (state, action) => {
const group = state[state.length - 1];
Expand Down Expand Up @@ -220,7 +220,7 @@ const nodeHasActiveTableFilters = (tables) => {
const hasTableValue = tables
.some(table =>
table.filters &&
table.filters.some(filter => !isEmpty(filter.value))
table.filters.some(filter => !isEmpty(filter.value) && filter.value !== filter.defaultValue)
);

const hasExcludedTable = tables.some(table => table.exclude);
Expand All @@ -245,7 +245,7 @@ const updateNodeTables = (state, andIdx, orIdx, tables) => {
const properties = {
tables,
hasActiveFilters: nodeHasActiveFilters(node, tables)
}
};

return setElementProperties(state, andIdx, orIdx, properties);
};
Expand Down Expand Up @@ -294,6 +294,9 @@ const setNodeFilterProperties = (state, action, obj) => {
);
}

if (properties.value === undefined && filter.defaultValue)
properties.value = filter.defaultValue;

const newTable = {
...table,
filters: [
Expand Down Expand Up @@ -342,7 +345,7 @@ const resetNodeAllFilters = (state, action) => {
// $FlowFixMe
? table.filters.map((filter) => ({
...filter,
value: null
value: filter.defaultValue
}))
: null;

Expand Down