mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-20 07:45:20 +00:00
Compare commits
49 Commits
dependabot
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c47c411161 | ||
|
|
e88e262abe | ||
|
|
6cacc9b83f | ||
|
|
1f1791feb7 | ||
|
|
08a08e73b3 | ||
|
|
2d9c082607 | ||
|
|
7968c4357b | ||
|
|
25c08e7279 | ||
|
|
68d7b0a416 | ||
|
|
43546c84eb | ||
|
|
eac36ee442 | ||
|
|
9a88394efe | ||
|
|
173562654b | ||
|
|
8f7e5ab1ed | ||
|
|
4334480675 | ||
|
|
6aa406927a | ||
|
|
5b50024712 | ||
|
|
ce746a2a21 | ||
|
|
7120ab4b22 | ||
|
|
12e777b32e | ||
|
|
9378103ddd | ||
|
|
ec794d5de2 | ||
|
|
12b18a3e8c | ||
|
|
91e8a13e59 | ||
|
|
931ba0f540 | ||
|
|
d321d7275c | ||
|
|
3855486a00 | ||
|
|
ab494521b1 | ||
|
|
549e1ead1d | ||
|
|
a0759a79a1 | ||
|
|
14e1a119d3 | ||
|
|
6e066d38b0 | ||
|
|
21f72639b6 | ||
|
|
8a0c2031d4 | ||
|
|
56d3a466e5 | ||
|
|
563e505cc1 | ||
|
|
c44c02b8ba | ||
|
|
b9ab35a05b | ||
|
|
2fd519e102 | ||
|
|
a63c1ec364 | ||
|
|
e61ef2ca2a | ||
|
|
39b09b7f3f | ||
|
|
840cc214e3 | ||
|
|
72524db52d | ||
|
|
ab8fc11ab3 | ||
|
|
1831ca4e75 | ||
|
|
0d04cc365f | ||
|
|
09baf2f32e | ||
|
|
3253d60900 |
@@ -255,6 +255,23 @@
|
|||||||
"resourceGoTo": "Go to Resource",
|
"resourceGoTo": "Go to Resource",
|
||||||
"resourceDelete": "Delete Resource",
|
"resourceDelete": "Delete Resource",
|
||||||
"resourceDeleteConfirm": "Confirm Delete Resource",
|
"resourceDeleteConfirm": "Confirm Delete Resource",
|
||||||
|
"labelDelete": "Delete Label",
|
||||||
|
"labelAdd": "Add Label",
|
||||||
|
"labelCreateSuccessMessage": "Label Created Successfully",
|
||||||
|
"labelEditSuccessMessage": "Label Modified Successfully",
|
||||||
|
"labelNameField": "Label Name",
|
||||||
|
"labelColorField": "Label Color",
|
||||||
|
"labelPlaceholder": "Ex: homelab",
|
||||||
|
"labelCreate": "Create Label",
|
||||||
|
"createLabelDialogTitle": "Create Label",
|
||||||
|
"createLabelDialogDescription": "Create a new label that can be attached to this organization",
|
||||||
|
"labelEdit": "Edit Label",
|
||||||
|
"editLabelDialogTitle": "Update Label",
|
||||||
|
"editLabelDialogDescription": "Edit a new label that can be attached to this organization",
|
||||||
|
"labelDeleteConfirm": "Confirm Delete Label",
|
||||||
|
"labelErrorDelete": "Failed to delete label",
|
||||||
|
"labelMessageRemove": "This action is permanent. All sites, resources, and clients tagged with this label will be untagged.",
|
||||||
|
"labelQuestionRemove": "Are you sure you want to remove the label from the organization?",
|
||||||
"visibility": "Visibility",
|
"visibility": "Visibility",
|
||||||
"enabled": "Enabled",
|
"enabled": "Enabled",
|
||||||
"disabled": "Disabled",
|
"disabled": "Disabled",
|
||||||
@@ -1140,6 +1157,15 @@
|
|||||||
"idpErrorConnectingTo": "There was a problem connecting to {name}. Please contact your administrator.",
|
"idpErrorConnectingTo": "There was a problem connecting to {name}. Please contact your administrator.",
|
||||||
"idpErrorNotFound": "IdP not found",
|
"idpErrorNotFound": "IdP not found",
|
||||||
"inviteInvalid": "Invalid Invite",
|
"inviteInvalid": "Invalid Invite",
|
||||||
|
"labels": "Labels",
|
||||||
|
"orgLabelsDescription": "Manage labels in this organization.",
|
||||||
|
"addLabels": "Add labels",
|
||||||
|
"siteLabelsTab": "Labels",
|
||||||
|
"siteLabelsDescription": "Manage labels associated with this site.",
|
||||||
|
"labelsNotFound": "Labels not found",
|
||||||
|
"labelSearch": "Search labels",
|
||||||
|
"selectColor": "Select color",
|
||||||
|
"createNewLabel": "Create new org label \"{label}\"",
|
||||||
"inviteInvalidDescription": "The invite link is invalid.",
|
"inviteInvalidDescription": "The invite link is invalid.",
|
||||||
"inviteErrorWrongUser": "Invite is not for this user",
|
"inviteErrorWrongUser": "Invite is not for this user",
|
||||||
"inviteErrorUserNotExists": "User does not exist. Please create an account first.",
|
"inviteErrorUserNotExists": "User does not exist. Please create an account first.",
|
||||||
|
|||||||
@@ -148,6 +148,12 @@ export enum ActionsEnum {
|
|||||||
updateAlertRule = "updateAlertRule",
|
updateAlertRule = "updateAlertRule",
|
||||||
deleteAlertRule = "deleteAlertRule",
|
deleteAlertRule = "deleteAlertRule",
|
||||||
listAlertRules = "listAlertRules",
|
listAlertRules = "listAlertRules",
|
||||||
|
listOrgLabels = "listOrgLabels",
|
||||||
|
createOrgLabel = "createOrgLabel",
|
||||||
|
updateOrgLabel = "updateOrgLabel",
|
||||||
|
deleteOrgLabel = "deleteOrgLabel",
|
||||||
|
attachLabelToItem = "attachLabelToItem",
|
||||||
|
detachLabelFromItem = "detachLabelFromItem",
|
||||||
getAlertRule = "getAlertRule",
|
getAlertRule = "getAlertRule",
|
||||||
createHealthCheck = "createHealthCheck",
|
createHealthCheck = "createHealthCheck",
|
||||||
updateHealthCheck = "updateHealthCheck",
|
updateHealthCheck = "updateHealthCheck",
|
||||||
|
|||||||
@@ -162,6 +162,89 @@ export const resources = pgTable("resources", {
|
|||||||
wildcard: boolean("wildcard").notNull().default(false)
|
wildcard: boolean("wildcard").notNull().default(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const labels = pgTable("labels", {
|
||||||
|
labelId: serial("labelId").primaryKey(),
|
||||||
|
name: varchar("name").notNull(),
|
||||||
|
color: varchar("color").notNull(),
|
||||||
|
orgId: varchar("orgId")
|
||||||
|
.references(() => orgs.orgId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull()
|
||||||
|
});
|
||||||
|
|
||||||
|
export const siteLabels = pgTable(
|
||||||
|
"siteLabels",
|
||||||
|
{
|
||||||
|
siteLabelId: serial("siteLabelId").primaryKey(),
|
||||||
|
siteId: integer("siteId")
|
||||||
|
.references(() => sites.siteId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull(),
|
||||||
|
labelId: integer("labelId")
|
||||||
|
.references(() => labels.labelId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull()
|
||||||
|
},
|
||||||
|
(t) => [unique("site_label_uniq").on(t.siteId, t.labelId)]
|
||||||
|
);
|
||||||
|
|
||||||
|
export const resourceLabels = pgTable(
|
||||||
|
"resourceLabels",
|
||||||
|
{
|
||||||
|
resourceLabelId: serial("resourceLabelId").primaryKey(),
|
||||||
|
resourceId: integer("resourceId")
|
||||||
|
.references(() => resources.resourceId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull(),
|
||||||
|
labelId: integer("labelId")
|
||||||
|
.references(() => labels.labelId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull()
|
||||||
|
},
|
||||||
|
(t) => [unique("resource_label_uniq").on(t.resourceId, t.labelId)]
|
||||||
|
);
|
||||||
|
|
||||||
|
export const siteResourceLabels = pgTable(
|
||||||
|
"siteResourceLabels",
|
||||||
|
{
|
||||||
|
siteResourceLabelId: serial("siteResourceLabelId").primaryKey(),
|
||||||
|
siteResourceId: integer("siteResourceId")
|
||||||
|
.references(() => siteResources.siteResourceId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull(),
|
||||||
|
labelId: integer("labelId")
|
||||||
|
.references(() => labels.labelId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull()
|
||||||
|
},
|
||||||
|
(t) => [unique("site_resource_label_uniq").on(t.siteResourceId, t.labelId)]
|
||||||
|
);
|
||||||
|
|
||||||
|
export const clientLabels = pgTable(
|
||||||
|
"clientLabels",
|
||||||
|
{
|
||||||
|
clientLabelId: serial("clientLabelId").primaryKey(),
|
||||||
|
clientId: integer("clientId")
|
||||||
|
.references(() => clients.clientId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull(),
|
||||||
|
labelId: integer("labelId")
|
||||||
|
.references(() => labels.labelId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull()
|
||||||
|
},
|
||||||
|
(t) => [unique("client_label_uniq").on(t.clientId, t.labelId)]
|
||||||
|
);
|
||||||
|
|
||||||
export const targets = pgTable("targets", {
|
export const targets = pgTable("targets", {
|
||||||
targetId: serial("targetId").primaryKey(),
|
targetId: serial("targetId").primaryKey(),
|
||||||
resourceId: integer("resourceId")
|
resourceId: integer("resourceId")
|
||||||
@@ -196,9 +279,11 @@ export const targetHealthCheck = pgTable("targetHealthCheck", {
|
|||||||
onDelete: "cascade"
|
onDelete: "cascade"
|
||||||
})
|
})
|
||||||
.notNull(),
|
.notNull(),
|
||||||
siteId: integer("siteId").references(() => sites.siteId, {
|
siteId: integer("siteId")
|
||||||
onDelete: "cascade"
|
.references(() => sites.siteId, {
|
||||||
}).notNull(),
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull(),
|
||||||
name: varchar("name"),
|
name: varchar("name"),
|
||||||
hcEnabled: boolean("hcEnabled").notNull().default(false),
|
hcEnabled: boolean("hcEnabled").notNull().default(false),
|
||||||
hcPath: varchar("hcPath"),
|
hcPath: varchar("hcPath"),
|
||||||
@@ -1097,19 +1182,30 @@ export const roundTripMessageTracker = pgTable("roundTripMessageTracker", {
|
|||||||
complete: boolean("complete").notNull().default(false)
|
complete: boolean("complete").notNull().default(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
export const statusHistory = pgTable("statusHistory", {
|
export const statusHistory = pgTable(
|
||||||
id: serial("id").primaryKey(),
|
"statusHistory",
|
||||||
entityType: varchar("entityType").notNull(),
|
{
|
||||||
entityId: integer("entityId").notNull(),
|
id: serial("id").primaryKey(),
|
||||||
orgId: varchar("orgId")
|
entityType: varchar("entityType").notNull(),
|
||||||
.notNull()
|
entityId: integer("entityId").notNull(),
|
||||||
.references(() => orgs.orgId, { onDelete: "cascade" }),
|
orgId: varchar("orgId")
|
||||||
status: varchar("status").notNull(),
|
.notNull()
|
||||||
timestamp: integer("timestamp").notNull(),
|
.references(() => orgs.orgId, { onDelete: "cascade" }),
|
||||||
}, (table) => [
|
status: varchar("status").notNull(),
|
||||||
index("idx_statusHistory_entity").on(table.entityType, table.entityId, table.timestamp),
|
timestamp: integer("timestamp").notNull()
|
||||||
index("idx_statusHistory_org_timestamp").on(table.orgId, table.timestamp),
|
},
|
||||||
]);
|
(table) => [
|
||||||
|
index("idx_statusHistory_entity").on(
|
||||||
|
table.entityType,
|
||||||
|
table.entityId,
|
||||||
|
table.timestamp
|
||||||
|
),
|
||||||
|
index("idx_statusHistory_org_timestamp").on(
|
||||||
|
table.orgId,
|
||||||
|
table.timestamp
|
||||||
|
)
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
export type Org = InferSelectModel<typeof orgs>;
|
export type Org = InferSelectModel<typeof orgs>;
|
||||||
export type User = InferSelectModel<typeof users>;
|
export type User = InferSelectModel<typeof users>;
|
||||||
@@ -1179,3 +1275,4 @@ export type RoundTripMessageTracker = InferSelectModel<
|
|||||||
>;
|
>;
|
||||||
export type Network = InferSelectModel<typeof networks>;
|
export type Network = InferSelectModel<typeof networks>;
|
||||||
export type StatusHistory = InferSelectModel<typeof statusHistory>;
|
export type StatusHistory = InferSelectModel<typeof statusHistory>;
|
||||||
|
export type Label = InferSelectModel<typeof labels>;
|
||||||
|
|||||||
@@ -183,6 +183,95 @@ export const resources = sqliteTable("resources", {
|
|||||||
wildcard: integer("wildcard", { mode: "boolean" }).notNull().default(false)
|
wildcard: integer("wildcard", { mode: "boolean" }).notNull().default(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const labels = sqliteTable("labels", {
|
||||||
|
labelId: integer("labelId").primaryKey({ autoIncrement: true }),
|
||||||
|
name: text("name").notNull(),
|
||||||
|
color: text("color").notNull(),
|
||||||
|
orgId: text("orgId")
|
||||||
|
.references(() => orgs.orgId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull()
|
||||||
|
});
|
||||||
|
|
||||||
|
export const siteLabels = sqliteTable(
|
||||||
|
"siteLabels",
|
||||||
|
{
|
||||||
|
siteLabelId: integer("siteLabelId").primaryKey({ autoIncrement: true }),
|
||||||
|
siteId: integer("siteId")
|
||||||
|
.references(() => sites.siteId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull(),
|
||||||
|
labelId: integer("labelId")
|
||||||
|
.references(() => labels.labelId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull()
|
||||||
|
},
|
||||||
|
(t) => [unique("site_label_uniq").on(t.siteId, t.labelId)]
|
||||||
|
);
|
||||||
|
|
||||||
|
export const resourceLabels = sqliteTable(
|
||||||
|
"resourceLabels",
|
||||||
|
{
|
||||||
|
resourceLabelId: integer("resourceLabelId").primaryKey({
|
||||||
|
autoIncrement: true
|
||||||
|
}),
|
||||||
|
resourceId: integer("resourceId")
|
||||||
|
.references(() => resources.resourceId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull(),
|
||||||
|
labelId: integer("labelId")
|
||||||
|
.references(() => labels.labelId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull()
|
||||||
|
},
|
||||||
|
(t) => [unique("resource_label_uniq").on(t.resourceId, t.labelId)]
|
||||||
|
);
|
||||||
|
|
||||||
|
export const siteResourceLabels = sqliteTable(
|
||||||
|
"siteResourceLabels",
|
||||||
|
{
|
||||||
|
siteResourceLabelId: integer("siteResourceLabelId").primaryKey({
|
||||||
|
autoIncrement: true
|
||||||
|
}),
|
||||||
|
siteResourceId: integer("siteResourceId")
|
||||||
|
.references(() => siteResources.siteResourceId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull(),
|
||||||
|
labelId: integer("labelId")
|
||||||
|
.references(() => labels.labelId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull()
|
||||||
|
},
|
||||||
|
(t) => [unique("site_resource_label_uniq").on(t.siteResourceId, t.labelId)]
|
||||||
|
);
|
||||||
|
|
||||||
|
export const clientLabels = sqliteTable(
|
||||||
|
"clientLabels",
|
||||||
|
{
|
||||||
|
clientLabelId: integer("clientLabelId").primaryKey({
|
||||||
|
autoIncrement: true
|
||||||
|
}),
|
||||||
|
clientId: integer("clientId")
|
||||||
|
.references(() => clients.clientId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull(),
|
||||||
|
labelId: integer("labelId")
|
||||||
|
.references(() => labels.labelId, {
|
||||||
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull()
|
||||||
|
},
|
||||||
|
(t) => [unique("client_label_uniq").on(t.clientId, t.labelId)]
|
||||||
|
);
|
||||||
|
|
||||||
export const targets = sqliteTable("targets", {
|
export const targets = sqliteTable("targets", {
|
||||||
targetId: integer("targetId").primaryKey({ autoIncrement: true }),
|
targetId: integer("targetId").primaryKey({ autoIncrement: true }),
|
||||||
resourceId: integer("resourceId")
|
resourceId: integer("resourceId")
|
||||||
@@ -219,9 +308,11 @@ export const targetHealthCheck = sqliteTable("targetHealthCheck", {
|
|||||||
onDelete: "cascade"
|
onDelete: "cascade"
|
||||||
})
|
})
|
||||||
.notNull(),
|
.notNull(),
|
||||||
siteId: integer("siteId").references(() => sites.siteId, {
|
siteId: integer("siteId")
|
||||||
onDelete: "cascade"
|
.references(() => sites.siteId, {
|
||||||
}).notNull(),
|
onDelete: "cascade"
|
||||||
|
})
|
||||||
|
.notNull(),
|
||||||
name: text("name"),
|
name: text("name"),
|
||||||
hcEnabled: integer("hcEnabled", { mode: "boolean" })
|
hcEnabled: integer("hcEnabled", { mode: "boolean" })
|
||||||
.notNull()
|
.notNull()
|
||||||
@@ -1196,19 +1287,30 @@ export const roundTripMessageTracker = sqliteTable("roundTripMessageTracker", {
|
|||||||
complete: integer("complete", { mode: "boolean" }).notNull().default(false)
|
complete: integer("complete", { mode: "boolean" }).notNull().default(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
export const statusHistory = sqliteTable("statusHistory", {
|
export const statusHistory = sqliteTable(
|
||||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
"statusHistory",
|
||||||
entityType: text("entityType").notNull(), // "site" | "healthCheck"
|
{
|
||||||
entityId: integer("entityId").notNull(), // siteId or targetHealthCheckId
|
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||||
orgId: text("orgId")
|
entityType: text("entityType").notNull(), // "site" | "healthCheck"
|
||||||
.notNull()
|
entityId: integer("entityId").notNull(), // siteId or targetHealthCheckId
|
||||||
.references(() => orgs.orgId, { onDelete: "cascade" }),
|
orgId: text("orgId")
|
||||||
status: text("status").notNull(), // "online"/"offline" for sites; "healthy"/"unhealthy"/"unknown" for healthChecks
|
.notNull()
|
||||||
timestamp: integer("timestamp").notNull(), // unix epoch seconds
|
.references(() => orgs.orgId, { onDelete: "cascade" }),
|
||||||
}, (table) => [
|
status: text("status").notNull(), // "online"/"offline" for sites; "healthy"/"unhealthy"/"unknown" for healthChecks
|
||||||
index("idx_statusHistory_entity").on(table.entityType, table.entityId, table.timestamp),
|
timestamp: integer("timestamp").notNull() // unix epoch seconds
|
||||||
index("idx_statusHistory_org_timestamp").on(table.orgId, table.timestamp),
|
},
|
||||||
]);
|
(table) => [
|
||||||
|
index("idx_statusHistory_entity").on(
|
||||||
|
table.entityType,
|
||||||
|
table.entityId,
|
||||||
|
table.timestamp
|
||||||
|
),
|
||||||
|
index("idx_statusHistory_org_timestamp").on(
|
||||||
|
table.orgId,
|
||||||
|
table.timestamp
|
||||||
|
)
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
export type Org = InferSelectModel<typeof orgs>;
|
export type Org = InferSelectModel<typeof orgs>;
|
||||||
export type User = InferSelectModel<typeof users>;
|
export type User = InferSelectModel<typeof users>;
|
||||||
@@ -1278,3 +1380,4 @@ export type RoundTripMessageTracker = InferSelectModel<
|
|||||||
typeof roundTripMessageTracker
|
typeof roundTripMessageTracker
|
||||||
>;
|
>;
|
||||||
export type StatusHistory = InferSelectModel<typeof statusHistory>;
|
export type StatusHistory = InferSelectModel<typeof statusHistory>;
|
||||||
|
export type Label = InferSelectModel<typeof labels>;
|
||||||
|
|||||||
@@ -24,10 +24,12 @@ export enum TierFeature {
|
|||||||
DomainNamespaces = "domainNamespaces", // handle downgrade by removing custom domain namespaces
|
DomainNamespaces = "domainNamespaces", // handle downgrade by removing custom domain namespaces
|
||||||
StandaloneHealthChecks = "standaloneHealthChecks",
|
StandaloneHealthChecks = "standaloneHealthChecks",
|
||||||
AlertingRules = "alertingRules",
|
AlertingRules = "alertingRules",
|
||||||
WildcardSubdomain = "wildcardSubdomain"
|
WildcardSubdomain = "wildcardSubdomain",
|
||||||
|
Labels = "labels"
|
||||||
}
|
}
|
||||||
|
|
||||||
export const tierMatrix: Record<TierFeature, Tier[]> = {
|
export const tierMatrix: Record<TierFeature, Tier[]> = {
|
||||||
|
[TierFeature.Labels]: ["tier2", "tier3", "enterprise"],
|
||||||
[TierFeature.OrgOidc]: ["tier1", "tier2", "tier3", "enterprise"],
|
[TierFeature.OrgOidc]: ["tier1", "tier2", "tier3", "enterprise"],
|
||||||
[TierFeature.LoginPageDomain]: ["tier1", "tier2", "tier3", "enterprise"],
|
[TierFeature.LoginPageDomain]: ["tier1", "tier2", "tier3", "enterprise"],
|
||||||
[TierFeature.DeviceApprovals]: ["tier1", "tier3", "enterprise"],
|
[TierFeature.DeviceApprovals]: ["tier1", "tier3", "enterprise"],
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ import { LogStreamingManager } from "./LogStreamingManager";
|
|||||||
*/
|
*/
|
||||||
export const logStreamingManager = new LogStreamingManager();
|
export const logStreamingManager = new LogStreamingManager();
|
||||||
|
|
||||||
if (build != "saas") { // this is handled separately in the saas build, so we don't want to start it here
|
if (build !== "saas") {
|
||||||
|
// this is handled separately in the saas build, so we don't want to start it here
|
||||||
logStreamingManager.start();
|
logStreamingManager.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export function verifyValidSubscription(tiers: Tier[]) {
|
|||||||
next: NextFunction
|
next: NextFunction
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
try {
|
try {
|
||||||
if (build != "saas") {
|
if (build !== "saas") {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import * as siteProvisioning from "#private/routers/siteProvisioning";
|
|||||||
import * as eventStreamingDestination from "#private/routers/eventStreamingDestination";
|
import * as eventStreamingDestination from "#private/routers/eventStreamingDestination";
|
||||||
import * as alertRule from "#private/routers/alertRule";
|
import * as alertRule from "#private/routers/alertRule";
|
||||||
import * as healthChecks from "#private/routers/healthChecks";
|
import * as healthChecks from "#private/routers/healthChecks";
|
||||||
|
import * as labels from "#private/routers/labels";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
verifyOrgAccess,
|
verifyOrgAccess,
|
||||||
@@ -732,6 +733,59 @@ authenticated.get(
|
|||||||
alertRule.getAlertRule
|
alertRule.getAlertRule
|
||||||
);
|
);
|
||||||
|
|
||||||
|
authenticated.get(
|
||||||
|
"/org/:orgId/labels",
|
||||||
|
verifyValidLicense,
|
||||||
|
verifyOrgAccess,
|
||||||
|
verifyValidSubscription(tierMatrix.labels),
|
||||||
|
verifyUserHasAction(ActionsEnum.listOrgLabels),
|
||||||
|
labels.listOrgLabels
|
||||||
|
);
|
||||||
|
|
||||||
|
authenticated.post(
|
||||||
|
"/org/:orgId/labels",
|
||||||
|
verifyValidLicense,
|
||||||
|
verifyOrgAccess,
|
||||||
|
verifyValidSubscription(tierMatrix.labels),
|
||||||
|
verifyUserHasAction(ActionsEnum.createOrgLabel),
|
||||||
|
labels.createOrgLabel
|
||||||
|
);
|
||||||
|
|
||||||
|
authenticated.patch(
|
||||||
|
"/org/:orgId/label/:labelId",
|
||||||
|
verifyValidLicense,
|
||||||
|
verifyOrgAccess,
|
||||||
|
verifyValidSubscription(tierMatrix.labels),
|
||||||
|
verifyUserHasAction(ActionsEnum.updateOrgLabel),
|
||||||
|
labels.updateOrgLabel
|
||||||
|
);
|
||||||
|
|
||||||
|
authenticated.delete(
|
||||||
|
"/org/:orgId/label/:labelId",
|
||||||
|
verifyValidLicense,
|
||||||
|
verifyOrgAccess,
|
||||||
|
verifyUserHasAction(ActionsEnum.deleteOrgLabel),
|
||||||
|
labels.deleteOrgLabel
|
||||||
|
);
|
||||||
|
|
||||||
|
authenticated.put(
|
||||||
|
"/org/:orgId/label/:labelId/attach",
|
||||||
|
verifyValidLicense,
|
||||||
|
verifyOrgAccess,
|
||||||
|
verifyValidSubscription(tierMatrix.labels),
|
||||||
|
verifyUserHasAction(ActionsEnum.attachLabelToItem),
|
||||||
|
labels.attachLabelToItem
|
||||||
|
);
|
||||||
|
|
||||||
|
authenticated.put(
|
||||||
|
"/org/:orgId/label/:labelId/detach",
|
||||||
|
verifyValidLicense,
|
||||||
|
verifyOrgAccess,
|
||||||
|
verifyValidSubscription(tierMatrix.labels),
|
||||||
|
verifyUserHasAction(ActionsEnum.detachLabelFromItem),
|
||||||
|
labels.detachLabelFromItem
|
||||||
|
);
|
||||||
|
|
||||||
authenticated.get(
|
authenticated.get(
|
||||||
"/org/:orgId/health-checks",
|
"/org/:orgId/health-checks",
|
||||||
verifyValidLicense,
|
verifyValidLicense,
|
||||||
|
|||||||
224
server/private/routers/labels/attachLabelToItem.ts
Normal file
224
server/private/routers/labels/attachLabelToItem.ts
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of a proprietary work.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025-2026 Fossorial, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is licensed under the Fossorial Commercial License.
|
||||||
|
* You may not use this file except in compliance with the License.
|
||||||
|
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||||
|
*
|
||||||
|
* This file is not licensed under the AGPLv3.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
clients,
|
||||||
|
clientLabels,
|
||||||
|
db,
|
||||||
|
labels,
|
||||||
|
resourceLabels,
|
||||||
|
resources,
|
||||||
|
siteLabels,
|
||||||
|
siteResourceLabels,
|
||||||
|
siteResources,
|
||||||
|
sites
|
||||||
|
} from "@server/db";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import { and, eq, isNull } from "drizzle-orm";
|
||||||
|
import { NextFunction, Request, Response } from "express";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
|
||||||
|
const paramsSchema = z.strictObject({
|
||||||
|
orgId: z.string().nonempty(),
|
||||||
|
labelId: z.string().transform(Number).pipe(z.int().positive())
|
||||||
|
});
|
||||||
|
|
||||||
|
const attachLabelBodySchema = z.strictObject({
|
||||||
|
siteId: z.number().int().optional(),
|
||||||
|
resourceId: z.number().int().optional(),
|
||||||
|
siteResourceId: z.number().int().optional(),
|
||||||
|
clientId: z.number().int().optional()
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function attachLabelToItem(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const parsedParams = paramsSchema.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { orgId, labelId } = parsedParams.data;
|
||||||
|
|
||||||
|
const parsedBody = attachLabelBodySchema.safeParse(req.body);
|
||||||
|
if (!parsedBody.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedBody.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { siteId, resourceId, siteResourceId, clientId } =
|
||||||
|
parsedBody.data;
|
||||||
|
|
||||||
|
if (!siteId && !resourceId && !siteResourceId && !clientId) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
"At least one of `siteId`, `resourceId`, `siteResourceId` or `clientId` should be provided."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [existing] = await db
|
||||||
|
.select()
|
||||||
|
.from(labels)
|
||||||
|
.where(and(eq(labels.labelId, labelId), eq(labels.orgId, orgId)));
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`Label with Id ${labelId} not found`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (siteId) {
|
||||||
|
const siteCount = await db.$count(
|
||||||
|
sites,
|
||||||
|
and(eq(sites.siteId, siteId), eq(sites.orgId, orgId))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (siteCount === 0) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`Site with Id ${siteId} doesn't exist.`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// idempotent, calling this endpoint multiple times should attach the label only once
|
||||||
|
await db
|
||||||
|
.insert(siteLabels)
|
||||||
|
.values({
|
||||||
|
labelId,
|
||||||
|
siteId
|
||||||
|
})
|
||||||
|
.onConflictDoNothing();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resourceId) {
|
||||||
|
const resourceCount = await db.$count(
|
||||||
|
resources,
|
||||||
|
and(
|
||||||
|
eq(resources.resourceId, resourceId),
|
||||||
|
eq(resources.orgId, orgId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (resourceCount === 0) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`Resource with Id ${resourceId} doesn't exist.`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// idempotent, calling this endpoint multiple times should attach the label only once
|
||||||
|
await db
|
||||||
|
.insert(resourceLabels)
|
||||||
|
.values({
|
||||||
|
labelId,
|
||||||
|
resourceId
|
||||||
|
})
|
||||||
|
.onConflictDoNothing();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (siteResourceId) {
|
||||||
|
const resourceCount = await db.$count(
|
||||||
|
siteResources,
|
||||||
|
and(
|
||||||
|
eq(siteResources.siteResourceId, siteResourceId),
|
||||||
|
eq(siteResources.orgId, orgId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (resourceCount === 0) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`SiteResource with Id ${siteResourceId} doesn't exist.`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// idempotent, calling this endpoint multiple times should attach the label only once
|
||||||
|
await db
|
||||||
|
.insert(siteResourceLabels)
|
||||||
|
.values({
|
||||||
|
labelId,
|
||||||
|
siteResourceId
|
||||||
|
})
|
||||||
|
.onConflictDoNothing();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clientId) {
|
||||||
|
const clientCount = await db.$count(
|
||||||
|
clients,
|
||||||
|
and(
|
||||||
|
eq(clients.clientId, clientId),
|
||||||
|
eq(clients.orgId, orgId),
|
||||||
|
isNull(clients.userId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (clientCount === 0) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`Client with Id ${clientId} doesn't exist.`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// idempotent, calling this endpoint multiple times should attach the label only once
|
||||||
|
await db
|
||||||
|
.insert(clientLabels)
|
||||||
|
.values({
|
||||||
|
labelId,
|
||||||
|
clientId
|
||||||
|
})
|
||||||
|
.onConflictDoNothing();
|
||||||
|
}
|
||||||
|
|
||||||
|
return response(res, {
|
||||||
|
data: {},
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Label attached successfully",
|
||||||
|
status: HttpCode.OK
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
149
server/private/routers/labels/createOrgLabel.ts
Normal file
149
server/private/routers/labels/createOrgLabel.ts
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of a proprietary work.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025-2026 Fossorial, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is licensed under the Fossorial Commercial License.
|
||||||
|
* You may not use this file except in compliance with the License.
|
||||||
|
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||||
|
*
|
||||||
|
* This file is not licensed under the AGPLv3.
|
||||||
|
*/
|
||||||
|
import {
|
||||||
|
db,
|
||||||
|
labels,
|
||||||
|
resourceLabels,
|
||||||
|
resources,
|
||||||
|
siteLabels,
|
||||||
|
sites
|
||||||
|
} from "@server/db";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import type { CreateOrEditLabelResponse } from "@server/routers/labels/types";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import { and, eq } from "drizzle-orm";
|
||||||
|
import { NextFunction, Request, Response } from "express";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
|
||||||
|
const paramsSchema = z.strictObject({
|
||||||
|
orgId: z.string().nonempty()
|
||||||
|
});
|
||||||
|
|
||||||
|
const bodySchema = z.strictObject({
|
||||||
|
name: z.string().nonempty(),
|
||||||
|
color: z
|
||||||
|
.string()
|
||||||
|
.regex(/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i)
|
||||||
|
.nonempty(),
|
||||||
|
siteId: z.number().int().optional(),
|
||||||
|
resourceId: z.number().int().optional()
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function createOrgLabel(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const parsedParams = paramsSchema.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { orgId } = parsedParams.data;
|
||||||
|
|
||||||
|
const parsedBody = bodySchema.safeParse(req.body);
|
||||||
|
if (!parsedBody.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedBody.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { name, color, siteId, resourceId } = parsedBody.data;
|
||||||
|
|
||||||
|
if (siteId) {
|
||||||
|
const siteCount = await db.$count(
|
||||||
|
sites,
|
||||||
|
and(eq(sites.siteId, siteId), eq(sites.orgId, orgId))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (siteCount === 0) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
`Site with Id ${siteId} doesn't exist.`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resourceId) {
|
||||||
|
const resourceCount = await db.$count(
|
||||||
|
resources,
|
||||||
|
and(
|
||||||
|
eq(resources.resourceId, resourceId),
|
||||||
|
eq(resources.orgId, orgId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (resourceCount === 0) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
`Resource with Id ${resourceId} doesn't exist.`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const label = await db.transaction(async (tx) => {
|
||||||
|
const [label] = await tx
|
||||||
|
.insert(labels)
|
||||||
|
.values({
|
||||||
|
name,
|
||||||
|
color,
|
||||||
|
orgId
|
||||||
|
})
|
||||||
|
.returning();
|
||||||
|
|
||||||
|
if (siteId) {
|
||||||
|
await tx.insert(siteLabels).values({
|
||||||
|
siteId,
|
||||||
|
labelId: label.labelId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resourceId) {
|
||||||
|
await tx.insert(resourceLabels).values({
|
||||||
|
resourceId,
|
||||||
|
labelId: label.labelId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return label;
|
||||||
|
});
|
||||||
|
|
||||||
|
return response<CreateOrEditLabelResponse>(res, {
|
||||||
|
data: { label },
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Org Label created successfully",
|
||||||
|
status: HttpCode.CREATED
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
72
server/private/routers/labels/deleteOrgLabel.ts
Normal file
72
server/private/routers/labels/deleteOrgLabel.ts
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of a proprietary work.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025-2026 Fossorial, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is licensed under the Fossorial Commercial License.
|
||||||
|
* You may not use this file except in compliance with the License.
|
||||||
|
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||||
|
*
|
||||||
|
* This file is not licensed under the AGPLv3.
|
||||||
|
*/
|
||||||
|
import { db, labels } from "@server/db";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import { and, eq } from "drizzle-orm";
|
||||||
|
import { NextFunction, Request, Response } from "express";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
|
||||||
|
const paramsSchema = z.strictObject({
|
||||||
|
orgId: z.string().nonempty(),
|
||||||
|
labelId: z.string().transform(Number).pipe(z.int().positive())
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function deleteOrgLabel(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const parsedParams = paramsSchema.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { orgId, labelId } = parsedParams.data;
|
||||||
|
|
||||||
|
const [existing] = await db
|
||||||
|
.select()
|
||||||
|
.from(labels)
|
||||||
|
.where(and(eq(labels.labelId, labelId), eq(labels.orgId, orgId)));
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return next(createHttpError(HttpCode.NOT_FOUND, "Label not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
await db
|
||||||
|
.delete(labels)
|
||||||
|
.where(and(eq(labels.labelId, labelId), eq(labels.orgId, orgId)));
|
||||||
|
|
||||||
|
return response(res, {
|
||||||
|
data: null,
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Label deleted successfully",
|
||||||
|
status: HttpCode.OK
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
224
server/private/routers/labels/detachLabelFromItem.ts
Normal file
224
server/private/routers/labels/detachLabelFromItem.ts
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of a proprietary work.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025-2026 Fossorial, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is licensed under the Fossorial Commercial License.
|
||||||
|
* You may not use this file except in compliance with the License.
|
||||||
|
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||||
|
*
|
||||||
|
* This file is not licensed under the AGPLv3.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
clients,
|
||||||
|
clientLabels,
|
||||||
|
db,
|
||||||
|
labels,
|
||||||
|
resourceLabels,
|
||||||
|
resources,
|
||||||
|
siteLabels,
|
||||||
|
siteResourceLabels,
|
||||||
|
siteResources,
|
||||||
|
sites
|
||||||
|
} from "@server/db";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import { and, eq, isNull } from "drizzle-orm";
|
||||||
|
import { NextFunction, Request, Response } from "express";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
|
||||||
|
const paramsSchema = z.strictObject({
|
||||||
|
orgId: z.string().nonempty(),
|
||||||
|
labelId: z.string().transform(Number).pipe(z.int().positive())
|
||||||
|
});
|
||||||
|
|
||||||
|
const detachLabelBodySchema = z.strictObject({
|
||||||
|
siteId: z.number().int().optional(),
|
||||||
|
resourceId: z.number().int().optional(),
|
||||||
|
siteResourceId: z.number().int().optional(),
|
||||||
|
clientId: z.number().int().optional()
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function detachLabelFromItem(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const parsedParams = paramsSchema.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { orgId, labelId } = parsedParams.data;
|
||||||
|
|
||||||
|
const parsedBody = detachLabelBodySchema.safeParse(req.body);
|
||||||
|
if (!parsedBody.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedBody.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { siteId, resourceId, siteResourceId, clientId } =
|
||||||
|
parsedBody.data;
|
||||||
|
|
||||||
|
if (!siteId && !resourceId && !siteResourceId && !clientId) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
"At least one of `siteId`, `resourceId`, `siteResourceId` or `clientId` should be provided."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [existing] = await db
|
||||||
|
.select()
|
||||||
|
.from(labels)
|
||||||
|
.where(and(eq(labels.labelId, labelId), eq(labels.orgId, orgId)));
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`Label with Id ${labelId} not found`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (siteId) {
|
||||||
|
const siteCount = await db.$count(
|
||||||
|
sites,
|
||||||
|
and(eq(sites.siteId, siteId), eq(sites.orgId, orgId))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (siteCount === 0) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`Site with Id ${siteId} doesn't exist.`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await db
|
||||||
|
.delete(siteLabels)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(siteLabels.labelId, labelId),
|
||||||
|
eq(siteLabels.siteId, siteId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resourceId) {
|
||||||
|
const resourceCount = await db.$count(
|
||||||
|
resources,
|
||||||
|
and(
|
||||||
|
eq(resources.resourceId, resourceId),
|
||||||
|
eq(resources.orgId, orgId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (resourceCount === 0) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`Resource with Id ${resourceId} doesn't exist.`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await db
|
||||||
|
.delete(resourceLabels)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(resourceLabels.labelId, labelId),
|
||||||
|
eq(resourceLabels.resourceId, resourceId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (siteResourceId) {
|
||||||
|
const resourceCount = await db.$count(
|
||||||
|
siteResources,
|
||||||
|
and(
|
||||||
|
eq(siteResources.siteResourceId, siteResourceId),
|
||||||
|
eq(siteResources.orgId, orgId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (resourceCount === 0) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`SiteResource with Id ${siteResourceId} doesn't exist.`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await db
|
||||||
|
.delete(siteResourceLabels)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(siteResourceLabels.labelId, labelId),
|
||||||
|
eq(siteResourceLabels.siteResourceId, siteResourceId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clientId) {
|
||||||
|
const clientCount = await db.$count(
|
||||||
|
clients,
|
||||||
|
and(
|
||||||
|
eq(clients.clientId, clientId),
|
||||||
|
eq(clients.orgId, orgId),
|
||||||
|
isNull(clients.userId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (clientCount === 0) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`Client with Id ${clientId} doesn't exist.`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await db
|
||||||
|
.delete(clientLabels)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(clientLabels.labelId, labelId),
|
||||||
|
eq(clientLabels.clientId, clientId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response(res, {
|
||||||
|
data: {},
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Label detached successfully",
|
||||||
|
status: HttpCode.OK
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
19
server/private/routers/labels/index.ts
Normal file
19
server/private/routers/labels/index.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of a proprietary work.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025-2026 Fossorial, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is licensed under the Fossorial Commercial License.
|
||||||
|
* You may not use this file except in compliance with the License.
|
||||||
|
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||||
|
*
|
||||||
|
* This file is not licensed under the AGPLv3.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./listOrgLabels";
|
||||||
|
export * from "./createOrgLabel";
|
||||||
|
export * from "./updateOrgLabel";
|
||||||
|
export * from "./attachLabelToItem";
|
||||||
|
export * from "./detachLabelFromItem";
|
||||||
|
export * from "./deleteOrgLabel";
|
||||||
155
server/private/routers/labels/listOrgLabels.ts
Normal file
155
server/private/routers/labels/listOrgLabels.ts
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of a proprietary work.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025-2026 Fossorial, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is licensed under the Fossorial Commercial License.
|
||||||
|
* You may not use this file except in compliance with the License.
|
||||||
|
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||||
|
*
|
||||||
|
* This file is not licensed under the AGPLv3.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { db, labels } from "@server/db";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import type { ListOrgLabelsResponse } from "@server/routers/labels/types";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import { and, asc, eq, like, sql } from "drizzle-orm";
|
||||||
|
import { NextFunction, Request, Response } from "express";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
|
||||||
|
const paramsSchema = z.strictObject({
|
||||||
|
orgId: z.string().nonempty()
|
||||||
|
});
|
||||||
|
|
||||||
|
const listLabelsSchema = z.object({
|
||||||
|
pageSize: z.coerce
|
||||||
|
.number<string>() // for prettier formatting
|
||||||
|
.int()
|
||||||
|
.positive()
|
||||||
|
.optional()
|
||||||
|
.catch(20)
|
||||||
|
.default(20)
|
||||||
|
.openapi({
|
||||||
|
type: "integer",
|
||||||
|
default: 20,
|
||||||
|
description: "Number of items per page"
|
||||||
|
}),
|
||||||
|
page: z.coerce
|
||||||
|
.number<string>() // for prettier formatting
|
||||||
|
.int()
|
||||||
|
.min(0)
|
||||||
|
.optional()
|
||||||
|
.catch(1)
|
||||||
|
.default(1)
|
||||||
|
.openapi({
|
||||||
|
type: "integer",
|
||||||
|
default: 1,
|
||||||
|
description: "Page number to retrieve"
|
||||||
|
}),
|
||||||
|
query: z.string().optional()
|
||||||
|
});
|
||||||
|
|
||||||
|
function queryLabelsBase() {
|
||||||
|
return db
|
||||||
|
.select({
|
||||||
|
labelId: labels.labelId,
|
||||||
|
name: labels.name,
|
||||||
|
color: labels.color
|
||||||
|
})
|
||||||
|
.from(labels);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listOrgLabels(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
): Promise<any> {
|
||||||
|
try {
|
||||||
|
const parsedQuery = listLabelsSchema.safeParse(req.query);
|
||||||
|
if (!parsedQuery.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedQuery.error)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsedParams = paramsSchema.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const { orgId } = parsedParams.data;
|
||||||
|
|
||||||
|
if (req.user && orgId && orgId !== req.userOrgId) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.FORBIDDEN,
|
||||||
|
"User does not have access to this organization"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { pageSize, page, query } = parsedQuery.data;
|
||||||
|
|
||||||
|
const conditions = [and(eq(labels.orgId, orgId))];
|
||||||
|
|
||||||
|
if (query) {
|
||||||
|
conditions.push(
|
||||||
|
like(
|
||||||
|
sql`LOWER(${labels.name})`,
|
||||||
|
"%" + query.toLowerCase() + "%"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const baseQuery = queryLabelsBase().where(and(...conditions));
|
||||||
|
|
||||||
|
// we need to add `as` so that drizzle filters the result as a subquery
|
||||||
|
const countQuery = db.$count(
|
||||||
|
queryLabelsBase()
|
||||||
|
.where(and(...conditions))
|
||||||
|
.as("filtered_labels")
|
||||||
|
);
|
||||||
|
|
||||||
|
const labelListQuery = baseQuery
|
||||||
|
.limit(pageSize)
|
||||||
|
.offset(pageSize * (page - 1))
|
||||||
|
.orderBy(asc(labels.name));
|
||||||
|
|
||||||
|
const [totalCount, rows] = await Promise.all([
|
||||||
|
countQuery,
|
||||||
|
labelListQuery
|
||||||
|
]);
|
||||||
|
|
||||||
|
return response<ListOrgLabelsResponse>(res, {
|
||||||
|
data: {
|
||||||
|
labels: rows,
|
||||||
|
pagination: {
|
||||||
|
total: totalCount,
|
||||||
|
pageSize,
|
||||||
|
page
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Labels retrieved successfully",
|
||||||
|
status: HttpCode.OK
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
101
server/private/routers/labels/updateOrgLabel.ts
Normal file
101
server/private/routers/labels/updateOrgLabel.ts
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of a proprietary work.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025-2026 Fossorial, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is licensed under the Fossorial Commercial License.
|
||||||
|
* You may not use this file except in compliance with the License.
|
||||||
|
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||||
|
*
|
||||||
|
* This file is not licensed under the AGPLv3.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { db, labels } from "@server/db";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import type { CreateOrEditLabelResponse } from "@server/routers/labels/types";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import { and, eq } from "drizzle-orm";
|
||||||
|
import { NextFunction, Request, Response } from "express";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
|
||||||
|
const paramsSchema = z.strictObject({
|
||||||
|
orgId: z.string().nonempty(),
|
||||||
|
labelId: z.string().transform(Number).pipe(z.int().positive())
|
||||||
|
});
|
||||||
|
|
||||||
|
const updateLabelBodySchema = z.strictObject({
|
||||||
|
name: z.string().min(1).max(255).optional(),
|
||||||
|
color: z
|
||||||
|
.string()
|
||||||
|
.regex(/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i)
|
||||||
|
.nonempty()
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function updateOrgLabel(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const parsedParams = paramsSchema.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { orgId, labelId } = parsedParams.data;
|
||||||
|
|
||||||
|
const parsedBody = updateLabelBodySchema.safeParse(req.body);
|
||||||
|
if (!parsedBody.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedBody.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [existing] = await db
|
||||||
|
.select()
|
||||||
|
.from(labels)
|
||||||
|
.where(and(eq(labels.labelId, labelId), eq(labels.orgId, orgId)));
|
||||||
|
|
||||||
|
if (!existing) {
|
||||||
|
return next(createHttpError(HttpCode.NOT_FOUND, "Label not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
const { name, color } = parsedBody.data;
|
||||||
|
|
||||||
|
const [label] = await db
|
||||||
|
.update(labels)
|
||||||
|
.set({
|
||||||
|
name,
|
||||||
|
color
|
||||||
|
})
|
||||||
|
.where(and(eq(labels.labelId, labelId), eq(labels.orgId, orgId)))
|
||||||
|
.returning();
|
||||||
|
|
||||||
|
return response<CreateOrEditLabelResponse>(res, {
|
||||||
|
data: {
|
||||||
|
label
|
||||||
|
},
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Label updated successfully",
|
||||||
|
status: HttpCode.OK
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
logsDb,
|
logsDb,
|
||||||
newts,
|
newts,
|
||||||
roles,
|
roles,
|
||||||
|
roleSiteResources,
|
||||||
roundTripMessageTracker,
|
roundTripMessageTracker,
|
||||||
siteResources,
|
siteResources,
|
||||||
siteNetworks,
|
siteNetworks,
|
||||||
@@ -361,9 +362,26 @@ export async function signSshKey(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const roleRows = await db
|
const roleRows = await db
|
||||||
.select()
|
.select({
|
||||||
|
sshSudoCommands: roles.sshSudoCommands,
|
||||||
|
sshUnixGroups: roles.sshUnixGroups,
|
||||||
|
sshCreateHomeDir: roles.sshCreateHomeDir,
|
||||||
|
sshSudoMode: roles.sshSudoMode
|
||||||
|
})
|
||||||
.from(roles)
|
.from(roles)
|
||||||
.where(inArray(roles.roleId, roleIds));
|
.innerJoin(
|
||||||
|
roleSiteResources,
|
||||||
|
eq(roleSiteResources.roleId, roles.roleId)
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
inArray(roles.roleId, roleIds),
|
||||||
|
eq(
|
||||||
|
roleSiteResources.siteResourceId,
|
||||||
|
resource.siteResourceId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
const parsedSudoCommands: string[] = [];
|
const parsedSudoCommands: string[] = [];
|
||||||
const parsedGroupsSet = new Set<string>();
|
const parsedGroupsSet = new Set<string>();
|
||||||
@@ -379,13 +397,17 @@ export async function signSshKey(
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const grps = JSON.parse(roleRow?.sshUnixGroups ?? "[]");
|
const grps = JSON.parse(roleRow?.sshUnixGroups ?? "[]");
|
||||||
if (Array.isArray(grps)) grps.forEach((g: string) => parsedGroupsSet.add(g));
|
if (Array.isArray(grps))
|
||||||
|
grps.forEach((g: string) => parsedGroupsSet.add(g));
|
||||||
} catch {
|
} catch {
|
||||||
// skip
|
// skip
|
||||||
}
|
}
|
||||||
if (roleRow?.sshCreateHomeDir === true) homedir = true;
|
if (roleRow?.sshCreateHomeDir === true) homedir = true;
|
||||||
const m = roleRow?.sshSudoMode ?? "none";
|
const m = roleRow?.sshSudoMode ?? "none";
|
||||||
if (sudoModeOrder[m as keyof typeof sudoModeOrder] > sudoModeOrder[sudoMode]) {
|
if (
|
||||||
|
sudoModeOrder[m as keyof typeof sudoModeOrder] >
|
||||||
|
sudoModeOrder[sudoMode]
|
||||||
|
) {
|
||||||
sudoMode = m as "none" | "commands" | "full";
|
sudoMode = m as "none" | "commands" | "full";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
import {
|
import {
|
||||||
|
clientLabels,
|
||||||
clients,
|
clients,
|
||||||
clientSitesAssociationsCache,
|
clientSitesAssociationsCache,
|
||||||
currentFingerprint,
|
currentFingerprint,
|
||||||
db,
|
db,
|
||||||
|
labels,
|
||||||
olms,
|
olms,
|
||||||
orgs,
|
orgs,
|
||||||
roleClients,
|
roleClients,
|
||||||
sites,
|
sites,
|
||||||
userClients,
|
userClients,
|
||||||
users
|
users,
|
||||||
|
type Label
|
||||||
} from "@server/db";
|
} from "@server/db";
|
||||||
|
import { isLicensedOrSubscribed } from "#dynamic/lib/isLicencedOrSubscribed";
|
||||||
|
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
||||||
import response from "@server/lib/response";
|
import response from "@server/lib/response";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { OpenAPITags, registry } from "@server/openApi";
|
import { OpenAPITags, registry } from "@server/openApi";
|
||||||
@@ -169,6 +174,7 @@ type ClientWithSites = Awaited<ReturnType<typeof queryClientsBase>>[0] & {
|
|||||||
siteNiceId: string | null;
|
siteNiceId: string | null;
|
||||||
}>;
|
}>;
|
||||||
olmUpdateAvailable?: boolean;
|
olmUpdateAvailable?: boolean;
|
||||||
|
labels?: Array<Pick<Label, "labelId" | "name" | "color">>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type OlmWithUpdateAvailable = ClientWithSites;
|
type OlmWithUpdateAvailable = ClientWithSites;
|
||||||
@@ -255,6 +261,11 @@ export async function listClients(
|
|||||||
(client) => client.clientId
|
(client) => client.clientId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const isLabelFeatureEnabled = await isLicensedOrSubscribed(
|
||||||
|
orgId,
|
||||||
|
tierMatrix.labels
|
||||||
|
);
|
||||||
|
|
||||||
// Get client count with filter
|
// Get client count with filter
|
||||||
const conditions = [
|
const conditions = [
|
||||||
and(
|
and(
|
||||||
@@ -288,18 +299,29 @@ export async function listClients(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (query) {
|
if (query) {
|
||||||
conditions.push(
|
const q = "%" + query.toLowerCase() + "%";
|
||||||
or(
|
const queryList = [
|
||||||
like(
|
like(sql`LOWER(${clients.name})`, q),
|
||||||
sql`LOWER(${clients.name})`,
|
like(sql`LOWER(${clients.niceId})`, q)
|
||||||
"%" + query.toLowerCase() + "%"
|
];
|
||||||
),
|
|
||||||
like(
|
if (isLabelFeatureEnabled) {
|
||||||
sql`LOWER(${clients.niceId})`,
|
queryList.push(
|
||||||
"%" + query.toLowerCase() + "%"
|
inArray(
|
||||||
|
clients.clientId,
|
||||||
|
db
|
||||||
|
.select({ id: clientLabels.clientId })
|
||||||
|
.from(clientLabels)
|
||||||
|
.innerJoin(
|
||||||
|
labels,
|
||||||
|
eq(labels.labelId, clientLabels.labelId)
|
||||||
|
)
|
||||||
|
.where(like(sql`LOWER(${labels.name})`, q))
|
||||||
)
|
)
|
||||||
)
|
);
|
||||||
);
|
}
|
||||||
|
|
||||||
|
conditions.push(or(...queryList));
|
||||||
}
|
}
|
||||||
|
|
||||||
const baseQuery = queryClientsBase().where(and(...conditions));
|
const baseQuery = queryClientsBase().where(and(...conditions));
|
||||||
@@ -326,6 +348,30 @@ export async function listClients(
|
|||||||
const clientIds = clientsList.map((client) => client.clientId);
|
const clientIds = clientsList.map((client) => client.clientId);
|
||||||
const siteAssociations = await getSiteAssociations(clientIds);
|
const siteAssociations = await getSiteAssociations(clientIds);
|
||||||
|
|
||||||
|
let labelsForClients: Array<{
|
||||||
|
labelId: number;
|
||||||
|
name: string;
|
||||||
|
color: string;
|
||||||
|
clientId: number;
|
||||||
|
}> = [];
|
||||||
|
|
||||||
|
if (isLabelFeatureEnabled && clientIds.length > 0) {
|
||||||
|
labelsForClients = await db
|
||||||
|
.select({
|
||||||
|
labelId: labels.labelId,
|
||||||
|
name: labels.name,
|
||||||
|
color: labels.color,
|
||||||
|
clientId: clientLabels.clientId
|
||||||
|
})
|
||||||
|
.from(labels)
|
||||||
|
.innerJoin(
|
||||||
|
clientLabels,
|
||||||
|
eq(clientLabels.labelId, labels.labelId)
|
||||||
|
)
|
||||||
|
.where(inArray(clientLabels.clientId, clientIds))
|
||||||
|
.orderBy(asc(clientLabels.clientLabelId));
|
||||||
|
}
|
||||||
|
|
||||||
// Group site associations by client ID
|
// Group site associations by client ID
|
||||||
const sitesByClient = siteAssociations.reduce(
|
const sitesByClient = siteAssociations.reduce(
|
||||||
(acc, association) => {
|
(acc, association) => {
|
||||||
@@ -353,7 +399,10 @@ export async function listClients(
|
|||||||
const clientsWithSites = clientsList.map((client) => {
|
const clientsWithSites = clientsList.map((client) => {
|
||||||
return {
|
return {
|
||||||
...client,
|
...client,
|
||||||
sites: sitesByClient[client.clientId] || []
|
sites: sitesByClient[client.clientId] || [],
|
||||||
|
labels: labelsForClients.filter(
|
||||||
|
(l) => l.clientId === client.clientId
|
||||||
|
)
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
10
server/routers/labels/types.ts
Normal file
10
server/routers/labels/types.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import type { Label } from "@server/db";
|
||||||
|
import type { PaginatedResponse } from "@server/types/Pagination";
|
||||||
|
|
||||||
|
export type ListOrgLabelsResponse = PaginatedResponse<{
|
||||||
|
labels: Omit<Label, "orgId">[];
|
||||||
|
}>;
|
||||||
|
|
||||||
|
export type CreateOrEditLabelResponse = {
|
||||||
|
label: Label;
|
||||||
|
};
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
db,
|
db,
|
||||||
|
labels,
|
||||||
resourceHeaderAuth,
|
resourceHeaderAuth,
|
||||||
resourceHeaderAuthExtendedCompatibility,
|
resourceHeaderAuthExtendedCompatibility,
|
||||||
|
resourceLabels,
|
||||||
resourcePassword,
|
resourcePassword,
|
||||||
resourcePincode,
|
resourcePincode,
|
||||||
resources,
|
resources,
|
||||||
@@ -9,8 +11,11 @@ import {
|
|||||||
sites,
|
sites,
|
||||||
targetHealthCheck,
|
targetHealthCheck,
|
||||||
targets,
|
targets,
|
||||||
userResources
|
userResources,
|
||||||
|
type Label
|
||||||
} from "@server/db";
|
} from "@server/db";
|
||||||
|
import { isLicensedOrSubscribed } from "#dynamic/lib/isLicencedOrSubscribed";
|
||||||
|
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
||||||
import response from "@server/lib/response";
|
import response from "@server/lib/response";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { OpenAPITags, registry } from "@server/openApi";
|
import { OpenAPITags, registry } from "@server/openApi";
|
||||||
@@ -154,6 +159,7 @@ export type ResourceWithTargets = {
|
|||||||
siteNiceId: string;
|
siteNiceId: string;
|
||||||
online?: boolean; // undefined for local sites
|
online?: boolean; // undefined for local sites
|
||||||
}>;
|
}>;
|
||||||
|
labels?: Array<Pick<Label, "color" | "labelId" | "name">>;
|
||||||
};
|
};
|
||||||
|
|
||||||
function queryResourcesBase() {
|
function queryResourcesBase() {
|
||||||
@@ -288,6 +294,11 @@ export async function listResources(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isLabelFeatureEnabled = await isLicensedOrSubscribed(
|
||||||
|
orgId,
|
||||||
|
tierMatrix.labels
|
||||||
|
);
|
||||||
|
|
||||||
let accessibleResources: Array<{ resourceId: number }>;
|
let accessibleResources: Array<{ resourceId: number }>;
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
accessibleResources = await db
|
accessibleResources = await db
|
||||||
@@ -325,24 +336,6 @@ export async function listResources(
|
|||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
|
||||||
if (query) {
|
|
||||||
conditions.push(
|
|
||||||
or(
|
|
||||||
like(
|
|
||||||
sql`LOWER(${resources.name})`,
|
|
||||||
"%" + query.toLowerCase() + "%"
|
|
||||||
),
|
|
||||||
like(
|
|
||||||
sql`LOWER(${resources.niceId})`,
|
|
||||||
"%" + query.toLowerCase() + "%"
|
|
||||||
),
|
|
||||||
like(
|
|
||||||
sql`LOWER(${resources.fullDomain})`,
|
|
||||||
"%" + query.toLowerCase() + "%"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (typeof enabled !== "undefined") {
|
if (typeof enabled !== "undefined") {
|
||||||
conditions.push(eq(resources.enabled, enabled));
|
conditions.push(eq(resources.enabled, enabled));
|
||||||
}
|
}
|
||||||
@@ -386,6 +379,32 @@ export async function listResources(
|
|||||||
.where(and(eq(sites.orgId, orgId), eq(sites.siteId, siteId)));
|
.where(and(eq(sites.orgId, orgId), eq(sites.siteId, siteId)));
|
||||||
conditions.push(inArray(resources.resourceId, resourcesWithSite));
|
conditions.push(inArray(resources.resourceId, resourcesWithSite));
|
||||||
}
|
}
|
||||||
|
if (query) {
|
||||||
|
const q = "%" + query.toLowerCase() + "%";
|
||||||
|
const queryList = [
|
||||||
|
like(sql`LOWER(${resources.name})`, q),
|
||||||
|
like(sql`LOWER(${resources.niceId})`, q),
|
||||||
|
like(sql`LOWER(${resources.fullDomain})`, q)
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isLabelFeatureEnabled) {
|
||||||
|
queryList.push(
|
||||||
|
inArray(
|
||||||
|
resources.resourceId,
|
||||||
|
db
|
||||||
|
.select({ id: resourceLabels.resourceId })
|
||||||
|
.from(resourceLabels)
|
||||||
|
.innerJoin(
|
||||||
|
labels,
|
||||||
|
eq(labels.labelId, resourceLabels.labelId)
|
||||||
|
)
|
||||||
|
.where(like(sql`LOWER(${labels.name})`, q))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
conditions.push(or(...queryList));
|
||||||
|
}
|
||||||
|
|
||||||
const baseQuery = queryResourcesBase().where(and(...conditions));
|
const baseQuery = queryResourcesBase().where(and(...conditions));
|
||||||
|
|
||||||
@@ -407,6 +426,36 @@ export async function listResources(
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
const resourceIdList = rows.map((row) => row.resourceId);
|
const resourceIdList = rows.map((row) => row.resourceId);
|
||||||
|
|
||||||
|
let labelsForResources: Array<{
|
||||||
|
labelId: number;
|
||||||
|
name: string;
|
||||||
|
color: string;
|
||||||
|
resourceId: number;
|
||||||
|
}> = [];
|
||||||
|
|
||||||
|
if (isLabelFeatureEnabled) {
|
||||||
|
labelsForResources =
|
||||||
|
resourceIdList.length === 0
|
||||||
|
? []
|
||||||
|
: await db
|
||||||
|
.select({
|
||||||
|
labelId: labels.labelId,
|
||||||
|
name: labels.name,
|
||||||
|
color: labels.color,
|
||||||
|
resourceId: resourceLabels.resourceId
|
||||||
|
})
|
||||||
|
.from(labels)
|
||||||
|
.innerJoin(
|
||||||
|
resourceLabels,
|
||||||
|
eq(resourceLabels.labelId, labels.labelId)
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
inArray(resourceLabels.resourceId, resourceIdList)
|
||||||
|
)
|
||||||
|
.orderBy(asc(resourceLabels.resourceLabelId));
|
||||||
|
}
|
||||||
|
|
||||||
const allResourceTargets =
|
const allResourceTargets =
|
||||||
resourceIdList.length === 0
|
resourceIdList.length === 0
|
||||||
? []
|
? []
|
||||||
@@ -458,7 +507,10 @@ export async function listResources(
|
|||||||
headerAuthId: row.headerAuthId,
|
headerAuthId: row.headerAuthId,
|
||||||
health: row.health ?? null,
|
health: row.health ?? null,
|
||||||
targets: [],
|
targets: [],
|
||||||
sites: []
|
sites: [],
|
||||||
|
labels: labelsForResources.filter(
|
||||||
|
(l) => l.resourceId === row.resourceId
|
||||||
|
)
|
||||||
};
|
};
|
||||||
map.set(row.resourceId, entry);
|
map.set(row.resourceId, entry);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ import {
|
|||||||
siteResources,
|
siteResources,
|
||||||
targets,
|
targets,
|
||||||
sites,
|
sites,
|
||||||
userSites
|
userSites,
|
||||||
|
labels,
|
||||||
|
siteLabels,
|
||||||
|
type Label
|
||||||
} from "@server/db";
|
} from "@server/db";
|
||||||
import cache from "#dynamic/lib/cache";
|
import cache from "#dynamic/lib/cache";
|
||||||
import response from "@server/lib/response";
|
import response from "@server/lib/response";
|
||||||
@@ -23,6 +26,8 @@ import createHttpError from "http-errors";
|
|||||||
import semver from "semver";
|
import semver from "semver";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { fromError } from "zod-validation-error";
|
import { fromError } from "zod-validation-error";
|
||||||
|
import { isLicensedOrSubscribed } from "#dynamic/lib/isLicencedOrSubscribed";
|
||||||
|
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
||||||
|
|
||||||
// Stale-while-revalidate: keeps the last successfully fetched version so that
|
// Stale-while-revalidate: keeps the last successfully fetched version so that
|
||||||
// a transient network failure / timeout does not flip every site back to
|
// a transient network failure / timeout does not flip every site back to
|
||||||
@@ -187,7 +192,7 @@ const listSitesSchema = z.object({
|
|||||||
|
|
||||||
function querySitesBase() {
|
function querySitesBase() {
|
||||||
return db
|
return db
|
||||||
.select({
|
.selectDistinct({
|
||||||
siteId: sites.siteId,
|
siteId: sites.siteId,
|
||||||
niceId: sites.niceId,
|
niceId: sites.niceId,
|
||||||
name: sites.name,
|
name: sites.name,
|
||||||
@@ -233,6 +238,7 @@ type SiteRowBase = Awaited<ReturnType<typeof querySitesBase>>[0];
|
|||||||
type SiteWithUpdateAvailable = Omit<SiteRowBase, "online"> & {
|
type SiteWithUpdateAvailable = Omit<SiteRowBase, "online"> & {
|
||||||
online?: SiteRowBase["online"]; // undefined for local sites
|
online?: SiteRowBase["online"]; // undefined for local sites
|
||||||
newtUpdateAvailable?: boolean;
|
newtUpdateAvailable?: boolean;
|
||||||
|
labels?: Array<Pick<Label, "color" | "labelId" | "name">>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ListSitesResponse = PaginatedResponse<{
|
export type ListSitesResponse = PaginatedResponse<{
|
||||||
@@ -308,6 +314,11 @@ export async function listSites(
|
|||||||
.where(eq(sites.orgId, orgId));
|
.where(eq(sites.orgId, orgId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isLabelFeatureEnabled = await isLicensedOrSubscribed(
|
||||||
|
orgId,
|
||||||
|
tierMatrix.labels
|
||||||
|
);
|
||||||
|
|
||||||
const { pageSize, page, query, sort_by, order, online, status } =
|
const { pageSize, page, query, sort_by, order, online, status } =
|
||||||
parsedQuery.data;
|
parsedQuery.data;
|
||||||
|
|
||||||
@@ -319,33 +330,43 @@ export async function listSites(
|
|||||||
eq(sites.orgId, orgId)
|
eq(sites.orgId, orgId)
|
||||||
)
|
)
|
||||||
];
|
];
|
||||||
if (query) {
|
|
||||||
conditions.push(
|
|
||||||
or(
|
|
||||||
like(
|
|
||||||
sql`LOWER(${sites.name})`,
|
|
||||||
"%" + query.toLowerCase() + "%"
|
|
||||||
),
|
|
||||||
like(
|
|
||||||
sql`LOWER(${sites.niceId})`,
|
|
||||||
"%" + query.toLowerCase() + "%"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (typeof online !== "undefined") {
|
if (typeof online !== "undefined") {
|
||||||
conditions.push(eq(sites.online, online));
|
conditions.push(eq(sites.online, online));
|
||||||
}
|
}
|
||||||
if (typeof status !== "undefined") {
|
if (typeof status !== "undefined") {
|
||||||
conditions.push(eq(sites.status, status));
|
conditions.push(eq(sites.status, status));
|
||||||
}
|
}
|
||||||
|
if (query) {
|
||||||
|
const q = "%" + query.toLowerCase() + "%";
|
||||||
|
const queryList = [
|
||||||
|
like(sql`LOWER(${sites.name})`, q),
|
||||||
|
like(sql`LOWER(${sites.niceId})`, q)
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isLabelFeatureEnabled) {
|
||||||
|
queryList.push(
|
||||||
|
inArray(
|
||||||
|
sites.siteId,
|
||||||
|
db
|
||||||
|
.select({ id: siteLabels.siteId })
|
||||||
|
.from(siteLabels)
|
||||||
|
.innerJoin(
|
||||||
|
labels,
|
||||||
|
eq(labels.labelId, siteLabels.labelId)
|
||||||
|
)
|
||||||
|
.where(like(sql`LOWER(${labels.name})`, q))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
conditions.push(or(...queryList));
|
||||||
|
}
|
||||||
|
|
||||||
const baseQuery = querySitesBase().where(and(...conditions));
|
const baseQuery = querySitesBase().where(and(...conditions));
|
||||||
|
|
||||||
// we need to add `as` so that drizzle filters the result as a subquery
|
// we need to add `as` so that drizzle filters the result as a subquery
|
||||||
const countQuery = db.$count(
|
const countQuery = db.$count(
|
||||||
querySitesBase()
|
querySitesBase().where(and(...conditions)).as("filtered_sites")
|
||||||
.where(and(...conditions))
|
|
||||||
.as("filtered_sites")
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const siteListQuery = baseQuery
|
const siteListQuery = baseQuery
|
||||||
@@ -367,11 +388,46 @@ export async function listSites(
|
|||||||
// Get latest version asynchronously without blocking the response
|
// Get latest version asynchronously without blocking the response
|
||||||
const latestNewtVersionPromise = getLatestNewtVersion();
|
const latestNewtVersionPromise = getLatestNewtVersion();
|
||||||
|
|
||||||
|
const siteIds = rows.map((site) => site.siteId);
|
||||||
|
|
||||||
|
let labelsForSites: Array<{
|
||||||
|
labelId: number;
|
||||||
|
name: string;
|
||||||
|
color: string;
|
||||||
|
siteId: number;
|
||||||
|
}> = [];
|
||||||
|
|
||||||
|
if (isLabelFeatureEnabled) {
|
||||||
|
labelsForSites =
|
||||||
|
siteIds.length === 0
|
||||||
|
? []
|
||||||
|
: await db
|
||||||
|
.select({
|
||||||
|
labelId: labels.labelId,
|
||||||
|
name: labels.name,
|
||||||
|
color: labels.color,
|
||||||
|
siteId: siteLabels.siteId
|
||||||
|
})
|
||||||
|
.from(labels)
|
||||||
|
.innerJoin(
|
||||||
|
siteLabels,
|
||||||
|
eq(siteLabels.labelId, labels.labelId)
|
||||||
|
)
|
||||||
|
.where(inArray(siteLabels.siteId, siteIds))
|
||||||
|
.orderBy(asc(siteLabels.siteLabelId));
|
||||||
|
}
|
||||||
|
|
||||||
const sitesWithUpdates: SiteWithUpdateAvailable[] = rows.map((site) => {
|
const sitesWithUpdates: SiteWithUpdateAvailable[] = rows.map((site) => {
|
||||||
const siteWithUpdate: SiteWithUpdateAvailable = { ...site };
|
const siteWithUpdate: SiteWithUpdateAvailable = { ...site };
|
||||||
// Initially set to false, will be updated if version check succeeds
|
// Initially set to false, will be updated if version check succeeds
|
||||||
siteWithUpdate.newtUpdateAvailable = false;
|
siteWithUpdate.newtUpdateAvailable = false;
|
||||||
return siteWithUpdate;
|
|
||||||
|
// associate labels
|
||||||
|
const labelsForSite = labelsForSites.filter(
|
||||||
|
(label) => label.siteId === site.siteId
|
||||||
|
);
|
||||||
|
|
||||||
|
return { ...siteWithUpdate, labels: labelsForSite };
|
||||||
});
|
});
|
||||||
|
|
||||||
// Try to get the latest version, but don't block if it fails
|
// Try to get the latest version, but don't block if it fails
|
||||||
|
|||||||
@@ -1,4 +1,14 @@
|
|||||||
import { db, DB_TYPE, SiteResource, siteNetworks, siteResources, sites } from "@server/db";
|
import {
|
||||||
|
db,
|
||||||
|
DB_TYPE,
|
||||||
|
Label,
|
||||||
|
SiteResource,
|
||||||
|
siteNetworks,
|
||||||
|
siteResourceLabels,
|
||||||
|
siteResources,
|
||||||
|
sites,
|
||||||
|
labels
|
||||||
|
} from "@server/db";
|
||||||
import response from "@server/lib/response";
|
import response from "@server/lib/response";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { OpenAPITags, registry } from "@server/openApi";
|
import { OpenAPITags, registry } from "@server/openApi";
|
||||||
@@ -9,6 +19,8 @@ import { NextFunction, Request, Response } from "express";
|
|||||||
import createHttpError from "http-errors";
|
import createHttpError from "http-errors";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { fromError } from "zod-validation-error";
|
import { fromError } from "zod-validation-error";
|
||||||
|
import { isLicensedOrSubscribed } from "#dynamic/lib/isLicencedOrSubscribed";
|
||||||
|
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
||||||
|
|
||||||
const listAllSiteResourcesByOrgParamsSchema = z.strictObject({
|
const listAllSiteResourcesByOrgParamsSchema = z.strictObject({
|
||||||
orgId: z.string()
|
orgId: z.string()
|
||||||
@@ -69,16 +81,11 @@ const listAllSiteResourcesByOrgQuerySchema = z.object({
|
|||||||
default: "asc",
|
default: "asc",
|
||||||
description: "Sort order"
|
description: "Sort order"
|
||||||
}),
|
}),
|
||||||
siteId: z.coerce
|
siteId: z.coerce.number<string>().int().positive().optional().openapi({
|
||||||
.number<string>()
|
type: "integer",
|
||||||
.int()
|
description:
|
||||||
.positive()
|
"When set, only site resources associated with this site (via network) are returned"
|
||||||
.optional()
|
})
|
||||||
.openapi({
|
|
||||||
type: "integer",
|
|
||||||
description:
|
|
||||||
"When set, only site resources associated with this site (via network) are returned"
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export type ListAllSiteResourcesByOrgResponse = PaginatedResponse<{
|
export type ListAllSiteResourcesByOrgResponse = PaginatedResponse<{
|
||||||
@@ -88,6 +95,7 @@ export type ListAllSiteResourcesByOrgResponse = PaginatedResponse<{
|
|||||||
siteNames: string[];
|
siteNames: string[];
|
||||||
siteNiceIds: string[];
|
siteNiceIds: string[];
|
||||||
siteAddresses: (string | null)[];
|
siteAddresses: (string | null)[];
|
||||||
|
labels?: Array<Pick<Label, "labelId" | "name" | "color">>;
|
||||||
})[];
|
})[];
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
@@ -234,6 +242,11 @@ export async function listAllSiteResourcesByOrg(
|
|||||||
const { page, pageSize, query, mode, sort_by, order, siteId } =
|
const { page, pageSize, query, mode, sort_by, order, siteId } =
|
||||||
parsedQuery.data;
|
parsedQuery.data;
|
||||||
|
|
||||||
|
const isLabelFeatureEnabled = await isLicensedOrSubscribed(
|
||||||
|
orgId,
|
||||||
|
tierMatrix.labels
|
||||||
|
);
|
||||||
|
|
||||||
const conditions = [and(eq(siteResources.orgId, orgId))];
|
const conditions = [and(eq(siteResources.orgId, orgId))];
|
||||||
|
|
||||||
if (siteId != null) {
|
if (siteId != null) {
|
||||||
@@ -258,41 +271,41 @@ export async function listAllSiteResourcesByOrg(
|
|||||||
inArray(siteResources.siteResourceId, resourcesForSite)
|
inArray(siteResources.siteResourceId, resourcesForSite)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (query) {
|
|
||||||
conditions.push(
|
|
||||||
or(
|
|
||||||
like(
|
|
||||||
sql`LOWER(${siteResources.name})`,
|
|
||||||
"%" + query.toLowerCase() + "%"
|
|
||||||
),
|
|
||||||
like(
|
|
||||||
sql`LOWER(${siteResources.niceId})`,
|
|
||||||
"%" + query.toLowerCase() + "%"
|
|
||||||
),
|
|
||||||
like(
|
|
||||||
sql`LOWER(${siteResources.destination})`,
|
|
||||||
"%" + query.toLowerCase() + "%"
|
|
||||||
),
|
|
||||||
like(
|
|
||||||
sql`LOWER(${siteResources.alias})`,
|
|
||||||
"%" + query.toLowerCase() + "%"
|
|
||||||
),
|
|
||||||
like(
|
|
||||||
sql`LOWER(${siteResources.aliasAddress})`,
|
|
||||||
"%" + query.toLowerCase() + "%"
|
|
||||||
),
|
|
||||||
like(
|
|
||||||
sql`LOWER(${sites.name})`,
|
|
||||||
"%" + query.toLowerCase() + "%"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mode) {
|
if (mode) {
|
||||||
conditions.push(eq(siteResources.mode, mode));
|
conditions.push(eq(siteResources.mode, mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (query) {
|
||||||
|
const q = "%" + query.toLowerCase() + "%";
|
||||||
|
const queryList = [
|
||||||
|
like(sql`LOWER(${siteResources.name})`, q),
|
||||||
|
like(sql`LOWER(${siteResources.niceId})`, q),
|
||||||
|
like(sql`LOWER(${siteResources.destination})`, q),
|
||||||
|
like(sql`LOWER(${siteResources.alias})`, q),
|
||||||
|
like(sql`LOWER(${siteResources.aliasAddress})`, q),
|
||||||
|
like(sql`LOWER(${sites.name})`, q)
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isLabelFeatureEnabled) {
|
||||||
|
queryList.push(
|
||||||
|
inArray(
|
||||||
|
siteResources.siteResourceId,
|
||||||
|
db
|
||||||
|
.select({ id: siteResourceLabels.siteResourceId })
|
||||||
|
.from(siteResourceLabels)
|
||||||
|
.innerJoin(
|
||||||
|
labels,
|
||||||
|
eq(labels.labelId, siteResourceLabels.labelId)
|
||||||
|
)
|
||||||
|
.where(like(sql`LOWER(${labels.name})`, q))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
conditions.push(or(...queryList));
|
||||||
|
}
|
||||||
|
|
||||||
const baseQuery = querySiteResourcesBase().where(and(...conditions));
|
const baseQuery = querySiteResourcesBase().where(and(...conditions));
|
||||||
|
|
||||||
const countQuery = db.$count(
|
const countQuery = db.$count(
|
||||||
@@ -315,11 +328,51 @@ export async function listAllSiteResourcesByOrg(
|
|||||||
countQuery
|
countQuery
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const siteResourcesList = siteResourcesRaw.map(transformSiteResourceRow);
|
const siteResourcesList = siteResourcesRaw.map(
|
||||||
|
transformSiteResourceRow
|
||||||
|
);
|
||||||
|
|
||||||
|
const siteResourceIdList = siteResourcesList.map(
|
||||||
|
(r) => r.siteResourceId
|
||||||
|
);
|
||||||
|
|
||||||
|
let labelsForSiteResources: Array<{
|
||||||
|
labelId: number;
|
||||||
|
name: string;
|
||||||
|
color: string;
|
||||||
|
siteResourceId: number;
|
||||||
|
}> = [];
|
||||||
|
|
||||||
|
if (isLabelFeatureEnabled && siteResourceIdList.length > 0) {
|
||||||
|
labelsForSiteResources = await db
|
||||||
|
.select({
|
||||||
|
labelId: labels.labelId,
|
||||||
|
name: labels.name,
|
||||||
|
color: labels.color,
|
||||||
|
siteResourceId: siteResourceLabels.siteResourceId
|
||||||
|
})
|
||||||
|
.from(labels)
|
||||||
|
.innerJoin(
|
||||||
|
siteResourceLabels,
|
||||||
|
eq(siteResourceLabels.labelId, labels.labelId)
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
inArray(
|
||||||
|
siteResourceLabels.siteResourceId,
|
||||||
|
siteResourceIdList
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.orderBy(asc(siteResourceLabels.siteResourceLabelId));
|
||||||
|
}
|
||||||
|
|
||||||
return response<ListAllSiteResourcesByOrgResponse>(res, {
|
return response<ListAllSiteResourcesByOrgResponse>(res, {
|
||||||
data: {
|
data: {
|
||||||
siteResources: siteResourcesList,
|
siteResources: siteResourcesList.map((r) => ({
|
||||||
|
...r,
|
||||||
|
labels: labelsForSiteResources.filter(
|
||||||
|
(l) => l.siteResourceId === r.siteResourceId
|
||||||
|
)
|
||||||
|
})),
|
||||||
pagination: {
|
pagination: {
|
||||||
total: totalCount,
|
total: totalCount,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -340,4 +393,4 @@ export async function listAllSiteResourcesByOrg(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
63
src/app/[orgId]/settings/(private)/labels/page.tsx
Normal file
63
src/app/[orgId]/settings/(private)/labels/page.tsx
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import { internal } from "@app/lib/api";
|
||||||
|
import { authCookieHeader } from "@app/lib/api/cookies";
|
||||||
|
import { ListOrgLabelsResponse } from "@server/routers/labels/types";
|
||||||
|
import { AxiosResponse } from "axios";
|
||||||
|
import OrgLabelsTable from "@app/components/OrgLabelsTable";
|
||||||
|
import SettingsSectionTitle from "@app/components/SettingsSectionTitle";
|
||||||
|
import type { Metadata } from "next";
|
||||||
|
import { getTranslations } from "next-intl/server";
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "Labels"
|
||||||
|
};
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
params: Promise<{ orgId: string }>;
|
||||||
|
searchParams: Promise<Record<string, string>>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
export default async function LabelsPage({ params, searchParams }: Props) {
|
||||||
|
const { orgId } = await params;
|
||||||
|
|
||||||
|
const searchParamsObj = new URLSearchParams(await searchParams);
|
||||||
|
|
||||||
|
let labels: ListOrgLabelsResponse["labels"] = [];
|
||||||
|
let pagination: ListOrgLabelsResponse["pagination"] = {
|
||||||
|
total: 0,
|
||||||
|
page: 1,
|
||||||
|
pageSize: 20
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await internal.get<AxiosResponse<ListOrgLabelsResponse>>(
|
||||||
|
`/org/${orgId}/labels?${searchParamsObj.toString()}`,
|
||||||
|
await authCookieHeader()
|
||||||
|
);
|
||||||
|
const responseData = res.data.data;
|
||||||
|
labels = responseData.labels;
|
||||||
|
pagination = responseData.pagination;
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
const t = await getTranslations();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<SettingsSectionTitle
|
||||||
|
title={t("labels")}
|
||||||
|
description={t("orgLabelsDescription")}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<OrgLabelsTable
|
||||||
|
labels={labels}
|
||||||
|
orgId={orgId}
|
||||||
|
rowCount={pagination.total}
|
||||||
|
pagination={{
|
||||||
|
pageIndex: pagination.page - 1,
|
||||||
|
pageSize: pagination.pageSize
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -76,7 +76,8 @@ export default async function ClientsPage(props: ClientsPageProps) {
|
|||||||
agent: client.agent,
|
agent: client.agent,
|
||||||
archived: client.archived || false,
|
archived: client.archived || false,
|
||||||
blocked: client.blocked || false,
|
blocked: client.blocked || false,
|
||||||
approvalState: client.approvalState ?? "approved"
|
approvalState: client.approvalState ?? "approved",
|
||||||
|
labels: client.labels ?? []
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { useEnvContext } from "@app/hooks/useEnvContext";
|
|||||||
import { usePaidStatus } from "@app/hooks/usePaidStatus";
|
import { usePaidStatus } from "@app/hooks/usePaidStatus";
|
||||||
import { useStoredPageSize } from "@app/hooks/useStoredPageSize";
|
import { useStoredPageSize } from "@app/hooks/useStoredPageSize";
|
||||||
import { toast } from "@app/hooks/useToast";
|
import { toast } from "@app/hooks/useToast";
|
||||||
import { createApiClient } from "@app/lib/api";
|
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
||||||
import { getSevenDaysAgo } from "@app/lib/getSevenDaysAgo";
|
import { getSevenDaysAgo } from "@app/lib/getSevenDaysAgo";
|
||||||
import { build } from "@server/build";
|
import { build } from "@server/build";
|
||||||
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
||||||
@@ -294,7 +294,7 @@ export default function ConnectionLogsPage() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast({
|
toast({
|
||||||
title: t("error"),
|
title: t("error"),
|
||||||
description: t("Failed to filter logs"),
|
description: formatAxiosError(error),
|
||||||
variant: "destructive"
|
variant: "destructive"
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -127,7 +127,8 @@ export default async function ClientResourcesPage(
|
|||||||
authDaemonPort: siteResource.authDaemonPort ?? null,
|
authDaemonPort: siteResource.authDaemonPort ?? null,
|
||||||
subdomain: siteResource.subdomain ?? null,
|
subdomain: siteResource.subdomain ?? null,
|
||||||
domainId: siteResource.domainId ?? null,
|
domainId: siteResource.domainId ?? null,
|
||||||
fullDomain: siteResource.fullDomain ?? null
|
fullDomain: siteResource.fullDomain ?? null,
|
||||||
|
labels: siteResource.labels ?? []
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ export default async function ProxyResourcesPage(
|
|||||||
protocol: resource.protocol,
|
protocol: resource.protocol,
|
||||||
proxyPort: resource.proxyPort,
|
proxyPort: resource.proxyPort,
|
||||||
http: resource.http,
|
http: resource.http,
|
||||||
|
labels: resource.labels,
|
||||||
authState: !resource.http
|
authState: !resource.http
|
||||||
? "none"
|
? "none"
|
||||||
: resource.sso ||
|
: resource.sso ||
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ export default async function SitesPage(props: SitesPageProps) {
|
|||||||
return {
|
return {
|
||||||
name: site.name,
|
name: site.name,
|
||||||
id: site.siteId,
|
id: site.siteId,
|
||||||
|
labels: site.labels,
|
||||||
nice: site.niceId.toString(),
|
nice: site.niceId.toString(),
|
||||||
address: site.address?.split("/")[0],
|
address: site.address?.split("/")[0],
|
||||||
mbIn: formatSize(site.megabytesIn || 0, site.type),
|
mbIn: formatSize(site.megabytesIn || 0, site.type),
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
Server,
|
Server,
|
||||||
Settings,
|
Settings,
|
||||||
SquareMousePointer,
|
SquareMousePointer,
|
||||||
|
TagIcon,
|
||||||
TicketCheck,
|
TicketCheck,
|
||||||
Unplug,
|
Unplug,
|
||||||
User,
|
User,
|
||||||
@@ -99,7 +100,7 @@ export const orgNavSections = (
|
|||||||
href: "/{orgId}/settings/domains",
|
href: "/{orgId}/settings/domains",
|
||||||
icon: <Globe className="size-4 flex-none" />
|
icon: <Globe className="size-4 flex-none" />
|
||||||
},
|
},
|
||||||
...(build == "saas"
|
...(build === "saas"
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
title: "sidebarRemoteExitNodes",
|
title: "sidebarRemoteExitNodes",
|
||||||
@@ -237,10 +238,19 @@ export const orgNavSections = (
|
|||||||
title: "sidebarApiKeys",
|
title: "sidebarApiKeys",
|
||||||
href: "/{orgId}/settings/api-keys",
|
href: "/{orgId}/settings/api-keys",
|
||||||
icon: <KeyRound className="size-4 flex-none" />
|
icon: <KeyRound className="size-4 flex-none" />
|
||||||
}
|
},
|
||||||
|
...(build !== "oss"
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
title: "labels",
|
||||||
|
href: "/{orgId}/settings/labels",
|
||||||
|
icon: <TagIcon className="size-4 flex-none" />
|
||||||
|
}
|
||||||
|
]
|
||||||
|
: [])
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
...(build == "saas" && options?.isPrimaryOrg
|
...(build === "saas" && options?.isPrimaryOrg
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
title: "sidebarBillingAndLicenses",
|
title: "sidebarBillingAndLicenses",
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import ConfirmDeleteDialog from "@app/components/ConfirmDeleteDialog";
|
import ConfirmDeleteDialog from "@app/components/ConfirmDeleteDialog";
|
||||||
import CopyToClipboard from "@app/components/CopyToClipboard";
|
import CopyToClipboard from "@app/components/CopyToClipboard";
|
||||||
import { DataTable } from "@app/components/ui/data-table";
|
|
||||||
import { ExtendedColumnDef } from "@app/components/ui/data-table";
|
import { ExtendedColumnDef } from "@app/components/ui/data-table";
|
||||||
import { Badge } from "@app/components/ui/badge";
|
import { Badge } from "@app/components/ui/badge";
|
||||||
import { Button } from "@app/components/ui/button";
|
import { Button } from "@app/components/ui/button";
|
||||||
@@ -30,13 +29,21 @@ import {
|
|||||||
ChevronDown,
|
ChevronDown,
|
||||||
ChevronsUpDownIcon,
|
ChevronsUpDownIcon,
|
||||||
Funnel,
|
Funnel,
|
||||||
MoreHorizontal
|
MoreHorizontal,
|
||||||
|
PlusIcon
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { Selectedsite, SitesSelector } from "@app/components/site-selector";
|
import { Selectedsite, SitesSelector } from "@app/components/site-selector";
|
||||||
import { useEffect, useMemo, useState, useTransition } from "react";
|
import {
|
||||||
|
startTransition,
|
||||||
|
useEffect,
|
||||||
|
useMemo,
|
||||||
|
useOptimistic,
|
||||||
|
useState,
|
||||||
|
useTransition
|
||||||
|
} from "react";
|
||||||
import CreateInternalResourceDialog from "@app/components/CreateInternalResourceDialog";
|
import CreateInternalResourceDialog from "@app/components/CreateInternalResourceDialog";
|
||||||
import EditInternalResourceDialog from "@app/components/EditInternalResourceDialog";
|
import EditInternalResourceDialog from "@app/components/EditInternalResourceDialog";
|
||||||
import type { PaginationState } from "@tanstack/react-table";
|
import type { PaginationState } from "@tanstack/react-table";
|
||||||
@@ -53,6 +60,10 @@ import {
|
|||||||
} from "@app/components/ResourceSitesStatusCell";
|
} from "@app/components/ResourceSitesStatusCell";
|
||||||
import { ResourceAccessCertIndicator } from "@app/components/ResourceAccessCertIndicator";
|
import { ResourceAccessCertIndicator } from "@app/components/ResourceAccessCertIndicator";
|
||||||
import { build } from "@server/build";
|
import { build } from "@server/build";
|
||||||
|
import { usePaidStatus } from "@app/hooks/usePaidStatus";
|
||||||
|
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
||||||
|
import { LabelBadge } from "./label-badge";
|
||||||
|
import { LabelsSelector, type SelectedLabel } from "./labels-selector";
|
||||||
|
|
||||||
export type InternalResourceSiteRow = ResourceSiteRow;
|
export type InternalResourceSiteRow = ResourceSiteRow;
|
||||||
|
|
||||||
@@ -84,6 +95,11 @@ export type InternalResourceRow = {
|
|||||||
subdomain?: string | null;
|
subdomain?: string | null;
|
||||||
domainId?: string | null;
|
domainId?: string | null;
|
||||||
fullDomain?: string | null;
|
fullDomain?: string | null;
|
||||||
|
labels?: Array<{
|
||||||
|
labelId: number;
|
||||||
|
name: string;
|
||||||
|
color: string;
|
||||||
|
}>;
|
||||||
};
|
};
|
||||||
|
|
||||||
function formatDestinationDisplay(row: InternalResourceRow): string {
|
function formatDestinationDisplay(row: InternalResourceRow): string {
|
||||||
@@ -141,7 +157,10 @@ export default function ClientResourcesTable({
|
|||||||
const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false);
|
const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false);
|
||||||
const [siteFilterOpen, setSiteFilterOpen] = useState(false);
|
const [siteFilterOpen, setSiteFilterOpen] = useState(false);
|
||||||
|
|
||||||
const [isRefreshing, startTransition] = useTransition();
|
const [isRefreshing, startRefreshTransition] = useTransition();
|
||||||
|
|
||||||
|
const { isPaidUser } = usePaidStatus();
|
||||||
|
const isLabelFeatureEnabled = isPaidUser(tierMatrix.labels);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
@@ -167,7 +186,7 @@ export default function ClientResourcesTable({
|
|||||||
}, [initialFilterSite, siteIdQ, siteIdNum, t]);
|
}, [initialFilterSite, siteIdQ, siteIdNum, t]);
|
||||||
|
|
||||||
const refreshData = () => {
|
const refreshData = () => {
|
||||||
startTransition(() => {
|
startRefreshTransition(() => {
|
||||||
try {
|
try {
|
||||||
router.refresh();
|
router.refresh();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -185,8 +204,8 @@ export default function ClientResourcesTable({
|
|||||||
siteId: number
|
siteId: number
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
await api.delete(`/site-resource/${resourceId}`).then(() => {
|
startTransition(async () => {
|
||||||
startTransition(() => {
|
await api.delete(`/site-resource/${resourceId}`).then(() => {
|
||||||
router.refresh();
|
router.refresh();
|
||||||
setIsDeleteModalOpen(false);
|
setIsDeleteModalOpen(false);
|
||||||
});
|
});
|
||||||
@@ -254,296 +273,333 @@ export default function ClientResourcesTable({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const internalColumns: ExtendedColumnDef<InternalResourceRow>[] = [
|
const internalColumns = useMemo<
|
||||||
{
|
ExtendedColumnDef<InternalResourceRow>[]
|
||||||
accessorKey: "name",
|
>(() => {
|
||||||
enableHiding: false,
|
const cols: ExtendedColumnDef<InternalResourceRow>[] = [
|
||||||
friendlyName: t("name"),
|
{
|
||||||
header: () => {
|
accessorKey: "name",
|
||||||
const nameOrder = getSortDirection("name", searchParams);
|
enableHiding: false,
|
||||||
const Icon =
|
friendlyName: t("name"),
|
||||||
nameOrder === "asc"
|
header: () => {
|
||||||
? ArrowDown01Icon
|
const nameOrder = getSortDirection("name", searchParams);
|
||||||
: nameOrder === "desc"
|
const Icon =
|
||||||
? ArrowUp10Icon
|
nameOrder === "asc"
|
||||||
: ChevronsUpDownIcon;
|
? ArrowDown01Icon
|
||||||
|
: nameOrder === "desc"
|
||||||
|
? ArrowUp10Icon
|
||||||
|
: ChevronsUpDownIcon;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
className="p-3"
|
|
||||||
onClick={() => toggleSort("name")}
|
|
||||||
>
|
|
||||||
{t("name")}
|
|
||||||
<Icon className="ml-2 h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "niceId",
|
|
||||||
accessorKey: "niceId",
|
|
||||||
friendlyName: t("identifier"),
|
|
||||||
enableHiding: true,
|
|
||||||
header: ({ column }) => {
|
|
||||||
return (
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
onClick={() =>
|
|
||||||
column.toggleSorting(column.getIsSorted() === "asc")
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{t("identifier")}
|
|
||||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
cell: ({ row }) => {
|
|
||||||
return <span>{row.original.niceId || "-"}</span>;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "sites",
|
|
||||||
accessorFn: (row) => row.sites.map((s) => s.siteName).join(", "),
|
|
||||||
friendlyName: t("sites"),
|
|
||||||
header: () => (
|
|
||||||
<Popover open={siteFilterOpen} onOpenChange={setSiteFilterOpen}>
|
|
||||||
<PopoverTrigger asChild>
|
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
role="combobox"
|
className="p-3"
|
||||||
className={cn(
|
onClick={() => toggleSort("name")}
|
||||||
"justify-between text-sm h-8 px-2 w-full p-3",
|
|
||||||
!selectedSite && "text-muted-foreground"
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
<div className="flex items-center gap-2 min-w-0">
|
{t("name")}
|
||||||
{t("sites")}
|
<Icon className="ml-2 h-4 w-4" />
|
||||||
<Funnel className="size-4 flex-none" />
|
|
||||||
{selectedSite && (
|
|
||||||
<Badge
|
|
||||||
className="truncate max-w-[10rem]"
|
|
||||||
variant="secondary"
|
|
||||||
>
|
|
||||||
{selectedSite.name}
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</Button>
|
</Button>
|
||||||
</PopoverTrigger>
|
);
|
||||||
<PopoverContent
|
}
|
||||||
className={dataTableFilterPopoverContentClassName}
|
},
|
||||||
align="start"
|
{
|
||||||
|
id: "niceId",
|
||||||
|
accessorKey: "niceId",
|
||||||
|
friendlyName: t("identifier"),
|
||||||
|
enableHiding: true,
|
||||||
|
header: ({ column }) => {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() =>
|
||||||
|
column.toggleSorting(
|
||||||
|
column.getIsSorted() === "asc"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{t("identifier")}
|
||||||
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
return <span>{row.original.niceId || "-"}</span>;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "sites",
|
||||||
|
accessorFn: (row) =>
|
||||||
|
row.sites.map((s) => s.siteName).join(", "),
|
||||||
|
friendlyName: t("sites"),
|
||||||
|
header: () => (
|
||||||
|
<Popover
|
||||||
|
open={siteFilterOpen}
|
||||||
|
onOpenChange={setSiteFilterOpen}
|
||||||
>
|
>
|
||||||
<div className="border-b p-1">
|
<PopoverTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
role="combobox"
|
||||||
className="h-8 w-full justify-start font-normal"
|
className={cn(
|
||||||
onClick={clearSiteFilter}
|
"justify-between text-sm h-8 px-2 w-full p-3",
|
||||||
|
!selectedSite && "text-muted-foreground"
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
{t("standaloneHcFilterAnySite")}
|
<div className="flex items-center gap-2 min-w-0">
|
||||||
|
{t("sites")}
|
||||||
|
<Funnel className="size-4 flex-none" />
|
||||||
|
{selectedSite && (
|
||||||
|
<Badge
|
||||||
|
className="truncate max-w-[10rem]"
|
||||||
|
variant="secondary"
|
||||||
|
>
|
||||||
|
{selectedSite.name}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</PopoverTrigger>
|
||||||
<SitesSelector
|
<PopoverContent
|
||||||
orgId={orgId}
|
className={dataTableFilterPopoverContentClassName}
|
||||||
selectedSite={selectedSite}
|
align="start"
|
||||||
onSelectSite={onPickSite}
|
>
|
||||||
|
<div className="border-b p-1">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
className="h-8 w-full justify-start font-normal"
|
||||||
|
onClick={clearSiteFilter}
|
||||||
|
>
|
||||||
|
{t("standaloneHcFilterAnySite")}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<SitesSelector
|
||||||
|
orgId={orgId}
|
||||||
|
selectedSite={selectedSite}
|
||||||
|
onSelectSite={onPickSite}
|
||||||
|
/>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
),
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const resourceRow = row.original;
|
||||||
|
return (
|
||||||
|
<ResourceSitesStatusCell
|
||||||
|
orgId={resourceRow.orgId}
|
||||||
|
resourceSites={resourceRow.sites}
|
||||||
/>
|
/>
|
||||||
</PopoverContent>
|
);
|
||||||
</Popover>
|
}
|
||||||
),
|
},
|
||||||
cell: ({ row }) => {
|
{
|
||||||
const resourceRow = row.original;
|
accessorKey: "mode",
|
||||||
return (
|
friendlyName: t("editInternalResourceDialogMode"),
|
||||||
<ResourceSitesStatusCell
|
header: () => (
|
||||||
orgId={resourceRow.orgId}
|
<ColumnFilterButton
|
||||||
resourceSites={resourceRow.sites}
|
options={[
|
||||||
/>
|
{
|
||||||
);
|
value: "host",
|
||||||
}
|
label: t("editInternalResourceDialogModeHost")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: "mode",
|
value: "cidr",
|
||||||
friendlyName: t("editInternalResourceDialogMode"),
|
label: t("editInternalResourceDialogModeCidr")
|
||||||
header: () => (
|
},
|
||||||
<ColumnFilterButton
|
{
|
||||||
options={[
|
value: "http",
|
||||||
{
|
label: t("editInternalResourceDialogModeHttp")
|
||||||
value: "host",
|
}
|
||||||
label: t("editInternalResourceDialogModeHost")
|
]}
|
||||||
},
|
selectedValue={searchParams.get("mode") ?? undefined}
|
||||||
{
|
onValueChange={(value) =>
|
||||||
value: "cidr",
|
handleFilterChange("mode", value)
|
||||||
label: t("editInternalResourceDialogModeCidr")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
value: "http",
|
|
||||||
label: t("editInternalResourceDialogModeHttp")
|
|
||||||
}
|
}
|
||||||
]}
|
searchPlaceholder={t("searchPlaceholder")}
|
||||||
selectedValue={searchParams.get("mode") ?? undefined}
|
emptyMessage={t("emptySearchOptions")}
|
||||||
onValueChange={(value) => handleFilterChange("mode", value)}
|
label={t("editInternalResourceDialogMode")}
|
||||||
searchPlaceholder={t("searchPlaceholder")}
|
className="p-3"
|
||||||
emptyMessage={t("emptySearchOptions")}
|
|
||||||
label={t("editInternalResourceDialogMode")}
|
|
||||||
className="p-3"
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
cell: ({ row }) => {
|
|
||||||
const resourceRow = row.original;
|
|
||||||
const modeLabels: Record<
|
|
||||||
"host" | "cidr" | "port" | "http",
|
|
||||||
string
|
|
||||||
> = {
|
|
||||||
host: t("editInternalResourceDialogModeHost"),
|
|
||||||
cidr: t("editInternalResourceDialogModeCidr"),
|
|
||||||
port: t("editInternalResourceDialogModePort"),
|
|
||||||
http: t("editInternalResourceDialogModeHttp")
|
|
||||||
};
|
|
||||||
return <span>{modeLabels[resourceRow.mode]}</span>;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: "destination",
|
|
||||||
friendlyName: t("resourcesTableDestination"),
|
|
||||||
header: () => (
|
|
||||||
<span className="p-3">{t("resourcesTableDestination")}</span>
|
|
||||||
),
|
|
||||||
cell: ({ row }) => {
|
|
||||||
const resourceRow = row.original;
|
|
||||||
const display = formatDestinationDisplay(resourceRow);
|
|
||||||
return (
|
|
||||||
<CopyToClipboard
|
|
||||||
text={display}
|
|
||||||
isLink={false}
|
|
||||||
displayText={display}
|
|
||||||
/>
|
/>
|
||||||
);
|
),
|
||||||
}
|
cell: ({ row }) => {
|
||||||
},
|
const resourceRow = row.original;
|
||||||
{
|
const modeLabels: Record<
|
||||||
accessorKey: "alias",
|
"host" | "cidr" | "port" | "http",
|
||||||
friendlyName: t("resourcesTableAlias"),
|
string
|
||||||
header: () => (
|
> = {
|
||||||
<span className="p-3">{t("resourcesTableAlias")}</span>
|
host: t("editInternalResourceDialogModeHost"),
|
||||||
),
|
cidr: t("editInternalResourceDialogModeCidr"),
|
||||||
cell: ({ row }) => {
|
port: t("editInternalResourceDialogModePort"),
|
||||||
const resourceRow = row.original;
|
http: t("editInternalResourceDialogModeHttp")
|
||||||
if (resourceRow.mode === "host" && resourceRow.alias) {
|
};
|
||||||
|
return <span>{modeLabels[resourceRow.mode]}</span>;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "destination",
|
||||||
|
friendlyName: t("resourcesTableDestination"),
|
||||||
|
header: () => (
|
||||||
|
<span className="p-3">
|
||||||
|
{t("resourcesTableDestination")}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const resourceRow = row.original;
|
||||||
|
const display = formatDestinationDisplay(resourceRow);
|
||||||
return (
|
return (
|
||||||
<CopyToClipboard
|
<CopyToClipboard
|
||||||
text={resourceRow.alias}
|
text={display}
|
||||||
isLink={false}
|
isLink={false}
|
||||||
displayText={resourceRow.alias}
|
displayText={display}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (resourceRow.mode === "http") {
|
},
|
||||||
const domainId = resourceRow.domainId;
|
{
|
||||||
const fullDomain = resourceRow.fullDomain;
|
accessorKey: "alias",
|
||||||
const url = `${resourceRow.ssl ? "https" : "http"}://${fullDomain}`;
|
friendlyName: t("resourcesTableAlias"),
|
||||||
const did =
|
header: () => (
|
||||||
build !== "oss" &&
|
<span className="p-3">{t("resourcesTableAlias")}</span>
|
||||||
resourceRow.ssl &&
|
),
|
||||||
domainId != null &&
|
cell: ({ row }) => {
|
||||||
domainId !== "" &&
|
const resourceRow = row.original;
|
||||||
fullDomain != null &&
|
if (resourceRow.mode === "host" && resourceRow.alias) {
|
||||||
fullDomain !== "";
|
return (
|
||||||
|
<CopyToClipboard
|
||||||
|
text={resourceRow.alias}
|
||||||
|
isLink={false}
|
||||||
|
displayText={resourceRow.alias}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (resourceRow.mode === "http") {
|
||||||
|
const domainId = resourceRow.domainId;
|
||||||
|
const fullDomain = resourceRow.fullDomain;
|
||||||
|
const url = `${resourceRow.ssl ? "https" : "http"}://${fullDomain}`;
|
||||||
|
const did =
|
||||||
|
build !== "oss" &&
|
||||||
|
resourceRow.ssl &&
|
||||||
|
domainId != null &&
|
||||||
|
domainId !== "" &&
|
||||||
|
fullDomain != null &&
|
||||||
|
fullDomain !== "";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-2 min-w-0">
|
<div className="flex items-center gap-2 min-w-0">
|
||||||
{did ? (
|
{did ? (
|
||||||
<ResourceAccessCertIndicator
|
<ResourceAccessCertIndicator
|
||||||
orgId={resourceRow.orgId}
|
orgId={resourceRow.orgId}
|
||||||
domainId={domainId}
|
domainId={domainId}
|
||||||
fullDomain={fullDomain}
|
fullDomain={fullDomain}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
<div className="">
|
<div className="">
|
||||||
<CopyToClipboard
|
<CopyToClipboard
|
||||||
text={url}
|
text={url}
|
||||||
isLink={isSafeUrlForLink(url)}
|
isLink={isSafeUrlForLink(url)}
|
||||||
displayText={url}
|
displayText={url}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return <span>-</span>;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "aliasAddress",
|
||||||
|
friendlyName: t("resourcesTableAliasAddress"),
|
||||||
|
enableHiding: true,
|
||||||
|
header: () => (
|
||||||
|
<div className="flex items-center gap-2 p-3">
|
||||||
|
<span>{t("resourcesTableAliasAddress")}</span>
|
||||||
|
<InfoPopup info={t("resourcesTableAliasAddressInfo")} />
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const resourceRow = row.original;
|
||||||
|
return resourceRow.aliasAddress ? (
|
||||||
|
<CopyToClipboard
|
||||||
|
text={resourceRow.aliasAddress}
|
||||||
|
isLink={false}
|
||||||
|
displayText={resourceRow.aliasAddress}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<span>-</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "actions",
|
||||||
|
enableHiding: false,
|
||||||
|
header: () => <span className="p-3"></span>,
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const resourceRow = row.original;
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2 justify-end">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
className="h-8 w-8 p-0"
|
||||||
|
>
|
||||||
|
<span className="sr-only">
|
||||||
|
{t("openMenu")}
|
||||||
|
</span>
|
||||||
|
<MoreHorizontal className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedInternalResource(
|
||||||
|
resourceRow
|
||||||
|
);
|
||||||
|
setIsDeleteModalOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span className="text-red-500">
|
||||||
|
{t("delete")}
|
||||||
|
</span>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
<Button
|
||||||
|
variant={"outline"}
|
||||||
|
onClick={() => {
|
||||||
|
setEditingResource(resourceRow);
|
||||||
|
setIsEditDialogOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("edit")}
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return <span>-</span>;
|
|
||||||
}
|
}
|
||||||
},
|
];
|
||||||
{
|
|
||||||
accessorKey: "aliasAddress",
|
if (isLabelFeatureEnabled) {
|
||||||
friendlyName: t("resourcesTableAliasAddress"),
|
cols.splice(cols.length - 1, 0, {
|
||||||
enableHiding: true,
|
id: "labels",
|
||||||
header: () => (
|
accessorKey: "labels",
|
||||||
<div className="flex items-center gap-2 p-3">
|
header: () => (
|
||||||
<span>{t("resourcesTableAliasAddress")}</span>
|
<span className="p-3 text-end w-full inline-block">
|
||||||
<InfoPopup info={t("resourcesTableAliasAddressInfo")} />
|
{t("labels")}
|
||||||
</div>
|
</span>
|
||||||
),
|
),
|
||||||
cell: ({ row }) => {
|
cell: ({ row }: { row: { original: InternalResourceRow } }) => (
|
||||||
const resourceRow = row.original;
|
<ClientResourceLabelCell
|
||||||
return resourceRow.aliasAddress ? (
|
resource={row.original}
|
||||||
<CopyToClipboard
|
orgId={orgId}
|
||||||
text={resourceRow.aliasAddress}
|
|
||||||
isLink={false}
|
|
||||||
displayText={resourceRow.aliasAddress}
|
|
||||||
/>
|
/>
|
||||||
) : (
|
)
|
||||||
<span>-</span>
|
});
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "actions",
|
|
||||||
enableHiding: false,
|
|
||||||
header: () => <span className="p-3"></span>,
|
|
||||||
cell: ({ row }) => {
|
|
||||||
const resourceRow = row.original;
|
|
||||||
return (
|
|
||||||
<div className="flex items-center gap-2 justify-end">
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownMenuTrigger asChild>
|
|
||||||
<Button variant="ghost" className="h-8 w-8 p-0">
|
|
||||||
<span className="sr-only">
|
|
||||||
{t("openMenu")}
|
|
||||||
</span>
|
|
||||||
<MoreHorizontal className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
<DropdownMenuContent align="end">
|
|
||||||
<DropdownMenuItem
|
|
||||||
onClick={() => {
|
|
||||||
setSelectedInternalResource(
|
|
||||||
resourceRow
|
|
||||||
);
|
|
||||||
setIsDeleteModalOpen(true);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span className="text-red-500">
|
|
||||||
{t("delete")}
|
|
||||||
</span>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
<Button
|
|
||||||
variant={"outline"}
|
|
||||||
onClick={() => {
|
|
||||||
setEditingResource(resourceRow);
|
|
||||||
setIsEditDialogOpen(true);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("edit")}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
];
|
|
||||||
|
return cols;
|
||||||
|
}, [isLabelFeatureEnabled, orgId, t, searchParams]);
|
||||||
|
|
||||||
function handleFilterChange(
|
function handleFilterChange(
|
||||||
column: string,
|
column: string,
|
||||||
@@ -638,7 +694,8 @@ export default function ClientResourcesTable({
|
|||||||
enableColumnVisibility
|
enableColumnVisibility
|
||||||
columnVisibility={{
|
columnVisibility={{
|
||||||
niceId: false,
|
niceId: false,
|
||||||
aliasAddress: false
|
aliasAddress: false,
|
||||||
|
labels: false
|
||||||
}}
|
}}
|
||||||
stickyLeftColumn="name"
|
stickyLeftColumn="name"
|
||||||
stickyRightColumn="actions"
|
stickyRightColumn="actions"
|
||||||
@@ -674,3 +731,101 @@ export default function ClientResourcesTable({
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ClientResourceLabelCellProps = {
|
||||||
|
resource: InternalResourceRow;
|
||||||
|
orgId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function ClientResourceLabelCell({
|
||||||
|
resource,
|
||||||
|
orgId
|
||||||
|
}: ClientResourceLabelCellProps) {
|
||||||
|
const t = useTranslations();
|
||||||
|
const api = createApiClient(useEnvContext());
|
||||||
|
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const labels = resource.labels ?? [];
|
||||||
|
const [optimisticLabels, setOptimisticLabels] = useOptimistic(labels);
|
||||||
|
|
||||||
|
function toggleResourceLabel(
|
||||||
|
label: SelectedLabel,
|
||||||
|
action: "attach" | "detach"
|
||||||
|
) {
|
||||||
|
startTransition(async () => {
|
||||||
|
try {
|
||||||
|
if (action === "attach") {
|
||||||
|
setOptimisticLabels([...optimisticLabels, label]);
|
||||||
|
await api.put(
|
||||||
|
`/org/${orgId}/label/${label.labelId}/attach`,
|
||||||
|
{ siteResourceId: resource.id }
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setOptimisticLabels(
|
||||||
|
optimisticLabels.filter(
|
||||||
|
(lb) => lb.labelId !== label.labelId
|
||||||
|
)
|
||||||
|
);
|
||||||
|
await api.put(
|
||||||
|
`/org/${orgId}/label/${label.labelId}/detach`,
|
||||||
|
{ siteResourceId: resource.id }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
toast({
|
||||||
|
title: t("error"),
|
||||||
|
description: formatAxiosError(e, t("errorOccurred")),
|
||||||
|
variant: "destructive"
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
router.refresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="inline-flex flex-wrap items-center justify-end w-full gap-1">
|
||||||
|
{optimisticLabels.slice(0, 3).map((label) => (
|
||||||
|
<LabelBadge
|
||||||
|
key={label.labelId}
|
||||||
|
onClick={() => setIsPopoverOpen(true)}
|
||||||
|
{...label}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
{optimisticLabels.length > 3 && (
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className={cn(
|
||||||
|
"inline-flex gap-1 items-center",
|
||||||
|
"rounded-full text-sm cursor-pointer",
|
||||||
|
"px-1.5 py-0 h-auto"
|
||||||
|
)}
|
||||||
|
onClick={() => setIsPopoverOpen(true)}
|
||||||
|
>
|
||||||
|
+{optimisticLabels.length - 3}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Popover open={isPopoverOpen} onOpenChange={setIsPopoverOpen}>
|
||||||
|
<PopoverTrigger asChild>
|
||||||
|
<Button
|
||||||
|
size="icon"
|
||||||
|
variant="outline"
|
||||||
|
className="p-1 size-auto rounded-full"
|
||||||
|
title={t("addLabels")}
|
||||||
|
>
|
||||||
|
<span className="sr-only">{t("addLabels")}</span>
|
||||||
|
<PlusIcon className="size-3" />
|
||||||
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent align="center" className="p-0 w-full">
|
||||||
|
<LabelsSelector
|
||||||
|
orgId={orgId}
|
||||||
|
selectedLabels={optimisticLabels}
|
||||||
|
toggleLabel={toggleResourceLabel}
|
||||||
|
/>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import { toast } from "@app/hooks/useToast";
|
|||||||
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
||||||
import { AxiosResponse } from "axios";
|
import { AxiosResponse } from "axios";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { useState } from "react";
|
import { useState, useTransition } from "react";
|
||||||
import {
|
import {
|
||||||
cleanForFQDN,
|
cleanForFQDN,
|
||||||
InternalResourceForm,
|
InternalResourceForm,
|
||||||
@@ -39,30 +39,30 @@ export default function CreateInternalResourceDialog({
|
|||||||
}: CreateInternalResourceDialogProps) {
|
}: CreateInternalResourceDialogProps) {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
const api = createApiClient(useEnvContext());
|
const api = createApiClient(useEnvContext());
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
||||||
const [isHttpModeDisabled, setIsHttpModeDisabled] = useState(false);
|
const [isHttpModeDisabled, setIsHttpModeDisabled] = useState(false);
|
||||||
|
const [isSubmitting, startTransition] = useTransition();
|
||||||
|
|
||||||
async function handleSubmit(values: InternalResourceFormValues) {
|
function handleSubmit(values: InternalResourceFormValues) {
|
||||||
setIsSubmitting(true);
|
startTransition(async () => {
|
||||||
try {
|
try {
|
||||||
let data = { ...values };
|
let data = { ...values };
|
||||||
if (
|
if (
|
||||||
(data.mode === "host" || data.mode === "http") &&
|
(data.mode === "host" || data.mode === "http") &&
|
||||||
isHostname(data.destination)
|
isHostname(data.destination)
|
||||||
) {
|
) {
|
||||||
const currentAlias = data.alias?.trim() || "";
|
const currentAlias = data.alias?.trim() || "";
|
||||||
if (!currentAlias) {
|
if (!currentAlias) {
|
||||||
let aliasValue = data.destination;
|
let aliasValue = data.destination;
|
||||||
if (data.destination.toLowerCase() === "localhost") {
|
if (data.destination.toLowerCase() === "localhost") {
|
||||||
aliasValue = `${cleanForFQDN(data.name)}.internal`;
|
aliasValue = `${cleanForFQDN(data.name)}.internal`;
|
||||||
|
}
|
||||||
|
data = { ...data, alias: aliasValue };
|
||||||
}
|
}
|
||||||
data = { ...data, alias: aliasValue };
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
await api.put<AxiosResponse<{ data: { siteResourceId: number } }>>(
|
await api.put<
|
||||||
`/org/${orgId}/site-resource`,
|
AxiosResponse<{ data: { siteResourceId: number } }>
|
||||||
{
|
>(`/org/${orgId}/site-resource`, {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
siteIds: data.siteIds,
|
siteIds: data.siteIds,
|
||||||
mode: data.mode,
|
mode: data.mode,
|
||||||
@@ -106,32 +106,30 @@ export default function CreateInternalResourceDialog({
|
|||||||
clientIds: data.clients
|
clientIds: data.clients
|
||||||
? data.clients.map((c) => parseInt(c.id))
|
? data.clients.map((c) => parseInt(c.id))
|
||||||
: []
|
: []
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: t("createInternalResourceDialogSuccess"),
|
title: t("createInternalResourceDialogSuccess"),
|
||||||
description: t(
|
description: t(
|
||||||
"createInternalResourceDialogInternalResourceCreatedSuccessfully"
|
"createInternalResourceDialogInternalResourceCreatedSuccessfully"
|
||||||
),
|
),
|
||||||
variant: "default"
|
variant: "default"
|
||||||
});
|
});
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
onSuccess?.();
|
onSuccess?.();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast({
|
toast({
|
||||||
title: t("createInternalResourceDialogError"),
|
title: t("createInternalResourceDialogError"),
|
||||||
description: formatAxiosError(
|
description: formatAxiosError(
|
||||||
error,
|
error,
|
||||||
t(
|
t(
|
||||||
"createInternalResourceDialogFailedToCreateInternalResource"
|
"createInternalResourceDialogFailedToCreateInternalResource"
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
variant: "destructive"
|
variant: "destructive"
|
||||||
});
|
});
|
||||||
} finally {
|
}
|
||||||
setIsSubmitting(false);
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
102
src/components/CreateOrgLabelDialog.tsx
Normal file
102
src/components/CreateOrgLabelDialog.tsx
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
|
import { toast } from "@app/hooks/useToast";
|
||||||
|
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
||||||
|
import type { CreateOrEditLabelResponse } from "@server/routers/labels/types";
|
||||||
|
import type { AxiosResponse } from "axios";
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
import { useTransition } from "react";
|
||||||
|
import {
|
||||||
|
Credenza,
|
||||||
|
CredenzaBody,
|
||||||
|
CredenzaClose,
|
||||||
|
CredenzaContent,
|
||||||
|
CredenzaDescription,
|
||||||
|
CredenzaFooter,
|
||||||
|
CredenzaHeader,
|
||||||
|
CredenzaTitle
|
||||||
|
} from "./Credenza";
|
||||||
|
import { OrgLabelForm } from "./OrgLabelForm";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
|
||||||
|
export type CreateOrgLabelDialogProps = {
|
||||||
|
open: boolean;
|
||||||
|
setOpen: (val: boolean) => void;
|
||||||
|
orgId: string;
|
||||||
|
onSuccess?: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function CreateOrgLabelDialog({
|
||||||
|
open,
|
||||||
|
setOpen,
|
||||||
|
orgId,
|
||||||
|
onSuccess
|
||||||
|
}: CreateOrgLabelDialogProps) {
|
||||||
|
const t = useTranslations();
|
||||||
|
const api = createApiClient(useEnvContext());
|
||||||
|
const [isSubmitting, startTransition] = useTransition();
|
||||||
|
|
||||||
|
async function createOrgLabel(data: { name: string; color: string }) {
|
||||||
|
try {
|
||||||
|
const res = await api.post<
|
||||||
|
AxiosResponse<CreateOrEditLabelResponse>
|
||||||
|
>(`/org/${orgId}/labels`, data);
|
||||||
|
|
||||||
|
if (res.status === 201) {
|
||||||
|
setOpen(false);
|
||||||
|
onSuccess?.();
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: t("success"),
|
||||||
|
description: t("labelCreateSuccessMessage")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
toast({
|
||||||
|
title: t("error"),
|
||||||
|
description: formatAxiosError(e, t("errorOccurred")),
|
||||||
|
variant: "destructive"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Credenza open={open} onOpenChange={setOpen}>
|
||||||
|
<CredenzaContent className="md:max-w-md">
|
||||||
|
<CredenzaHeader>
|
||||||
|
<CredenzaTitle>{t("createLabelDialogTitle")}</CredenzaTitle>
|
||||||
|
<CredenzaDescription>
|
||||||
|
{t("createLabelDialogDescription")}
|
||||||
|
</CredenzaDescription>
|
||||||
|
</CredenzaHeader>
|
||||||
|
<CredenzaBody>
|
||||||
|
<OrgLabelForm
|
||||||
|
onSubmit={(data) => {
|
||||||
|
startTransition(async () => createOrgLabel(data));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</CredenzaBody>
|
||||||
|
<CredenzaFooter>
|
||||||
|
<CredenzaClose asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => setOpen(false)}
|
||||||
|
disabled={isSubmitting}
|
||||||
|
>
|
||||||
|
{t("cancel")}
|
||||||
|
</Button>
|
||||||
|
</CredenzaClose>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
form="org-label-form"
|
||||||
|
disabled={isSubmitting}
|
||||||
|
loading={isSubmitting}
|
||||||
|
>
|
||||||
|
{t("labelCreate")}
|
||||||
|
</Button>
|
||||||
|
</CredenzaFooter>
|
||||||
|
</CredenzaContent>
|
||||||
|
</Credenza>
|
||||||
|
);
|
||||||
|
}
|
||||||
109
src/components/EditOrgLabelDialog.tsx
Normal file
109
src/components/EditOrgLabelDialog.tsx
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
|
import { toast } from "@app/hooks/useToast";
|
||||||
|
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
||||||
|
import type { CreateOrEditLabelResponse } from "@server/routers/labels/types";
|
||||||
|
import type { AxiosResponse } from "axios";
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
import { useTransition } from "react";
|
||||||
|
import {
|
||||||
|
Credenza,
|
||||||
|
CredenzaBody,
|
||||||
|
CredenzaClose,
|
||||||
|
CredenzaContent,
|
||||||
|
CredenzaDescription,
|
||||||
|
CredenzaFooter,
|
||||||
|
CredenzaHeader,
|
||||||
|
CredenzaTitle
|
||||||
|
} from "./Credenza";
|
||||||
|
import { OrgLabelForm } from "./OrgLabelForm";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
|
||||||
|
export type EditOrgLabelDialogProps = {
|
||||||
|
open: boolean;
|
||||||
|
setOpen: (val: boolean) => void;
|
||||||
|
orgId: string;
|
||||||
|
onSuccess?: () => void;
|
||||||
|
label: {
|
||||||
|
name: string;
|
||||||
|
color: string;
|
||||||
|
labelId: number;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export function EditOrgLabelDialog({
|
||||||
|
open,
|
||||||
|
setOpen,
|
||||||
|
orgId,
|
||||||
|
onSuccess,
|
||||||
|
label
|
||||||
|
}: EditOrgLabelDialogProps) {
|
||||||
|
const t = useTranslations();
|
||||||
|
const api = createApiClient(useEnvContext());
|
||||||
|
const [isSubmitting, startTransition] = useTransition();
|
||||||
|
|
||||||
|
async function editOrgLabel(data: { name: string; color: string }) {
|
||||||
|
try {
|
||||||
|
const res = await api.patch<
|
||||||
|
AxiosResponse<CreateOrEditLabelResponse>
|
||||||
|
>(`/org/${orgId}/label/${label.labelId}`, data);
|
||||||
|
|
||||||
|
if (res.status === 200) {
|
||||||
|
setOpen(false);
|
||||||
|
onSuccess?.();
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: t("success"),
|
||||||
|
description: t("labelEditSuccessMessage")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
toast({
|
||||||
|
title: t("error"),
|
||||||
|
description: formatAxiosError(e, t("errorOccurred")),
|
||||||
|
variant: "destructive"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Credenza open={open} onOpenChange={setOpen}>
|
||||||
|
<CredenzaContent className="md:max-w-md">
|
||||||
|
<CredenzaHeader>
|
||||||
|
<CredenzaTitle>{t("editLabelDialogTitle")}</CredenzaTitle>
|
||||||
|
<CredenzaDescription>
|
||||||
|
{t("editLabelDialogDescription")}
|
||||||
|
</CredenzaDescription>
|
||||||
|
</CredenzaHeader>
|
||||||
|
<CredenzaBody>
|
||||||
|
<OrgLabelForm
|
||||||
|
defaultValue={label}
|
||||||
|
onSubmit={(data) => {
|
||||||
|
startTransition(async () => editOrgLabel(data));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</CredenzaBody>
|
||||||
|
<CredenzaFooter>
|
||||||
|
<CredenzaClose asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => setOpen(false)}
|
||||||
|
disabled={isSubmitting}
|
||||||
|
>
|
||||||
|
{t("cancel")}
|
||||||
|
</Button>
|
||||||
|
</CredenzaClose>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
form="org-label-form"
|
||||||
|
disabled={isSubmitting}
|
||||||
|
loading={isSubmitting}
|
||||||
|
>
|
||||||
|
{t("labelEdit")}
|
||||||
|
</Button>
|
||||||
|
</CredenzaFooter>
|
||||||
|
</CredenzaContent>
|
||||||
|
</Credenza>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -10,8 +10,11 @@ import {
|
|||||||
DropdownMenuTrigger
|
DropdownMenuTrigger
|
||||||
} from "@app/components/ui/dropdown-menu";
|
} from "@app/components/ui/dropdown-menu";
|
||||||
import { useEnvContext } from "@app/hooks/useEnvContext";
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
|
import { usePaidStatus } from "@app/hooks/usePaidStatus";
|
||||||
import { toast } from "@app/hooks/useToast";
|
import { toast } from "@app/hooks/useToast";
|
||||||
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
||||||
|
import { cn } from "@app/lib/cn";
|
||||||
|
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
||||||
import {
|
import {
|
||||||
ArrowRight,
|
ArrowRight,
|
||||||
ArrowUpDown,
|
ArrowUpDown,
|
||||||
@@ -19,12 +22,26 @@ import {
|
|||||||
CircleSlash,
|
CircleSlash,
|
||||||
ArrowDown01Icon,
|
ArrowDown01Icon,
|
||||||
ArrowUp10Icon,
|
ArrowUp10Icon,
|
||||||
ChevronsUpDownIcon
|
ChevronsUpDownIcon,
|
||||||
|
PlusIcon
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useMemo, useState, useTransition } from "react";
|
import {
|
||||||
|
startTransition,
|
||||||
|
useMemo,
|
||||||
|
useOptimistic,
|
||||||
|
useState,
|
||||||
|
useTransition
|
||||||
|
} from "react";
|
||||||
|
import { LabelBadge } from "./label-badge";
|
||||||
|
import { LabelsSelector, type SelectedLabel } from "./labels-selector";
|
||||||
|
import {
|
||||||
|
Popover,
|
||||||
|
PopoverContent,
|
||||||
|
PopoverTrigger
|
||||||
|
} from "./ui/popover";
|
||||||
import { Badge } from "./ui/badge";
|
import { Badge } from "./ui/badge";
|
||||||
import type { PaginationState } from "@tanstack/react-table";
|
import type { PaginationState } from "@tanstack/react-table";
|
||||||
import { ControlledDataTable } from "./ui/controlled-data-table";
|
import { ControlledDataTable } from "./ui/controlled-data-table";
|
||||||
@@ -53,6 +70,11 @@ export type ClientRow = {
|
|||||||
archived?: boolean;
|
archived?: boolean;
|
||||||
blocked?: boolean;
|
blocked?: boolean;
|
||||||
approvalState: "approved" | "pending" | "denied";
|
approvalState: "approved" | "pending" | "denied";
|
||||||
|
labels?: Array<{
|
||||||
|
labelId: number;
|
||||||
|
name: string;
|
||||||
|
color: string;
|
||||||
|
}>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ClientTableProps = {
|
type ClientTableProps = {
|
||||||
@@ -84,17 +106,21 @@ export default function MachineClientsTable({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const api = createApiClient(useEnvContext());
|
const api = createApiClient(useEnvContext());
|
||||||
const [isRefreshing, startTransition] = useTransition();
|
const [isRefreshing, startRefreshTransition] = useTransition();
|
||||||
const [isNavigatingToAddPage, startNavigation] = useTransition();
|
const [isNavigatingToAddPage, startNavigation] = useTransition();
|
||||||
|
|
||||||
|
const { isPaidUser } = usePaidStatus();
|
||||||
|
const isLabelFeatureEnabled = isPaidUser(tierMatrix.labels);
|
||||||
|
|
||||||
const defaultMachineColumnVisibility = {
|
const defaultMachineColumnVisibility = {
|
||||||
subnet: false,
|
subnet: false,
|
||||||
userId: false,
|
userId: false,
|
||||||
niceId: false
|
niceId: false,
|
||||||
|
labels: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const refreshData = () => {
|
const refreshData = () => {
|
||||||
startTransition(() => {
|
startRefreshTransition(() => {
|
||||||
try {
|
try {
|
||||||
router.refresh();
|
router.refresh();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -384,6 +410,24 @@ export default function MachineClientsTable({
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (isLabelFeatureEnabled) {
|
||||||
|
baseColumns.push({
|
||||||
|
id: "labels",
|
||||||
|
accessorKey: "labels",
|
||||||
|
header: () => (
|
||||||
|
<span className="p-3 text-end w-full inline-block">
|
||||||
|
{t("labels")}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
cell: ({ row }: { row: { original: ClientRow } }) => (
|
||||||
|
<MachineClientLabelCell
|
||||||
|
client={row.original}
|
||||||
|
orgId={orgId}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Only include actions column if there are rows without userIds
|
// Only include actions column if there are rows without userIds
|
||||||
if (hasRowsWithoutUserId) {
|
if (hasRowsWithoutUserId) {
|
||||||
baseColumns.push({
|
baseColumns.push({
|
||||||
@@ -464,7 +508,7 @@ export default function MachineClientsTable({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return baseColumns;
|
return baseColumns;
|
||||||
}, [hasRowsWithoutUserId, t, getSortDirection, toggleSort]);
|
}, [hasRowsWithoutUserId, isLabelFeatureEnabled, orgId, t, searchParams]);
|
||||||
|
|
||||||
const booleanSearchFilterSchema = z
|
const booleanSearchFilterSchema = z
|
||||||
.enum(["true", "false"])
|
.enum(["true", "false"])
|
||||||
@@ -591,3 +635,95 @@ export default function MachineClientsTable({
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MachineClientLabelCellProps = {
|
||||||
|
client: ClientRow;
|
||||||
|
orgId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function MachineClientLabelCell({ client, orgId }: MachineClientLabelCellProps) {
|
||||||
|
const t = useTranslations();
|
||||||
|
const api = createApiClient(useEnvContext());
|
||||||
|
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const labels = client.labels ?? [];
|
||||||
|
const [optimisticLabels, setOptimisticLabels] = useOptimistic(labels);
|
||||||
|
|
||||||
|
function toggleClientLabel(label: SelectedLabel, action: "attach" | "detach") {
|
||||||
|
startTransition(async () => {
|
||||||
|
try {
|
||||||
|
if (action === "attach") {
|
||||||
|
setOptimisticLabels([...optimisticLabels, label]);
|
||||||
|
await api.put(
|
||||||
|
`/org/${orgId}/label/${label.labelId}/attach`,
|
||||||
|
{ clientId: client.id }
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setOptimisticLabels(
|
||||||
|
optimisticLabels.filter(
|
||||||
|
(lb) => lb.labelId !== label.labelId
|
||||||
|
)
|
||||||
|
);
|
||||||
|
await api.put(
|
||||||
|
`/org/${orgId}/label/${label.labelId}/detach`,
|
||||||
|
{ clientId: client.id }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
toast({
|
||||||
|
title: t("error"),
|
||||||
|
description: formatAxiosError(e, t("errorOccurred")),
|
||||||
|
variant: "destructive"
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
router.refresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="inline-flex flex-wrap items-center justify-end w-full gap-1">
|
||||||
|
{optimisticLabels.slice(0, 3).map((label) => (
|
||||||
|
<LabelBadge
|
||||||
|
key={label.labelId}
|
||||||
|
onClick={() => setIsPopoverOpen(true)}
|
||||||
|
{...label}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
{optimisticLabels.length > 3 && (
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className={cn(
|
||||||
|
"inline-flex gap-1 items-center",
|
||||||
|
"rounded-full text-sm cursor-pointer",
|
||||||
|
"px-1.5 py-0 h-auto"
|
||||||
|
)}
|
||||||
|
onClick={() => setIsPopoverOpen(true)}
|
||||||
|
>
|
||||||
|
+{optimisticLabels.length - 3}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Popover open={isPopoverOpen} onOpenChange={setIsPopoverOpen}>
|
||||||
|
<PopoverTrigger asChild>
|
||||||
|
<Button
|
||||||
|
size="icon"
|
||||||
|
variant="outline"
|
||||||
|
className="p-1 size-auto rounded-full"
|
||||||
|
title={t("addLabels")}
|
||||||
|
>
|
||||||
|
<span className="sr-only">{t("addLabels")}</span>
|
||||||
|
<PlusIcon className="size-3" />
|
||||||
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent align="center" className="p-0 w-full">
|
||||||
|
<LabelsSelector
|
||||||
|
orgId={orgId}
|
||||||
|
selectedLabels={optimisticLabels}
|
||||||
|
toggleLabel={toggleClientLabel}
|
||||||
|
/>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
126
src/components/OrgLabelForm.tsx
Normal file
126
src/components/OrgLabelForm.tsx
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import z from "zod";
|
||||||
|
import { Input } from "./ui/input";
|
||||||
|
import { useTranslations } from "use-intl";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage
|
||||||
|
} from "./ui/form";
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue
|
||||||
|
} from "./ui/select";
|
||||||
|
import { LABEL_COLORS } from "./labels-selector";
|
||||||
|
|
||||||
|
const labelFormSchema = z.object({
|
||||||
|
name: z.string().nonempty(),
|
||||||
|
color: z
|
||||||
|
.string()
|
||||||
|
.regex(/^#?([0-9a-f]{6}|[0-9a-f]{3})$/i)
|
||||||
|
.nonempty()
|
||||||
|
});
|
||||||
|
|
||||||
|
export type LabelFormData = z.infer<typeof labelFormSchema>;
|
||||||
|
|
||||||
|
export type OrgLabelFormProps = {
|
||||||
|
onSubmit: (data: LabelFormData) => void;
|
||||||
|
defaultValue?: LabelFormData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function OrgLabelForm({ onSubmit, defaultValue }: OrgLabelFormProps) {
|
||||||
|
const t = useTranslations();
|
||||||
|
|
||||||
|
const colorValues = Object.values(LABEL_COLORS);
|
||||||
|
const randomColor =
|
||||||
|
colorValues[Math.floor(Math.random() * colorValues.length)];
|
||||||
|
|
||||||
|
const form = useForm({
|
||||||
|
resolver: zodResolver(labelFormSchema),
|
||||||
|
defaultValues: {
|
||||||
|
name: defaultValue?.name ?? "",
|
||||||
|
color: defaultValue?.color ?? randomColor
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<form
|
||||||
|
id="org-label-form"
|
||||||
|
className="flex flex-col gap-4 px-0.5"
|
||||||
|
action={async () => {
|
||||||
|
if (await form.trigger()) {
|
||||||
|
onSubmit(form.getValues());
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="name"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{t("labelNameField")}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
placeholder={t("labelPlaceholder")}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="color"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{t("labelColorField")}</FormLabel>
|
||||||
|
<Select
|
||||||
|
onValueChange={field.onChange}
|
||||||
|
value={field.value}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="w-full">
|
||||||
|
<SelectValue
|
||||||
|
placeholder={t("selectColor")}
|
||||||
|
/>
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{Object.entries(LABEL_COLORS).map(
|
||||||
|
([color, value]) => (
|
||||||
|
<SelectItem
|
||||||
|
value={value}
|
||||||
|
key={color}
|
||||||
|
className="flex items-center gap-2"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="size-4 rounded-full bg-(--color) flex-none"
|
||||||
|
style={{
|
||||||
|
// @ts-expect-error css color
|
||||||
|
"--color": value
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<span data-name>{color}</span>
|
||||||
|
</SelectItem>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
240
src/components/OrgLabelsTable.tsx
Normal file
240
src/components/OrgLabelsTable.tsx
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { Button } from "@app/components/ui/button";
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuTrigger
|
||||||
|
} from "@app/components/ui/dropdown-menu";
|
||||||
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
|
import { useNavigationContext } from "@app/hooks/useNavigationContext";
|
||||||
|
import { toast } from "@app/hooks/useToast";
|
||||||
|
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
||||||
|
import { type PaginationState } from "@tanstack/react-table";
|
||||||
|
import {
|
||||||
|
ArrowDown01Icon,
|
||||||
|
ArrowUp10Icon,
|
||||||
|
ChevronsUpDownIcon,
|
||||||
|
MoreHorizontal,
|
||||||
|
PencilIcon,
|
||||||
|
PencilLineIcon
|
||||||
|
} from "lucide-react";
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
import { usePathname, useRouter } from "next/navigation";
|
||||||
|
import { useActionState, useMemo, useState, useTransition } from "react";
|
||||||
|
import { useDebouncedCallback } from "use-debounce";
|
||||||
|
import {
|
||||||
|
ControlledDataTable,
|
||||||
|
type ExtendedColumnDef
|
||||||
|
} from "./ui/controlled-data-table";
|
||||||
|
import { LabelBadge } from "./label-badge";
|
||||||
|
import { getNextSortOrder, getSortDirection } from "@app/lib/sortColumn";
|
||||||
|
import { cn } from "@app/lib/cn";
|
||||||
|
import ConfirmDeleteDialog from "./ConfirmDeleteDialog";
|
||||||
|
import { CreateOrgLabelDialog } from "./CreateOrgLabelDialog";
|
||||||
|
import { EditOrgLabelDialog } from "./EditOrgLabelDialog";
|
||||||
|
|
||||||
|
export type LabelRow = {
|
||||||
|
labelId: number;
|
||||||
|
name: string;
|
||||||
|
color: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type OrgLabelsTableProps = {
|
||||||
|
labels: LabelRow[];
|
||||||
|
pagination: PaginationState;
|
||||||
|
orgId: string;
|
||||||
|
rowCount: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function OrgLabelsTable({
|
||||||
|
labels,
|
||||||
|
orgId,
|
||||||
|
pagination,
|
||||||
|
rowCount
|
||||||
|
}: OrgLabelsTableProps) {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const {
|
||||||
|
navigate: filter,
|
||||||
|
isNavigating: isFiltering,
|
||||||
|
searchParams
|
||||||
|
} = useNavigationContext();
|
||||||
|
|
||||||
|
const [selectedLabel, setSelectedLabel] = useState<LabelRow | null>(null);
|
||||||
|
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||||
|
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
||||||
|
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
|
||||||
|
|
||||||
|
const [isRefreshing, startTransition] = useTransition();
|
||||||
|
|
||||||
|
const api = createApiClient(useEnvContext());
|
||||||
|
const t = useTranslations();
|
||||||
|
|
||||||
|
function refreshData() {
|
||||||
|
startTransition(async () => {
|
||||||
|
try {
|
||||||
|
router.refresh();
|
||||||
|
} catch {
|
||||||
|
toast({
|
||||||
|
title: t("error"),
|
||||||
|
description: t("refreshError"),
|
||||||
|
variant: "destructive"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const handlePaginationChange = (newPage: PaginationState) => {
|
||||||
|
searchParams.set("page", (newPage.pageIndex + 1).toString());
|
||||||
|
searchParams.set("pageSize", newPage.pageSize.toString());
|
||||||
|
filter({ searchParams });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSearchChange = useDebouncedCallback((query: string) => {
|
||||||
|
searchParams.set("query", query);
|
||||||
|
searchParams.delete("page");
|
||||||
|
filter({ searchParams });
|
||||||
|
}, 300);
|
||||||
|
|
||||||
|
const columns = useMemo<ExtendedColumnDef<LabelRow>[]>(
|
||||||
|
() => [
|
||||||
|
{
|
||||||
|
accessorKey: "name",
|
||||||
|
enableHiding: false,
|
||||||
|
header: () => {
|
||||||
|
return <span className="p-3">{t("name")}</span>;
|
||||||
|
},
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex items-center gap-1.5 group">
|
||||||
|
<div
|
||||||
|
className="size-2.5 rounded-full bg-(--color) flex-none"
|
||||||
|
style={{
|
||||||
|
// @ts-expect-error css color
|
||||||
|
"--color": row.original.color
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{row.original.name}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: "actions",
|
||||||
|
enableHiding: false,
|
||||||
|
header: () => {
|
||||||
|
return <span className="p-3">{t("actions")}</span>;
|
||||||
|
},
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||||
|
<span className="sr-only">{t("openMenu")}</span>
|
||||||
|
<MoreHorizontal className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedLabel(row.original);
|
||||||
|
setIsEditModalOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("edit")}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedLabel(row.original);
|
||||||
|
setIsDeleteModalOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span className="text-red-500">
|
||||||
|
{t("delete")}
|
||||||
|
</span>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
],
|
||||||
|
[searchParams, t]
|
||||||
|
);
|
||||||
|
|
||||||
|
function deleteLabel(label: LabelRow) {
|
||||||
|
startTransition(async () => {
|
||||||
|
await api
|
||||||
|
.delete(`/org/${orgId}/label/${label.labelId}`)
|
||||||
|
.catch((e) => {
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: t("labelErrorDelete"),
|
||||||
|
description: formatAxiosError(e, t("labelErrorDelete"))
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
router.refresh();
|
||||||
|
setIsDeleteModalOpen(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{selectedLabel && (
|
||||||
|
<>
|
||||||
|
<ConfirmDeleteDialog
|
||||||
|
open={isDeleteModalOpen}
|
||||||
|
setOpen={(val) => {
|
||||||
|
setIsDeleteModalOpen(val);
|
||||||
|
setSelectedLabel(null);
|
||||||
|
}}
|
||||||
|
dialog={
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p>{t("labelQuestionRemove")}</p>
|
||||||
|
<p>{t("labelMessageRemove")}</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
buttonText={t("labelDeleteConfirm")}
|
||||||
|
onConfirm={async () => deleteLabel(selectedLabel)}
|
||||||
|
string={selectedLabel.name}
|
||||||
|
title={t("labelDelete")}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<EditOrgLabelDialog
|
||||||
|
open={isEditModalOpen}
|
||||||
|
setOpen={setIsEditModalOpen}
|
||||||
|
orgId={orgId}
|
||||||
|
onSuccess={() =>
|
||||||
|
startTransition(() => router.refresh())
|
||||||
|
}
|
||||||
|
label={selectedLabel}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<CreateOrgLabelDialog
|
||||||
|
open={isCreateModalOpen}
|
||||||
|
setOpen={setIsCreateModalOpen}
|
||||||
|
orgId={orgId}
|
||||||
|
onSuccess={() => startTransition(() => router.refresh())}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ControlledDataTable
|
||||||
|
columns={columns}
|
||||||
|
rows={labels}
|
||||||
|
addButtonText={t("labelAdd")}
|
||||||
|
onAdd={() => setIsCreateModalOpen(true)}
|
||||||
|
tableId="org-labels-table"
|
||||||
|
searchPlaceholder={t("labelSearch")}
|
||||||
|
pagination={pagination}
|
||||||
|
onPaginationChange={handlePaginationChange}
|
||||||
|
searchQuery={searchParams.get("query")?.toString()}
|
||||||
|
onSearch={handleSearchChange}
|
||||||
|
onRefresh={refreshData}
|
||||||
|
isRefreshing={isRefreshing || isFiltering}
|
||||||
|
rowCount={rowCount}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,16 @@
|
|||||||
import ConfirmDeleteDialog from "@app/components/ConfirmDeleteDialog";
|
import ConfirmDeleteDialog from "@app/components/ConfirmDeleteDialog";
|
||||||
import UptimeMiniBar from "@app/components/UptimeMiniBar";
|
import UptimeMiniBar from "@app/components/UptimeMiniBar";
|
||||||
|
|
||||||
|
import {
|
||||||
|
Credenza,
|
||||||
|
CredenzaBody,
|
||||||
|
CredenzaContent,
|
||||||
|
CredenzaDescription,
|
||||||
|
CredenzaFooter,
|
||||||
|
CredenzaHeader,
|
||||||
|
CredenzaTitle
|
||||||
|
} from "@app/components/Credenza";
|
||||||
|
import SiteResourcesOverview from "@app/components/SiteResourcesOverview";
|
||||||
import { Badge } from "@app/components/ui/badge";
|
import { Badge } from "@app/components/ui/badge";
|
||||||
import { Button } from "@app/components/ui/button";
|
import { Button } from "@app/components/ui/button";
|
||||||
import {
|
import {
|
||||||
@@ -14,9 +24,9 @@ import {
|
|||||||
import { InfoPopup } from "@app/components/ui/info-popup";
|
import { InfoPopup } from "@app/components/ui/info-popup";
|
||||||
import { useEnvContext } from "@app/hooks/useEnvContext";
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
import { useNavigationContext } from "@app/hooks/useNavigationContext";
|
import { useNavigationContext } from "@app/hooks/useNavigationContext";
|
||||||
import { getNextSortOrder, getSortDirection } from "@app/lib/sortColumn";
|
|
||||||
import { toast } from "@app/hooks/useToast";
|
import { toast } from "@app/hooks/useToast";
|
||||||
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
||||||
|
import { getNextSortOrder, getSortDirection } from "@app/lib/sortColumn";
|
||||||
import { build } from "@server/build";
|
import { build } from "@server/build";
|
||||||
import { type PaginationState } from "@tanstack/react-table";
|
import { type PaginationState } from "@tanstack/react-table";
|
||||||
import {
|
import {
|
||||||
@@ -26,30 +36,35 @@ import {
|
|||||||
ArrowUpRight,
|
ArrowUpRight,
|
||||||
ChevronDown,
|
ChevronDown,
|
||||||
ChevronsUpDownIcon,
|
ChevronsUpDownIcon,
|
||||||
MoreHorizontal
|
MoreHorizontal,
|
||||||
|
PlusIcon
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { usePathname, useRouter } from "next/navigation";
|
import { usePathname, useRouter } from "next/navigation";
|
||||||
import { useState, useTransition, useEffect } from "react";
|
import {
|
||||||
|
startTransition,
|
||||||
|
useEffect,
|
||||||
|
useMemo,
|
||||||
|
useOptimistic,
|
||||||
|
useState,
|
||||||
|
useTransition
|
||||||
|
} from "react";
|
||||||
import { useDebouncedCallback } from "use-debounce";
|
import { useDebouncedCallback } from "use-debounce";
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
import { ColumnFilterButton } from "./ColumnFilterButton";
|
import { ColumnFilterButton } from "./ColumnFilterButton";
|
||||||
import SiteResourcesOverview from "@app/components/SiteResourcesOverview";
|
|
||||||
import {
|
|
||||||
Credenza,
|
|
||||||
CredenzaBody,
|
|
||||||
CredenzaContent,
|
|
||||||
CredenzaDescription,
|
|
||||||
CredenzaFooter,
|
|
||||||
CredenzaHeader,
|
|
||||||
CredenzaTitle
|
|
||||||
} from "@app/components/Credenza";
|
|
||||||
import {
|
import {
|
||||||
ControlledDataTable,
|
ControlledDataTable,
|
||||||
type ExtendedColumnDef
|
type ExtendedColumnDef
|
||||||
} from "./ui/controlled-data-table";
|
} from "./ui/controlled-data-table";
|
||||||
|
|
||||||
|
import { usePaidStatus } from "@app/hooks/usePaidStatus";
|
||||||
|
import { cn } from "@app/lib/cn";
|
||||||
|
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
||||||
|
import { LabelBadge } from "./label-badge";
|
||||||
|
import { LabelsSelector, type SelectedLabel } from "./labels-selector";
|
||||||
|
import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover";
|
||||||
|
|
||||||
export type SiteRow = {
|
export type SiteRow = {
|
||||||
id: number;
|
id: number;
|
||||||
nice: string;
|
nice: string;
|
||||||
@@ -66,6 +81,11 @@ export type SiteRow = {
|
|||||||
exitNodeEndpoint?: string;
|
exitNodeEndpoint?: string;
|
||||||
remoteExitNodeId?: string;
|
remoteExitNodeId?: string;
|
||||||
resourceCount: number;
|
resourceCount: number;
|
||||||
|
labels?: Array<{
|
||||||
|
labelId: number;
|
||||||
|
name: string;
|
||||||
|
color: string;
|
||||||
|
}>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type SitesTableProps = {
|
type SitesTableProps = {
|
||||||
@@ -96,6 +116,9 @@ export default function SitesTable({
|
|||||||
const [isRefreshing, startTransition] = useTransition();
|
const [isRefreshing, startTransition] = useTransition();
|
||||||
const [isNavigatingToAddPage, startNavigation] = useTransition();
|
const [isNavigatingToAddPage, startNavigation] = useTransition();
|
||||||
|
|
||||||
|
const { isPaidUser } = usePaidStatus();
|
||||||
|
const isLabelFeatureEnabled = isPaidUser(tierMatrix.labels);
|
||||||
|
|
||||||
const api = createApiClient(useEnvContext());
|
const api = createApiClient(useEnvContext());
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
|
|
||||||
@@ -158,7 +181,8 @@ export default function SitesTable({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const columns: ExtendedColumnDef<SiteRow>[] = [
|
const columns = useMemo<ExtendedColumnDef<SiteRow>[]>(() => {
|
||||||
|
const cols: ExtendedColumnDef<SiteRow>[] = [
|
||||||
{
|
{
|
||||||
accessorKey: "name",
|
accessorKey: "name",
|
||||||
enableHiding: false,
|
enableHiding: false,
|
||||||
@@ -366,7 +390,7 @@ export default function SitesTable({
|
|||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => setResourcesDialogSite(siteRow)}
|
onClick={() => setResourcesDialogSite(siteRow)}
|
||||||
className="flex h-8 items-center gap-2 px-0 font-normal"
|
className="flex h-8 items-center gap-2 px-2 font-normal"
|
||||||
>
|
>
|
||||||
<span className="text-sm tabular-nums">
|
<span className="text-sm tabular-nums">
|
||||||
{siteRow.resourceCount} {t("resources")}
|
{siteRow.resourceCount} {t("resources")}
|
||||||
@@ -437,7 +461,7 @@ export default function SitesTable({
|
|||||||
header: () => {
|
header: () => {
|
||||||
return <span className="p-3">{t("address")}</span>;
|
return <span className="p-3">{t("address")}</span>;
|
||||||
},
|
},
|
||||||
cell: ({ row }: { row: any }) => {
|
cell: ({ row }) => {
|
||||||
const originalRow = row.original;
|
const originalRow = row.original;
|
||||||
return originalRow.address ? (
|
return originalRow.address ? (
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
@@ -488,16 +512,6 @@ export default function SitesTable({
|
|||||||
{t("sitesTableViewPrivateResources")}
|
{t("sitesTableViewPrivateResources")}
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</Link>
|
</Link>
|
||||||
<DropdownMenuItem
|
|
||||||
onClick={() => {
|
|
||||||
setSelectedSite(siteRow);
|
|
||||||
setIsDeleteModalOpen(true);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span className="text-red-500">
|
|
||||||
{t("delete")}
|
|
||||||
</span>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
<Link
|
<Link
|
||||||
@@ -512,7 +526,24 @@ export default function SitesTable({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (isLabelFeatureEnabled) {
|
||||||
|
cols.splice(cols.length - 1, 0, {
|
||||||
|
accessorKey: "labels",
|
||||||
|
header: () => (
|
||||||
|
<span className="p-3 text-end w-full inline-block">
|
||||||
|
{t("labels")}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
cell: ({ row }: { row: { original: SiteRow } }) => (
|
||||||
|
<SiteLabelCell site={row.original} orgId={orgId} />
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return cols;
|
||||||
|
}, [isLabelFeatureEnabled, orgId, t, searchParams]);
|
||||||
|
|
||||||
function toggleSort(column: string) {
|
function toggleSort(column: string) {
|
||||||
const newSearch = getNextSortOrder(column, searchParams);
|
const newSearch = getNextSortOrder(column, searchParams);
|
||||||
@@ -622,7 +653,8 @@ export default function SitesTable({
|
|||||||
niceId: false,
|
niceId: false,
|
||||||
nice: false,
|
nice: false,
|
||||||
exitNode: false,
|
exitNode: false,
|
||||||
address: false
|
address: false,
|
||||||
|
labels: false
|
||||||
}}
|
}}
|
||||||
enableColumnVisibility
|
enableColumnVisibility
|
||||||
stickyLeftColumn="name"
|
stickyLeftColumn="name"
|
||||||
@@ -631,3 +663,102 @@ export default function SitesTable({
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SiteLabelCellProps = {
|
||||||
|
site: SiteRow;
|
||||||
|
orgId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function SiteLabelCell({ site, orgId }: SiteLabelCellProps) {
|
||||||
|
const t = useTranslations();
|
||||||
|
|
||||||
|
const api = createApiClient(useEnvContext());
|
||||||
|
|
||||||
|
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const labels = site.labels ?? [];
|
||||||
|
const [optimisticLabels, setOptimisticLabels] = useOptimistic(labels);
|
||||||
|
|
||||||
|
function toggleSiteLabel(
|
||||||
|
label: SelectedLabel,
|
||||||
|
action: "attach" | "detach"
|
||||||
|
) {
|
||||||
|
startTransition(async () => {
|
||||||
|
try {
|
||||||
|
if (action === "attach") {
|
||||||
|
setOptimisticLabels([...optimisticLabels, label]);
|
||||||
|
|
||||||
|
await api.put(
|
||||||
|
`/org/${orgId}/label/${label.labelId}/attach`,
|
||||||
|
{ siteId: site.id }
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setOptimisticLabels(
|
||||||
|
optimisticLabels.filter(
|
||||||
|
(lb) => lb.labelId !== label.labelId
|
||||||
|
)
|
||||||
|
);
|
||||||
|
await api.put(
|
||||||
|
`/org/${orgId}/label/${label.labelId}/detach`,
|
||||||
|
{ siteId: site.id }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
toast({
|
||||||
|
title: t("error"),
|
||||||
|
description: formatAxiosError(e, t("errorOccurred")),
|
||||||
|
variant: "destructive"
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
router.refresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="inline-flex flex-wrap items-center justify-end w-full gap-1">
|
||||||
|
{optimisticLabels.slice(0, 3).map((label) => (
|
||||||
|
<LabelBadge
|
||||||
|
key={label.labelId}
|
||||||
|
onClick={() => setIsPopoverOpen(true)}
|
||||||
|
{...label}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
{optimisticLabels.length > 3 && (
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className={cn(
|
||||||
|
"inline-flex gap-1 items-center",
|
||||||
|
"rounded-full text-sm cursor-pointer",
|
||||||
|
"px-1.5 py-0 h-auto"
|
||||||
|
)}
|
||||||
|
onClick={() => setIsPopoverOpen(true)}
|
||||||
|
>
|
||||||
|
+{optimisticLabels.length - 3}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Popover open={isPopoverOpen} onOpenChange={setIsPopoverOpen}>
|
||||||
|
<PopoverTrigger asChild>
|
||||||
|
<Button
|
||||||
|
size="icon"
|
||||||
|
variant="outline"
|
||||||
|
className="p-1 size-auto rounded-full"
|
||||||
|
title={t("addLabels")}
|
||||||
|
>
|
||||||
|
<span className="sr-only">{t("addLabels")}</span>
|
||||||
|
<PlusIcon className="size-3" />
|
||||||
|
</Button>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent align="center" className="p-0 w-full">
|
||||||
|
<LabelsSelector
|
||||||
|
orgId={orgId}
|
||||||
|
selectedLabels={optimisticLabels}
|
||||||
|
toggleLabel={toggleSiteLabel}
|
||||||
|
/>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
40
src/components/label-badge.tsx
Normal file
40
src/components/label-badge.tsx
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import { cn } from "@app/lib/cn";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
|
||||||
|
export type LabelBadgeProps = {
|
||||||
|
name: string;
|
||||||
|
color: string;
|
||||||
|
onClick?: () => void;
|
||||||
|
className?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function LabelBadge({
|
||||||
|
onClick,
|
||||||
|
name,
|
||||||
|
color,
|
||||||
|
className
|
||||||
|
}: LabelBadgeProps) {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={onClick}
|
||||||
|
className={cn(
|
||||||
|
"inline-flex gap-1 items-center",
|
||||||
|
"rounded-full text-sm cursor-pointer",
|
||||||
|
"pl-1.5 pr-2 py-0 h-auto",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="size-3 rounded-full bg-(--color) flex-none"
|
||||||
|
style={{
|
||||||
|
// @ts-expect-error css color
|
||||||
|
"--color": color
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<span className="whitespace-nowrap text-ellipsis max-w-16 overflow-hidden relative">
|
||||||
|
{name}
|
||||||
|
</span>
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
236
src/components/labels-selector.tsx
Normal file
236
src/components/labels-selector.tsx
Normal file
@@ -0,0 +1,236 @@
|
|||||||
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
|
import { toast } from "@app/hooks/useToast";
|
||||||
|
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
||||||
|
import { orgQueries } from "@app/lib/queries";
|
||||||
|
import type { CreateOrEditLabelResponse } from "@server/routers/labels/types";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import type { AxiosResponse } from "axios";
|
||||||
|
import { useTranslations } from "next-intl";
|
||||||
|
import { useActionState, useMemo, useState } from "react";
|
||||||
|
import { useDebounce } from "use-debounce";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import { Checkbox } from "./ui/checkbox";
|
||||||
|
import {
|
||||||
|
Command,
|
||||||
|
CommandEmpty,
|
||||||
|
CommandGroup,
|
||||||
|
CommandInput,
|
||||||
|
CommandItem,
|
||||||
|
CommandList
|
||||||
|
} from "./ui/command";
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue
|
||||||
|
} from "./ui/select";
|
||||||
|
|
||||||
|
export type SelectedLabel = {
|
||||||
|
name: string;
|
||||||
|
color: string;
|
||||||
|
labelId: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type LabelsSelectorProps = {
|
||||||
|
orgId: string;
|
||||||
|
selectedLabels: SelectedLabel[];
|
||||||
|
toggleLabel: (newlabel: SelectedLabel, action: "detach" | "attach") => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const LABEL_COLORS = {
|
||||||
|
red: "#ff6467",
|
||||||
|
green: "#05df72",
|
||||||
|
blue: "#51a2ff",
|
||||||
|
yellow: "#fdc744",
|
||||||
|
orange: "#ff8905",
|
||||||
|
purple: "#a684ff",
|
||||||
|
gray: "#b4b4b4"
|
||||||
|
};
|
||||||
|
|
||||||
|
export function LabelsSelector({
|
||||||
|
orgId,
|
||||||
|
selectedLabels,
|
||||||
|
toggleLabel
|
||||||
|
}: LabelsSelectorProps) {
|
||||||
|
const t = useTranslations();
|
||||||
|
const [labelSearchQuery, setlabelsSearchQuery] = useState("");
|
||||||
|
const [debouncedQuery] = useDebounce(labelSearchQuery, 150);
|
||||||
|
|
||||||
|
const api = createApiClient(useEnvContext());
|
||||||
|
|
||||||
|
const { data: labels = [] } = useQuery(
|
||||||
|
orgQueries.labels({
|
||||||
|
orgId,
|
||||||
|
query: debouncedQuery,
|
||||||
|
perPage: 10
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const labelsShown = useMemo(() => {
|
||||||
|
const base = [...labels];
|
||||||
|
if (debouncedQuery.trim().length === 0 && selectedLabels.length > 0) {
|
||||||
|
const selectedNotInBase = selectedLabels.filter(
|
||||||
|
(sel) => !base.some((s) => s.labelId === sel.labelId)
|
||||||
|
);
|
||||||
|
return [...selectedNotInBase, ...base];
|
||||||
|
}
|
||||||
|
return base;
|
||||||
|
}, [debouncedQuery, labels, selectedLabels]);
|
||||||
|
|
||||||
|
const selectedIds = useMemo(
|
||||||
|
() => new Set(selectedLabels.map((s) => s.labelId)),
|
||||||
|
[selectedLabels]
|
||||||
|
);
|
||||||
|
|
||||||
|
const colorValues = Object.values(LABEL_COLORS);
|
||||||
|
const randomColor =
|
||||||
|
colorValues[Math.floor(Math.random() * colorValues.length)];
|
||||||
|
|
||||||
|
const [, action, isPending] = useActionState(createLabel, null);
|
||||||
|
|
||||||
|
async function createLabel(_: any, formData: FormData) {
|
||||||
|
const name = formData.get("name")?.toString();
|
||||||
|
const color = formData.get("color")?.toString();
|
||||||
|
try {
|
||||||
|
const res = await api.post<
|
||||||
|
AxiosResponse<CreateOrEditLabelResponse>
|
||||||
|
>(`/org/${orgId}/labels`, { name, color });
|
||||||
|
|
||||||
|
const { label } = res.data.data;
|
||||||
|
|
||||||
|
toggleLabel(
|
||||||
|
{
|
||||||
|
labelId: label.labelId,
|
||||||
|
name: label.name,
|
||||||
|
color: label.color
|
||||||
|
},
|
||||||
|
"attach"
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
toast({
|
||||||
|
title: t("error"),
|
||||||
|
description: formatAxiosError(e, t("errorOccurred")),
|
||||||
|
variant: "destructive"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
setlabelsSearchQuery("");
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Command shouldFilter={false}>
|
||||||
|
<CommandInput
|
||||||
|
placeholder={t("labelSearch")}
|
||||||
|
value={labelSearchQuery}
|
||||||
|
onValueChange={setlabelsSearchQuery}
|
||||||
|
/>
|
||||||
|
<CommandList>
|
||||||
|
<CommandEmpty className="px-3 break-all wrap-anywhere text-wrap">
|
||||||
|
{labelSearchQuery.trim().length > 0 ? (
|
||||||
|
<div className="flex flex-col gap-2 items-center">
|
||||||
|
<span className="max-w-34">
|
||||||
|
{t("createNewLabel", {
|
||||||
|
label: labelSearchQuery.trim()
|
||||||
|
})}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<form
|
||||||
|
action={action}
|
||||||
|
className="flex items-center gap-2"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="hidden"
|
||||||
|
name="name"
|
||||||
|
value={labelSearchQuery.trim()}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Select defaultValue={randomColor} name="color">
|
||||||
|
<SelectTrigger className="w-18 [&_[data-name]]:hidden [&_[svg]]:hidden!">
|
||||||
|
<SelectValue
|
||||||
|
placeholder={t("selectColor")}
|
||||||
|
/>
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{Object.entries(LABEL_COLORS).map(
|
||||||
|
([color, value]) => (
|
||||||
|
<SelectItem
|
||||||
|
value={value}
|
||||||
|
key={color}
|
||||||
|
className="flex items-center gap-2"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="size-4 rounded-full bg-(--color) flex-none"
|
||||||
|
style={{
|
||||||
|
// @ts-expect-error css color
|
||||||
|
"--color": value
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<span data-name>
|
||||||
|
{color}
|
||||||
|
</span>
|
||||||
|
</SelectItem>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
loading={isPending}
|
||||||
|
type="submit"
|
||||||
|
>
|
||||||
|
{t("create")}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
t("labelsNotFound")
|
||||||
|
)}
|
||||||
|
</CommandEmpty>
|
||||||
|
<CommandGroup>
|
||||||
|
{labelsShown.map((label) => (
|
||||||
|
<CommandItem
|
||||||
|
key={label.labelId}
|
||||||
|
value={`${label.labelId}`}
|
||||||
|
onSelect={() => {
|
||||||
|
toggleLabel(
|
||||||
|
label,
|
||||||
|
selectedIds.has(label.labelId)
|
||||||
|
? "detach"
|
||||||
|
: "attach"
|
||||||
|
);
|
||||||
|
// } else {
|
||||||
|
// onSelectionChange([
|
||||||
|
// ...selectedLabels,
|
||||||
|
// label
|
||||||
|
// ]);
|
||||||
|
// }
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Checkbox
|
||||||
|
className="pointer-events-none shrink-0"
|
||||||
|
checked={selectedIds.has(label.labelId)}
|
||||||
|
onCheckedChange={() => {}}
|
||||||
|
aria-hidden
|
||||||
|
tabIndex={-1}
|
||||||
|
/>
|
||||||
|
<div className="min-w-0 flex-1 flex items-center gap-2">
|
||||||
|
<span
|
||||||
|
className="inline-block size-3 flex-none rounded-full bg-(--label-color)"
|
||||||
|
style={{
|
||||||
|
// @ts-expect-error CSS variable
|
||||||
|
"--label-color": label.color
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<span className="min-w-0 flex-1 truncate">
|
||||||
|
{label.name}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</CommandItem>
|
||||||
|
))}
|
||||||
|
</CommandGroup>
|
||||||
|
</CommandList>
|
||||||
|
</Command>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -41,7 +41,7 @@ export function MultiSelectTagInput<T extends TagValue>({
|
|||||||
variant: "outline"
|
variant: "outline"
|
||||||
}),
|
}),
|
||||||
"justify-between w-full inline-flex",
|
"justify-between w-full inline-flex",
|
||||||
"text-muted-foreground pl-1.5 cursor-text",
|
"text-muted-foreground pl-1.5 cursor-text h-auto py-1",
|
||||||
"hover:bg-transparent hover:text-muted-foreground",
|
"hover:bg-transparent hover:text-muted-foreground",
|
||||||
props.disabled && "pointer-events-none opacity-50"
|
props.disabled && "pointer-events-none opacity-50"
|
||||||
)}
|
)}
|
||||||
@@ -49,7 +49,7 @@ export function MultiSelectTagInput<T extends TagValue>({
|
|||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
"inline-flex items-center gap-1",
|
"inline-flex items-center gap-1",
|
||||||
"overflow-x-auto"
|
"overflow-x-auto flex-wrap h-auto"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{props.value.map((option) => (
|
{props.value.map((option) => (
|
||||||
@@ -61,7 +61,9 @@ export function MultiSelectTagInput<T extends TagValue>({
|
|||||||
)}
|
)}
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
>
|
>
|
||||||
{option.text}
|
<span className="max-w-40 text-ellipsis overflow-hidden">
|
||||||
|
{option.text}
|
||||||
|
</span>
|
||||||
<button
|
<button
|
||||||
className="p-0.5 flex-none cursor-pointer"
|
className="p-0.5 flex-none cursor-pointer"
|
||||||
type="button"
|
type="button"
|
||||||
|
|||||||
@@ -305,6 +305,7 @@ export function ControlledDataTable<TData, TValue>({
|
|||||||
onSearch(e.currentTarget.value)
|
onSearch(e.currentTarget.value)
|
||||||
}
|
}
|
||||||
className="w-full pl-8"
|
className="w-full pl-8"
|
||||||
|
type="search"
|
||||||
/>
|
/>
|
||||||
<Search className="h-4 w-4 absolute left-2 top-1/2 transform -translate-y-1/2 text-muted-foreground" />
|
<Search className="h-4 w-4 absolute left-2 top-1/2 transform -translate-y-1/2 text-muted-foreground" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import { remote } from "./api";
|
|||||||
import { durationToMs } from "./durationToMs";
|
import { durationToMs } from "./durationToMs";
|
||||||
import { ListHealthChecksResponse } from "@server/routers/healthChecks/types";
|
import { ListHealthChecksResponse } from "@server/routers/healthChecks/types";
|
||||||
import { StatusHistoryResponse } from "@server/lib/statusHistory";
|
import { StatusHistoryResponse } from "@server/lib/statusHistory";
|
||||||
|
import type { ListOrgLabelsResponse } from "@server/routers/labels/types";
|
||||||
|
|
||||||
export type ProductUpdate = {
|
export type ProductUpdate = {
|
||||||
link: string | null;
|
link: string | null;
|
||||||
@@ -208,6 +209,33 @@ export const orgQueries = {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
labels: ({
|
||||||
|
orgId,
|
||||||
|
query,
|
||||||
|
perPage = 10_000
|
||||||
|
}: {
|
||||||
|
orgId: string;
|
||||||
|
query?: string;
|
||||||
|
perPage?: number;
|
||||||
|
}) =>
|
||||||
|
queryOptions({
|
||||||
|
queryKey: ["ORG", orgId, "LABELS", { query, perPage }] as const,
|
||||||
|
queryFn: async ({ signal, meta }) => {
|
||||||
|
const sp = new URLSearchParams({
|
||||||
|
pageSize: perPage.toString()
|
||||||
|
});
|
||||||
|
|
||||||
|
if (query?.trim()) {
|
||||||
|
sp.set("query", query);
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await meta!.api.get<
|
||||||
|
AxiosResponse<ListOrgLabelsResponse>
|
||||||
|
>(`/org/${orgId}/labels?${sp.toString()}`, { signal });
|
||||||
|
return res.data.data.labels;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
domains: ({ orgId }: { orgId: string }) =>
|
domains: ({ orgId }: { orgId: string }) =>
|
||||||
queryOptions({
|
queryOptions({
|
||||||
queryKey: ["ORG", orgId, "DOMAINS"] as const,
|
queryKey: ["ORG", orgId, "DOMAINS"] as const,
|
||||||
|
|||||||
Reference in New Issue
Block a user