diff --git a/assets/css/app.css b/assets/css/app.css index 255a904fc..354cffc1f 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -318,3 +318,71 @@ iframe[hidden] { .filter-list-text:hover ~ .filter-list-remove { display: none; } + +.filter-select__control:focus-within { + box-shadow: rgb(255, 255, 255) 0px 0px 0px 0px, rgb(99, 102, 241) 0px 0px 0px 1px, rgba(0, 0, 0, 0) 0px 0px 0px 0px; /* indigo-500 */ +} + +.filter-select__control { + @apply dark:bg-gray-900 border-gray-300 dark:border-gray-700 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500; +} + +.filter-select__control:hover { + @apply cursor-pointer; + border-color: rgb(156, 163, 175) !important; /* gray-400 */ +} + +.filter-select__indicator-separator { + @apply hidden; +} + +.filter-select__indicator { + @apply text-gray-400; +} + +.filter-select__input { + @apply w-full; +} + +.filter-select__input input { + width: 100% !important; + box-shadow: none !important; +} + +.dark .filter-select__input input { + color: rgb(209, 213, 219) !important; /* gray-300 */ +} + +.filter-select__value-container > :not(.filter-select__single-value) { + @apply w-full; +} + +.filter-select__loading-indicator { + color: rgb(79, 70, 229) !important; /* indigo-600 */ +} + +.filter-select__loading-indicator > span { + height: 1.5em; + width: 1.5em; +} + +.filter-select__single-value { + @apply dark:text-gray-400; +} + +.filter-select__menu-list { + @apply dark:bg-gray-900; +} + +.filter-select__option { + @apply dark:text-gray-300; +} + +.filter-select__option--is-focused { + background-color: rgb(165, 180, 252) !important; /* indigo-300 */ +} + +.dark .filter-select__option--is-focused { + background-color: rgb(79, 70, 229) !important; /* indigo-600 */ +} + diff --git a/assets/js/dashboard/stats/modals/filter.js b/assets/js/dashboard/stats/modals/filter.js index 2149e1f01..52225788e 100644 --- a/assets/js/dashboard/stats/modals/filter.js +++ b/assets/js/dashboard/stats/modals/filter.js @@ -1,11 +1,13 @@ import React from "react"; import { withRouter, Redirect } from 'react-router-dom' +import Datamap from 'datamaps' +import AsyncSelect from 'react-select/async' +import debounce from 'lodash.debounce' import Modal from './modal' import { parseQuery, formattedFilters, navigateToQuery } from '../../query' import Transition from "../../../transition"; import * as api from '../../api' -import Datamap from 'datamaps' class FilterModal extends React.Component { constructor(props) { @@ -15,32 +17,32 @@ class FilterModal extends React.Component { selectedFilter: "", negated: false, updatedValue: "", - filterSaved: false, - suggestions: [], - fetchSuggestionsTimeout: undefined, - focusedSuggestionIndex: -1, - preventSuggestions: true + inputValue: "", + forceReloadSuggestions: 0, + defaultOptions: [] } this.editableGoals = Object.keys(this.state.query.filters).filter(filter => !['props'].includes(filter)) this.renderSelector = this.renderSelector.bind(this) this.fetchSuggestions = this.fetchSuggestions.bind(this) this.handleKeydown = this.handleKeydown.bind(this) + this.handleSubmit = this.handleSubmit.bind(this) + this.fieldSelectRef = React.createRef() + this.debouncedFetchSuggestions = debounce((q, callback) => this.fetchSuggestions(q, callback), 150) } componentDidMount() { this.setState({ selectedFilter: this.props.match.params.field }) - - document.addEventListener("keydown", this.handleKeydown); + this.fieldSelectRef.current.focus() + document.addEventListener("keydown", this.handleKeydown) } componentDidUpdate(prevProps, prevState) { - const { query, selectedFilter, updatedValue, preventSuggestions, fetchSuggestionsTimeout } = this.state + const { query, selectedFilter, updatedValue, forceReloadSuggestions } = this.state if (prevState.selectedFilter !== selectedFilter) { - const negated = query.filters[selectedFilter] && query.filters[selectedFilter][0] == '!' && this.negationSupported(selectedFilter) + const negated = !!query.filters[selectedFilter] && query.filters[selectedFilter][0] == '!' && this.negationSupported(selectedFilter) let updatedValue = negated ? query.filters[selectedFilter].slice(1) : (query.filters[selectedFilter] || "") - clearTimeout(fetchSuggestionsTimeout) if (selectedFilter == 'country') { const allCountries = Datamap.prototype.worldTopo.objects.world.geometries; @@ -48,24 +50,8 @@ class FilterModal extends React.Component { updatedValue = selectedCountry.properties.name } - this.setState({ updatedValue, negated, suggestions: [], fetchSuggestionsTimeout: undefined, focusedSuggestionIndex: -1, noSuggestions: false }, () => { - if (selectedFilter) { - this.fetchSuggestions() - } - }) - } - - if (prevState.updatedValue !== updatedValue) { - if (!preventSuggestions || prevState.preventSuggestions) { - let fetchSuggestionsTimeout; - clearTimeout(this.state.fetchSuggestionsTimeout) - - this.setState({ suggestions: [], preventSuggestions: false, focusedSuggestionIndex: -1, noSuggestions: false }, () => { - this.setState({ fetchSuggestionsTimeout: setTimeout(this.fetchSuggestions, 200) }) - }) - } else { - this.setState({ suggestions: [], fetchSuggestionsTimeout: undefined, focusedSuggestionIndex: -1, noSuggestions: false }) - } + if (selectedFilter) this.fetchSuggestions('', (defaultOptions) => this.setState({ defaultOptions })) + this.setState({ updatedValue, inputValue: updatedValue, negated, forceReloadSuggestions: forceReloadSuggestions + 1 }) } } @@ -74,152 +60,124 @@ class FilterModal extends React.Component { } handleKeydown(e) { - const { suggestions } = this.state - let { focusedSuggestionIndex, updatedValue, preventSuggestions, selectedFilter } = this.state - const navigationKeys = ['ArrowUp', undefined, 'ArrowDown'] - - if (e.target.id !== 'suggestions_input') return true if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || e.isComposing || e.keyCode === 229) return - if ((e.key === 'Enter' || e.key === 'Tab') && suggestions[focusedSuggestionIndex]) { - updatedValue = suggestions[focusedSuggestionIndex] - focusedSuggestionIndex = -1 - preventSuggestions = true - e.preventDefault() - } - - if (navigationKeys.includes(e.key)) { - focusedSuggestionIndex += navigationKeys.indexOf(e.key) - 1 - if (focusedSuggestionIndex < 0) { - focusedSuggestionIndex = suggestions.length - 1 - } else if (focusedSuggestionIndex >= suggestions.length) { - focusedSuggestionIndex = 0 - } - e.preventDefault() + if (e.target.tagName == 'BODY' && e.key == 'Enter') { + this.handleSubmit() } - - this.setState({ focusedSuggestionIndex, updatedValue, preventSuggestions }) } negationSupported(filter) { return ['page', 'entry_page', 'exit_page'].includes(filter) } - fetchSuggestions() { - const { query, updatedValue, selectedFilter } = this.state + fetchSuggestions(searchQuery = "", callback) { + const { query, selectedFilter } = this.state const updatedQuery = { ...query, filters: { ...query.filters, [selectedFilter]: null } } if (selectedFilter == 'country') { - const matchedCountries = Datamap.prototype.worldTopo.objects.world.geometries.filter(c => c.properties.name.includes(updatedValue.trim())) + const matchedCountries = Datamap.prototype.worldTopo.objects.world.geometries.filter(c => c.properties.name.includes(searchQuery.trim())) const matches = matchedCountries.map(c => c.id) api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/suggestions/country`, updatedQuery, { q: matches }) .then((res) => { - const suggestions = res.map(code => matchedCountries.filter(c => c.id == code)[0].properties.name) - - this.setState({ suggestions, fetchSuggestionsTimeout: undefined, focusedSuggestionIndex: -1, noSuggestions: res.length == 0 }) + const result = res.map(code => matchedCountries.filter(c => c.id == code)[0].properties.name).map(r => ({ label: r, value: r })) + callback(result) }) } else { - api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/suggestions/${selectedFilter}`, updatedQuery, { q: updatedValue.trim() }) + api.get(`/api/stats/${encodeURIComponent(this.props.site.domain)}/suggestions/${selectedFilter}`, updatedQuery, { q: searchQuery.trim() }) .then((res) => { - this.setState({ suggestions: res, fetchSuggestionsTimeout: undefined, focusedSuggestionIndex: -1, noSuggestions: res.length == 0 }) + const result = res.map(r => ({ label: r, value: r })) + callback(result) }) } } renderSelector(filter) { - const { updatedValue, suggestions, inputFocused, focusedSuggestionIndex, selectedFilter } = this.state; + const { updatedValue, selectedFilter, inputValue, forceReloadSuggestions, defaultOptions } = this.state; if (!filter) return null - return
- { - this.setState({ - updatedValue: e.target.value - }) + return ( + this.debouncedFetchSuggestions(q, callback)} + placeholder='Filter value' + maxMenuHeight={250} + tabSelectsValue={false} + classNamePrefix='filter-select' + noOptionsMessage={() => ( + + + No results found in current dashboard, try removing some filters, checking your input and ensuring this {formattedFilters[selectedFilter].toLowerCase()} exists + + )} + loadingMessage={() => ( + + Loading filter suggestions + + )} + value={inputValue == '' ? { label: 'Enter a filter value', value: '' } : { label: updatedValue, value: `${updatedValue } ` }} + onChange={({ value }, a) => { + this.setState({ updatedValue: value, inputValue: value, forceReloadSuggestions: forceReloadSuggestions + 1 }) }} - onFocus={() => { - this.setState({ inputFocused: true }) + onInputChange={(value, { action }) => { + if (action == 'input-change') this.setState({ inputValue: value }) + if (action == 'menu-close' || action == 'input-blur') this.setState({ updatedValue: inputValue }) }} - onBlur={() => this.setState({ inputFocused: false })} - /> - -
-
- {suggestions.map((suggestion, index) => ( - { - this.setState({ updatedValue: suggestion, preventSuggestions: true, suggestions: [] }) - }} - > - {suggestion} - ))} -
-
-
-
+ inputValue={inputValue} + onBlur={() => this.setState({ forceReloadSuggestions: forceReloadSuggestions + 1 })} + />) } - renderBody() { - const { selectedFilter, negated, updatedValue, query, noSuggestions } = this.state; + handleSubmit() { + const { selectedFilter, negated, updatedValue } = this.state; + const validFilter = this.editableGoals.includes(selectedFilter) && updatedValue.trim() + + let finalFilterValue = (this.negationSupported(selectedFilter) && negated ? '!' : '') + updatedValue.trim() + if (selectedFilter == 'country') { + const allCountries = Datamap.prototype.worldTopo.objects.world.geometries; + const selectedCountry = allCountries.find((c) => c.properties.name === finalFilterValue) || { id: finalFilterValue }; + finalFilterValue = selectedCountry.id + } + const finalizedQuery = new URLSearchParams(window.location.search) + finalizedQuery.set(selectedFilter, finalFilterValue) + if (validFilter) { + this.setState({ finalizedQuery }) + } + } + + renderBody() { + const { selectedFilter, negated, updatedValue, query } = this.state; const validFilter = this.editableGoals.includes(selectedFilter) && updatedValue.trim() return ( - + <>

{query.filters[selectedFilter] ? 'Edit' : 'Add'} Filter

-
{ - let finalFilterValue = (this.negationSupported(selectedFilter) && negated ? '!' : '') + updatedValue.trim() - if (selectedFilter == 'country') { - const allCountries = Datamap.prototype.worldTopo.objects.world.geometries; - const selectedCountry = allCountries.find((c) => c.properties.name === finalFilterValue) || { id: finalFilterValue }; - finalFilterValue = selectedCountry.id - } - const finalizedQuery = new URLSearchParams(window.location.search) - finalizedQuery.set(selectedFilter, finalFilterValue) - - if (validFilter) { - this.setState({ finalizedQuery }) - } - }}> + - {this.negationSupported(selectedFilter) && -
+ {this.negationSupported(selectedFilter) && ( +
- } + )} {this.renderSelector(selectedFilter)} - {noSuggestions && - - - No results found in current dashboard, try removing some filters{updatedValue.trim().length ? ', checking your input' : ''} and ensuring this data exists - - } - - {query.filters[selectedFilter] && + {query.filters[selectedFilter] && ( - } - + )}
-
+ ) } render() { - const { finalizedQuery } = this.state + const { finalizedQuery } = this.state; - if (finalizedQuery) { + if (finalizedQuery) return - } return ( diff --git a/assets/package-lock.json b/assets/package-lock.json index 2fc0cafb0..2931c2272 100644 --- a/assets/package-lock.json +++ b/assets/package-lock.json @@ -21,17 +21,19 @@ "css-loader": "^3.6.0", "datamaps": "^0.5.9", "iframe-resizer": "^4.3.1", + "lodash.debounce": "^4.0.8", "mini-css-extract-plugin": "^0.8.2", "optimize-css-assets-webpack-plugin": "^5.0.3", "phoenix": "file:../deps/phoenix", "phoenix_html": "file:../deps/phoenix_html", "postcss": "^7.0.35", "postcss-loader": "^4.0.4", - "react": "^16.13.1", - "react-dom": "^16.13.1", + "react": "^17.0.1", + "react-dom": "^17.0.1", "react-flatpickr": "^3.10.5", "react-flip-move": "^3.0.4", "react-router-dom": "^5.2.0", + "react-select": "^4.3.1", "react-transition-group": "^4.4.1", "tailwindcss": "^2.0.1-compat", "terser-webpack-plugin": "^4.2.3", @@ -1125,9 +1127,9 @@ } }, "node_modules/@babel/runtime": { - "version": "7.12.5", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.12.5.tgz", - "integrity": "sha512-plcc+hbExy3McchJCEQG3knOsuh3HH+Prx1P6cLIkET/0dLuQDEnrT+s27Axgc9bqfsmNUNHfscgMUdBpC9xfg==", + "version": "7.14.0", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.14.0.tgz", + "integrity": "sha512-JELkvo/DlpNdJ7dlyw/eY7E0suy5i5GQH+Vlxaq1nsNJ+H7f4Vtv3jMeCEgRhZZQFXTjldYfQgv2qmM6M1v5wA==", "dependencies": { "regenerator-runtime": "^0.13.4" } @@ -1178,6 +1180,86 @@ "to-fast-properties": "^2.0.0" } }, + "node_modules/@emotion/cache": { + "version": "11.4.0", + "resolved": "https://registry.npmjs.org/@emotion/cache/-/cache-11.4.0.tgz", + "integrity": "sha512-Zx70bjE7LErRO9OaZrhf22Qye1y4F7iDl+ITjet0J+i+B88PrAOBkKvaAWhxsZf72tDLajwCgfCjJ2dvH77C3g==", + "dependencies": { + "@emotion/memoize": "^0.7.4", + "@emotion/sheet": "^1.0.0", + "@emotion/utils": "^1.0.0", + "@emotion/weak-memoize": "^0.2.5", + "stylis": "^4.0.3" + } + }, + "node_modules/@emotion/hash": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@emotion/hash/-/hash-0.8.0.tgz", + "integrity": "sha512-kBJtf7PH6aWwZ6fka3zQ0p6SBYzx4fl1LoZXE2RrnYST9Xljm7WfKJrU4g/Xr3Beg72MLrp1AWNUmuYJTL7Cow==" + }, + "node_modules/@emotion/memoize": { + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.7.5.tgz", + "integrity": "sha512-igX9a37DR2ZPGYtV6suZ6whr8pTFtyHL3K/oLUotxpSVO2ASaprmAe2Dkq7tBo7CRY7MMDrAa9nuQP9/YG8FxQ==" + }, + "node_modules/@emotion/react": { + "version": "11.4.0", + "resolved": "https://registry.npmjs.org/@emotion/react/-/react-11.4.0.tgz", + "integrity": "sha512-4XklWsl9BdtatLoJpSjusXhpKv9YVteYKh9hPKP1Sxl+mswEFoUe0WtmtWjxEjkA51DQ2QRMCNOvKcSlCQ7ivg==", + "dependencies": { + "@babel/runtime": "^7.13.10", + "@emotion/cache": "^11.4.0", + "@emotion/serialize": "^1.0.2", + "@emotion/sheet": "^1.0.1", + "@emotion/utils": "^1.0.0", + "@emotion/weak-memoize": "^0.2.5", + "hoist-non-react-statics": "^3.3.1" + }, + "peerDependencies": { + "@babel/core": "^7.0.0", + "react": ">=16.8.0" + }, + "peerDependenciesMeta": { + "@babel/core": { + "optional": true + }, + "@types/react": { + "optional": true + } + } + }, + "node_modules/@emotion/serialize": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@emotion/serialize/-/serialize-1.0.2.tgz", + "integrity": "sha512-95MgNJ9+/ajxU7QIAruiOAdYNjxZX7G2mhgrtDWswA21VviYIRP1R5QilZ/bDY42xiKsaktP4egJb3QdYQZi1A==", + "dependencies": { + "@emotion/hash": "^0.8.0", + "@emotion/memoize": "^0.7.4", + "@emotion/unitless": "^0.7.5", + "@emotion/utils": "^1.0.0", + "csstype": "^3.0.2" + } + }, + "node_modules/@emotion/sheet": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@emotion/sheet/-/sheet-1.0.1.tgz", + "integrity": "sha512-GbIvVMe4U+Zc+929N1V7nW6YYJtidj31lidSmdYcWozwoBIObXBnaJkKNDjZrLm9Nc0BR+ZyHNaRZxqNZbof5g==" + }, + "node_modules/@emotion/unitless": { + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.7.5.tgz", + "integrity": "sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg==" + }, + "node_modules/@emotion/utils": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@emotion/utils/-/utils-1.0.0.tgz", + "integrity": "sha512-mQC2b3XLDs6QCW+pDQDiyO/EdGZYOygE8s5N5rrzjSI4M3IejPE/JPndCBwRT9z982aqQNi6beWs1UeayrQxxA==" + }, + "node_modules/@emotion/weak-memoize": { + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/@emotion/weak-memoize/-/weak-memoize-0.2.5.tgz", + "integrity": "sha512-6U71C2Wp7r5XtFtQzYrW5iKFT67OixrSxjI4MptCHzdSVlgabczzqLe0ZSgnub/5Kp4hSbpDB1tMytZY9pwxxA==" + }, "node_modules/@eslint/eslintrc": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.2.2.tgz", @@ -7355,6 +7437,11 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==" }, + "node_modules/lodash.debounce": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", + "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=" + }, "node_modules/lodash.memoize": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", @@ -7604,6 +7691,11 @@ "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.4.tgz", "integrity": "sha512-iV3XNKw06j5Q7mi6h+9vbx23Tv7JkjEVgKHW4pimwyDGWm0OIQntJJ+u1C6mg6mK1EaTv42XQ7w76yuzH7M2cA==" }, + "node_modules/memoize-one": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/memoize-one/-/memoize-one-5.2.1.tgz", + "integrity": "sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q==" + }, "node_modules/memory-fs": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/memory-fs/-/memory-fs-0.4.1.tgz", @@ -11667,27 +11759,28 @@ } }, "node_modules/react": { - "version": "16.13.1", - "resolved": "https://registry.npmjs.org/react/-/react-16.13.1.tgz", - "integrity": "sha512-YMZQQq32xHLX0bz5Mnibv1/LHb3Sqzngu7xstSM+vrkE5Kzr9xE0yMByK5kMoTK30YVJE61WfbxIFFvfeDKT1w==", + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react/-/react-17.0.2.tgz", + "integrity": "sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==", "dependencies": { "loose-envify": "^1.1.0", - "object-assign": "^4.1.1", - "prop-types": "^15.6.2" + "object-assign": "^4.1.1" }, "engines": { "node": ">=0.10.0" } }, "node_modules/react-dom": { - "version": "16.13.1", - "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.13.1.tgz", - "integrity": "sha512-81PIMmVLnCNLO/fFOQxdQkvEq/+Hfpv24XNJfpyZhTRfO0QcmQIF/PgCa1zCOj2w1hrn12MFLyaJ/G0+Mxtfag==", + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-17.0.2.tgz", + "integrity": "sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==", "dependencies": { "loose-envify": "^1.1.0", "object-assign": "^4.1.1", - "prop-types": "^15.6.2", - "scheduler": "^0.19.1" + "scheduler": "^0.20.2" + }, + "peerDependencies": { + "react": "17.0.2" } }, "node_modules/react-flatpickr": { @@ -11704,6 +11797,17 @@ "resolved": "https://registry.npmjs.org/react-flip-move/-/react-flip-move-3.0.4.tgz", "integrity": "sha512-HyUVv9g3t/BS7Yz9HgrtYSWyRNdR2F81nkj+C5iRY675AwlqCLB5JU9mnZWg0cdVz7IM4iquoyZx70vzZv3Z8Q==" }, + "node_modules/react-input-autosize": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/react-input-autosize/-/react-input-autosize-3.0.0.tgz", + "integrity": "sha512-nL9uS7jEs/zu8sqwFE5MAPx6pPkNAriACQ2rGLlqmKr2sPGtN7TXTyDdQt4lbNXVx7Uzadb40x8qotIuru6Rhg==", + "dependencies": { + "prop-types": "^15.5.8" + }, + "peerDependencies": { + "react": "^16.3.0 || ^17.0.0" + } + }, "node_modules/react-is": { "version": "16.11.0", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.11.0.tgz", @@ -11740,6 +11844,24 @@ "tiny-warning": "^1.0.0" } }, + "node_modules/react-select": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/react-select/-/react-select-4.3.1.tgz", + "integrity": "sha512-HBBd0dYwkF5aZk1zP81Wx5UsLIIT2lSvAY2JiJo199LjoLHoivjn9//KsmvQMEFGNhe58xyuOITjfxKCcGc62Q==", + "dependencies": { + "@babel/runtime": "^7.12.0", + "@emotion/cache": "^11.4.0", + "@emotion/react": "^11.1.1", + "memoize-one": "^5.0.0", + "prop-types": "^15.6.0", + "react-input-autosize": "^3.0.0", + "react-transition-group": "^4.3.0" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0", + "react-dom": "^16.8.0 || ^17.0.0" + } + }, "node_modules/react-transition-group": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.1.tgz", @@ -12240,9 +12362,9 @@ "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" }, "node_modules/scheduler": { - "version": "0.19.1", - "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.19.1.tgz", - "integrity": "sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.20.2.tgz", + "integrity": "sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==", "dependencies": { "loose-envify": "^1.1.0", "object-assign": "^4.1.1" @@ -13444,6 +13566,11 @@ "node": ">=8.0" } }, + "node_modules/stylis": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/stylis/-/stylis-4.0.10.tgz", + "integrity": "sha512-m3k+dk7QeJw660eIKRRn3xPF6uuvHs/FFzjX3HQ5ove0qYsiygoAhwn5a3IYKaZPo5LrYD0rfVmtv1gNY1uYwg==" + }, "node_modules/sugarss": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/sugarss/-/sugarss-2.0.0.tgz", @@ -16139,9 +16266,9 @@ } }, "@babel/runtime": { - "version": "7.12.5", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.12.5.tgz", - "integrity": "sha512-plcc+hbExy3McchJCEQG3knOsuh3HH+Prx1P6cLIkET/0dLuQDEnrT+s27Axgc9bqfsmNUNHfscgMUdBpC9xfg==", + "version": "7.14.0", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.14.0.tgz", + "integrity": "sha512-JELkvo/DlpNdJ7dlyw/eY7E0suy5i5GQH+Vlxaq1nsNJ+H7f4Vtv3jMeCEgRhZZQFXTjldYfQgv2qmM6M1v5wA==", "requires": { "regenerator-runtime": "^0.13.4" } @@ -16192,6 +16319,74 @@ "to-fast-properties": "^2.0.0" } }, + "@emotion/cache": { + "version": "11.4.0", + "resolved": "https://registry.npmjs.org/@emotion/cache/-/cache-11.4.0.tgz", + "integrity": "sha512-Zx70bjE7LErRO9OaZrhf22Qye1y4F7iDl+ITjet0J+i+B88PrAOBkKvaAWhxsZf72tDLajwCgfCjJ2dvH77C3g==", + "requires": { + "@emotion/memoize": "^0.7.4", + "@emotion/sheet": "^1.0.0", + "@emotion/utils": "^1.0.0", + "@emotion/weak-memoize": "^0.2.5", + "stylis": "^4.0.3" + } + }, + "@emotion/hash": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@emotion/hash/-/hash-0.8.0.tgz", + "integrity": "sha512-kBJtf7PH6aWwZ6fka3zQ0p6SBYzx4fl1LoZXE2RrnYST9Xljm7WfKJrU4g/Xr3Beg72MLrp1AWNUmuYJTL7Cow==" + }, + "@emotion/memoize": { + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.7.5.tgz", + "integrity": "sha512-igX9a37DR2ZPGYtV6suZ6whr8pTFtyHL3K/oLUotxpSVO2ASaprmAe2Dkq7tBo7CRY7MMDrAa9nuQP9/YG8FxQ==" + }, + "@emotion/react": { + "version": "11.4.0", + "resolved": "https://registry.npmjs.org/@emotion/react/-/react-11.4.0.tgz", + "integrity": "sha512-4XklWsl9BdtatLoJpSjusXhpKv9YVteYKh9hPKP1Sxl+mswEFoUe0WtmtWjxEjkA51DQ2QRMCNOvKcSlCQ7ivg==", + "requires": { + "@babel/runtime": "^7.13.10", + "@emotion/cache": "^11.4.0", + "@emotion/serialize": "^1.0.2", + "@emotion/sheet": "^1.0.1", + "@emotion/utils": "^1.0.0", + "@emotion/weak-memoize": "^0.2.5", + "hoist-non-react-statics": "^3.3.1" + } + }, + "@emotion/serialize": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@emotion/serialize/-/serialize-1.0.2.tgz", + "integrity": "sha512-95MgNJ9+/ajxU7QIAruiOAdYNjxZX7G2mhgrtDWswA21VviYIRP1R5QilZ/bDY42xiKsaktP4egJb3QdYQZi1A==", + "requires": { + "@emotion/hash": "^0.8.0", + "@emotion/memoize": "^0.7.4", + "@emotion/unitless": "^0.7.5", + "@emotion/utils": "^1.0.0", + "csstype": "^3.0.2" + } + }, + "@emotion/sheet": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@emotion/sheet/-/sheet-1.0.1.tgz", + "integrity": "sha512-GbIvVMe4U+Zc+929N1V7nW6YYJtidj31lidSmdYcWozwoBIObXBnaJkKNDjZrLm9Nc0BR+ZyHNaRZxqNZbof5g==" + }, + "@emotion/unitless": { + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/@emotion/unitless/-/unitless-0.7.5.tgz", + "integrity": "sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg==" + }, + "@emotion/utils": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@emotion/utils/-/utils-1.0.0.tgz", + "integrity": "sha512-mQC2b3XLDs6QCW+pDQDiyO/EdGZYOygE8s5N5rrzjSI4M3IejPE/JPndCBwRT9z982aqQNi6beWs1UeayrQxxA==" + }, + "@emotion/weak-memoize": { + "version": "0.2.5", + "resolved": "https://registry.npmjs.org/@emotion/weak-memoize/-/weak-memoize-0.2.5.tgz", + "integrity": "sha512-6U71C2Wp7r5XtFtQzYrW5iKFT67OixrSxjI4MptCHzdSVlgabczzqLe0ZSgnub/5Kp4hSbpDB1tMytZY9pwxxA==" + }, "@eslint/eslintrc": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.2.2.tgz", @@ -21152,6 +21347,11 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==" }, + "lodash.debounce": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", + "integrity": "sha1-gteb/zCmfEAF/9XiUVMArZyk168=" + }, "lodash.memoize": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", @@ -21344,6 +21544,11 @@ "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.4.tgz", "integrity": "sha512-iV3XNKw06j5Q7mi6h+9vbx23Tv7JkjEVgKHW4pimwyDGWm0OIQntJJ+u1C6mg6mK1EaTv42XQ7w76yuzH7M2cA==" }, + "memoize-one": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/memoize-one/-/memoize-one-5.2.1.tgz", + "integrity": "sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q==" + }, "memory-fs": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/memory-fs/-/memory-fs-0.4.1.tgz", @@ -24596,24 +24801,22 @@ } }, "react": { - "version": "16.13.1", - "resolved": "https://registry.npmjs.org/react/-/react-16.13.1.tgz", - "integrity": "sha512-YMZQQq32xHLX0bz5Mnibv1/LHb3Sqzngu7xstSM+vrkE5Kzr9xE0yMByK5kMoTK30YVJE61WfbxIFFvfeDKT1w==", + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react/-/react-17.0.2.tgz", + "integrity": "sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==", "requires": { "loose-envify": "^1.1.0", - "object-assign": "^4.1.1", - "prop-types": "^15.6.2" + "object-assign": "^4.1.1" } }, "react-dom": { - "version": "16.13.1", - "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-16.13.1.tgz", - "integrity": "sha512-81PIMmVLnCNLO/fFOQxdQkvEq/+Hfpv24XNJfpyZhTRfO0QcmQIF/PgCa1zCOj2w1hrn12MFLyaJ/G0+Mxtfag==", + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-17.0.2.tgz", + "integrity": "sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==", "requires": { "loose-envify": "^1.1.0", "object-assign": "^4.1.1", - "prop-types": "^15.6.2", - "scheduler": "^0.19.1" + "scheduler": "^0.20.2" } }, "react-flatpickr": { @@ -24630,6 +24833,14 @@ "resolved": "https://registry.npmjs.org/react-flip-move/-/react-flip-move-3.0.4.tgz", "integrity": "sha512-HyUVv9g3t/BS7Yz9HgrtYSWyRNdR2F81nkj+C5iRY675AwlqCLB5JU9mnZWg0cdVz7IM4iquoyZx70vzZv3Z8Q==" }, + "react-input-autosize": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/react-input-autosize/-/react-input-autosize-3.0.0.tgz", + "integrity": "sha512-nL9uS7jEs/zu8sqwFE5MAPx6pPkNAriACQ2rGLlqmKr2sPGtN7TXTyDdQt4lbNXVx7Uzadb40x8qotIuru6Rhg==", + "requires": { + "prop-types": "^15.5.8" + } + }, "react-is": { "version": "16.11.0", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.11.0.tgz", @@ -24666,6 +24877,20 @@ "tiny-warning": "^1.0.0" } }, + "react-select": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/react-select/-/react-select-4.3.1.tgz", + "integrity": "sha512-HBBd0dYwkF5aZk1zP81Wx5UsLIIT2lSvAY2JiJo199LjoLHoivjn9//KsmvQMEFGNhe58xyuOITjfxKCcGc62Q==", + "requires": { + "@babel/runtime": "^7.12.0", + "@emotion/cache": "^11.4.0", + "@emotion/react": "^11.1.1", + "memoize-one": "^5.0.0", + "prop-types": "^15.6.0", + "react-input-autosize": "^3.0.0", + "react-transition-group": "^4.3.0" + } + }, "react-transition-group": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.1.tgz", @@ -25068,9 +25293,9 @@ "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" }, "scheduler": { - "version": "0.19.1", - "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.19.1.tgz", - "integrity": "sha512-n/zwRWRYSUj0/3g/otKDRPMh6qv2SYMWNq85IEa8iZyAv8od9zDYpGSnpBEjNgcMNq6Scbu5KfIPxNF72R/2EA==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.20.2.tgz", + "integrity": "sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==", "requires": { "loose-envify": "^1.1.0", "object-assign": "^4.1.1" @@ -26043,6 +26268,11 @@ "stylelint-config-recommended": "^3.0.0" } }, + "stylis": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/stylis/-/stylis-4.0.10.tgz", + "integrity": "sha512-m3k+dk7QeJw660eIKRRn3xPF6uuvHs/FFzjX3HQ5ove0qYsiygoAhwn5a3IYKaZPo5LrYD0rfVmtv1gNY1uYwg==" + }, "sugarss": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/sugarss/-/sugarss-2.0.0.tgz", diff --git a/assets/package.json b/assets/package.json index b0f7e7624..f8092fe9d 100644 --- a/assets/package.json +++ b/assets/package.json @@ -21,17 +21,19 @@ "css-loader": "^3.6.0", "datamaps": "^0.5.9", "iframe-resizer": "^4.3.1", + "lodash.debounce": "^4.0.8", "mini-css-extract-plugin": "^0.8.2", "optimize-css-assets-webpack-plugin": "^5.0.3", "phoenix": "file:../deps/phoenix", "phoenix_html": "file:../deps/phoenix_html", "postcss": "^7.0.35", "postcss-loader": "^4.0.4", - "react": "^16.13.1", - "react-dom": "^16.13.1", + "react": "^17.0.1", + "react-dom": "^17.0.1", "react-flatpickr": "^3.10.5", "react-flip-move": "^3.0.4", "react-router-dom": "^5.2.0", + "react-select": "^4.3.1", "react-transition-group": "^4.4.1", "tailwindcss": "^2.0.1-compat", "terser-webpack-plugin": "^4.2.3", diff --git a/lib/plausible/stats/clickhouse.ex b/lib/plausible/stats/clickhouse.ex index 87f16ef0c..032af4b37 100644 --- a/lib/plausible/stats/clickhouse.ex +++ b/lib/plausible/stats/clickhouse.ex @@ -1618,7 +1618,7 @@ defmodule Plausible.Stats.Clickhouse do |> Enum.map(fn {x} -> x end) |> Enum.filter(fn c -> Enum.find(filter_search, false, fn x -> x == c end) end) |> Enum.map(fn c -> Plausible.Stats.CountryName.to_alpha3(c) end) - |> Enum.slice(0..9) + |> Enum.slice(0..24) end def make_suggestions(site, _query, "goal", filter_search) do @@ -1633,7 +1633,10 @@ defmodule Plausible.Stats.Clickhouse do end def make_suggestions(site, query, filter_name, filter_search) do - filter_query = "%#{filter_search}%" + filter_query = + if Enum.member?(["entry_page", "page", "exit_page"], filter_name), + do: "%#{String.replace(filter_search, "*", "")}%", + else: "%#{filter_search}%" filter_name = case filter_name do @@ -1653,7 +1656,7 @@ defmodule Plausible.Stats.Clickhouse do |> from( group_by: ^String.to_atom(filter_name), order_by: [desc: fragment("count(*)")], - limit: 10 + limit: 25 ) q =