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

fix: Fix bundle select not updating list of bundles when changing branch #2765

Merged
Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { forwardRef, useState } from 'react'
import { forwardRef, useMemo, useState } from 'react'
import { useHistory, useParams } from 'react-router-dom'

import { useBranchBundlesNames } from 'services/bundleAnalysis'
Expand Down Expand Up @@ -50,6 +50,7 @@ const BundleSelector = forwardRef(({}, ref) => {
branch: branchParam,
bundle,
} = useParams<URLParams>()

const [selectedBundle, setSelectedBundle] = useState<string | undefined>(
() => {
if (bundle) {
Expand Down Expand Up @@ -77,8 +78,11 @@ const BundleSelector = forwardRef(({}, ref) => {

// Note: There's no real way to test this as the data is resolved during
// suspense and the component is not rendered until the data is resolved.
const bundles = bundleData?.bundles ?? []
const [bundlesState, setBundlesState] = useState<Array<string>>(() => bundles)
const bundles = useMemo(
() => bundleData?.bundles ?? [],
[bundleData?.bundles]
)
const [filteredBundles, setFilteredBundles] = useState<Array<string>>([])

return (
<div className="md:w-[16rem]">
Expand All @@ -97,7 +101,7 @@ const BundleSelector = forwardRef(({}, ref) => {
ariaName="bundle tab bundle selector"
variant="gray"
isLoading={bundlesIsLoading}
items={bundlesState}
items={search !== '' ? filteredBundles : bundles}
value={selectedBundle ?? 'Select bundle'}
onChange={(name: string) => {
setSelectedBundle(name)
Expand All @@ -115,13 +119,13 @@ const BundleSelector = forwardRef(({}, ref) => {
onSearch={(term: string) => {
setSearch(term)
if (term !== '') {
setBundlesState(
setFilteredBundles(
bundles.filter((bundle) =>
bundle.toLowerCase().includes(term.toLowerCase())
)
)
} else {
setBundlesState(bundles)
setFilteredBundles([])
}
}}
searchValue={search}
Expand Down
Loading