Skip to content

Commit

Permalink
Refactor resource types filter to a filters tree (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Jul 28, 2021
1 parent 30e1394 commit bc11ab9
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,34 @@ function FilterItems({
}
if (field.type === 'filter') {
const customFilters = castArray(values.f || []);
const filterChild = () => {
return field.items && field.items.map((item) => {
const active = customFilters.find(value => value === item.id);
return (
<Checkbox
type="checkbox"
checked={!!active}
value={item.id}
onChange={() => {
onChange({
f: active
? customFilters.filter(value => value !== item.id)
: [...customFilters, item.id]
});
}}
>
<Message msgId={item.labelId}/>
</Checkbox>
);
} );
};
const active = customFilters.find(value => value === field.id);
const parentFilterIds = [
field.id,
...(field.items
? field.items.map((item) => item.id)
: [])
];
return (
<FormGroup controlId={'gn-radio-filter-' + field.id}>
<Checkbox
Expand All @@ -106,11 +133,12 @@ function FilterItems({
onChange={() => {
onChange({
f: active
? customFilters.filter(value => value !== field.id)
? customFilters.filter(value => !parentFilterIds.includes(value))
: [...customFilters, field.id]
});
}}>
<Message msgId={field.labelId}/>
{!!active && filterChild()}
</Checkbox>
</FormGroup>
);
Expand Down
19 changes: 13 additions & 6 deletions geonode_mapstore_client/client/js/selectors/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,19 @@ export const getCustomMenuFilters = (state) => {
const confWithHandleExpression = mapObjectFunc(v => handleExpression(getMonitorState, {}, v))(geoNodeConfiguration);
const filtersFormItemsAllowed = reduceArrayRecursive(confWithHandleExpression?.filtersForm?.items, (item) => filterMenuItems(userState, item));
const menuFilters = [
...filtersFormItemsAllowed.reduce((acc, item) => [
...acc,
...(item.type === 'group'
? item.items || []
: [item])
], [])
...filtersFormItemsAllowed
.reduce((acc, item) => [
...acc,
...(item.type === 'group'
? item.items || []
: [item])
], [])
.reduce((acc, item) => [
...acc,
...(item.type === 'filter' && item.items
? item.items && [...item.items, item] || []
: [item])
], [])
].filter(({ type }) => type === 'filter');
return menuFilters;
};
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@
{
"type": "group",
"labelId": "gnhome.customFiltersTitle",
"authenticated": true,
"items": [
{
"id": "my-resources",
Expand All @@ -213,6 +212,72 @@
},
"authenticated": true
},
{
"id": "dataset",
"labelId": "gnhome.datasets",
"type": "filter",
"query": {
"filter{resource_type.in}": "dataset"
},
"items": [
{
"id": "store-vector",
"labelId": "gnhome.vector",
"type": "filter",
"query": {
"filter{subtype.in}": "vector"
}
},
{
"id": "store-raster",
"labelId": "gnhome.raster",
"type": "filter",
"query": {
"filter{subtype.in}": "raster"
}
},
{
"id": "store-remote",
"labelId": "gnhome.remote",
"type": "filter",
"query": {
"filter{subtype.in}": "remote"
}
},
{
"id": "store-time-series",
"labelId": "gnhome.timeSeries",
"type": "filter",
"query": {
"filter{subtype.in}": "vector_time"
}
}
]
},
{
"id": "documents",
"labelId": "gnhome.documents",
"type": "filter",
"query": {
"filter{resource_type.in}": "document"
}
},
{
"id": "maps",
"labelId": "gnhome.maps",
"type": "filter",
"query": {
"filter{resource_type.in}": "map"
}
},
{
"id": "geostory",
"labelId": "gnhome.geostory",
"type": "filter",
"query": {
"filter{resource_type.in}": "geostory"
}
},
{
"id": "favorite",
"labelId": "gnhome.favorites",
Expand All @@ -228,12 +293,6 @@
"type": "divider",
"authenticated": true
},
{
"labelId": "gnhome.resourceTypes",
"placeholderId": "gnhome.resourceTypesPlaceholder",
"type": "select",
"suggestionsRequestKey": "resourceTypes"
},
{
"labelId": "gnhome.categories",
"placeholderId": "gnhome.categoriesPlaceholder",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"register": "Registrieren",
"signIn": "Anmelden",
"filters": "Filter",
"vector": "Vektor",
"raster": "Raster",
"remote": "Remote",
"timeSeries": "Zeitfolgen",
"filtersCount": "{count, plural, =0 { Filter } other {Filter (#)}}",
"admin": "Admin",
"logOut": "Ausloggen",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
"register": "Register",
"signIn": "Sign in",
"filters": "Filters",
"vector": "Vector",
"raster": "Raster",
"remote": "Remote",
"timeSeries": "Time series",
"filtersCount": "{count, plural, =0 { Filters } other {Filters (#)}}",
"admin": "Admin",
"logOut": "Log out",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"register": "Registrarse",
"signIn": "Ingresar",
"filters": "Filtros",
"vector": "Vector",
"raster": "Raster",
"remote": "Remota",
"timeSeries": "Series de tiempo",
"filtersCount": "{count, plural, =0 { Filtros } other {Filtros (#)}}",
"admin": "Administración",
"logOut": "Salir",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"register": "S'inscrire",
"signIn": "Connexion",
"filters": "Filtres",
"vector": "Vecteur",
"raster": "Raster",
"remote": "Reculé",
"timeSeries": "Des séries chronologiques",
"filtersCount": "{count, plural, =0 { Filtres } other {Filtres (#)}}",
"admin": "Administration",
"logOut": "Se déconnecter",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"register": "Registrati",
"signIn": "Accedi",
"filters": "Filtri",
"vector": "Vettoriale",
"raster": "Raster",
"remote": "Remoto",
"timeSeries": "Serie temporale vettoriale",
"filtersCount": "{count, plural, =0 { Filtri } other {Filtri (#)}}",
"myresources": "Risorse",
"mylink": "I miei Link",
Expand Down

0 comments on commit bc11ab9

Please sign in to comment.