Files
supabase/apps/studio/components/interfaces/Support/OrganizationSelector.tsx
Joshen Lim 6d08d66b7d Add eslint rule for google translate dynamic spans + address all issues (#52949)
## Context

We've been seeing many `NotFoundError: Failed to execute 'removeChild'
on 'Node'` and `NotFoundError: Failed to execute 'insertBefore' on
'Node'` events on Sentry which are historically known to be caused by
Google Translate in the browser.

There's technically no _right way_ to address this unfortunately, but
one of the solutions which should address most of these issues is to
wrap any dynamic text within a span - we've considered that quite a
while back tbh but never took the time to do this until today with the
help of Claude. Although just a heads up that it might not necessarily
completely eradicate those issues.

Also added an eslint rule which should prevent future occurences of this
<img width="1264" height="192" alt="image"
src="https://github.com/user-attachments/assets/b2c32ea0-45a2-4ccd-82fe-1a859905fc29"
/>
2026-11-05 23:28:46 +08:00

85 lines
3.1 KiB
TypeScript

import type { UseFormReturn } from 'react-hook-form'
import {
Badge,
FormControl,
FormField,
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectTrigger,
SelectValue,
} from 'ui'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import type { SupportFormValues } from './SupportForm.schema'
import { getOrgSubscriptionPlan, NO_ORG_MARKER, NO_PROJECT_MARKER } from './SupportForm.utils'
// End of third-party imports
import { useOrganizationsQuery } from '@/data/organizations/organizations-query'
interface OrganizationSelectorProps {
form: UseFormReturn<SupportFormValues>
orgSlug: string | null
}
export function OrganizationSelector({ form, orgSlug }: OrganizationSelectorProps) {
const { data: organizations, isSuccess: isSuccessOrganizations } = useOrganizationsQuery()
const subscriptionPlanId = getOrgSubscriptionPlan(organizations, orgSlug)
return (
<FormField
name="organizationSlug"
control={form.control}
render={({ field }) => {
const { ref: _ref, ...fieldWithoutRef } = field
return (
<FormItemLayout hideMessage layout="vertical" label="Which organization is affected?">
<FormControl>
<Select
{...fieldWithoutRef}
disabled={!isSuccessOrganizations}
defaultValue={field.value}
onValueChange={(value) => {
const previousOrgSlug = form.getValues('organizationSlug')
field.onChange(value)
if (previousOrgSlug !== value) {
form.resetField('projectRef', { defaultValue: NO_PROJECT_MARKER })
}
}}
>
<SelectTrigger className="w-full" aria-label="Select an organization">
<SelectValue asChild placeholder="Select an organization">
<div className="flex items-center gap-x-2">
{orgSlug === NO_ORG_MARKER ? (
<span>No specific organization</span>
) : (
<span>
{(organizations ?? []).find((o) => o.slug === field.value)?.name}
</span>
)}
{subscriptionPlanId && <Badge variant="default">{subscriptionPlanId}</Badge>}
</div>
</SelectValue>
</SelectTrigger>
<SelectContent>
<SelectGroup>
{organizations?.map((org) => (
<SelectItem key={org.slug} value={org.slug}>
{org.name}
</SelectItem>
))}
{isSuccessOrganizations && (organizations ?? []).length === 0 && (
<SelectItem value={NO_ORG_MARKER}>No specific organization</SelectItem>
)}
</SelectGroup>
</SelectContent>
</Select>
</FormControl>
</FormItemLayout>
)
}}
/>
)
}