From c35789fa3f7ac3355c07e4ae2557361e7fa74a47 Mon Sep 17 00:00:00 2001 From: Renaud Heluin Date: Wed, 24 May 2023 08:38:27 +0000 Subject: [PATCH 1/2] fix --- src/components/filters-bar.js | 111 ++++++++++++++++++++++++---------- 1 file changed, 79 insertions(+), 32 deletions(-) diff --git a/src/components/filters-bar.js b/src/components/filters-bar.js index 31fa2792..01542262 100755 --- a/src/components/filters-bar.js +++ b/src/components/filters-bar.js @@ -59,12 +59,19 @@ function FiltersBar({ // console.log(`selectedFilters`, selectedFilters) // console.log(type, propertyToMatch) + // reset + if (type === 'reset') { + // console.log(`RESET`) + // fill w/ default/reset value + setSelectedFilters([{ propertyToMatch: allItemsLabel, type: `reset` }]) + // send reseted list outside of the component + resetList() + return + } + // console.log(type, propertyToMatch, selectedFilters) if (filterType === FiltersBar.SEARCH_TYPE_OR || forceOR) { - if (propertyToMatch === allItemsLabel) { - // fill w/ default/reset value - setSelectedFilters([{ propertyToMatch: allItemsLabel, type: `reset` }]) - // send reseted list outside of the component - resetList() + if (type === 'reset') { + // done upper in code } else { setSelectedFilters([{ propertyToMatch: propertyToMatch, type: type }]) // filter list @@ -78,11 +85,7 @@ function FiltersBar({ // console.log(type, propertyToMatch, selectedFilters) // reset if (type === 'reset') { - // console.log(`RESET`) - // fill w/ default/reset value - setSelectedFilters([{ propertyToMatch: allItemsLabel, type: `reset` }]) - // send reseted list outside of the component - resetList() + // done upper in code } else { // console.log(`FILTER`) // rm reset filter @@ -92,7 +95,8 @@ function FiltersBar({ } // add new filter only let hasFilter = false - tmpFilters.map(filter => { + let hasTypeFilter = false + tmpFilters.forEach(filter => { if ( filter?.type === type && filter?.propertyToMatch === propertyToMatch && @@ -100,33 +104,76 @@ function FiltersBar({ ) { hasFilter = true } + if (filter?.type === type && hasTypeFilter !== true) { + hasTypeFilter = true + } }) // console.log(`hasFilter`, hasFilter) - if (!hasFilter) { - // add to setSelectedFilters listened by buttons - tmpFilters.push({ propertyToMatch: propertyToMatch, type: type }) - setSelectedFilters(tmpFilters) - // trics to refresh bt - forceUpdate() - // filter list - const tmpList = [] - // console.log(`current`, type, propertyToMatch) - fullList.map(item => { - // console.log(`item`, _.get(item, type)) - selectedFilters.map(selected => { - if (_.get(item, type) === selected.propertyToMatch) { - tmpList.push(item) - } - }) - }) - // send filtered list outside of the component - filteredList(tmpList) + if (hasTypeFilter && !hasFilter) { + // console.log(`rm and replace`) + removeFilter(tmpFilters, propertyToMatch, type) + addFilter(tmpFilters, propertyToMatch, type) + // return + } else if (hasTypeFilter && hasFilter) { + // console.log(`rm filter`) + // removeFilter(tmpFilters, propertyToMatch, type) + } else if (!hasFilter) { + // console.log(`add`) + addFilter(tmpFilters, propertyToMatch, type) } } - console.log(type, propertyToMatch, selectedFilters) + // console.log(type, propertyToMatch, selectedFilters) } } + const addFilter = (tmpFilters = [], propertyToMatch, type) => { + // add to setSelectedFilters listened by buttons + // console.log(`addFilter`) + tmpFilters.push({ propertyToMatch: propertyToMatch, type: type }) + setSelectedFilters(tmpFilters) + updateFilter() + } + + const removeFilter = (tmpFilters = [], propertyToMatch, type) => { + // console.log(`removeFilter`) + let posExact = -1 + let posType = -1 + tmpFilters.forEach((item, index) => { + if (item.type === type) { + posType = index + } + if (item.propertyToMatch === propertyToMatch && item.type === type) { + posExact = index + posType = -1 + } + }) + if (posType !== -1) tmpFilters = _.pullAt(tmpFilters, [posType]) + if (posExact !== -1) tmpFilters = _.pullAt(tmpFilters, [posExact]) + setSelectedFilters(tmpFilters) + updateFilter() + } + + const updateFilter = () => { + // console.log(`removeFilter`) + // trics to refresh bt + forceUpdate() + // filter list + const tmpList = [] + // console.log(`current`, type, propertyToMatch) + fullList.forEach(item => { + let count = 0 + selectedFilters.forEach(selected => { + // console.log(`item.${selected.type}`, _.get(item, selected.type)) + if (_.get(item, selected.type) === selected.propertyToMatch) { + count = count + 1 + } + }) + if (selectedFilters.length === count) tmpList.push(item) + }) + // send filtered list outside of the component + filteredList(tmpList) + } + // select method const filterSelect = event => { @@ -215,7 +262,7 @@ function FiltersBar({ // value={object.type} value={JSON.stringify(val)} label={`${key} (${value})`} - textContent={`${key} (${value})`} + // textContent={`${key} (${value})`} selected={getBtState(object.type, key) || null} >{`${key} (${value})`} ) From 6be95e76738f7b428068bfb14d3d1b768b7c1dca Mon Sep 17 00:00:00 2001 From: Renaud Heluin Date: Wed, 24 May 2023 08:41:35 +0000 Subject: [PATCH 2/2] add extensions Review and manage your GitHub pull requests and issues directly in VS Code --- .devcontainer/devcontainer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 451a1e11..0b670e85 100755 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -38,7 +38,8 @@ "yzhang.markdown-all-in-one", "adam-bender.commit-message-editor", "mhutchie.git-graph", - "unifiedjs.vscode-mdx" + "unifiedjs.vscode-mdx", + "GitHub.vscode-pull-request-github" ] } },