Skip to content
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
5 changes: 1 addition & 4 deletions app/pages/project/floating-ips/AttachFloatingIpModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ function FloatingIpLabel({ fip }: { fip: FloatingIp }) {
export const AttachFloatingIpModal = ({
floatingIps,
instance,
project,
onDismiss,
}: {
floatingIps: Array<FloatingIp>
instance: Instance
project: string
onDismiss: () => void
}) => {
const queryClient = useApiQueryClient()
Expand Down Expand Up @@ -88,8 +86,7 @@ export const AttachFloatingIpModal = ({
disabled={!floatingIp}
onAction={() =>
floatingIpAttach.mutate({
path: { floatingIp },
query: { project },
path: { floatingIp }, // note that this is an ID!
body: { kind: 'instance', parent: instance.id },
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ export function NetworkingTab() {
floatingIps={availableIps}
instance={instance}
onDismiss={() => setAttachModalOpen(false)}
project={project}
/>
)}
</TableControls>
Expand Down
11 changes: 10 additions & 1 deletion mock-api/msw/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as mock from '@oxide/api-mocks'

import { json } from '~/api/__generated__/msw-handlers'
import { pick } from '~/util/object'
import { commaSeries } from '~/util/str'

import type { Json } from '../json-type'
import { internalError } from './util'
Expand All @@ -25,6 +26,11 @@ export const notFoundErr = (msg?: string) => {
return json({ error_code: 'ObjectNotFound', message } as const, { status: 404 })
}

export const badSelectorErr = (resource: string, parents: string[]) => {
const message = `when ${resource} is specified by ID, ${commaSeries(parents, 'and')} should not be specified`
return json({ error_code: 'InvalidRequest', message }, { status: 400 })
}

export const lookupById = <T extends { id: string }>(table: T[], id: string) => {
const item = table.find((i) => i.id === id)
if (!item) throw notFoundErr
Expand Down Expand Up @@ -85,7 +91,10 @@ export const lookup = {
floatingIp({ floatingIp: id, ...projectSelector }: PP.FloatingIp): Json<Api.FloatingIp> {
if (!id) throw notFoundErr

if (isUuid(id)) return lookupById(db.floatingIps, id)
if (isUuid(id)) {
if (projectSelector.project) throw badSelectorErr('floating IP', ['project'])
return lookupById(db.floatingIps, id)
}

const project = lookup.project(projectSelector)
const floatingIp = db.floatingIps.find(
Expand Down