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

Don't prefetch IP pools for floating IP create #1969

Merged
merged 1 commit into from
Feb 23, 2024
Merged
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
17 changes: 5 additions & 12 deletions app/forms/floating-ip-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import { useNavigate } from 'react-router-dom'
import type { SetRequired } from 'type-fest'

import {
apiQueryClient,
useApiMutation,
useApiQuery,
useApiQueryClient,
usePrefetchedApiQuery,
type FloatingIpCreate,
type SiloIpPool,
} from '@oxide/api'
Expand All @@ -32,13 +31,6 @@ import {
import { useForm, useProjectSelector, useToast } from 'app/hooks'
import { pb } from 'app/util/path-builder'

CreateFloatingIpSideModalForm.loader = async () => {
await apiQueryClient.prefetchQuery('projectIpPoolList', {
query: { limit: 1000 },
})
return null
}

const toListboxItem = (p: SiloIpPool) => {
if (!p.isDefault) {
return { value: p.name, label: p.name }
Expand Down Expand Up @@ -66,8 +58,9 @@ const defaultValues: SetRequired<FloatingIpCreate, 'address'> = {
}

export function CreateFloatingIpSideModalForm() {
// Fetch 1000 to we can be sure to get them all.
const { data: allPools } = usePrefetchedApiQuery('projectIpPoolList', {
// Fetch 1000 to we can be sure to get them all. Don't bother prefetching
// because the list is hidden under the Advanced accordion.
const { data: allPools } = useApiQuery('projectIpPoolList', {
query: { limit: 1000 },
})

Expand Down Expand Up @@ -126,7 +119,7 @@ export function CreateFloatingIpSideModalForm() {

<ListboxField
name="pool"
items={allPools.items.map((p) => toListboxItem(p))}
items={(allPools?.items || []).map((p) => toListboxItem(p))}
label="IP pool"
control={form.control}
placeholder="Select pool"
Expand Down
1 change: 0 additions & 1 deletion app/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ export const routes = createRoutesFromElements(
<Route path="floating-ips" handle={{ crumb: 'Floating IPs' }} element={null} />
<Route
path="floating-ips-new"
loader={CreateFloatingIpSideModalForm.loader}
element={<CreateFloatingIpSideModalForm />}
handle={{ crumb: 'New Floating IP' }}
/>
Expand Down
Loading