fix release v2 recovery flows
This commit is contained in:
1 parent
ca856f9f54
commit
4905ea6738
44 files changed
+871
-201
No files matched your search
@@ -71,15 +71,16 @@ export const getDockerReconciliationAsync = async (db: Database) => {
|
||||
const app = linkedApp ?? exactApp ?? nameApp;
|
||||
const exactUrl = Boolean(exactIntegration || exactApp);
|
||||
const linked = Boolean(integration?.appId && linkedApp);
|
||||
const integrationMoved = Boolean(integration && !exactIntegration);
|
||||
const integrationAmbiguous =
|
||||
exactIntegrationMatches.length > 1 || (exactIntegrationMatches.length === 0 && nameIntegrationMatches.length > 1);
|
||||
const appAmbiguous =
|
||||
!linkedApp && (exactAppMatches.length > 1 || (exactAppMatches.length === 0 && nameAppMatches.length > 1));
|
||||
const ambiguous = integrationAmbiguous || appAmbiguous;
|
||||
const state: DockerReconciliationState = linked
|
||||
? "linked"
|
||||
: integration && !exactUrl
|
||||
? "moved"
|
||||
const state: DockerReconciliationState = integrationMoved
|
||||
? "moved"
|
||||
: linked
|
||||
? "linked"
|
||||
: integration || app
|
||||
? "represented"
|
||||
: match
|
||||
@@ -115,6 +116,8 @@ export const getDockerReconciliationAsync = async (db: Database) => {
|
||||
app: app ? { id: app.id, name: app.name, href: app.href } : null,
|
||||
signals: {
|
||||
exactUrl,
|
||||
exactIntegrationUrl: Boolean(exactIntegration),
|
||||
exactAppUrl: Boolean(exactApp),
|
||||
nameMatch: Boolean(nameIntegration || nameApp),
|
||||
linked,
|
||||
ambiguous,
|
||||
|
||||
@@ -90,21 +90,14 @@ export const integrationRouter = createTRPCRouter({
|
||||
});
|
||||
return integrations
|
||||
.map((integration) => {
|
||||
const permissions = integration.userPermissions
|
||||
.map(({ permission }) => permission)
|
||||
.concat(integration.groupPermissions.map(({ permission }) => permission));
|
||||
const permissions = constructIntegrationPermissions(integration, ctx.session);
|
||||
|
||||
return {
|
||||
id: integration.id,
|
||||
name: integration.name,
|
||||
kind: integration.kind,
|
||||
url: integration.url,
|
||||
permissions: {
|
||||
hasUseAccess:
|
||||
permissions.includes("use") || permissions.includes("interact") || permissions.includes("full"),
|
||||
hasInteractAccess: permissions.includes("interact") || permissions.includes("full"),
|
||||
hasFullAccess: permissions.includes("full"),
|
||||
},
|
||||
permissions,
|
||||
};
|
||||
})
|
||||
.toSorted(
|
||||
@@ -138,21 +131,14 @@ export const integrationRouter = createTRPCRouter({
|
||||
});
|
||||
return integrationsFromDb
|
||||
.map((integration) => {
|
||||
const permissions = integration.userPermissions
|
||||
.map(({ permission }) => permission)
|
||||
.concat(integration.groupPermissions.map(({ permission }) => permission));
|
||||
const permissions = constructIntegrationPermissions(integration, ctx.session);
|
||||
|
||||
return {
|
||||
id: integration.id,
|
||||
name: integration.name,
|
||||
kind: integration.kind,
|
||||
url: integration.url,
|
||||
permissions: {
|
||||
hasUseAccess:
|
||||
permissions.includes("use") || permissions.includes("interact") || permissions.includes("full"),
|
||||
hasInteractAccess: permissions.includes("interact") || permissions.includes("full"),
|
||||
hasFullAccess: permissions.includes("full"),
|
||||
},
|
||||
permissions,
|
||||
};
|
||||
})
|
||||
.toSorted(
|
||||
@@ -189,21 +175,14 @@ export const integrationRouter = createTRPCRouter({
|
||||
});
|
||||
return integrationsFromDb
|
||||
.map((integration) => {
|
||||
const permissions = integration.userPermissions
|
||||
.map(({ permission }) => permission)
|
||||
.concat(integration.groupPermissions.map(({ permission }) => permission));
|
||||
const permissions = constructIntegrationPermissions(integration, ctx.session);
|
||||
|
||||
return {
|
||||
id: integration.id,
|
||||
name: integration.name,
|
||||
kind: integration.kind,
|
||||
url: integration.url,
|
||||
permissions: {
|
||||
hasUseAccess:
|
||||
permissions.includes("use") || permissions.includes("interact") || permissions.includes("full"),
|
||||
hasInteractAccess: permissions.includes("interact") || permissions.includes("full"),
|
||||
hasFullAccess: permissions.includes("full"),
|
||||
},
|
||||
permissions,
|
||||
};
|
||||
})
|
||||
.toSorted(
|
||||
|
||||
@@ -42,10 +42,10 @@ describe("KubernetesClientRegistry", () => {
|
||||
for (const contextId of ["home", "remote", "metrics-degraded"]) {
|
||||
const client = registry.getClient(contextId);
|
||||
vi.spyOn(client.versionApi, "getCode").mockResolvedValue({} as never);
|
||||
vi.spyOn(client.metricsApi, "getNodeMetrics").mockResolvedValue({ items: [] } as never);
|
||||
vi.spyOn(client.metricsProbeApi, "listClusterCustomObject").mockResolvedValue({ items: [] } as never);
|
||||
}
|
||||
registry.getClient("remote").versionApi.getCode = vi.fn().mockRejectedValue(new Error("offline"));
|
||||
registry.getClient("metrics-degraded").metricsApi.getNodeMetrics = vi
|
||||
registry.getClient("metrics-degraded").metricsProbeApi.listClusterCustomObject = vi
|
||||
.fn()
|
||||
.mockRejectedValue(new Error("no metrics"));
|
||||
|
||||
@@ -65,6 +65,40 @@ describe("KubernetesClientRegistry", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
test("times out an unresponsive context without delaying healthy contexts", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const registry = createRegistry();
|
||||
for (const contextId of ["home", "remote", "metrics-degraded"]) {
|
||||
const client = registry.getClient(contextId);
|
||||
vi.spyOn(client.versionApi, "getCode").mockResolvedValue({} as never);
|
||||
vi.spyOn(client.metricsProbeApi, "listClusterCustomObject").mockResolvedValue({ items: [] } as never);
|
||||
}
|
||||
let observedSignal: AbortSignal | undefined;
|
||||
vi.spyOn(registry.getClient("remote").versionApi, "getCode").mockImplementation(async (_request, options) => {
|
||||
const middleware = (
|
||||
options as { middleware?: { pre?: (request: unknown) => { toPromise: () => Promise<unknown> } }[] }
|
||||
).middleware?.[0];
|
||||
await middleware?.pre?.({ setSignal: (signal: AbortSignal) => (observedSignal = signal) }).toPromise();
|
||||
return await new Promise<never>(() => undefined);
|
||||
});
|
||||
|
||||
const resultPromise = registry.getContextsAsync(50);
|
||||
await vi.advanceTimersByTimeAsync(50);
|
||||
const result = await resultPromise;
|
||||
|
||||
expect(observedSignal?.aborted).toBe(true);
|
||||
expect(result.contexts).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ contextId: "home", status: "available" }),
|
||||
expect.objectContaining({ contextId: "remote", status: "unavailable" }),
|
||||
]),
|
||||
);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
test("rejects unknown context IDs", () => {
|
||||
expect(() => createRegistry().getClient("missing")).toThrow(KubernetesContextNotFoundError);
|
||||
});
|
||||
@@ -80,7 +114,7 @@ describe("KubernetesClientRegistry", () => {
|
||||
const registry = new KubernetesClientRegistry(kubeConfig);
|
||||
const client = registry.getClient("first");
|
||||
vi.spyOn(client.versionApi, "getCode").mockResolvedValue({} as never);
|
||||
vi.spyOn(client.metricsApi, "getNodeMetrics").mockResolvedValue({ items: [] } as never);
|
||||
vi.spyOn(client.metricsProbeApi, "listClusterCustomObject").mockResolvedValue({ items: [] } as never);
|
||||
|
||||
const result = await registry.getContextsAsync();
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import * as fs from "fs";
|
||||
import { CoreV1Api, KubeConfig, Metrics, NetworkingV1Api, VersionApi } from "@kubernetes/client-node";
|
||||
import type { RequestContext, ResponseContext } from "@kubernetes/client-node";
|
||||
import { CoreV1Api, CustomObjectsApi, KubeConfig, Metrics, NetworkingV1Api, VersionApi } from "@kubernetes/client-node";
|
||||
import { of } from "@kubernetes/client-node/dist/gen/rxjsStub.js";
|
||||
|
||||
import { env } from "../../env";
|
||||
|
||||
@@ -11,12 +13,50 @@ export interface KubernetesContextStatus {
|
||||
isDefault: boolean;
|
||||
}
|
||||
|
||||
export const kubernetesContextProbeTimeoutMs = 5_000;
|
||||
|
||||
const withKubernetesProbeTimeoutAsync = async <T>(
|
||||
operation: (signal: AbortSignal) => Promise<T>,
|
||||
timeoutMs: number,
|
||||
) => {
|
||||
const controller = new AbortController();
|
||||
const timeoutError = new Error("Kubernetes context probe timed out");
|
||||
let timeout: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
try {
|
||||
return await Promise.race([
|
||||
operation(controller.signal),
|
||||
new Promise<never>((_, reject) => {
|
||||
timeout = setTimeout(() => {
|
||||
controller.abort(timeoutError);
|
||||
reject(timeoutError);
|
||||
}, timeoutMs);
|
||||
}),
|
||||
]);
|
||||
} finally {
|
||||
if (timeout) clearTimeout(timeout);
|
||||
}
|
||||
};
|
||||
|
||||
const abortableKubernetesRequest = (signal: AbortSignal) => ({
|
||||
middleware: [
|
||||
{
|
||||
pre: (request: RequestContext) => {
|
||||
request.setSignal(signal);
|
||||
return of(request);
|
||||
},
|
||||
post: (response: ResponseContext) => of(response),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
export class KubernetesClient {
|
||||
private static registry: KubernetesClientRegistry | null = null;
|
||||
public kubeConfig: KubeConfig;
|
||||
public coreApi: CoreV1Api;
|
||||
public networkingApi: NetworkingV1Api;
|
||||
public metricsApi: Metrics;
|
||||
public metricsProbeApi: CustomObjectsApi;
|
||||
public versionApi: VersionApi;
|
||||
|
||||
public constructor(kubeConfig: KubeConfig) {
|
||||
@@ -24,6 +64,7 @@ export class KubernetesClient {
|
||||
this.coreApi = kubeConfig.makeApiClient(CoreV1Api);
|
||||
this.networkingApi = kubeConfig.makeApiClient(NetworkingV1Api);
|
||||
this.metricsApi = new Metrics(kubeConfig);
|
||||
this.metricsProbeApi = kubeConfig.makeApiClient(CustomObjectsApi);
|
||||
this.versionApi = kubeConfig.makeApiClient(VersionApi);
|
||||
}
|
||||
|
||||
@@ -76,12 +117,22 @@ export class KubernetesClientRegistry {
|
||||
return this.getClient(this.defaultContextId);
|
||||
}
|
||||
|
||||
public async getContextsAsync() {
|
||||
public async getContextsAsync(timeoutMs = kubernetesContextProbeTimeoutMs) {
|
||||
const contexts = await Promise.all(
|
||||
[...this.clients.entries()].map(async ([contextId, client]): Promise<KubernetesContextStatus> => {
|
||||
const [api, metrics] = await Promise.allSettled([
|
||||
client.versionApi.getCode(),
|
||||
client.metricsApi.getNodeMetrics(),
|
||||
withKubernetesProbeTimeoutAsync(
|
||||
async (signal) => await client.versionApi.getCode(undefined, abortableKubernetesRequest(signal)),
|
||||
timeoutMs,
|
||||
),
|
||||
withKubernetesProbeTimeoutAsync(
|
||||
async (signal) =>
|
||||
await client.metricsProbeApi.listClusterCustomObject(
|
||||
{ group: "metrics.k8s.io", version: "v1beta1", plural: "nodes" },
|
||||
abortableKubernetesRequest(signal),
|
||||
),
|
||||
timeoutMs,
|
||||
),
|
||||
]);
|
||||
const status =
|
||||
api.status === "rejected" ? "unavailable" : metrics.status === "rejected" ? "degraded" : "available";
|
||||
|
||||
@@ -418,6 +418,40 @@ test("prefers an explicitly linked app over duplicate app matches", async () =>
|
||||
expect(result.candidates[0]?.state).toBe("linked");
|
||||
});
|
||||
|
||||
test("marks a linked integration as moved when only its app URL still matches", async () => {
|
||||
getDockerDataAsyncMock.mockResolvedValueOnce({
|
||||
data: {
|
||||
containers: [createInventoryContainer({ endpointId: "home", id: "one", name: "sonarr", publicPort: 8989 })],
|
||||
endpoints: [{ id: "home", name: "Home", status: "available" }],
|
||||
},
|
||||
timestamp: new Date(),
|
||||
});
|
||||
findIntegrationsAsyncMock.mockResolvedValueOnce([
|
||||
{
|
||||
id: "integration",
|
||||
name: "Sonarr",
|
||||
kind: "sonarr",
|
||||
url: "http://old.example:8989",
|
||||
appId: "linked",
|
||||
items: [],
|
||||
secrets: [],
|
||||
},
|
||||
]);
|
||||
findAppsAsyncMock.mockResolvedValueOnce([
|
||||
{ id: "linked", name: "Sonarr", href: "http://home.example:8989", iconUrl: "" },
|
||||
]);
|
||||
|
||||
const result = await createAdminCaller().reconcileServices();
|
||||
|
||||
expect(result.candidates[0]?.state).toBe("moved");
|
||||
expect(result.candidates[0]?.nextAction).toBe("reviewIntegration");
|
||||
expect(result.candidates[0]?.representation.signals).toMatchObject({
|
||||
exactIntegrationUrl: false,
|
||||
exactAppUrl: true,
|
||||
linked: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("does not offer to create an app when existing app matches are ambiguous", async () => {
|
||||
const dockerData = {
|
||||
data: {
|
||||
|
||||
@@ -56,6 +56,7 @@ describe("all should return all integrations", () => {
|
||||
expect(result.length).toBe(2);
|
||||
expect(result[0]!.kind).toBe("plex");
|
||||
expect(result[1]!.kind).toBe("homeAssistant");
|
||||
expect(result.every(({ permissions }) => permissions.hasFullAccess && permissions.hasUseAccess)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -15,14 +15,15 @@ export const constructIntegrationPermissions = (integration: IntegrationPermissi
|
||||
const permissions = integration.userPermissions
|
||||
.concat(integration.groupPermissions)
|
||||
.map(({ permission }) => permission);
|
||||
const hasGlobalFullAccess = session?.user.permissions.includes("integration-full-all") ?? false;
|
||||
const hasGlobalInteractAccess =
|
||||
hasGlobalFullAccess || (session?.user.permissions.includes("integration-interact-all") ?? false);
|
||||
const hasGlobalUseAccess =
|
||||
hasGlobalInteractAccess || (session?.user.permissions.includes("integration-use-all") ?? false);
|
||||
|
||||
return {
|
||||
hasFullAccess:
|
||||
(session?.user.permissions.includes("integration-full-all") ?? false) || permissions.includes("full"),
|
||||
hasInteractAccess:
|
||||
permissions.includes("full") ||
|
||||
permissions.includes("interact") ||
|
||||
(session?.user.permissions.includes("integration-interact-all") ?? false),
|
||||
hasUseAccess: permissions.length >= 1 || (session?.user.permissions.includes("integration-use-all") ?? false),
|
||||
hasFullAccess: hasGlobalFullAccess || permissions.includes("full"),
|
||||
hasInteractAccess: hasGlobalInteractAccess || permissions.includes("full") || permissions.includes("interact"),
|
||||
hasUseAccess: hasGlobalUseAccess || permissions.length >= 1,
|
||||
};
|
||||
};
|
||||
@@ -30,6 +30,18 @@ describe("constructIntegrationPermissions", () => {
|
||||
expect(result.hasUseAccess).toBe(true);
|
||||
});
|
||||
|
||||
test("should derive lower access levels from an unexpanded full permission", () => {
|
||||
const result = constructIntegrationPermissions(
|
||||
{ userPermissions: [], groupPermissions: [] },
|
||||
{
|
||||
user: { id: "2", permissions: ["integration-full-all"], colorScheme: "light" },
|
||||
expires: new Date().toISOString(),
|
||||
},
|
||||
);
|
||||
|
||||
expect(result).toEqual({ hasFullAccess: true, hasInteractAccess: true, hasUseAccess: true });
|
||||
});
|
||||
|
||||
test("should return hasInteractAccess as true when session permissions include integration-interact-all", () => {
|
||||
// Arrange
|
||||
const integration = {
|
||||
|
||||
@@ -77,7 +77,11 @@ export const buildDockerServiceUrlCandidates = ({
|
||||
|
||||
for (const port of tcpPorts) {
|
||||
if (port.PublicPort) {
|
||||
const publishedHost = isUsablePublishedAddress(port.IP) ? port.IP : endpointHostname;
|
||||
const publishedHost = isUsablePublishedAddress(port.IP)
|
||||
? port.IP
|
||||
: isUsablePublishedAddress(endpointHostname ?? undefined)
|
||||
? endpointHostname
|
||||
: null;
|
||||
if (publishedHost) {
|
||||
addCandidate({
|
||||
url: `http://${formatUrlHost(publishedHost)}:${port.PublicPort}`,
|
||||
@@ -120,8 +124,16 @@ export const normalizeDockerServiceUrl = (value: string | null | undefined) => {
|
||||
}
|
||||
};
|
||||
|
||||
const isUsablePublishedAddress = (value: string | undefined): value is string =>
|
||||
Boolean(value && !["0.0.0.0", "::", "::0"].includes(value));
|
||||
const isUsablePublishedAddress = (value: string | undefined): value is string => {
|
||||
if (!value) return false;
|
||||
const host = value.toLowerCase().replace(/^\[|\]$/gu, "");
|
||||
return (
|
||||
!["0.0.0.0", "::", "::0", "::1", "localhost"].includes(host) &&
|
||||
!host.endsWith(".localhost") &&
|
||||
!/^127(?:\.\d{1,3}){3}$/.test(host) &&
|
||||
!host.startsWith("::ffff:127.")
|
||||
);
|
||||
};
|
||||
|
||||
const getEndpointHostname = (host: string) => {
|
||||
if (host === "socket" || host.startsWith("/")) return null;
|
||||
|
||||
@@ -332,6 +332,7 @@ export type HomarrDocumentationPath =
|
||||
| "/docs/integrations/peanut"
|
||||
| "/docs/integrations/beszel"
|
||||
| "/docs/integrations/traefik"
|
||||
| "/docs/integrations/archiveteam-warrior"
|
||||
| "/docs/integrations/whats-up-docker"
|
||||
| "/docs/widgets/clock"
|
||||
| "/docs/widgets/weather"
|
||||
|
||||
@@ -50,4 +50,30 @@ describe("buildDockerServiceUrlCandidates", () => {
|
||||
reason: "dockerEndpointHost",
|
||||
});
|
||||
});
|
||||
|
||||
test.each(["127.0.0.1", "127.12.0.9", "::1", "::ffff:127.0.0.1", "localhost"])(
|
||||
"does not advertise loopback address %s to browsers",
|
||||
(address) => {
|
||||
const candidates = buildDockerServiceUrlCandidates({
|
||||
containerName: "sonarr",
|
||||
endpointHost: "socket",
|
||||
preferredPort: 8989,
|
||||
ports: [{ IP: address, PrivatePort: 8989, PublicPort: 8989, Type: "tcp" }],
|
||||
});
|
||||
|
||||
expect(candidates.some(({ source }) => source === "publishedAddress")).toBe(false);
|
||||
expect(candidates.some(({ url, scopes }) => url.includes(address) && scopes.includes("browser"))).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
test("does not use a loopback Docker endpoint as a browser URL", () => {
|
||||
const candidates = buildDockerServiceUrlCandidates({
|
||||
containerName: "sonarr",
|
||||
endpointHost: "[::1]:2375",
|
||||
preferredPort: 8989,
|
||||
ports: [{ IP: "0.0.0.0", PrivatePort: 8989, PublicPort: 8989, Type: "tcp" }],
|
||||
});
|
||||
|
||||
expect(candidates.some(({ source }) => source === "endpointHost")).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -28,6 +28,20 @@ describe("native feature capability descriptor", () => {
|
||||
|
||||
test("derives optional connections and server selection limits", () => {
|
||||
expect(widgetKindsWithOptionalIntegrations).toEqual(new Set(["calendar"]));
|
||||
expect(widgetIntegrationLimits).toEqual({ audioStats: 1 });
|
||||
expect(widgetIntegrationLimits).toEqual({
|
||||
"smartHome-entityState": 1,
|
||||
"smartHome-executeAutomation": 1,
|
||||
mediaTranscoding: 1,
|
||||
"immich-serverStats": 1,
|
||||
"immich-albumCarousel": 1,
|
||||
paperlessNgx: 1,
|
||||
patchmon: 1,
|
||||
bazarr: 1,
|
||||
audioStats: 1,
|
||||
umami: 1,
|
||||
archiveTeamWarrior: 1,
|
||||
anchorNote: 1,
|
||||
wud: 1,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -18,14 +18,20 @@ export interface NativeFeatureCapabilityDescriptor {
|
||||
export const nativeFeatureCapabilities = {
|
||||
dnsHoleSummary: { integrations: getIntegrationKindsByCategory("dnsHole") },
|
||||
dnsHoleControls: { integrations: getIntegrationKindsByCategory("dnsHole") },
|
||||
"smartHome-entityState": { integrations: getIntegrationKindsByCategory("smartHomeServer") },
|
||||
"smartHome-executeAutomation": { integrations: getIntegrationKindsByCategory("smartHomeServer") },
|
||||
"smartHome-entityState": {
|
||||
integrations: getIntegrationKindsByCategory("smartHomeServer"),
|
||||
serverMaxIntegrations: 1,
|
||||
},
|
||||
"smartHome-executeAutomation": {
|
||||
integrations: getIntegrationKindsByCategory("smartHomeServer"),
|
||||
serverMaxIntegrations: 1,
|
||||
},
|
||||
mediaServer: { integrations: getIntegrationKindsByCategory("mediaService") },
|
||||
calendar: { integrations: getIntegrationKindsByCategory("calendar"), connectionOptional: true },
|
||||
downloads: { integrations: getIntegrationKindsByCategory("downloadClient") },
|
||||
"mediaRequests-requestList": { integrations: getIntegrationKindsByCategory("mediaRequest") },
|
||||
"mediaRequests-requestStats": { integrations: getIntegrationKindsByCategory("mediaRequest") },
|
||||
mediaTranscoding: { integrations: getIntegrationKindsByCategory("mediaTranscoding") },
|
||||
mediaTranscoding: { integrations: getIntegrationKindsByCategory("mediaTranscoding"), serverMaxIntegrations: 1 },
|
||||
mediaMissing: { integrations: getIntegrationKindsByCategory("mediaOrganizer") },
|
||||
networkControllerSummary: { integrations: getIntegrationKindsByCategory("networkController") },
|
||||
networkControllerStatus: { integrations: getIntegrationKindsByCategory("networkController") },
|
||||
@@ -45,22 +51,22 @@ export const nativeFeatureCapabilities = {
|
||||
beszelSystemStats: { integrations: ["beszel", "mock"] },
|
||||
beszelSystemTable: { integrations: ["beszel", "mock"] },
|
||||
coolify: { integrations: ["coolify"] },
|
||||
"immich-serverStats": { integrations: ["immich"] },
|
||||
"immich-albumCarousel": { integrations: ["immich"] },
|
||||
paperlessNgx: { integrations: ["paperlessNgx"] },
|
||||
patchmon: { integrations: ["patchmon"] },
|
||||
bazarr: { integrations: ["bazarr"] },
|
||||
"immich-serverStats": { integrations: ["immich"], serverMaxIntegrations: 1 },
|
||||
"immich-albumCarousel": { integrations: ["immich"], serverMaxIntegrations: 1 },
|
||||
paperlessNgx: { integrations: ["paperlessNgx"], serverMaxIntegrations: 1 },
|
||||
patchmon: { integrations: ["patchmon"], serverMaxIntegrations: 1 },
|
||||
bazarr: { integrations: ["bazarr"], serverMaxIntegrations: 1 },
|
||||
tracearr: { integrations: ["tracearr"] },
|
||||
speedtestTracker: { integrations: ["speedtestTracker"] },
|
||||
uptimeKuma: { integrations: ["uptimeKuma"] },
|
||||
audioStats: { integrations: ["navidrome", "audiobookshelf"], serverMaxIntegrations: 1 },
|
||||
umami: { integrations: ["umami"] },
|
||||
umami: { integrations: ["umami"], serverMaxIntegrations: 1 },
|
||||
vpn: { integrations: getIntegrationKindsByCategory("vpn") },
|
||||
ups: { integrations: getIntegrationKindsByCategory("ups") },
|
||||
archiveTeamWarrior: { integrations: ["archiveTeamWarrior"] },
|
||||
anchorNote: { integrations: ["anchor"] },
|
||||
archiveTeamWarrior: { integrations: ["archiveTeamWarrior"], serverMaxIntegrations: 1 },
|
||||
anchorNote: { integrations: ["anchor"], serverMaxIntegrations: 1 },
|
||||
traefik: { integrations: ["traefik"] },
|
||||
wud: { integrations: ["wud"] },
|
||||
wud: { integrations: ["wud"], serverMaxIntegrations: 1 },
|
||||
} as const satisfies Partial<Record<WidgetKind, NativeFeatureCapabilityDescriptor>>;
|
||||
|
||||
const nativeFeatureCapabilityEntries = Object.entries(nativeFeatureCapabilities) as [
|
||||
|
||||
@@ -15,6 +15,31 @@ import { createDockerLogStreamProcessor, decodeDockerLogs } from "./docker-log-d
|
||||
import { createWidgetRequestHandler } from "./lib/widget-request-handler";
|
||||
|
||||
const logger = createLogger({ module: "dockerRequestHandler" });
|
||||
export const dockerWidgetEndpointTimeoutMs = 5_000;
|
||||
|
||||
const withDockerTimeoutAsync = async <T>(
|
||||
operation: (signal: AbortSignal) => Promise<T>,
|
||||
message: string,
|
||||
timeoutMs: number,
|
||||
) => {
|
||||
const controller = new AbortController();
|
||||
const timeoutError = new Error(message);
|
||||
let timeout: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
try {
|
||||
return await Promise.race([
|
||||
operation(controller.signal),
|
||||
new Promise<never>((_, reject) => {
|
||||
timeout = setTimeout(() => {
|
||||
controller.abort(timeoutError);
|
||||
reject(timeoutError);
|
||||
}, timeoutMs);
|
||||
}),
|
||||
]);
|
||||
} finally {
|
||||
if (timeout) clearTimeout(timeout);
|
||||
}
|
||||
};
|
||||
|
||||
const isDemoMode = ["1", "yes", "t", "true"].includes((process.env.DEMO_MODE ?? "").toLowerCase());
|
||||
|
||||
@@ -275,11 +300,15 @@ export const streamContainerLogsAsync = async (
|
||||
};
|
||||
};
|
||||
|
||||
export async function getContainersWithStatsAsync() {
|
||||
export async function getContainersWithStatsAsync(timeoutMs = dockerWidgetEndpointTimeoutMs) {
|
||||
const dockerInstances = DockerSingleton.getInstances();
|
||||
const results = await Promise.allSettled(
|
||||
dockerInstances.map(async ({ instance, host, endpointId, endpointName }) => {
|
||||
const instanceContainers = await instance.listContainers({ all: true });
|
||||
const instanceContainers = await withDockerTimeoutAsync(
|
||||
async (signal) => await instance.listContainers({ all: true, abortSignal: signal }),
|
||||
`Timed out listing containers from Docker host ${host}`,
|
||||
timeoutMs,
|
||||
);
|
||||
return instanceContainers
|
||||
.filter((container) => !(dockerLabels.hide in container.Labels))
|
||||
.map((container) => ({ ...container, instance: host, endpointId, endpointName }));
|
||||
@@ -329,16 +358,20 @@ export async function getContainersWithStatsAsync() {
|
||||
const instance = DockerSingleton.findInstance(container.endpointId)?.instance;
|
||||
if (!instance) return null;
|
||||
|
||||
const stats = await instance
|
||||
.getContainer(container.Id)
|
||||
.stats({ stream: false, "one-shot": true })
|
||||
.catch(
|
||||
() =>
|
||||
({
|
||||
cpu_stats: { online_cpus: 0, cpu_usage: { total_usage: 0 }, system_cpu_usage: 0 },
|
||||
memory_stats: { usage: 0 },
|
||||
}) as ContainerStats,
|
||||
);
|
||||
const stats = await withDockerTimeoutAsync(
|
||||
async (signal) => {
|
||||
const options = { stream: false as const, "one-shot": true, abortSignal: signal };
|
||||
return await instance.getContainer(container.Id).stats(options);
|
||||
},
|
||||
`Timed out reading Docker container stats for ${container.Id}`,
|
||||
timeoutMs,
|
||||
).catch(
|
||||
() =>
|
||||
({
|
||||
cpu_stats: { online_cpus: 0, cpu_usage: { total_usage: 0 }, system_cpu_usage: 0 },
|
||||
memory_stats: { usage: 0 },
|
||||
}) as ContainerStats,
|
||||
);
|
||||
|
||||
const cpuUsage = calculateCpuUsage(stats);
|
||||
const memoryUsage = calculateMemoryUsage(stats);
|
||||
|
||||
@@ -2,8 +2,9 @@ import type { ContainerStats } from "dockerode";
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
|
||||
import { createDb } from "@homarr/db/test";
|
||||
import { DockerSingleton } from "@homarr/docker";
|
||||
|
||||
import { calculateCpuUsage, calculateMemoryUsage } from "../docker";
|
||||
import { calculateCpuUsage, calculateMemoryUsage, getContainersWithStatsAsync } from "../docker";
|
||||
|
||||
vi.mock("@homarr/db", async (importActual) => {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
|
||||
@@ -119,3 +120,76 @@ describe("calculateMemoryUsage", () => {
|
||||
expect(calculateMemoryUsage(stats)).toBe(512);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getContainersWithStatsAsync", () => {
|
||||
test("marks a timed-out endpoint unavailable without blocking healthy endpoints", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
vi.spyOn(DockerSingleton, "getInstances").mockReturnValue([
|
||||
createDockerInstance("stalled", () => new Promise(() => undefined)),
|
||||
createDockerInstance("healthy", async () => []),
|
||||
] as never);
|
||||
|
||||
const resultPromise = getContainersWithStatsAsync(50);
|
||||
await vi.advanceTimersByTimeAsync(50);
|
||||
const result = await resultPromise;
|
||||
|
||||
expect(result.endpoints).toEqual([
|
||||
expect.objectContaining({ id: "stalled", status: "unavailable" }),
|
||||
expect.objectContaining({ id: "healthy", status: "available" }),
|
||||
]);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
vi.restoreAllMocks();
|
||||
}
|
||||
});
|
||||
|
||||
test("returns a container with zeroed stats when its stats request times out", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const dockerInstance = createDockerInstance("healthy", async () => [
|
||||
{
|
||||
Id: "container-1",
|
||||
Image: "sonarr:latest",
|
||||
Labels: {},
|
||||
Names: ["/sonarr"],
|
||||
State: "running",
|
||||
Ports: [],
|
||||
},
|
||||
]);
|
||||
let observedSignal: AbortSignal | undefined;
|
||||
dockerInstance.instance.getContainer = (() => ({
|
||||
stats: (options: { abortSignal?: AbortSignal }) => {
|
||||
observedSignal = options.abortSignal;
|
||||
return new Promise(() => undefined);
|
||||
},
|
||||
})) as never;
|
||||
vi.spyOn(DockerSingleton, "getInstances").mockReturnValue([dockerInstance] as never);
|
||||
vi.spyOn(DockerSingleton, "findInstance").mockReturnValue(dockerInstance as never);
|
||||
|
||||
const resultPromise = getContainersWithStatsAsync(50);
|
||||
await vi.advanceTimersByTimeAsync(50);
|
||||
const result = await resultPromise;
|
||||
|
||||
expect(observedSignal?.aborted).toBe(true);
|
||||
expect(result.containers).toEqual([expect.objectContaining({ id: "container-1", cpuUsage: 0, memoryUsage: 0 })]);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
vi.restoreAllMocks();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const createDockerInstance = (endpointId: string, listContainers: () => Promise<unknown[]>) => ({
|
||||
endpointId,
|
||||
endpointName: endpointId,
|
||||
host: endpointId,
|
||||
descriptor: {
|
||||
kind: "docker",
|
||||
transport: { type: "socket" },
|
||||
capabilities: ["inventory"],
|
||||
source: "environment",
|
||||
scope: "admin",
|
||||
},
|
||||
instance: { listContainers, getContainer: () => ({}) },
|
||||
});
|
||||
@@ -1613,6 +1613,10 @@
|
||||
"label": "Create app",
|
||||
"description": "Create an app with the same name and icon as the integration. Leave the input field below empty to create the app with the integration URL."
|
||||
},
|
||||
"linkApp": {
|
||||
"label": "Link an existing app",
|
||||
"description": "Connect this integration to an app you can already use."
|
||||
},
|
||||
"appHref": {
|
||||
"placeholder": "Custom app URL"
|
||||
},
|
||||
@@ -2742,18 +2746,29 @@
|
||||
"title": "Edit item",
|
||||
"tab": {
|
||||
"widget": "Edit widget",
|
||||
"app": "Edit app"
|
||||
"app": "Edit app",
|
||||
"integration": "Edit integration"
|
||||
},
|
||||
"app": {
|
||||
"propagationNotice": "Changes to this app will be applied everywhere it is used across all dashboards."
|
||||
},
|
||||
"integration": {
|
||||
"action": "Edit connection",
|
||||
"description": "Test or repair a selected connection without leaving this widget.",
|
||||
"editLabel": "Edit {name} integration",
|
||||
"fullAccessRequired": "Full access required",
|
||||
"propagationNotice": "Changes to this integration apply everywhere it is used. The connection is tested before it is saved.",
|
||||
"loading": "Loading integration",
|
||||
"loadError": "This integration could not be loaded. Try again before changing its connection settings."
|
||||
},
|
||||
"advancedOptions": {
|
||||
"label": "Advanced options",
|
||||
"title": "Advanced item options"
|
||||
},
|
||||
"field": {
|
||||
"integrations": {
|
||||
"label": "Integrations"
|
||||
"label": "Integrations",
|
||||
"removeLabel": "Remove {name} integration"
|
||||
},
|
||||
"title": {
|
||||
"label": "Title"
|
||||
@@ -3974,7 +3989,8 @@
|
||||
},
|
||||
"integration": {
|
||||
"noData": "No integration found",
|
||||
"description": "Click <here></here> to create a new integration"
|
||||
"description": "Click <here></here> to create a new integration",
|
||||
"manage": "Manage integrations"
|
||||
},
|
||||
"app": {
|
||||
"noData": "No app found",
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
import { useRef, useState } from "react";
|
||||
import type { FormEvent } from "react";
|
||||
import { Button, Group, Stack, Tabs } from "@mantine/core";
|
||||
import { Button, Group, Stack, Tabs, Text } from "@mantine/core";
|
||||
import { schemaResolver } from "@mantine/form";
|
||||
import { IconPencil } from "@tabler/icons-react";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
import { objectEntries } from "@homarr/common";
|
||||
@@ -13,6 +14,7 @@ import type { WidgetKind } from "@homarr/definitions";
|
||||
import { createModal, ModalFormFooter, modalSizeForm, useModalAction } from "@homarr/modals";
|
||||
import type { SettingsContextProps } from "@homarr/settings/creator";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
import { IntegrationAvatar } from "@homarr/ui";
|
||||
import { zodErrorMap } from "@homarr/validation/form/i18n";
|
||||
|
||||
import { getInputForType } from "../_inputs";
|
||||
@@ -44,8 +46,15 @@ export interface WidgetEditModalProps<TSort extends WidgetKind> {
|
||||
itemId?: string;
|
||||
boardId?: string;
|
||||
appId?: string;
|
||||
onEditIntegration?: (integrationId: string) => void;
|
||||
onIntegrationSaved?: () => void;
|
||||
}
|
||||
|
||||
export const getSelectedWidgetIntegrations = (
|
||||
integrationData: readonly IntegrationSelectOption[],
|
||||
selectedIds: readonly string[],
|
||||
) => integrationData.filter((integration) => selectedIds.includes(integration.id));
|
||||
|
||||
export const WidgetEditModal = createModal<WidgetEditModalProps<WidgetKind>>(({ actions, innerProps }) => {
|
||||
const t = useI18n();
|
||||
const board = useOptionalBoard();
|
||||
@@ -61,6 +70,7 @@ export const WidgetEditModal = createModal<WidgetEditModalProps<WidgetKind>>(({
|
||||
const integrationsRequired =
|
||||
innerProps.integrationSupport &&
|
||||
(!("integrationsRequired" in definition) || definition.integrationsRequired !== false);
|
||||
const maxIntegrations = (definition as { maxIntegrations?: number }).maxIntegrations ?? Infinity;
|
||||
const options = definition.createOptions(innerProps.settings) as Record<string, OptionsBuilderResult[string]>;
|
||||
const optionsSuperRefine = (options as Record<symbol, unknown>)[OPTIONS_SUPER_REFINE] as
|
||||
| ((data: Record<string, unknown>, ctx: z.RefinementCtx) => void)
|
||||
@@ -79,13 +89,17 @@ export const WidgetEditModal = createModal<WidgetEditModalProps<WidgetKind>>(({
|
||||
? z.object(optionsFieldSchema).superRefine(optionsSuperRefine)
|
||||
: z.object(optionsFieldSchema);
|
||||
|
||||
let integrationIdsSchema = z.array(z.string());
|
||||
if (integrationsRequired) integrationIdsSchema = integrationIdsSchema.min(1);
|
||||
if (Number.isFinite(maxIntegrations)) integrationIdsSchema = integrationIdsSchema.max(maxIntegrations);
|
||||
|
||||
const form = useForm({
|
||||
mode: "controlled",
|
||||
initialValues: innerProps.value,
|
||||
validate: schemaResolver(
|
||||
z.object({
|
||||
options: optionsSchema,
|
||||
integrationIds: integrationsRequired ? z.array(z.string()).min(1) : z.array(z.string()),
|
||||
integrationIds: integrationIdsSchema,
|
||||
advancedOptions: z.object({
|
||||
customCssClasses: z.array(z.string()),
|
||||
borderColor: z.string(),
|
||||
@@ -102,6 +116,10 @@ export const WidgetEditModal = createModal<WidgetEditModalProps<WidgetKind>>(({
|
||||
const canConfigureWidget = innerProps.kind !== "customApi" || (session?.user.permissions.includes("admin") ?? false);
|
||||
const appId = innerProps.appId;
|
||||
const showAppTab = innerProps.kind === "app" && canModifyApps && Boolean(appId);
|
||||
const canModifyAllIntegrations = session?.user.permissions.includes("integration-full-all") ?? false;
|
||||
const selectedIntegrations = getSelectedWidgetIntegrations(innerProps.integrationData, form.values.integrationIds);
|
||||
const showIntegrationTab = Boolean(innerProps.onEditIntegration) && selectedIntegrations.length > 0;
|
||||
const showResourceTabs = showAppTab || showIntegrationTab;
|
||||
|
||||
const handleSubmit = form.onSubmit(async (values) => {
|
||||
setIsSubmitting(true);
|
||||
@@ -132,7 +150,7 @@ export const WidgetEditModal = createModal<WidgetEditModalProps<WidgetKind>>(({
|
||||
<WidgetIntegrationSelect
|
||||
label={t("item.edit.field.integrations.label")}
|
||||
data={innerProps.integrationData}
|
||||
canSelectMultiple={((definition as { maxIntegrations?: number }).maxIntegrations ?? Infinity) > 1}
|
||||
canSelectMultiple={maxIntegrations > 1}
|
||||
withAsterisk={integrationsRequired}
|
||||
{...form.getInputProps("integrationIds")}
|
||||
/>
|
||||
@@ -165,7 +183,7 @@ export const WidgetEditModal = createModal<WidgetEditModalProps<WidgetKind>>(({
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{showAppTab ? (
|
||||
{showResourceTabs ? (
|
||||
<Button
|
||||
variant="subtle"
|
||||
type="button"
|
||||
@@ -203,19 +221,64 @@ export const WidgetEditModal = createModal<WidgetEditModalProps<WidgetKind>>(({
|
||||
return (
|
||||
<form onSubmit={onFormSubmit}>
|
||||
<FormProvider form={form}>
|
||||
{showAppTab ? (
|
||||
{showResourceTabs ? (
|
||||
<Stack>
|
||||
<Tabs defaultValue="widget">
|
||||
<Tabs.List grow>
|
||||
<Tabs.Tab value="widget">{t("item.edit.tab.widget")}</Tabs.Tab>
|
||||
<Tabs.Tab value="app">{t("item.edit.tab.app")}</Tabs.Tab>
|
||||
{showAppTab && <Tabs.Tab value="app">{t("item.edit.tab.app")}</Tabs.Tab>}
|
||||
{showIntegrationTab && <Tabs.Tab value="integration">{t("item.edit.tab.integration")}</Tabs.Tab>}
|
||||
</Tabs.List>
|
||||
<Tabs.Panel value="widget" pt="md">
|
||||
{widgetFormContent}
|
||||
</Tabs.Panel>
|
||||
<Tabs.Panel value="app" pt="md">
|
||||
{appId && <EmbeddedAppEditForm appId={appId} handleRef={appEditRef} />}
|
||||
</Tabs.Panel>
|
||||
{showAppTab && (
|
||||
<Tabs.Panel value="app" pt="md">
|
||||
{appId && <EmbeddedAppEditForm appId={appId} handleRef={appEditRef} />}
|
||||
</Tabs.Panel>
|
||||
)}
|
||||
{showIntegrationTab && (
|
||||
<Tabs.Panel value="integration" pt="md">
|
||||
<Stack>
|
||||
<Text size="sm" c="dimmed">
|
||||
{t("item.edit.integration.description")}
|
||||
</Text>
|
||||
{selectedIntegrations.map((integration) => {
|
||||
const canEdit = canModifyAllIntegrations || integration.permissions?.hasFullAccess === true;
|
||||
return (
|
||||
<Group key={integration.id} justify="space-between" wrap="nowrap" gap="sm">
|
||||
<Group gap="sm" wrap="nowrap" style={{ minWidth: 0 }}>
|
||||
<IntegrationAvatar kind={integration.kind} size="sm" />
|
||||
<Stack gap={0} style={{ minWidth: 0 }}>
|
||||
<Text fw={600} size="sm" truncate>
|
||||
{integration.name}
|
||||
</Text>
|
||||
<Text size="xs" c="dimmed" truncate>
|
||||
{integration.url}
|
||||
</Text>
|
||||
</Stack>
|
||||
</Group>
|
||||
{canEdit ? (
|
||||
<Button
|
||||
type="button"
|
||||
variant="light"
|
||||
leftSection={<IconPencil size={16} />}
|
||||
onClick={() => innerProps.onEditIntegration?.(integration.id)}
|
||||
aria-label={t("item.edit.integration.editLabel", { name: integration.name })}
|
||||
>
|
||||
{t("item.edit.integration.action")}
|
||||
</Button>
|
||||
) : (
|
||||
<Text size="xs" c="dimmed" ta="end">
|
||||
{t("item.edit.integration.fullAccessRequired")}
|
||||
</Text>
|
||||
)}
|
||||
</Group>
|
||||
);
|
||||
})}
|
||||
</Stack>
|
||||
</Tabs.Panel>
|
||||
)}
|
||||
</Tabs>
|
||||
<Group justify="end">
|
||||
<Button onClick={actions.closeModal} variant="subtle" color="gray">
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
CloseButton,
|
||||
Combobox,
|
||||
Group,
|
||||
Input,
|
||||
Pill,
|
||||
PillsInput,
|
||||
Stack,
|
||||
@@ -38,6 +37,7 @@ export const WidgetIntegrationSelect = ({
|
||||
data,
|
||||
onChange,
|
||||
value: valueProp,
|
||||
label,
|
||||
canSelectMultiple = true,
|
||||
withAsterisk = false,
|
||||
...props
|
||||
@@ -79,6 +79,7 @@ export const WidgetIntegrationSelect = ({
|
||||
option={option}
|
||||
onRemove={() => handleValueRemove(item)}
|
||||
showRemoveButton={canSelectMultiple}
|
||||
removeLabel={t("item.edit.field.integrations.removeLabel", { name: option.name })}
|
||||
/>
|
||||
);
|
||||
});
|
||||
@@ -92,7 +93,7 @@ export const WidgetIntegrationSelect = ({
|
||||
<Avatar src={getIconUrl(item.kind)} size="sm" />
|
||||
<Stack gap={0}>
|
||||
<span>{item.name}</span>
|
||||
<Text size="xs" c="gray.6">
|
||||
<Text size="xs" c="dimmed">
|
||||
{item.url}
|
||||
</Text>
|
||||
</Stack>
|
||||
@@ -109,33 +110,42 @@ export const WidgetIntegrationSelect = ({
|
||||
inputWrapperOrder={["label", "input", "description", "error"]}
|
||||
description={
|
||||
<Text size="xs" span>
|
||||
{t.rich("widget.common.integration.description", {
|
||||
here: () => (
|
||||
<Anchor size="xs" component={Link} target="_blank" href="/manage/integrations">
|
||||
{t("common.here")}
|
||||
</Anchor>
|
||||
),
|
||||
})}
|
||||
<Anchor size="xs" component={Link} target="_blank" href="/manage/integrations">
|
||||
{t("widget.common.integration.manage")}
|
||||
</Anchor>
|
||||
</Text>
|
||||
}
|
||||
pointer
|
||||
onClick={() => combobox.toggleDropdown()}
|
||||
onClick={() => combobox.openDropdown()}
|
||||
label={label}
|
||||
withAsterisk={withAsterisk}
|
||||
{...props}
|
||||
>
|
||||
<Pill.Group>
|
||||
{values.length > 0 ? values : <Input.Placeholder>{t("common.multiSelect.placeholder")}</Input.Placeholder>}
|
||||
{values}
|
||||
|
||||
<Combobox.EventsTarget>
|
||||
<PillsInput.Field
|
||||
type="hidden"
|
||||
readOnly
|
||||
aria-label={label}
|
||||
placeholder={values.length === 0 ? t("common.multiSelect.placeholder") : undefined}
|
||||
onFocus={() => combobox.openDropdown()}
|
||||
onBlur={() => combobox.closeDropdown()}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key !== "Backspace") return;
|
||||
|
||||
event.preventDefault();
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
handleValueRemove(multiSelectValues[multiSelectValues.length - 1]!);
|
||||
if (["ArrowDown", "Enter", " "].includes(event.key)) {
|
||||
event.preventDefault();
|
||||
combobox.openDropdown();
|
||||
return;
|
||||
}
|
||||
if (event.key === "Escape") {
|
||||
combobox.closeDropdown();
|
||||
return;
|
||||
}
|
||||
if (event.key === "Backspace" && multiSelectValues.length > 0) {
|
||||
event.preventDefault();
|
||||
const lastValue = multiSelectValues.at(-1);
|
||||
if (lastValue) handleValueRemove(lastValue);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</Combobox.EventsTarget>
|
||||
@@ -163,22 +173,38 @@ export interface IntegrationSelectOption {
|
||||
name: string;
|
||||
url: string;
|
||||
kind: IntegrationKind;
|
||||
permissions?: {
|
||||
hasUseAccess: boolean;
|
||||
hasInteractAccess: boolean;
|
||||
hasFullAccess: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
interface IntegrationPillProps {
|
||||
option: IntegrationSelectOption;
|
||||
onRemove: () => void;
|
||||
showRemoveButton: boolean;
|
||||
removeLabel: string;
|
||||
}
|
||||
|
||||
const IntegrationPill = ({ option, onRemove, showRemoveButton }: IntegrationPillProps) => (
|
||||
const IntegrationPill = ({ option, onRemove, showRemoveButton, removeLabel }: IntegrationPillProps) => (
|
||||
<Group align="center" wrap="nowrap" gap={0} className={classes.pill} mih={24} pr={!showRemoveButton ? 10 : undefined}>
|
||||
<Avatar src={getIconUrl(option.kind)} size={14} mr={6} />
|
||||
<Text span size="xs" lh={1} fw={500}>
|
||||
{option.name}
|
||||
</Text>
|
||||
{showRemoveButton && (
|
||||
<CloseButton onMouseDown={onRemove} variant="transparent" color="gray" size={22} iconSize={14} tabIndex={-1} />
|
||||
<CloseButton
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
onRemove();
|
||||
}}
|
||||
aria-label={removeLabel}
|
||||
variant="transparent"
|
||||
color="gray"
|
||||
size={24}
|
||||
iconSize={14}
|
||||
/>
|
||||
)}
|
||||
</Group>
|
||||
);
|
||||
Reference in new issue
Block a user