Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Clear filters on user and features page #5055

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
36 changes: 31 additions & 5 deletions frontend/web/components/pages/FeaturesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ 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 { 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 @@ -67,6 +66,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)
getTags(getStore(), {
projectId: `${this.props.match.params.projectId}`,
Expand Down Expand Up @@ -221,6 +224,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 @@ -506,6 +529,9 @@ const FeaturesPage = class extends Component {
this.setState({ sort }, this.filter)
}}
/>
{hasFilters && (
<ClearFilters onClick={clearFilters} />
)}
</Row>
</div>
</Row>
Expand Down
Loading