Skip to content

Commit

Permalink
feat: Clear filters on user and features page (#5055)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg authored Feb 17, 2025
1 parent 06e95fc commit 76c2f5f
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 125 deletions.
21 changes: 21 additions & 0 deletions frontend/web/components/ClearFilters.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, { FC } from 'react'
import { IonIcon } from '@ionic/react'
import { closeCircle, informationCircleOutline } from 'ionicons/icons'

type ClearFiltersType = {
onClick: () => void
}

const ClearFilters: FC<ClearFiltersType> = ({ onClick }) => {
return (
<div
onClick={onClick}
className='fw-semibold cursor-pointer text-primary d-flex align-items-center ms-2 gap-1'
>
<IonIcon className='h6 mb-0' color='#6837fc' icon={closeCircle} />
Clear all
</div>
)
}

export default ClearFilters
37 changes: 31 additions & 6 deletions frontend/web/components/pages/FeaturesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@ import TableOwnerFilter from 'components/tables/TableOwnerFilter'
import TableGroupsFilter from 'components/tables/TableGroupsFilter'
import TableValueFilter from 'components/tables/TableValueFilter'
import classNames from 'classnames'
import ClearFilters from 'components/ClearFilters'
import Button from 'components/base/forms/Button'
import { isEqual } from 'lodash';

const FeaturesPage = class extends Component {
static displayName = 'FeaturesPage'

static contextTypes = {
router: propTypes.object.isRequired,
}

constructor(props, context) {
super(props, context)
const params = Utils.fromParam()
this.state = {
getFiltersFromParams = (params) => {
return {
group_owners:
typeof params.group_owners === 'string'
? params.group_owners.split(',').map((v) => parseInt(v))
Expand Down Expand Up @@ -66,6 +65,10 @@ const FeaturesPage = class extends Component {
value_search:
typeof params.value_search === 'string' ? params.value_search : '',
}
}
constructor(props, context) {
super(props, context)
this.state = this.getFiltersFromParams(Utils.fromParam())
ES6Component(this)

AppActions.getFeatures(
Expand Down Expand Up @@ -218,7 +221,26 @@ const FeaturesPage = class extends Component {
const { environmentId, projectId } = this.props.match.params
const readOnly = Utils.getFlagsmithHasFeature('read_only_mode')
const environment = ProjectStore.getEnvironment(environmentId)

const params = Utils.fromParam()
const hasFilters = !isEqual(
this.getFiltersFromParams({ ...params, page: '1' }),
this.getFiltersFromParams({ page: '1' }),
)
const clearFilters = () => {
this.props.router.history.replace(`${document.location.pathname}`)
const newState = this.getFiltersFromParams({})
this.setState(newState, () => {
AppActions.getFeatures(
this.props.match.params.projectId,
this.props.match.params.environmentId,
true,
this.state.search,
this.state.sort,
1,
this.getFilter(),
)
})
}
return (
<div
data-test='features-page'
Expand Down Expand Up @@ -504,6 +526,9 @@ const FeaturesPage = class extends Component {
this.setState({ sort }, this.filter)
}}
/>
{hasFilters && (
<ClearFilters onClick={clearFilters} />
)}
</Row>
</div>
</Row>
Expand Down
Loading

0 comments on commit 76c2f5f

Please sign in to comment.