Skip to content

Commit 606def2

Browse files
committed
fix: Show and properly apply licenses
https://harperdb.atlassian.net/browse/STUDIO-650
1 parent 283f54d commit 606def2

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed

src/components/ApplyLicensesButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function ApplyLicensesButton({
3030
</Button>
3131
</TooltipTrigger>
3232
<TooltipContent>
33-
{countNewLicensesAre} available for this instance. After applying, you will want to restart the instance.
33+
{countNewLicensesAre} available for this instance.
3434
</TooltipContent>
3535
</Tooltip>
3636
);

src/features/cluster/queries/getInstanceInfoQuery.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export function getInstanceInfoQueryOptions(params: GetInstanceInfoParams) {
2929
return queryOptions({
3030
queryKey: [params.clusterId, params.instanceId] as const,
3131
queryFn: () => getInstanceInfo(params),
32+
enabled: !!params.clusterId && !!params.instanceId,
3233
retry: false,
3334
});
3435
}

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { ApplicationURL } from '@/features/instance/config/overview/components/A
88
import { HarperVersion } from '@/features/instance/config/overview/components/HarperVersion';
99
import { InstanceNodeName } from '@/features/instance/config/overview/components/InstanceNodeName';
1010
import { InstanceURL } from '@/features/instance/config/overview/components/InstanceURL';
11-
import { Instance } from '@/integrations/api/api.patch';
1211
import { getConfigurationQueryOptions } from '@/integrations/api/instance/status/getConfiguration';
1312
import {
1413
getRegistrationInfoQueryOptions,
@@ -19,7 +18,7 @@ import { keyBy } from '@/lib/keyBy';
1918
import { wasAReleasedBeforeB } from '@/lib/string/wasAReleasedBeforeB';
2019
import Editor from '@monaco-editor/react';
2120
import { useQuery } from '@tanstack/react-query';
22-
import { useLoaderData, useParams, useRouteContext } from '@tanstack/react-router';
21+
import { useLoaderData, useParams } from '@tanstack/react-router';
2322
import { ReactNode, useMemo } from 'react';
2423

2524
const LocalStudioOverview = ({ children }: { children: ReactNode }) => {
@@ -31,8 +30,10 @@ const CloudStudioOverview = ({ children }: { children: ReactNode }) => {
3130
};
3231

3332
export function ConfigOverviewIndex() {
34-
const { clusterId, instanceId }: { instanceId?: string; clusterId: string } = useParams({ strict: false });
35-
const { instance: cloudInstance }: { instance?: Instance } = useRouteContext({ strict: false });
33+
const { clusterId, instanceId }: { instanceId?: string; clusterId?: string } = useParams({ strict: false });
34+
const { data: cloudInstance } = useQuery(
35+
getInstanceInfoQueryOptions({ clusterId, instanceId }),
36+
);
3637
const targetNoun = (instanceId || isLocalStudio) ? 'Instance' : 'Cluster';
3738
const instanceParams = useInstanceClientIdParams();
3839

@@ -55,13 +56,13 @@ export function ConfigOverviewIndex() {
5556
);
5657

5758
const newLicenses = useMemo(() => {
58-
if (clusterId && !instanceId) {
59-
// We won't check the licenses when running through a load balancer.
59+
if (isLocalStudio) {
6060
return [];
6161
}
62-
if (appliedLicenses && cloudInstance?.licenses) {
62+
const cloudLicenses = cloudInstance?.instance?.licenses;
63+
if (appliedLicenses && cloudLicenses) {
6364
const appliedLicensesById = keyBy(appliedLicenses, 'id');
64-
return cloudInstance.licenses.filter(cloudLicense => !appliedLicensesById[cloudLicense.id]);
65+
return cloudLicenses.filter(cloudLicense => !appliedLicensesById[cloudLicense.id]);
6566
}
6667
return [];
6768
}, [clusterId, instanceId, appliedLicenses, cloudInstance]);

src/hooks/useApplyLicensesClick.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { ProgressBar } from '@/components/ProgressBar';
2-
import { useInstanceClient } from '@/config/useInstanceClient';
3-
import { useRestartInstanceClick } from '@/hooks/useRestartInstanceClick';
2+
import { useInstanceClient, useInstanceClientIdParams } from '@/config/useInstanceClient';
43
import { SchemaLicense } from '@/integrations/api/api.gen';
54
import { installUsageLicense } from '@/integrations/api/instance/auth/installUsageLicense';
65
import { getInstanceUserInfo } from '@/integrations/api/instance/status/getInstanceUserInfo';
76
import { excludeFalsy } from '@/lib/arrays/excludeFalsy';
87
import { sleep } from '@/lib/sleep';
98
import { useQueryClient } from '@tanstack/react-query';
10-
import { useParams } from '@tanstack/react-router';
119
import { useCallback, useState } from 'react';
1210
import { toast } from 'sonner';
1311

@@ -21,13 +19,9 @@ interface ApplyLicensesClickResponse {
2119
}
2220

2321
export function useApplyLicensesClick({ licenses }: ApplyLicensesClickParams): ApplyLicensesClickResponse {
22+
const instanceParams = useInstanceClientIdParams();
2423
const instanceClient = useInstanceClient();
25-
const { instanceId }: { instanceId?: string } = useParams({ strict: false });
2624
const queryClient = useQueryClient();
27-
const { isRestartPending, onRestartClick } = useRestartInstanceClick({
28-
operation: 'restart_service',
29-
instanceClient,
30-
});
3125

3226
const [isApplyLicensesPending, setIsApplyLicensesPending] = useState(false);
3327

@@ -100,10 +94,12 @@ export function useApplyLicensesClick({ licenses }: ApplyLicensesClickParams): A
10094
}
10195
}
10296

97+
await queryClient.invalidateQueries({
98+
queryKey: [instanceParams.entityId, 'get_usage_licenses'],
99+
refetchType: 'active',
100+
});
103101
setIsApplyLicensesPending(false);
104102

105-
void queryClient.invalidateQueries({ queryKey: [instanceId, 'get_configuration'], refetchType: 'active' });
106-
107103
const licenseWord = licenses.length === 1 ? 'License' : 'Licenses';
108104
if (canceled) {
109105
toast.error('Cancelled', {
@@ -118,13 +114,12 @@ export function useApplyLicensesClick({ licenses }: ApplyLicensesClickParams): A
118114
} else if (licenses.length === licensesApplied) {
119115
toast.success('Success', {
120116
id: toastId,
121-
description: `${licenseWord} applied!\nPlease restart your instance.`,
117+
description: `${licenseWord} applied!`,
122118
duration: 0,
123119
action: {
124-
label: 'Restart',
120+
label: 'OK',
125121
onClick: () => {
126122
toast.dismiss(toastId);
127-
onRestartClick();
128123
},
129124
},
130125
});
@@ -143,10 +138,10 @@ export function useApplyLicensesClick({ licenses }: ApplyLicensesClickParams): A
143138
},
144139
});
145140
}
146-
}, [instanceClient, instanceId, licenses, onRestartClick, queryClient]);
141+
}, [instanceClient, instanceParams.entityId, licenses, queryClient]);
147142

148143
return {
149144
onApplyLicensesClick,
150-
isApplyLicensesPending: isApplyLicensesPending || isRestartPending,
145+
isApplyLicensesPending,
151146
};
152147
}

0 commit comments

Comments
 (0)