Skip to content

Commit

Permalink
fix: Preserve selected environment (#4190)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg authored Jun 20, 2024
1 parent 8d46e06 commit 6bf9858
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
22 changes: 13 additions & 9 deletions frontend/web/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,19 @@ const App = class extends Component {
this.listenTo(AccountStore, 'change', this.getOrganisationUsage)
this.getOrganisationUsage()
window.addEventListener('scroll', this.handleScroll)
AsyncStorage.getItem('lastEnv').then((res) => {
if (res) {
const lastEnv = JSON.parse(res)
this.setState({
lastEnvironmentId: lastEnv.environmentId,
lastProjectId: lastEnv.projectId,
})
}
})
const updateLastViewed = () => {
AsyncStorage.getItem('lastEnv').then((res) => {
if (res) {
const lastEnv = JSON.parse(res)
this.setState({
lastEnvironmentId: lastEnv.environmentId,
lastProjectId: lastEnv.projectId,
})
}
})
}
this.props.history.listen(updateLastViewed)
updateLastViewed()
}

getOrganisationUsage = () => {
Expand Down
32 changes: 14 additions & 18 deletions frontend/web/components/pages/HomeAside.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,20 @@ const HomeAside: FC<HomeAsideType> = ({
}}
onChange={(newEnvironmentId) => {
if (newEnvironmentId !== environmentId) {
history.push(
`${document.location.pathname}${
document.location.search || ''
}`.replace(environmentId, newEnvironmentId),
)
AsyncStorage.setItem(
'lastEnv',
JSON.stringify({
environmentId: newEnvironmentId,
orgId: AccountStore.getOrganisation().id,
projectId: projectId,
}),
).finally(() => {
history.push(
`${document.location.pathname}${
document.location.search || ''
}`.replace(environmentId, newEnvironmentId),
)
})
}
}}
/>
Expand Down Expand Up @@ -262,19 +271,6 @@ const HomeAside: FC<HomeAsideType> = ({
projectId={projectId}
environmentId={environmentId}
clearableValue={false}
onChange={(environment: string) => {
history.push(
`/project/${projectId}/environment/${environment}/features`,
)
AsyncStorage.setItem(
'lastEnv',
JSON.stringify({
environmentId: environment,
orgId: AccountStore.getOrganisation().id,
projectId: projectId,
}),
)
}}
/>
</div>
)
Expand Down

0 comments on commit 6bf9858

Please sign in to comment.