Skip to content

Commit 70f1c65

Browse files
authored
Fix open state in combobox (#2797)
* Fix open state in combobox * Improve filter suggestions when using the `contains` filter * Support contains filter type for utm filter group * Remove console.log
1 parent 66be99b commit 70f1c65

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

assets/.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"env": {
3-
"browser": true
3+
"browser": true,
4+
"es6": true
45
},
56
"extends": ["eslint:recommended",
67
"plugin:react/recommended",

assets/js/dashboard/components/combobox.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export default function PlausibleCombobox(props) {
9999

100100
function fetchOptions(query) {
101101
setLoading(true)
102+
setOpen(true)
102103

103104
return props.fetchOptions(query).then((loadedOptions) => {
104105
setLoading(false)
@@ -119,7 +120,6 @@ export default function PlausibleCombobox(props) {
119120
if (!isOpen) {
120121
fetchOptions(input)
121122
searchRef.current.focus()
122-
setOpen(true)
123123
} else {
124124
setInput('')
125125
setOpen(false)
@@ -186,11 +186,16 @@ export default function PlausibleCombobox(props) {
186186
Loading options...
187187
</div>
188188
)}
189-
{ noMatchesFound && (
189+
{ noMatchesFound && !props.freeChoice && (
190190
<div className="relative cursor-default select-none py-2 px-4 text-gray-700 dark:text-gray-300">
191191
No matches found in the current dashboard. Try selecting a different time range or searching for something different
192192
</div>
193193
)}
194+
{ noMatchesFound && props.freeChoice && (
195+
<div className="relative cursor-default select-none py-2 px-4 text-gray-700 dark:text-gray-300">
196+
Start typing to apply filter
197+
</div>
198+
)}
194199
{ matchesFound && (
195200
visibleOptions.map((option, i) => {
196201
const text = option.freeChoice ? `Filter by '${option.label}'` : option.label

assets/js/dashboard/stats/modals/filter.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ function getFormState(filterGroup, query) {
3535
}, {})
3636
}
3737

38-
function supportsContains(filterName) {
39-
return ['page', 'entry_page', 'exit_page'].includes(filterName)
40-
}
41-
4238
function supportsIsNot(filterName) {
4339
return !['goal', 'prop_key'].includes(filterName)
4440
}
@@ -122,6 +118,8 @@ class FilterModal extends React.Component {
122118
fetchOptions(filter) {
123119
return (input) => {
124120
const { query, formState } = this.state
121+
if (formState[filter].type === FILTER_TYPES.contains) {return Promise.resolve([])}
122+
125123
const formFilters = Object.fromEntries(
126124
Object.entries(formState).map(([filter, {type, clauses}]) => [filter, toFilterQuery(type, clauses)])
127125
)
@@ -147,6 +145,8 @@ class FilterModal extends React.Component {
147145
return filterVal
148146
} else if (filterVal.startsWith('!')) {
149147
return filterVal
148+
} else if (filterVal.startsWith('~')) {
149+
return null
150150
} else {
151151
return '!' + filterVal
152152
}
@@ -178,9 +178,12 @@ class FilterModal extends React.Component {
178178
this.props.history.replace({ pathname: siteBasePath(this.props.site), search: queryString.toString() })
179179
}
180180

181+
isFreeChoice() {
182+
return ['page', 'utm'].includes(this.state.selectedFilterGroup)
183+
}
184+
181185
renderSearchBox(filter) {
182-
const freeChoice = this.state.selectedFilterGroup === 'page'
183-
return <Combobox fetchOptions={this.fetchOptions(filter)} freeChoice={freeChoice} values={this.state.formState[filter].clauses} onChange={this.onChange(filter)} placeholder={`Select ${withIndefiniteArticle(formattedFilters[filter])}`} />
186+
return <Combobox fetchOptions={this.fetchOptions(filter)} freeChoice={this.isFreeChoice()} values={this.state.formState[filter].clauses} onChange={this.onChange(filter)} placeholder={`Select ${withIndefiniteArticle(formattedFilters[filter])}`} />
184187
}
185188

186189
renderFilterInputs() {
@@ -228,7 +231,7 @@ class FilterModal extends React.Component {
228231
<div className="py-1">
229232
{this.renderTypeItem(filterName, FILTER_TYPES.is, true)}
230233
{this.renderTypeItem(filterName, FILTER_TYPES.isNot, supportsIsNot(filterName))}
231-
{this.renderTypeItem(filterName, FILTER_TYPES.contains, supportsContains(filterName))}
234+
{this.renderTypeItem(filterName, FILTER_TYPES.contains, this.isFreeChoice())}
232235
</div>
233236
</Menu.Items>
234237
</Transition>

assets/js/dashboard/util/filters.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ try {
3131
NON_ESCAPED_PIPE_REGEX = '|'
3232
}
3333

34-
console.log(NON_ESCAPED_PIPE_REGEX)
35-
3634
const ESCAPED_PIPE = '\\|'
3735

3836
function escapeFilterValue(value) {

0 commit comments

Comments
 (0)