Skip to content

Commit 124b6e9

Browse files
committed
feat: Add domains to more spots
1 parent 64f9b68 commit 124b6e9

File tree

7 files changed

+102
-9
lines changed

7 files changed

+102
-9
lines changed

src/config/useEntityRestURL.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function useEntityRestURL(): string | null {
1414

1515
const isFabricConnect = (!!clusterId && authStore.checkForFabricConnect(clusterId))
1616
|| !!instanceId && authStore.checkForFabricConnect(instanceId);
17-
if (isFabricConnect) {
17+
if (isFabricConnect || (cluster && !instanceId)) {
1818
return getRestUrlForCluster(cluster);
1919
} else if (instanceClient.defaults.baseURL) {
2020
return instanceClient.defaults.baseURL.replace(/:9925\/?/, '');
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { TextLoadingSkeleton } from '@/components/TextLoadingSkeleton';
2+
import { Button } from '@/components/ui/button';
3+
import { useCopyToClipboard } from '@/hooks/useCopyToClipboard';
4+
import { Cluster } from '@/integrations/api/api.patch';
5+
import { CopyIcon } from 'lucide-react';
6+
7+
export const ClusterDomainsList = ({
8+
loadingInstanceInfo,
9+
clusterInfo,
10+
}: {
11+
loadingInstanceInfo?: boolean;
12+
clusterInfo?: Cluster | undefined;
13+
}) => {
14+
return (
15+
<>
16+
<dt className="font-bold text-sm/6">Cluster Domains</dt>
17+
<dd className="text-sm/6 sm:mt-2">
18+
{loadingInstanceInfo
19+
? <TextLoadingSkeleton />
20+
: clusterInfo?.domains?.map((domain) => <ClusterDomainUrl key={domain.id} domain={domain.domain} />)}
21+
</dd>
22+
</>
23+
);
24+
};
25+
26+
function ClusterDomainUrl({ domain }: { domain: string }) {
27+
const [onCopyClick] = useCopyToClipboard(domain || '');
28+
return (
29+
<div key={domain}>
30+
{domain}
31+
<Button
32+
className="ml-2"
33+
type="button"
34+
variant="default"
35+
size="sm"
36+
onClick={onCopyClick}
37+
>
38+
<CopyIcon className="w-4 h-4" />
39+
</Button>
40+
</div>
41+
);
42+
}

src/features/instance/config/overview/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { isLocalStudio } from '@/config/constants';
55
import { useInstanceClientIdParams } from '@/config/useInstanceClient';
66
import { getInstanceInfoQueryOptions } from '@/features/cluster/queries/getInstanceInfoQuery';
77
import { ApplicationURL } from '@/features/instance/config/overview/components/ApplicationURL';
8+
import { ClusterDomainsList } from '@/features/instance/config/overview/components/ClusterDomainsList';
89
import { HarperVersion } from '@/features/instance/config/overview/components/HarperVersion';
910
import { InstanceNodeName } from '@/features/instance/config/overview/components/InstanceNodeName';
1011
import { InstanceURL } from '@/features/instance/config/overview/components/InstanceURL';
@@ -108,6 +109,11 @@ export function ConfigOverviewIndex() {
108109
<div className="px-4 pb-4 sm:col-span-2 sm:px-0">
109110
<ApplicationURL loadingInstanceInfo={loadingInstanceInfo} clusterInfo={clusterInfo} />
110111
</div>
112+
{clusterInfo?.domains?.length && (
113+
<div className="px-4 pb-4 sm:col-span-3 sm:px-0">
114+
<ClusterDomainsList loadingInstanceInfo={loadingInstanceInfo} clusterInfo={clusterInfo} />
115+
</div>
116+
)}
111117
</dl>
112118
</CloudStudioOverview>
113119
)}

src/integrations/api/api.patch.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export interface Cluster extends SchemaCluster {
9696
// TODO: Can we return enums from the server to make this easier?
9797
status?: string | 'PROVISIONING' | 'UPDATING' | 'RUNNING' | 'TERMINATED' | 'FAILED';
9898
domainIds?: string[];
99-
domains?: Array<{ domain: string }>;
99+
domains?: Array<{ id: string; domain: string }>;
100100
}
101101

102102
export interface InstanceDatabaseMap {
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { Cluster } from '@/integrations/api/api.patch';
2+
import { linkify } from '@/lib/urls/linkify';
23

3-
export function getRestUrlForCluster(cluster: undefined | Pick<Cluster, 'fqdn'>): string | null {
4-
let fqdn = cluster?.fqdn;
5-
if (!fqdn) {
6-
return null;
4+
export function getRestUrlForCluster(cluster: undefined | Pick<Cluster, 'fqdn' | 'domains'>): string | null {
5+
if (cluster?.domains) {
6+
for (const domain of cluster.domains) {
7+
if (domain.domain) {
8+
return linkify(domain.domain);
9+
}
10+
}
711
}
8-
if (!fqdn.match(/^https?:\/\//i)) {
9-
fqdn = `https://${fqdn}`;
12+
if (!cluster?.fqdn) {
13+
return null;
1014
}
11-
return new URL(fqdn).toString();
15+
return linkify(cluster.fqdn);
1216
}

src/lib/urls/linkify.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { linkify } from './linkify';
3+
4+
describe('linkify', () => {
5+
it('should add https:// prefix if no protocol is present', () => {
6+
expect(linkify('example.com')).toBe('https://example.com/');
7+
});
8+
9+
it('should preserve http:// protocol', () => {
10+
expect(linkify('http://example.com')).toBe('http://example.com/');
11+
});
12+
13+
it('should preserve https:// protocol', () => {
14+
expect(linkify('https://example.com')).toBe('https://example.com/');
15+
});
16+
17+
it('should handle subdomains and paths', () => {
18+
expect(linkify('sub.example.com/path/to/resource')).toBe('https://sub.example.com/path/to/resource');
19+
});
20+
21+
it('should be case-insensitive when checking for protocol', () => {
22+
expect(linkify('HTTP://example.com')).toBe('http://example.com/');
23+
expect(linkify('Https://example.com')).toBe('https://example.com/');
24+
});
25+
26+
it('should handle fqdn with port', () => {
27+
expect(linkify('localhost:3000')).toBe('https://localhost:3000/');
28+
});
29+
30+
it('should throw error for invalid URL strings that cannot be parsed by URL constructor', () => {
31+
// URL constructor throws if the resulting string is not a valid URL
32+
expect(() => linkify('!!@@##')).toThrow();
33+
});
34+
});

src/lib/urls/linkify.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function linkify(fqdn: string): string {
2+
return new URL(
3+
!fqdn.match(/^https?:\/\//i)
4+
? `https://${fqdn}`
5+
: fqdn,
6+
).toString();
7+
}

0 commit comments

Comments
 (0)