Filtering by multiple custom properties (#3719)
* WIP: PropFilterRow * Get multi-behavior working * Render multiple prop filters in one * Modal reads from query string correctly * Backend support for multiple custom property filters * Add backend tests for multiple custom property filters * Disable already selected options in property keys We can't allow choosing the same property multiple times without changing the request params, which we decided against * Allow choosing any property under Behaviors > Custom props even if custom prop filter applied This was a limitation (I believe) introduced by using ARRAY JOINs to query custom properties * CHANGELOG.md * Solve credo warning about too deep nesting * Update assets/js/dashboard/stats/modals/prop-filter-modal.js Co-authored-by: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com> * Refactor internal function for clarity * Add another step -> Add another * Solve 500 error * Separate boxes per property filter * Retain other filters in props table * removeFilter behavior for props * matches_member support for custom props * filter_suggestions for prop keys should account for prop filter * find over filter * refactor appliedFilters * FILTER_TYPES => FILTER_OPERATIONS * Make add another link not wrap the whole page * Unique keys --------- Co-authored-by: RobertJoonas <56999674+RobertJoonas@users.noreply.github.com>pull/3777/head r2024.02.12-343
parent
c8b25347ed
commit
1cb7982cd9
@ -0,0 +1,85 @@
|
||||
import React from 'react'
|
||||
|
||||
import Combobox from '../../components/combobox'
|
||||
import FilterTypeSelector from "../../components/filter-type-selector";
|
||||
import { FILTER_OPERATIONS } from "../../util/filters";
|
||||
import * as api from '../../api'
|
||||
import { apiPath } from '../../util/url'
|
||||
import { TrashIcon } from '@heroicons/react/20/solid'
|
||||
|
||||
function PropFilterRow({
|
||||
id,
|
||||
query,
|
||||
site,
|
||||
propKey,
|
||||
type,
|
||||
clauses,
|
||||
showDelete,
|
||||
selectedPropKeys,
|
||||
onPropKeySelect,
|
||||
onPropValueSelect,
|
||||
onFilterTypeSelect,
|
||||
onPropDelete
|
||||
}) {
|
||||
function fetchPropKeyOptions() {
|
||||
return (input) => {
|
||||
return api.get(apiPath(site, "/suggestions/prop_key"), query, { q: input.trim() })
|
||||
}
|
||||
}
|
||||
|
||||
function fetchPropValueOptions() {
|
||||
return (input) => {
|
||||
if (type === FILTER_OPERATIONS.contains) {
|
||||
return Promise.resolve([])
|
||||
}
|
||||
|
||||
|
||||
const key = propKey?.value
|
||||
const updatedQuery = { ...query, filters: { ...query.filters, props: { [key]: '!(none)' } } }
|
||||
return api.get(apiPath(site, "/suggestions/prop_value"), updatedQuery, { q: input.trim() })
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-12 mt-6">
|
||||
<div className="col-span-4">
|
||||
<Combobox
|
||||
className="mr-2"
|
||||
fetchOptions={fetchPropKeyOptions()}
|
||||
singleOption={true}
|
||||
values={propKey ? [propKey] : []}
|
||||
onSelect={(value) => onPropKeySelect(id, value)}
|
||||
placeholder={'Property'}
|
||||
disabledOptions={selectedPropKeys}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-3 mx-2">
|
||||
<FilterTypeSelector
|
||||
isDisabled={!propKey}
|
||||
forFilter={'prop_value'}
|
||||
onSelect={(value) => onFilterTypeSelect(id, value)}
|
||||
selectedType={type}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-4">
|
||||
<Combobox
|
||||
isDisabled={!propKey}
|
||||
fetchOptions={fetchPropValueOptions()}
|
||||
values={clauses}
|
||||
onSelect={(value) => onPropValueSelect(id, value)}
|
||||
placeholder={'Value'}
|
||||
freeChoice={type == FILTER_OPERATIONS.contains}
|
||||
/>
|
||||
</div>
|
||||
{showDelete && (
|
||||
<div className="col-span-1 flex flex-col justify-center">
|
||||
<a className="ml-2 text-red-600 h-5 w-5 cursor-pointer" onClick={() => onPropDelete(id)}>
|
||||
<TrashIcon />
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default PropFilterRow
|
||||
Loading…
Reference in New Issue