Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

displaying applied filters

Blue Mouse959c6c6b231c
diff --git a/public/locales/en.json b/public/locales/en.json
index 77b8b1622..edd7e8098 100644
--- a/public/locales/en.json
+++ b/public/locales/en.json
@@ -30,7 +30,9 @@
"openMenu": "Open menu",
"closeMenu": "Close menu",
"yes": "Yes",
- "no": "No"
+ "no": "No",
+ "is": "is",
+ "isNot": "is not"
},
"main": {
"ukrSupport": "Support the Ukrainian army to fight Russian invasion.",
diff --git a/src/pages/Project/View/ViewProject.jsx b/src/pages/Project/View/ViewProject.jsx
index c0e15817c..154c2c234 100644
--- a/src/pages/Project/View/ViewProject.jsx
+++ b/src/pages/Project/View/ViewProject.jsx
@@ -27,6 +27,7 @@ import _isEmpty from 'lodash/isEmpty'
import _replace from 'lodash/replace'
import _find from 'lodash/find'
import _filter from 'lodash/filter'
+import _truncate from 'lodash/truncate'
import PropTypes from 'prop-types'
import Title from 'components/Title'
@@ -169,6 +170,54 @@ const NoEvents = ({ t }) => (
</div>
)
+const Filter = ({ column, filter, isExclusive, onRemoveFilter, onChangeExclusive, tnMapping, language, t }) => {
+ const displayColumn = tnMapping[column]
+ let displayFilter = filter
+
+ if (column === 'cc') {
+ displayFilter = countries.getName(filter, language)
+ }
+
+ displayFilter = _truncate(displayFilter)
+
+ return (
+ <span className='inline-flex rounded-md items-center py-0.5 pl-2.5 pr-1 mr-2 mt-2 text-sm font-medium bg-gray-200 text-gray-800 dark:text-gray-50 dark:bg-gray-700'>
+ {displayColumn}
+ &nbsp;
+ <span className='text-blue-400 border-blue-400 border-b-2 border-dotted cursor-pointer' onClick={() => onChangeExclusive(column, filter, !isExclusive)}>
+ {t(`common.${isExclusive ? 'isNot' : 'is'}`)}
+ </span>
+ &nbsp;
+ &quot;
+ {displayFilter}
+ &quot;
+ <button
+ onClick={() => onRemoveFilter(column, filter)}
+ type='button'
+ className='flex-shrink-0 ml-0.5 h-4 w-4 rounded-full inline-flex items-center justify-center text-gray-800 hover:text-gray-900 hover:bg-gray-300 focus:bg-gray-300 focus:text-gray-900 dark:text-gray-50 dark:bg-gray-700 dark:hover:text-gray-300 dark:hover:bg-gray-800 dark:focus:bg-gray-800 dark:focus:text-gray-300 focus:outline-none '
+ >
+ <span className='sr-only'>Remove filter</span>
+ <svg className='h-2 w-2' stroke='currentColor' fill='none' viewBox='0 0 8 8'>
+ <path strokeLinecap='round' strokeWidth='1.5' d='M1 1l6 6m0-6L1 7' />
+ </svg>
+ </button>
+ </span>
+ )
+}
+
+const Filters = ({ filters, onRemoveFilter, onChangeExclusive, language, t, tnMapping }) => (
+ <div className='flex justify-center md:justify-start flex-wrap -mt-2'>
+ {_map(filters, (props) => {
+ const { column, filter } = props
+ const key = `${column}${filter}`
+
+ return (
+ <Filter key={key} onRemoveFilter={onRemoveFilter} onChangeExclusive={onChangeExclusive} language={language} t={t} tnMapping={tnMapping} {...props} />
+ )
+ })}
+ </div>
+)
+
const ViewProject = ({
projects, isLoading: _isLoading, showError, cache, setProjectCache, projectViewPrefs, setProjectViewPrefs, setPublicProject,
setLiveStatsForProject, authenticated,
@@ -267,6 +316,22 @@ const ViewProject = ({
loadAnalytics(true, newFilters)
}
+ const onChangeExclusive = (column, filter, isExclusive) => {
+ const newFilters = _map(filters, (f) => {
+ if (f.column === column && f.filter === filter) {
+ return {
+ ...f,
+ isExclusive,
+ }
+ }
+
+ return f
+ })
+
+ setFilters(newFilters)
+ loadAnalytics(true, newFilters)
+ }
+
useEffect(() => {
if (!isLoading && !_isEmpty(chartData) && !_isEmpty(mainChart)) {
if (showTotal) {
@@ -434,6 +499,7 @@ const ViewProject = ({
</div>
<div className={cx('pt-4 md:pt-0', { hidden: isPanelsDataEmpty })}>
<div className='h-80' id='dataChart' />
+ <Filters filters={filters} onRemoveFilter={filterHandler} onChangeExclusive={onChangeExclusive} language={language} t={t} tnMapping={tnMapping} />
<div className='mt-5 grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-3'>
{!_isEmpty(project.overall) && (
<Overview