Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Make 'Remove filter' / 'Clear all filters' buttons less threatening & other tweaks (#5236)
Artur Patabcc734786491
diff --git a/assets/js/dashboard/components/popover.tsx b/assets/js/dashboard/components/popover.tsxindex 55738abb66..f2f3e7931e 100644--- a/assets/js/dashboard/components/popover.tsx+++ b/assets/js/dashboard/components/popover.tsx@@ -55,6 +55,7 @@ const items = {'first-of-type:rounded-t-md','last-of-type:rounded-b-md'),+ roundedEnd: classNames('last-of-type:rounded-b-md'),groupRoundedStartEnd: classNames('group-first-of-type:rounded-t-md','group-last-of-type:rounded-b-md'diff --git a/assets/js/dashboard/components/remove-filter-button.tsx b/assets/js/dashboard/components/remove-filter-button.tsxnew file mode 100644index 0000000000..c5e410f2b7--- /dev/null+++ b/assets/js/dashboard/components/remove-filter-button.tsx@@ -0,0 +1,9 @@+/** @format */++import classNames from 'classnames'++export const removeFilterButtonClassname = classNames(+ 'flex items-center py-1',+ 'text-sm font-medium whitespace-nowrap',+ 'text-indigo-600 dark:text-indigo-500 hover:text-indigo-700 dark:hover:text-indigo-600'+)diff --git a/assets/js/dashboard/keybinding.tsx b/assets/js/dashboard/keybinding.tsxindex ddcc9e9db1..1a56e8f78a 100644--- a/assets/js/dashboard/keybinding.tsx+++ b/assets/js/dashboard/keybinding.tsx@@ -3,6 +3,7 @@ import {AppNavigationTarget,useAppNavigate} from './navigation/use-app-navigate'+import classNames from 'classnames'/*** Returns whether a keydown or keyup event should be ignored or not.@@ -134,9 +135,20 @@ export function NavigateKeybind({)}-export function KeybindHint({ children }: { children: ReactNode }) {+export function KeybindHint({+ children,+ className+}: {+ children: ReactNode+ className?: string+}) {return (- <kbd className="rounded border border-gray-200 dark:border-gray-600 px-2 font-mono font-normal text-xs text-gray-400">+ <kbd+ className={classNames(+ 'rounded border border-gray-200 dark:border-gray-600 px-2 font-mono font-normal text-xs text-gray-400',+ className+ )}+ >{children}</kbd>)diff --git a/assets/js/dashboard/nav-menu/filter-pills-list.tsx b/assets/js/dashboard/nav-menu/filter-pills-list.tsxindex 746d5a908f..6ca03290aa 100644--- a/assets/js/dashboard/nav-menu/filter-pills-list.tsx+++ b/assets/js/dashboard/nav-menu/filter-pills-list.tsx@@ -32,7 +32,10 @@ type NoRenderOutsideSlice = {type AppliedFilterPillsListProps = Omit<FilterPillsListProps,'slice' | 'pillProps' | 'pills'-> & { slice?: InvisibleOutsideSlice | NoRenderOutsideSlice }+> & {+ slice?: InvisibleOutsideSlice | NoRenderOutsideSlice+ pillClassName?: string+}type FilterPillsListProps = {direction: 'horizontal' | 'vertical'@@ -43,7 +46,7 @@ type FilterPillsListProps = {export const AppliedFilterPillsList = React.forwardRef<HTMLDivElement,AppliedFilterPillsListProps->(({ className, style, slice, direction }, ref) => {+>(({ className, style, slice, direction, pillClassName }, ref) => {const { query } = useQueryContext()const navigate = useAppNavigate()@@ -65,7 +68,7 @@ export const AppliedFilterPillsList = React.forwardRef<return (<FilterPillsListpills={renderableFilters.map((filter, index) => ({- className: classNames(isInvisible(index) && 'invisible'),+ className: classNames(isInvisible(index) && 'invisible', pillClassName),plainText: plainFilterText(query, filter),children: styledFilterText(query, filter),interactive: {diff --git a/assets/js/dashboard/nav-menu/filters-bar.test.tsx b/assets/js/dashboard/nav-menu/filters-bar.test.tsxindex 3c08dc5de8..42c1e07c2f 100644--- a/assets/js/dashboard/nav-menu/filters-bar.test.tsx+++ b/assets/js/dashboard/nav-menu/filters-bar.test.tsx@@ -99,7 +99,10 @@ test('user can see expected filters and clear them one by one or all together',])await userEvent.click(- screen.getByRole('link', { hidden: false, name: 'Clear all filters' })+ screen.getByRole('link', {+ hidden: false,+ name: 'Clear all filters'+ }))expect(queryFilterPills().map((m) => m.textContent)).toEqual([])diff --git a/assets/js/dashboard/nav-menu/filters-bar.tsx b/assets/js/dashboard/nav-menu/filters-bar.tsxindex 69baf56716..6988d93861 100644--- a/assets/js/dashboard/nav-menu/filters-bar.tsx+++ b/assets/js/dashboard/nav-menu/filters-bar.tsx@@ -1,6 +1,6 @@import { EllipsisHorizontalIcon } from '@heroicons/react/24/solid'import classNames from 'classnames'-import React, { useRef, useState, useLayoutEffect, ReactNode } from 'react'+import React, { useRef, useState, useLayoutEffect } from 'react'import { AppliedFilterPillsList, PILL_X_GAP_PX } from './filter-pills-list'import { useQueryContext } from '../query-context'import { AppNavigationLink } from '../navigation/use-app-navigate'@@ -129,7 +129,12 @@ export const FiltersBar = ({ accessors }: FiltersBarProps) => {isEditingSegment: !!expandedSegment})- const mustShowSeeMoreMenu = showingClearAll || showingSaveAsSegment+ const actionsInSeeMoreMenu = [+ showingSaveAsSegment && ('save as segment' as const),+ showingClearAll && ('clear all filters' as const)+ ].filter((f) => f)++ const mustShowSeeMoreMenu = actionsInSeeMoreMenu.length > 0useLayoutEffect(() => {const topBar = accessors.topBar(containerRef.current)@@ -202,13 +207,11 @@ export const FiltersBar = ({ accessors }: FiltersBarProps) => {(query.filters.length !== visibility.visibleCount ||mustShowSeeMoreMenu) && (<SeeMoreMenu+ actions={actionsInSeeMoreMenu}className="md:relative"filtersCount={query.filters.length}visibleFiltersCount={visibility.visibleCount}- >- {showingClearAll && <ClearAction />}- {showingSaveAsSegment && <SaveAsSegmentAction />}- </SeeMoreMenu>+ />)}</div>)@@ -218,12 +221,12 @@ const SeeMoreMenu = ({className,filtersCount,visibleFiltersCount,- children+ actions}: {className?: stringfiltersCount: numbervisibleFiltersCount: number- children: ReactNode+ actions: Array<'save as segment' | 'clear all filters' | false>}) => {const seeMoreRef = useRef<HTMLButtonElement>(null)const filtersInMenuCount = filtersCount - visibleFiltersCount@@ -235,6 +238,9 @@ const SeeMoreMenu = ({? `See ${filtersInMenuCount} more filters and actions`: 'See actions'+ const showMoreFilters = filtersCount !== visibleFiltersCount+ const showSomeActions = actions.some((a) => a)+return (<Popover className={className}><BlurMenuButtonOnEscape targetRef={seeMoreRef} />@@ -244,7 +250,8 @@ const SeeMoreMenu = ({className={classNames(popover.toggleButton.classNames.rounded,popover.toggleButton.classNames.shadow,- 'justify-center'+ 'justify-center',+ 'relative group')}style={{height: SEE_MORE_WIDTH_PX,@@ -254,6 +261,16 @@ const SeeMoreMenu = ({}}><EllipsisHorizontalIcon className="block h-5 w-5" />+ {showMoreFilters && (+ <div+ aria-hidden="true"+ className="absolute flex justify-end left-0 right-0 bottom-0 translate-y-1/4 pr-[3px]"+ >+ <div className="text-[10px] leading-[10px] min-w-[10px] font-medium shadow px-[3px] py-[1px] flex items-center rounded-sm bg-gray-100 dark:bg-gray-850">+ +{filtersInMenuCount}+ </div>+ </div>+ )}</Popover.Button><Transition{...popover.transition.props}@@ -266,30 +283,66 @@ const SeeMoreMenu = ({<Popover.PanelclassName={classNames(popover.panel.classNames.roundedSheet,- 'flex flex-col p-4 gap-y-2'+ 'flex flex-col')}>- {filtersCount !== visibleFiltersCount && (- <AppliedFilterPillsList- direction="vertical"- slice={{- type: 'no-render-outside',- start: visibleFiltersCount- }}- />+ {showMoreFilters && (+ <>+ <div className="py-4 px-4">+ <AppliedFilterPillsList+ direction="vertical"+ pillClassName="dark:!shadow-gray-950/60"+ slice={{+ type: 'no-render-outside',+ start: visibleFiltersCount+ }}+ />+ </div>+ {showSomeActions && (+ <div className="mb-1 border-gray-200 dark:border-gray-500 border-b"></div>+ )}+ </>+ )}+ {showSomeActions && (+ <div className="flex flex-col">+ {actions.map((action, index) => {+ const linkClassName = classNames(+ popover.items.classNames.navigationLink,+ popover.items.classNames.selectedOption,+ popover.items.classNames.hoverLink,+ index === 0 && !showMoreFilters+ ? popover.items.classNames.roundedStartEnd+ : popover.items.classNames.roundedEnd,+ 'whitespace-nowrap'+ )++ switch (action) {+ case 'clear all filters':+ return (+ <ClearAction key={action} className={linkClassName} />+ )+ case 'save as segment':+ return (+ <SaveAsSegmentAction+ key={action}+ className={linkClassName}+ />+ )+ default:+ return null+ }+ })}+ </div>)}- {children}</Popover.Panel></Transition></Popover>)}-const ClearAction = () => (+const ClearAction = ({ className }: { className?: string }) => (<AppNavigationLink- className={classNames(- 'button flex self-start h-9 !px-3 !bg-red-500 dark:!bg-red-500 hover:!bg-red-600 dark:hover:!bg-red-700 whitespace-nowrap'- )}+ className={className}search={(search) => ({...search,filters: null,@@ -300,14 +353,12 @@ const ClearAction = () => (</AppNavigationLink>)-const SaveAsSegmentAction = () => {+const SaveAsSegmentAction = ({ className }: { className?: string }) => {const { setModal } = useRoutelessModalsContext()return (<AppNavigationLink- className={classNames(- 'button flex self-start h-9 !px-3 whitespace-nowrap'- )}+ className={className}search={(s) => s}onClick={() => setModal('create')}state={{ expandedSegment: null }}diff --git a/assets/js/dashboard/segments/segment-modals.tsx b/assets/js/dashboard/segments/segment-modals.tsxindex 9714e07470..67589a6aa4 100644--- a/assets/js/dashboard/segments/segment-modals.tsx+++ b/assets/js/dashboard/segments/segment-modals.tsx@@ -17,13 +17,14 @@ import { rootRoute } from '../router'import { FilterPillsList } from '../nav-menu/filter-pills-list'import classNames from 'classnames'import { SegmentAuthorship } from './segment-authorship'-import { ExclamationTriangleIcon, TrashIcon } from '@heroicons/react/24/outline'+import { ExclamationTriangleIcon } from '@heroicons/react/24/outline'import { MutationStatus } from '@tanstack/react-query'import { ApiError } from '../api'import { ErrorPanel } from '../components/error-panel'import { useSegmentsContext } from '../filtering/segments-context'import { useSiteContext } from '../site-context'import { useUserContext } from '../user-context'+import { removeFilterButtonClassname } from '../components/remove-filter-button'interface ApiRequestProps {status: MutationStatus@@ -41,15 +42,15 @@ interface SharedSegmentModalProps {namePlaceholder: string}-const primaryNeutralButtonClassName = 'button'+const primaryNeutralButtonClassName = 'button !px-3'const primaryNegativeButtonClassName = classNames(- 'button',+ 'button !px-3','items-center !bg-red-500 dark:!bg-red-500 hover:!bg-red-600 dark:hover:!bg-red-700 whitespace-nowrap')const secondaryButtonClassName = classNames(- 'button',+ 'button !px-3','border !border-gray-300 dark:!border-gray-500 !text-gray-700 dark:!text-gray-300 !bg-transparent hover:!bg-gray-100 dark:hover:!bg-gray-850')@@ -400,6 +401,7 @@ const FiltersInSegment = ({ segment_data }: { segment_data: SegmentData }) => {className="flex-wrap"direction="horizontal"pills={segment_data.filters.map((filter) => ({+ className: 'dark:!shadow-gray-950/60',plainText: plainFilterText({ labels: segment_data.labels }, filter),children: styledFilterText({ labels: segment_data.labels }, filter),interactive: false@@ -496,7 +498,7 @@ export const SegmentModal = ({ id }: { id: SavedSegment['id'] }) => {</AppNavigationLink><AppNavigationLink- className={primaryNegativeButtonClassName}+ className={removeFilterButtonClassname}path={rootRoute.path}search={(s) => {const nonSegmentFilters = query.filters.filter(@@ -514,7 +516,6 @@ export const SegmentModal = ({ id }: { id: SavedSegment['id'] }) => {}}}>- <TrashIcon className="w-4 h-4 mr-2" />Remove filter</AppNavigationLink></ButtonsRow>diff --git a/assets/js/dashboard/stats/modals/filter-modal.js b/assets/js/dashboard/stats/modals/filter-modal.jsindex 60be135ce6..2bfb83328c 100644--- a/assets/js/dashboard/stats/modals/filter-modal.js+++ b/assets/js/dashboard/stats/modals/filter-modal.js@@ -19,8 +19,8 @@ import FilterModalGroup from './filter-modal-group'import { rootRoute } from '../../router'import { useAppNavigate } from '../../navigation/use-app-navigate'import { SegmentModal } from '../../segments/segment-modals'-import { TrashIcon } from '@heroicons/react/24/outline'import { findAppliedSegmentFilter } from '../../filtering/segments'+import { removeFilterButtonClassname } from '../../components/remove-filter-button'function partitionFilters(modalType, filters) {const otherFilters = []@@ -192,10 +192,10 @@ class FilterModal extends React.Component {/>))}- <div className="mt-6 flex items-center justify-start">+ <div className="mt-6 flex gap-x-4 items-center justify-start"><buttontype="submit"- className="button"+ className="button !px-3"disabled={this.isDisabled()}>Apply filter@@ -204,16 +204,14 @@ class FilterModal extends React.Component {{this.state.hasRelevantFilters && (<buttontype="button"- className="ml-4 button px-4 flex bg-red-500 dark:bg-red-500 hover:bg-red-600 dark:hover:bg-red-700 items-center"+ className={removeFilterButtonClassname}onClick={() => {this.selectFiltersAndCloseModal(this.state.otherFilters)}}>- <TrashIcon className="w-4 h-4 mr-2" />- Remove filter{FILTER_MODAL_TO_FILTER_GROUP[this.props.modalType].length > 1- ? 's'- : ''}+ ? 'Remove filters'+ : 'Remove filter'}</button>)}</div>