-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* the new filtering experience * revert bug
- Loading branch information
1 parent
44a7976
commit 5245ee6
Showing
33 changed files
with
1,410 additions
and
897 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
frontend/src/lib/components/PropertyFilters/components/PropertyFilter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
.taxonomic-property-filter { | ||
width: 100%; | ||
|
||
&.in-dropdown { | ||
min-width: 300px; | ||
width: 550px; | ||
max-width: calc(100vw - 25px); | ||
background: white; | ||
} | ||
|
||
.taxonomic-filter-row { | ||
display: grid; | ||
grid-column-gap: 0.5rem; | ||
grid-row-gap: 0.25rem; | ||
grid-template-columns: 70px minmax(180px, 1fr) minmax(100px, auto); | ||
|
||
// only setting grid properties here, the rest are below | ||
.taxonomic-where { | ||
grid-column: 1; | ||
grid-row: 1; | ||
} | ||
|
||
.taxonomic-button { | ||
grid-column: 2; | ||
grid-row: 1; | ||
} | ||
|
||
.taxonomic-operator { | ||
grid-column: 3; | ||
grid-row: 1; | ||
} | ||
|
||
.taxonomic-value-select { | ||
grid-column: 2 / 4; | ||
grid-row: 2; | ||
} | ||
|
||
// small screens | ||
@media (max-width: 512px) { | ||
grid-template-columns: 35px auto 70px; | ||
.taxonomic-where { | ||
.arrow { | ||
display: none; | ||
} | ||
} | ||
} | ||
|
||
// bigger screens | ||
@media (min-width: 1080px) { | ||
grid-template-columns: 70px minmax(140px, 160px) minmax(100px, 120px) minmax(100px, 400px); | ||
.taxonomic-where { | ||
grid-column: 1; | ||
grid-row: 1; | ||
} | ||
.taxonomic-button { | ||
grid-column: 2; | ||
grid-row: 1; | ||
} | ||
.taxonomic-operator { | ||
grid-column: 3; | ||
grid-row: 1; | ||
} | ||
.taxonomic-value-select { | ||
grid-column: 4; | ||
grid-row: 1; | ||
} | ||
} | ||
// even more space for huge screens | ||
@media (min-width: 1280px) { | ||
grid-template-columns: 70px minmax(140px, 220px) minmax(80px, 160px) minmax(100px, 500px); | ||
} | ||
} | ||
|
||
.taxonomic-where { | ||
height: 32px; // matches antd Select height | ||
display: flex; | ||
align-items: center; | ||
justify-content: flex-end; | ||
|
||
.arrow { | ||
color: #c4c4c4; | ||
font-size: 18px; | ||
font-weight: bold; | ||
padding-left: 6px; | ||
padding-right: 8px; | ||
position: relative; | ||
top: -4px; | ||
user-select: none; | ||
} | ||
} | ||
|
||
.taxonomic-button { | ||
display: flex; | ||
justify-content: space-between; | ||
overflow: hidden; | ||
.property-key-info { | ||
width: auto; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
} | ||
&.add-filter { | ||
width: max-content; | ||
} | ||
} | ||
|
||
.taxonomic-operator { | ||
overflow: hidden; | ||
} | ||
|
||
.taxonomic-value-select { | ||
overflow: hidden; | ||
} | ||
} |
132 changes: 132 additions & 0 deletions
132
frontend/src/lib/components/PropertyFilters/components/TaxonomicPropertyFilter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import './TaxonomicPropertyFilter.scss' | ||
import React, { useMemo } from 'react' | ||
import { Button, Col } from 'antd' | ||
import { useActions, useValues } from 'kea' | ||
import { propertyFilterLogic } from 'lib/components/PropertyFilters/propertyFilterLogic' | ||
import { taxonomicPropertyFilterLogic } from './taxonomicPropertyFilterLogic' | ||
import { SelectDownIcon } from 'lib/components/SelectDownIcon' | ||
import { PropertyKeyInfo } from 'lib/components/PropertyKeyInfo' | ||
import { OperatorValueSelect } from 'lib/components/PropertyFilters/components/OperatorValueSelect' | ||
import { isOperatorMulti, isOperatorRegex } from 'lib/utils' | ||
import { Popup } from 'lib/components/Popup/Popup' | ||
import { PropertyFilterInternalProps } from 'lib/components/PropertyFilters' | ||
import { TaxonomicFilter } from 'lib/components/TaxonomicFilter/TaxonomicFilter' | ||
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types' | ||
import { | ||
propertyFilterTypeToTaxonomicFilterType, | ||
taxonomicFilterTypeToPropertyFilterType, | ||
} from 'lib/components/PropertyFilters/utils' | ||
|
||
let uniqueMemoizedIndex = 0 | ||
|
||
export function TaxonomicPropertyFilter({ | ||
pageKey: pageKeyInput, | ||
index, | ||
onComplete, | ||
disablePopover, // inside a dropdown if this is false | ||
}: PropertyFilterInternalProps): JSX.Element { | ||
const pageKey = useMemo(() => pageKeyInput || `filter-${uniqueMemoizedIndex++}`, [pageKeyInput]) | ||
const { setFilter } = useActions(propertyFilterLogic) | ||
|
||
const logic = taxonomicPropertyFilterLogic({ pageKey, filterIndex: index }) | ||
const { filter, dropdownOpen, selectedCohortName } = useValues(logic) | ||
const { openDropdown, closeDropdown, selectItem } = useActions(logic) | ||
|
||
const showInitialSearchInline = !disablePopover && ((!filter?.type && !filter?.key) || filter?.type === 'cohort') | ||
const showOperatorValueSelect = filter?.type && filter?.key && filter?.type !== 'cohort' | ||
|
||
const taxonomicFilter = ( | ||
<TaxonomicFilter | ||
groupType={propertyFilterTypeToTaxonomicFilterType(filter?.type)} | ||
value={filter?.type === 'cohort' ? filter?.value : filter?.key} | ||
onChange={(groupType, value) => { | ||
selectItem(taxonomicFilterTypeToPropertyFilterType(groupType), value) | ||
if (groupType === TaxonomicFilterGroupType.Cohorts) { | ||
onComplete?.() | ||
} | ||
}} | ||
groupTypes={[ | ||
TaxonomicFilterGroupType.EventProperties, | ||
TaxonomicFilterGroupType.PersonProperties, | ||
TaxonomicFilterGroupType.Cohorts, | ||
TaxonomicFilterGroupType.Elements, | ||
]} | ||
/> | ||
) | ||
|
||
return ( | ||
<div className={`taxonomic-property-filter${!disablePopover ? ' in-dropdown' : ' row-on-page'}`}> | ||
{showInitialSearchInline ? ( | ||
taxonomicFilter | ||
) : ( | ||
<div className="taxonomic-filter-row"> | ||
<Col className="taxonomic-where"> | ||
{index === 0 ? ( | ||
<> | ||
<span className="arrow">↳</span> | ||
<span className="text">where</span> | ||
</> | ||
) : ( | ||
<span className="stateful-badge and" style={{ fontSize: '90%' }}> | ||
AND | ||
</span> | ||
)} | ||
</Col> | ||
|
||
<Popup | ||
overlay={dropdownOpen ? taxonomicFilter : null} | ||
placement={'bottom-start'} | ||
fallbackPlacements={['bottom-end']} | ||
visible={dropdownOpen} | ||
onClickOutside={closeDropdown} | ||
> | ||
<Button | ||
className={`taxonomic-button${!filter?.type && !filter?.key ? ' add-filter' : ''}`} | ||
onClick={() => (dropdownOpen ? closeDropdown() : openDropdown())} | ||
> | ||
{filter?.type === 'cohort' ? ( | ||
<div>{selectedCohortName || `Cohort #${filter?.value}`}</div> | ||
) : filter?.key ? ( | ||
<PropertyKeyInfo value={filter.key} disablePopover /> | ||
) : ( | ||
<div>Add filter</div> | ||
)} | ||
<SelectDownIcon /> | ||
</Button> | ||
</Popup> | ||
|
||
{showOperatorValueSelect && ( | ||
<OperatorValueSelect | ||
type={filter?.type} | ||
propkey={filter?.key} | ||
operator={filter?.operator} | ||
value={filter?.value} | ||
placeholder="Enter value..." | ||
onChange={(newOperator, newValue) => { | ||
if (filter?.key && filter?.type) { | ||
setFilter(index, filter?.key, newValue || null, newOperator, filter?.type) | ||
} | ||
if ( | ||
newOperator && | ||
newValue && | ||
!isOperatorMulti(newOperator) && | ||
!isOperatorRegex(newOperator) | ||
) { | ||
onComplete() | ||
} | ||
}} | ||
columnOptions={[ | ||
{ | ||
className: 'taxonomic-operator', | ||
}, | ||
{ | ||
className: 'taxonomic-value-select', | ||
}, | ||
]} | ||
/> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} |
Oops, something went wrong.