Skip to content

Commit

Permalink
chore: Make features, identities and audit search, closed/open change…
Browse files Browse the repository at this point in the history
… requests filter based on URL (#3738)
  • Loading branch information
kyle-ssg authored Apr 11, 2024
1 parent c637e86 commit 54f0d80
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 238 deletions.
2 changes: 0 additions & 2 deletions frontend/common/dispatcher/app-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ const AppActions = Object.assign({}, require('./base/_app-actions'), {
force,
search,
sort,
page,
filter,
pageSize,
) {
Expand All @@ -382,7 +381,6 @@ const AppActions = Object.assign({}, require('./base/_app-actions'), {
environmentId,
filter,
force,
page,
pageSize,
projectId,
search,
Expand Down
2 changes: 1 addition & 1 deletion frontend/web/components/ExistingChangeRequestAlert.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useRef } from 'react';
import { FC, useRef } from 'react'
import { useGetChangeRequestsQuery } from 'common/services/useChangeRequest'
import WarningMessage from './WarningMessage'
import moment from 'moment'
Expand Down
14 changes: 12 additions & 2 deletions frontend/web/components/pages/AuditLogPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, useState } from 'react' // we need this to make JSX compile
import React, { FC, useEffect, useState } from 'react' // we need this to make JSX compile
import ConfigProvider from 'common/providers/ConfigProvider'
import ToggleChip from 'components/ToggleChip'
import Utils from 'common/utils/utils'
Expand All @@ -23,7 +23,17 @@ const AuditLogPage: FC<AuditLogType> = (props) => {
const projectId = props.match.params.projectId

const [environment, setEnvironment] = useState(Utils.fromParam().env)

useEffect(() => {
const currentParams = Utils.fromParam()
if (currentParams.env !== environment) {
props.router.history.replace(
`${document.location.pathname}?${Utils.toParam({
env: environment,
search: currentParams.search,
})}`,
)
}
}, [environment])
const hasRbacPermission = Utils.getPlansPermission('AUDIT')
if (!hasRbacPermission) {
return (
Expand Down
10 changes: 9 additions & 1 deletion frontend/web/components/pages/ChangeRequestsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Link } from 'react-router-dom'
import PageTitle from 'components/PageTitle'
import { timeOutline } from 'ionicons/icons'
import { IonIcon } from '@ionic/react'
import Utils from 'common/utils/utils'

const ChangeRequestsPage = class extends Component {
static displayName = 'ChangeRequestsPage'
Expand All @@ -25,6 +26,7 @@ const ChangeRequestsPage = class extends Component {
this.state = {
live_after: new Date().toISOString(),
showArchived: false,
tab: Utils.fromParam().tab === 'closed' ? 1 : 0,
tags: [],
}
ES6Component(this)
Expand Down Expand Up @@ -114,7 +116,13 @@ const ChangeRequestsPage = class extends Component {
<Tabs
value={this.state.tab}
onChange={(tab) => {
this.setState({ tab })
this.setState({ tab }, (tab) => {
this.props.router.history.replace(
`${document.location.pathname}?${Utils.toParam({
tab: this.state.tab ? 'closed' : 'open',
})}`,
)
})
}}
>
<TabItem
Expand Down
177 changes: 93 additions & 84 deletions frontend/web/components/pages/FeaturesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import TableSearchFilter from 'components/tables/TableSearchFilter'
import TableTagFilter from 'components/tables/TableTagFilter'
import { getViewMode, setViewMode } from 'common/useViewMode'
import TableFilterOptions from 'components/tables/TableFilterOptions'
import Format from 'common/utils/format'
import EnvironmentDocumentCodeHelp from 'components/EnvironmentDocumentCodeHelp'
import TableOwnerFilter from 'components/tables/TableOwnerFilter'
import TableGroupsFilter from 'components/tables/TableGroupsFilter'
Expand All @@ -32,17 +33,38 @@ const FeaturesPage = class extends Component {

constructor(props, context) {
super(props, context)
const params = Utils.fromParam()
this.state = {
group_owners: [],
is_enabled: null,
group_owners:
typeof params.group_owners === 'string'
? params.group_owners.split(',').map((v) => parseInt(v))
: [],
is_enabled:
params.is_enabled === 'true'
? true
: params.is_enabled === 'false'
? false
: null,
loadedOnce: false,
owners: [],
search: null,
showArchived: false,
sort: { label: 'Name', sortBy: 'name', sortOrder: 'asc' },
tag_strategy: 'INTERSECTION',
tags: [],
value_search: null,
owners:
typeof params.owners === 'string'
? params.owners.split(',').map((v) => parseInt(v))
: [],
page: params.page ? parseInt(params.page) - 1 : 1,
search: params.search || null,
showArchived: !!params.is_archived,
sort: {
label: Format.camelCase(params.sortBy || 'Name'),
sortBy: params.sortBy || 'name',
sortOrder: params.sortOrder || 'asc',
},
tag_strategy: params.tag_strategy || 'INTERSECTION',
tags:
typeof params.tags === 'string'
? params.tags.split(',').map((v) => parseInt(v))
: [],
value_search:
typeof params.value_search === 'string' ? params.value_search : '',
}
ES6Component(this)
getTags(getStore(), {
Expand All @@ -54,7 +76,7 @@ const FeaturesPage = class extends Component {
true,
this.state.search,
this.state.sort,
0,
this.state.page,
this.getFilter(),
)
}
Expand All @@ -71,15 +93,7 @@ const FeaturesPage = class extends Component {
params.projectId !== oldParams.projectId
) {
this.state.loadedOnce = false
AppActions.getFeatures(
params.projectId,
params.environmentId,
true,
this.state.search,
this.state.sort,
0,
this.getFilter(),
)
this.filter()
}
}

Expand Down Expand Up @@ -109,6 +123,17 @@ const FeaturesPage = class extends Component {
)
}

getURLParams = () => ({
...this.getFilter(),
group_owners: (this.state.group_owners || [])?.join(',') || undefined,
owners: (this.state.owners || [])?.join(',') || undefined,
page: this.state.page || 1,
search: this.state.search || '',
sortBy: this.state.sort.sortBy,
sortOrder: this.state.sort.sortOrder,
tags: (this.state.tags || [])?.join(',') || undefined,
})

getFilter = () => ({
group_owners: this.state.group_owners?.length
? this.state.group_owners
Expand Down Expand Up @@ -142,16 +167,37 @@ const FeaturesPage = class extends Component {
}
}

filter = () => {
AppActions.searchFeatures(
this.props.match.params.projectId,
this.props.match.params.environmentId,
true,
this.state.search,
this.state.sort,
0,
this.getFilter(),
)
filter = (page) => {
const currentParams = Utils.fromParam()
// this.props.router.push()
this.setState({ page }, () => {
if (!currentParams.feature) {
// don't replace page if we are currently viewing a feature
this.props.router.history.replace(
`${document.location.pathname}?${Utils.toParam(this.getURLParams())}`,
)
}
if (page) {
AppActions.getFeatures(
this.props.match.params.projectId,
this.props.match.params.environmentId,
true,
this.state.search,
this.state.sort,
page,
this.getFilter(),
)
} else {
AppActions.searchFeatures(
this.props.match.params.projectId,
this.props.match.params.environmentId,
true,
this.state.search,
this.state.sort,
this.getFilter(),
)
}
})
}

createFeaturePermission(el) {
Expand Down Expand Up @@ -203,16 +249,17 @@ const FeaturesPage = class extends Component {
totalFeatures,
maxFeaturesAllowed,
)
if (projectFlags?.length && !this.state.loadedOnce) {
if (FeatureListStore.hasLoaded && !this.state.loadedOnce) {
this.state.loadedOnce = true
}
return (
<div className='features-page'>
{isLoading && (!projectFlags || !projectFlags.length) && (
<div className='centered-container'>
<Loader />
</div>
)}
{(isLoading || !this.state.loadedOnce) &&
(!projectFlags || !projectFlags.length) && (
<div className='centered-container'>
<Loader />
</div>
)}
{(!isLoading || this.state.loadedOnce) && (
<div>
{this.state.loadedOnce ||
Expand Down Expand Up @@ -306,19 +353,7 @@ const FeaturesPage = class extends Component {
search:
Utils.safeParseEventValue(e),
},
() => {
AppActions.searchFeatures(
this.props.match.params
.projectId,
this.props.match.params
.environmentId,
true,
this.state.search,
this.state.sort,
0,
this.getFilter(),
)
},
this.filter,
)
}}
value={this.state.search}
Expand All @@ -331,7 +366,10 @@ const FeaturesPage = class extends Component {
className='me-4'
title='Tags'
tagStrategy={this.state.tag_strategy}
onChangeStrategy={(tag_strategy) => {
onChangeStrategy={(
tag_strategy,
isAutomated,
) => {
this.setState(
{
tag_strategy,
Expand Down Expand Up @@ -362,7 +400,7 @@ const FeaturesPage = class extends Component {
this.filter,
)
}}
onChange={(tags) => {
onChange={(tags, isAutomated) => {
FeatureListStore.isLoading = true
if (
tags.includes('') &&
Expand Down Expand Up @@ -391,10 +429,6 @@ const FeaturesPage = class extends Component {
this.filter,
)
}
AsyncStorage.setItem(
`${projectId}tags`,
JSON.stringify(tags),
)
}}
/>
{enabledStateFilter && (
Expand Down Expand Up @@ -503,38 +537,12 @@ const FeaturesPage = class extends Component {
</Row>
}
nextPage={() =>
AppActions.getFeatures(
this.props.match.params.projectId,
this.props.match.params.environmentId,
true,
this.state.search,
this.state.sort,
FeatureListStore.paging.next,
this.getFilter(),
)
this.filter(FeatureListStore.paging.next)
}
prevPage={() =>
AppActions.getFeatures(
this.props.match.params.projectId,
this.props.match.params.environmentId,
true,
this.state.search,
this.state.sort,
FeatureListStore.paging.previous,
this.getFilter(),
)
}
goToPage={(page) =>
AppActions.getFeatures(
this.props.match.params.projectId,
this.props.match.params.environmentId,
true,
this.state.search,
this.state.sort,
page,
this.getFilter(),
)
this.filter(FeatureListStore.paging.previous)
}
goToPage={(page) => this.filter(page)}
items={projectFlags?.filter((v) => !v.ignore)}
renderFooter={() => (
<>
Expand Down Expand Up @@ -602,7 +610,8 @@ const FeaturesPage = class extends Component {
</FormGroup>
</div>
) : (
!isLoading && (
!isLoading &&
this.state.loadedOnce && (
<div>
<h3>Brilliant! Now create your features.</h3>
<FormGroup>
Expand Down
Loading

0 comments on commit 54f0d80

Please sign in to comment.