Repository navigation
Bind on the Domains page sends only the domains still offered for binding #1840
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { Cluster, SchemaOrganizationDomain } from '@/integrations/api/api.patch'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { bindableDomainIds, canBindDomain } from './canBindDomain'; | ||
|
|
||
| const cluster = { id: 'clu-1', plans: [{ planId: 'standard' }] } as Cluster; | ||
| const domain = { id: 'dom-1', domain: 'a.example.com', status: 'ACTIVE' } as SchemaOrganizationDomain; | ||
|
|
||
| describe('canBindDomain', () => { | ||
| it('offers a verified domain that no cluster holds', () => { | ||
| expect(canBindDomain(domain, cluster)).toBe(true); | ||
| }); | ||
|
|
||
| it('does not offer a domain still awaiting verification', () => { | ||
| expect(canBindDomain({ ...domain, status: 'PENDING_VALIDATION' }, cluster)).toBe(false); | ||
| }); | ||
|
|
||
| it('does not offer a domain bound to any cluster, this one included', () => { | ||
| expect(canBindDomain({ ...domain, clusterId: 'clu-2' }, cluster)).toBe(false); | ||
| expect(canBindDomain({ ...domain, clusterId: 'clu-1' }, cluster)).toBe(false); | ||
| }); | ||
|
|
||
| it('offers nothing to a self-managed cluster', () => { | ||
| expect(canBindDomain(domain, { ...cluster, plans: [{ planId: 'self-hosted' }] } as Cluster)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('bindableDomainIds', () => { | ||
| const other = { ...domain, id: 'dom-2', domain: 'b.example.com' }; | ||
|
|
||
| it('keeps the ticked ids the list still offers, in the order they were ticked', () => { | ||
| expect(bindableDomainIds(['dom-2', 'dom-1'], [domain, other], cluster)).toEqual(['dom-2', 'dom-1']); | ||
| }); | ||
|
|
||
| it('drops a ticked id the list no longer has, or no longer offers', () => { | ||
| expect(bindableDomainIds(['dom-1', 'dom-2'], [{ ...domain, clusterId: 'clu-2' }], cluster)).toEqual([]); | ||
| }); | ||
|
|
||
| it('offers nothing before the list has loaded', () => { | ||
| expect(bindableDomainIds(['dom-1'], undefined, cluster)).toEqual([]); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { Cluster, SchemaOrganizationDomain } from '@/integrations/api/api.patch'; | ||
| import { clusterIsSelfManaged } from '@/integrations/api/clusterIsSelfManaged'; | ||
|
|
||
| export function canBindDomain(domain: SchemaOrganizationDomain, cluster: Cluster): boolean { | ||
| return domain.status === 'ACTIVE' && !domain.clusterId && !clusterIsSelfManaged(cluster); | ||
| } | ||
|
|
||
| /** The ticked ids the list still offers for binding, in the order they were ticked. */ | ||
| export function bindableDomainIds( | ||
| selectedDomainIds: string[], | ||
| domains: SchemaOrganizationDomain[] | undefined, | ||
| cluster: Cluster, | ||
| ): string[] { | ||
| return selectedDomainIds.filter((id) => | ||
| domains?.some((domain) => domain.id === id && canBindDomain(domain, cluster)) | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,24 @@ | ||
| import { Button } from '@/components/ui/button'; | ||
| import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'; | ||
| import { AssociateDomainWithCluster } from '@/features/cluster/domains/AssociateDomainWithCluster'; | ||
| import { canBindDomain } from '@/features/cluster/domains/canBindDomain'; | ||
| import { CertificateProgress } from '@/features/cluster/domains/components/CertificateProgress'; | ||
| import { | ||
| isGeneratingCertificate, | ||
| useChallengeCertificates, | ||
| } from '@/features/cluster/domains/queries/getChallengeCertificates'; | ||
| import { VerifyDomainOwnership } from '@/features/cluster/domains/VerifyDomainOwnership'; | ||
| import { useIsSettingDomainIds, useSetDomainIdsOnCluster } from '@/features/clusters/mutations/setDomainIdsOnCluster'; | ||
| import { | ||
| isSettingDomainIds, | ||
| useIsSettingDomainIds, | ||
| useSetDomainIdsOnCluster, | ||
| } from '@/features/clusters/mutations/setDomainIdsOnCluster'; | ||
| import { useDeleteDomain } from '@/features/organization/mutations/deleteDomain'; | ||
| import { Cluster, SchemaOrganizationDomain } from '@/integrations/api/api.patch'; | ||
| import { clusterIsSelfManaged } from '@/integrations/api/clusterIsSelfManaged'; | ||
| import { ColumnDef, createColumnHelper } from '@/lib/table'; | ||
| import { queryClient } from '@/react-query/queryClient'; | ||
| import { useQueryClient } from '@tanstack/react-query'; | ||
| import { useCallback, useMemo } from 'react'; | ||
| import { toast } from 'sonner'; | ||
|
|
||
|
|
@@ -33,17 +39,23 @@ export function useDataTableColumns( | |
| const settingDomainIds = useIsSettingDomainIds(); | ||
| const { mutate: deleteDomain, isPending: deletePending } = useDeleteDomain(); | ||
| const isPending = settingDomainIds || deletePending; | ||
| const activeQueryClient = useQueryClient(); | ||
|
|
||
| const deleteDomainById = useCallback((domainId: string) => { | ||
| // A Bind sending this domain disables Remove only once React re-renders. | ||
| if (isSettingDomainIds(activeQueryClient)) { | ||
| return; | ||
| } | ||
| deleteDomain({ | ||
| domainId: domainId, | ||
| organizationId: cluster.organizationId, | ||
| }, { | ||
| onSuccess: () => { | ||
| void queryClient.invalidateQueries({ queryKey: [cluster.organizationId, 'domains'], refetchType: 'active' }); | ||
| toast.success('Domain removed!'); | ||
| }, | ||
| }); | ||
| }, [deleteDomain, cluster.organizationId]); | ||
| }, [activeQueryClient, deleteDomain, cluster.organizationId]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||
|
|
||
| const unbindDomainById = useCallback((domainId: string) => { | ||
| // No `generateDomainCerts`: the flag is cluster-wide, so restating it here would decide cert | ||
|
|
@@ -66,8 +78,7 @@ export function useDataTableColumns( | |
| size: 50, | ||
| cell: (props) => { | ||
| const domain = props.row.original; | ||
| const canBind = domain.status === 'ACTIVE' && !domain.clusterId && !clusterIsSelfManaged(cluster); | ||
| if (!canBind) { | ||
| if (!canBindDomain(domain, cluster)) { | ||
| return null; | ||
| } | ||
| return ( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
onBindClick,queryClient.invalidateQueriesis called on line 128 using the globalqueryClientimport instead of the context-providedactiveQueryClient. This can cause query invalidation to fail or be ignored in environments with custom query clients (such as during testing). Please update it to useactiveQueryClient.invalidateQuerieson line 128.