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

Extract const for APPROXIMATELY_EVERYTHING #2462

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion app/api/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// Here we add some handy stuff to window for use from the browser JS console.
// requests will use the session cookie, same as normal API calls

import { APPROXIMATELY_EVERYTHING } from '~/util/consts'

import { type ApiResult } from './__generated__/http-client'
import { api } from './client'

Expand Down Expand Up @@ -58,7 +60,9 @@ if (typeof window !== 'undefined') {
return data
},
schemas: async (search?: string) => {
const result = await api.methods.timeseriesSchemaList({ query: { limit: 1000 } })
const result = await api.methods.timeseriesSchemaList({
query: { limit: APPROXIMATELY_EVERYTHING },
})
const data = handleResult(result)

let filtered = data.items
Expand Down
3 changes: 2 additions & 1 deletion app/components/AttachEphemeralIpModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import { useInstanceSelector } from '~/hooks/use-params'
import { addToast } from '~/stores/toast'
import { Badge } from '~/ui/lib/Badge'
import { Modal } from '~/ui/lib/Modal'
import { APPROXIMATELY_EVERYTHING } from '~/util/consts'

export const AttachEphemeralIpModal = ({ onDismiss }: { onDismiss: () => void }) => {
const queryClient = useApiQueryClient()
const { project, instance } = useInstanceSelector()
const { data: siloPools } = usePrefetchedApiQuery('projectIpPoolList', {
query: { limit: 1000 },
query: { limit: APPROXIMATELY_EVERYTHING },
})
const defaultPool = useMemo(
() => siloPools?.items.find((pool) => pool.isDefault),
Expand Down
5 changes: 4 additions & 1 deletion app/forms/disk-attach.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useApiQuery, type ApiError } from '@oxide/api'
import { ComboboxField } from '~/components/form/fields/ComboboxField'
import { SideModalForm } from '~/components/form/SideModalForm'
import { useProjectSelector } from '~/hooks/use-params'
import { APPROXIMATELY_EVERYTHING } from '~/util/consts'

const defaultValues = { name: '' }

Expand All @@ -37,7 +38,9 @@ export function AttachDiskSideModalForm({
}: AttachDiskProps) {
const { project } = useProjectSelector()

const { data } = useApiQuery('diskList', { query: { project, limit: 1000 } })
const { data } = useApiQuery('diskList', {
query: { project, limit: APPROXIMATELY_EVERYTHING },
})
const detachedDisks =
data?.items.filter(
(d) => d.state.state === 'detached' && !diskNamesToExclude.includes(d.name)
Expand Down
5 changes: 3 additions & 2 deletions app/forms/firewall-rules-common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { Message } from '~/ui/lib/Message'
import * as MiniTable from '~/ui/lib/MiniTable'
import { TextInputHint } from '~/ui/lib/TextInput'
import { KEYS } from '~/ui/util/keys'
import { APPROXIMATELY_EVERYTHING } from '~/util/consts'
import { links } from '~/util/links'
import { capitalize } from '~/util/str'

Expand Down Expand Up @@ -244,12 +245,12 @@ export const CommonFields = ({ control, nameTaken, error }: CommonFieldsProps) =
const {
data: { items: instances },
} = usePrefetchedApiQuery('instanceList', {
query: { project, limit: 1000 },
query: { project, limit: APPROXIMATELY_EVERYTHING },
})
const {
data: { items: vpcs },
} = usePrefetchedApiQuery('vpcList', {
query: { project, limit: 1000 },
query: { project, limit: APPROXIMATELY_EVERYTHING },
})
const {
data: { items: vpcSubnets },
Expand Down
9 changes: 7 additions & 2 deletions app/forms/firewall-rules-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import { SideModalForm } from '~/components/form/SideModalForm'
import { getVpcSelector, useVpcSelector } from '~/hooks/use-params'
import { addToast } from '~/stores/toast'
import { APPROXIMATELY_EVERYTHING } from '~/util/consts'
import { pb } from '~/util/path-builder'

import { CommonFields } from './firewall-rules-common'
Expand Down Expand Up @@ -57,8 +58,12 @@ CreateFirewallRuleForm.loader = async ({ params }: LoaderFunctionArgs) => {
const { project, vpc } = getVpcSelector(params)
await Promise.all([
apiQueryClient.prefetchQuery('vpcFirewallRulesView', { query: { project, vpc } }),
apiQueryClient.prefetchQuery('instanceList', { query: { project, limit: 1000 } }),
apiQueryClient.prefetchQuery('vpcList', { query: { project, limit: 1000 } }),
apiQueryClient.prefetchQuery('instanceList', {
query: { project, limit: APPROXIMATELY_EVERYTHING },
}),
apiQueryClient.prefetchQuery('vpcList', {
query: { project, limit: APPROXIMATELY_EVERYTHING },
}),
apiQueryClient.prefetchQuery('vpcSubnetList', { query: { project, vpc } }),
])

Expand Down
9 changes: 7 additions & 2 deletions app/forms/firewall-rules-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
useFirewallRuleSelector,
useVpcSelector,
} from '~/hooks/use-params'
import { APPROXIMATELY_EVERYTHING } from '~/util/consts'
import { invariant } from '~/util/invariant'
import { pb } from '~/util/path-builder'

Expand All @@ -34,8 +35,12 @@ EditFirewallRuleForm.loader = async ({ params }: LoaderFunctionArgs) => {

const [firewallRules] = await Promise.all([
apiQueryClient.fetchQuery('vpcFirewallRulesView', { query: { project, vpc } }),
apiQueryClient.prefetchQuery('instanceList', { query: { project, limit: 1000 } }),
apiQueryClient.prefetchQuery('vpcList', { query: { project, limit: 1000 } }),
apiQueryClient.prefetchQuery('instanceList', {
query: { project, limit: APPROXIMATELY_EVERYTHING },
}),
apiQueryClient.prefetchQuery('vpcList', {
query: { project, limit: APPROXIMATELY_EVERYTHING },
}),
apiQueryClient.prefetchQuery('vpcSubnetList', { query: { project, vpc } }),
])

Expand Down
3 changes: 2 additions & 1 deletion app/forms/floating-ip-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useProjectSelector } from '~/hooks/use-params'
import { addToast } from '~/stores/toast'
import { Badge } from '~/ui/lib/Badge'
import { Message } from '~/ui/lib/Message'
import { APPROXIMATELY_EVERYTHING } from '~/util/consts'
import { pb } from '~/util/path-builder'

const toListboxItem = (p: SiloIpPool) => {
Expand Down Expand Up @@ -58,7 +59,7 @@ export function CreateFloatingIpSideModalForm() {
// 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 },
query: { limit: APPROXIMATELY_EVERYTHING },
})

const queryClient = useApiQueryClient()
Expand Down
13 changes: 9 additions & 4 deletions app/forms/instance-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import { Slash } from '~/ui/lib/Slash'
import { Tabs } from '~/ui/lib/Tabs'
import { TextInputHint } from '~/ui/lib/TextInput'
import { TipIcon } from '~/ui/lib/TipIcon'
import { APPROXIMATELY_EVERYTHING } from '~/util/consts'
import { readBlobAsBase64 } from '~/util/file'
import { docLinks, links } from '~/util/links'
import { nearest10 } from '~/util/math'
Expand Down Expand Up @@ -161,8 +162,12 @@ CreateInstanceForm.loader = async ({ params }: LoaderFunctionArgs) => {
query: { project, limit: DISK_FETCH_LIMIT },
}),
apiQueryClient.prefetchQuery('currentUserSshKeyList', {}),
apiQueryClient.prefetchQuery('projectIpPoolList', { query: { limit: 1000 } }),
apiQueryClient.prefetchQuery('floatingIpList', { query: { project, limit: 1000 } }),
apiQueryClient.prefetchQuery('projectIpPoolList', {
query: { limit: APPROXIMATELY_EVERYTHING },
}),
apiQueryClient.prefetchQuery('floatingIpList', {
query: { project, limit: APPROXIMATELY_EVERYTHING },
}),
])
return null
}
Expand Down Expand Up @@ -208,7 +213,7 @@ export function CreateInstanceForm() {

// projectIpPoolList fetches the pools linked to the current silo
const { data: siloPools } = usePrefetchedApiQuery('projectIpPoolList', {
query: { limit: 1000 },
query: { limit: APPROXIMATELY_EVERYTHING },
})
const defaultPool = useMemo(
() => (siloPools ? siloPools.items.find((p) => p.isDefault)?.name : undefined),
Expand Down Expand Up @@ -627,7 +632,7 @@ const AdvancedAccordion = ({

const { project } = useProjectSelector()
const { data: floatingIpList } = usePrefetchedApiQuery('floatingIpList', {
query: { project, limit: 1000 },
query: { project, limit: APPROXIMATELY_EVERYTHING },
})

// Filter out the IPs that are already attached to an instance
Expand Down
3 changes: 2 additions & 1 deletion app/forms/snapshot-create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import { NameField } from '~/components/form/fields/NameField'
import { SideModalForm } from '~/components/form/SideModalForm'
import { useProjectSelector } from '~/hooks/use-params'
import { addToast } from '~/stores/toast'
import { APPROXIMATELY_EVERYTHING } from '~/util/consts'
import { pb } from '~/util/path-builder'

const useSnapshotDiskItems = (projectSelector: PP.Project) => {
const { data: disks } = useApiQuery('diskList', {
query: { ...projectSelector, limit: 1000 },
query: { ...projectSelector, limit: APPROXIMATELY_EVERYTHING },
})
return (
disks?.items
Expand Down
3 changes: 2 additions & 1 deletion app/pages/project/floating-ips/FloatingIpsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { Modal } from '~/ui/lib/Modal'
import { PageHeader, PageTitle } from '~/ui/lib/PageHeader'
import { TableActions } from '~/ui/lib/Table'
import { Tooltip } from '~/ui/lib/Tooltip'
import { APPROXIMATELY_EVERYTHING } from '~/util/consts'
import { docLinks } from '~/util/links'
import { pb } from '~/util/path-builder'

Expand All @@ -63,7 +64,7 @@ FloatingIpsPage.loader = async ({ params }: LoaderFunctionArgs) => {
query: { project },
}),
apiQueryClient
.fetchQuery('projectIpPoolList', { query: { limit: 1000 } })
.fetchQuery('projectIpPoolList', { query: { limit: APPROXIMATELY_EVERYTHING } })
.then((pools) => {
for (const pool of pools.items) {
apiQueryClient.setQueryData(
Expand Down
11 changes: 6 additions & 5 deletions app/pages/project/instances/instance/tabs/NetworkingTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { CreateButton } from '~/ui/lib/CreateButton'
import { EmptyMessage } from '~/ui/lib/EmptyMessage'
import { TableControls, TableEmptyBox, TableTitle } from '~/ui/lib/Table'
import { TipIcon } from '~/ui/lib/TipIcon'
import { APPROXIMATELY_EVERYTHING } from '~/util/consts'
import { pb } from '~/util/path-builder'

import { fancifyStates } from './common'
Expand Down Expand Up @@ -86,10 +87,10 @@ NetworkingTab.loader = async ({ params }: LoaderFunctionArgs) => {
await Promise.all([
apiQueryClient.prefetchQuery('instanceNetworkInterfaceList', {
// we want this to cover all NICs; TODO: determine actual limit?
query: { project, instance, limit: 1000 },
query: { project, instance, limit: APPROXIMATELY_EVERYTHING },
}),
apiQueryClient.prefetchQuery('floatingIpList', {
query: { project, limit: 1000 },
query: { project, limit: APPROXIMATELY_EVERYTHING },
}),
// dupe of page-level fetch but that's fine, RQ dedupes
apiQueryClient.prefetchQuery('instanceExternalIpList', {
Expand All @@ -104,7 +105,7 @@ NetworkingTab.loader = async ({ params }: LoaderFunctionArgs) => {
}),
// This is used in AttachEphemeralIpModal
apiQueryClient.prefetchQuery('projectIpPoolList', {
query: { limit: 1000 },
query: { limit: APPROXIMATELY_EVERYTHING },
}),
])
return null
Expand Down Expand Up @@ -184,7 +185,7 @@ export function NetworkingTab() {

// Fetch the floating IPs to show in the "Attach floating IP" modal
const { data: ips } = usePrefetchedApiQuery('floatingIpList', {
query: { project, limit: 1000 },
query: { project, limit: APPROXIMATELY_EVERYTHING },
})
// Filter out the IPs that are already attached to an instance
const availableIps = useMemo(() => ips.items.filter((ip) => !ip.instanceId), [ips])
Expand Down Expand Up @@ -266,7 +267,7 @@ export function NetworkingTab() {
const columns = useColsWithActions(staticCols, makeActions)

const nics = usePrefetchedApiQuery('instanceNetworkInterfaceList', {
query: { ...instanceSelector, limit: 1000 },
query: { ...instanceSelector, limit: APPROXIMATELY_EVERYTHING },
}).data.items

const tableInstance = useReactTable({
Expand Down
5 changes: 3 additions & 2 deletions app/pages/system/networking/IpPoolPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { Modal } from '~/ui/lib/Modal'
import { PageHeader, PageTitle } from '~/ui/lib/PageHeader'
import { Tabs } from '~/ui/lib/Tabs'
import { TipIcon } from '~/ui/lib/TipIcon'
import { APPROXIMATELY_EVERYTHING } from '~/util/consts'
import { docLinks } from '~/util/links'
import { pb } from '~/util/path-builder'

Expand Down Expand Up @@ -371,9 +372,9 @@ function LinkSiloModal({ onDismiss }: { onDismiss: () => void }) {

const linkedSilos = useApiQuery('ipPoolSiloList', {
path: { pool },
query: { limit: 1000 },
query: { limit: APPROXIMATELY_EVERYTHING },
})
const allSilos = useApiQuery('siloList', { query: { limit: 1000 } })
const allSilos = useApiQuery('siloList', { query: { limit: APPROXIMATELY_EVERYTHING } })

// in order to get the list of remaining unlinked silos, we have to get the
// list of all silos and remove the already linked ones
Expand Down
7 changes: 4 additions & 3 deletions app/pages/system/silos/SiloIpPoolsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { CreateButton } from '~/ui/lib/CreateButton'
import { EmptyMessage } from '~/ui/lib/EmptyMessage'
import { Message } from '~/ui/lib/Message'
import { Modal } from '~/ui/lib/Modal'
import { APPROXIMATELY_EVERYTHING } from '~/util/consts'
import { pb } from '~/util/path-builder'

const EmptyState = () => (
Expand Down Expand Up @@ -62,7 +63,7 @@ export function SiloIpPoolsTab() {
// default that fast anyway.
const { data: allPools } = useApiQuery('siloIpPoolList', {
path: { silo },
query: { limit: 1000 },
query: { limit: APPROXIMATELY_EVERYTHING },
})

// used in change default confirm modal
Expand Down Expand Up @@ -198,9 +199,9 @@ function LinkPoolModal({ onDismiss }: { onDismiss: () => void }) {

const linkedPools = useApiQuery('siloIpPoolList', {
path: { silo },
query: { limit: 1000 },
query: { limit: APPROXIMATELY_EVERYTHING },
})
const allPools = useApiQuery('ipPoolList', { query: { limit: 1000 } })
const allPools = useApiQuery('ipPoolList', { query: { limit: APPROXIMATELY_EVERYTHING } })

// in order to get the list of remaining unlinked pools, we have to get the
// list of all pools and remove the already linked ones
Expand Down
9 changes: 9 additions & 0 deletions app/util/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright Oxide Computer Company
*/

export const APPROXIMATELY_EVERYTHING = 1000
Loading