Skip to content

Commit 2544ca0

Browse files
authored
feat: re-fetch features on page focus (#6483)
1 parent 253d232 commit 2544ca0

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

frontend/web/components/pages/FeaturesPage.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ const FeaturesPage = class extends Component {
3434
ES6Component(this)
3535
this.projectId = this.props.routeContext.projectId
3636
const { filters } = this.state
37+
this.fetchFeatures(filters)
38+
}
39+
40+
fetchFeatures = (filters = this.state.filters, page = filters.page) => {
3741
AppActions.getFeatures(
3842
this.projectId,
3943
this.props.match.params.environmentId,
4044
true,
4145
filters.search,
4246
filters.sort,
43-
filters.page,
47+
page,
4448
getServerFilter(filters),
4549
)
4650
}
@@ -73,6 +77,17 @@ const FeaturesPage = class extends Component {
7377
projectId: params.projectId,
7478
}),
7579
)
80+
81+
// Add window focus listener to refetch features
82+
this.handleWindowFocus = () => {
83+
this.fetchFeatures()
84+
}
85+
window.addEventListener('focus', this.handleWindowFocus)
86+
}
87+
88+
componentWillUnmount = () => {
89+
// Clean up the window focus listener
90+
window.removeEventListener('focus', this.handleWindowFocus)
7691
}
7792

7893
newFlag = () => {
@@ -119,15 +134,7 @@ const FeaturesPage = class extends Component {
119134
)
120135
}
121136
if (page) {
122-
AppActions.getFeatures(
123-
this.projectId,
124-
this.props.match.params.environmentId,
125-
true,
126-
f.search,
127-
f.sort,
128-
page,
129-
getServerFilter(f),
130-
)
137+
this.fetchFeatures(f, page)
131138
} else {
132139
AppActions.searchFeatures(
133140
this.projectId,
@@ -207,13 +214,13 @@ const FeaturesPage = class extends Component {
207214

208215
return (
209216
<div className='features-page'>
210-
{(isLoading || !this.state.loadedOnce) &&
217+
{!this.state.loadedOnce &&
211218
(!projectFlags || !projectFlags.length) && (
212219
<div className='centered-container'>
213220
<Loader />
214221
</div>
215222
)}
216-
{(!isLoading || this.state.loadedOnce) && (
223+
{this.state.loadedOnce && (
217224
<div>
218225
{this.state.loadedOnce ||
219226
((this.state.filters.is_archived ||
@@ -283,7 +290,7 @@ const FeaturesPage = class extends Component {
283290
</PageTitle>
284291
<FormGroup
285292
className={classNames('mb-4', {
286-
'opacity-50': isSaving,
293+
'opacity-50': isSaving || isLoading,
287294
})}
288295
>
289296
<PanelSearch

0 commit comments

Comments
 (0)