Dashboard Update
This commit is contained in:
1 parent
6165f2d4f3
commit
676283cce9
17 files changed
+4280
-213
No files matched your search
@@ -56,6 +56,65 @@ export const supportbotSchema: ConfigSchema = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Database",
|
||||
fields: [
|
||||
{
|
||||
path: "Database.Driver",
|
||||
label: "Database Engine",
|
||||
type: "select",
|
||||
options: [
|
||||
{ value: "sqlite", label: "SQLite (Local File)" },
|
||||
{ value: "mysql", label: "MySQL / MariaDB" },
|
||||
],
|
||||
description: "Select SQLite for zero-config file storage, or MySQL for external host servers.",
|
||||
},
|
||||
{
|
||||
path: "Database.MySQL.Host",
|
||||
label: "MySQL Host",
|
||||
type: "text",
|
||||
placeholder: "127.0.0.1 or localhost",
|
||||
description: "Hostname or IP address of your MySQL database server.",
|
||||
},
|
||||
{
|
||||
path: "Database.MySQL.Port",
|
||||
label: "MySQL Port",
|
||||
type: "number",
|
||||
placeholder: "3306",
|
||||
},
|
||||
{
|
||||
path: "Database.MySQL.Database",
|
||||
label: "Database Name",
|
||||
type: "text",
|
||||
placeholder: "supportbot",
|
||||
},
|
||||
{
|
||||
path: "Database.MySQL.User",
|
||||
label: "Database User",
|
||||
type: "text",
|
||||
placeholder: "root",
|
||||
},
|
||||
{
|
||||
path: "Database.MySQL.Password",
|
||||
label: "Database Password",
|
||||
type: "secret",
|
||||
placeholder: "••••••••••••",
|
||||
},
|
||||
{
|
||||
path: "Database.MySQL.ConnectionLimit",
|
||||
label: "Connection Pool Limit",
|
||||
type: "number",
|
||||
placeholder: "10",
|
||||
description: "Maximum simultaneous connections in the MySQL pool (default 10).",
|
||||
},
|
||||
{
|
||||
path: "Database.SQLite.File",
|
||||
label: "SQLite Database File Path",
|
||||
type: "text",
|
||||
placeholder: "./Data/supportbot.db",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Activity",
|
||||
fields: [
|
||||
@@ -382,6 +441,22 @@ export const supportbotSchema: ConfigSchema = [
|
||||
label: "AI welcome message",
|
||||
type: "textarea",
|
||||
},
|
||||
{
|
||||
path: "Ticket.Questions.Enabled",
|
||||
label: "Ticket questions",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Ticket.Questions.List",
|
||||
label: "Default questions",
|
||||
type: "stringList",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Ticket Departments",
|
||||
description: "Configure ticket department channels, emojis, staff roles, and custom department questions.",
|
||||
fields: [
|
||||
{
|
||||
path: "Ticket.DepartmentSystem.Enabled",
|
||||
label: "Departments enabled",
|
||||
@@ -397,6 +472,12 @@ export const supportbotSchema: ConfigSchema = [
|
||||
label: "Default department key",
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Ticket Priorities",
|
||||
description: "Configure ticket priority levels and emojis.",
|
||||
fields: [
|
||||
{
|
||||
path: "Ticket.PrioritySystem.Enabled",
|
||||
label: "Priority system",
|
||||
@@ -412,16 +493,6 @@ export const supportbotSchema: ConfigSchema = [
|
||||
label: "User picks priority on open",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Ticket.Questions.Enabled",
|
||||
label: "Ticket questions",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
path: "Ticket.Questions.List",
|
||||
label: "Default questions",
|
||||
type: "stringList",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -14,6 +14,7 @@ function inferFieldType(key: string, value: unknown): FieldType {
|
||||
|
||||
if (typeof value === "string") {
|
||||
const k = key.toLowerCase();
|
||||
if (/prefix/.test(k)) return "text";
|
||||
if (/emoji/.test(k)) return "emoji";
|
||||
if (/guild.?id|guild_id/.test(k)) return "discordId";
|
||||
if (/category/.test(k)) return "discordCategory";
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import type { ConfigField, ConfigSchema } from "@/lib/config-schemas";
|
||||
import { collectConfigFields } from "@/lib/generic-config-schema";
|
||||
|
||||
function labelFromTopKey(key: string): string {
|
||||
return key
|
||||
function sectionTitleFromPath(path: string): string {
|
||||
if (path.startsWith("Ticket.DepartmentSystem.")) return "Ticket Departments";
|
||||
if (path.startsWith("Ticket.PrioritySystem.")) return "Ticket Priorities";
|
||||
if (path.startsWith("Ticket.")) return "Tickets";
|
||||
const top = path.split(".")[0] ?? "Other";
|
||||
return top
|
||||
.replace(/_/g, " ")
|
||||
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
||||
.replace(/\b\w/g, (c) => c.toUpperCase());
|
||||
@@ -18,22 +22,34 @@ export function mergeSchemaWithData(
|
||||
|
||||
if (discovered.length === 0) return schema;
|
||||
|
||||
const byTop = new Map<string, ConfigField[]>();
|
||||
const result: ConfigSchema = schema.map((sec) => ({
|
||||
...sec,
|
||||
fields: [...sec.fields],
|
||||
}));
|
||||
|
||||
const bySection = new Map<string, ConfigField[]>();
|
||||
for (const field of discovered) {
|
||||
const top = field.path.split(".")[0] ?? "Other";
|
||||
const list = byTop.get(top) ?? [];
|
||||
const title = sectionTitleFromPath(field.path);
|
||||
const list = bySection.get(title) ?? [];
|
||||
list.push(field);
|
||||
byTop.set(top, list);
|
||||
bySection.set(title, list);
|
||||
}
|
||||
|
||||
const extraSections = [...byTop.entries()]
|
||||
.sort(([a], [b]) => a.localeCompare(b))
|
||||
.map(([top, fields]) => ({
|
||||
title: labelFromTopKey(top),
|
||||
description:
|
||||
"These options exist in your config file but are not in the main editor sections.",
|
||||
fields: fields.sort((a, b) => a.path.localeCompare(b.path)),
|
||||
}));
|
||||
for (const [title, fields] of bySection.entries()) {
|
||||
const existing = result.find(
|
||||
(s) => s.title.toLowerCase() === title.toLowerCase()
|
||||
);
|
||||
|
||||
return [...schema, ...extraSections];
|
||||
if (existing) {
|
||||
existing.fields.push(...fields);
|
||||
} else {
|
||||
result.push({
|
||||
title,
|
||||
description: "These options exist in your config file but are not in the main editor sections.",
|
||||
fields: fields.sort((a, b) => a.path.localeCompare(b.path)),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -26,6 +26,7 @@ export interface DashboardPermissions {
|
||||
tickets: boolean;
|
||||
logs: boolean;
|
||||
transcripts: boolean;
|
||||
rawYaml?: boolean;
|
||||
settings: { view: boolean; update: boolean };
|
||||
configs: Record<ConfigFile, ConfigFilePermission>;
|
||||
users: { view: boolean; manage: boolean };
|
||||
@@ -97,6 +98,9 @@ export function hasPermission(
|
||||
if (key === "tickets") return permissions.tickets ?? permissions.overview;
|
||||
if (key === "logs") return permissions.logs;
|
||||
if (key === "transcripts") return permissions.transcripts;
|
||||
if (key === "rawYaml" || key === "configs.raw_yaml" || key === "configs.rawYaml") {
|
||||
return Boolean(permissions.rawYaml ?? (permissions.configs as unknown as Record<string, boolean>)?.rawYaml ?? false);
|
||||
}
|
||||
if (key === "settings.view") return permissions.settings.view;
|
||||
if (key === "settings.update") return permissions.settings.update;
|
||||
if (key === "users.view") return permissions.users.view;
|
||||
@@ -147,15 +151,19 @@ function configMap(view: boolean, edit: boolean): Record<ConfigFile, ConfigFileP
|
||||
);
|
||||
}
|
||||
|
||||
export function fullPermissions(): DashboardPermissions {
|
||||
export function fullPermissions(
|
||||
rawYaml: boolean = true,
|
||||
userManage: boolean = true,
|
||||
): DashboardPermissions {
|
||||
return {
|
||||
overview: true,
|
||||
tickets: true,
|
||||
logs: true,
|
||||
transcripts: true,
|
||||
rawYaml,
|
||||
settings: { view: true, update: true },
|
||||
configs: configMap(true, true),
|
||||
users: { view: true, manage: true },
|
||||
users: { view: true, manage: userManage },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -165,14 +173,16 @@ export function defaultPermissionsForRole(
|
||||
): DashboardPermissions {
|
||||
switch (role) {
|
||||
case "owner":
|
||||
return fullPermissions(true, true);
|
||||
case "admin":
|
||||
return fullPermissions();
|
||||
return fullPermissions(false, false);
|
||||
case "moderator":
|
||||
return {
|
||||
overview: true,
|
||||
tickets: true,
|
||||
logs: true,
|
||||
transcripts: true,
|
||||
rawYaml: false,
|
||||
settings: { view: true, update: false },
|
||||
configs: configMap(true, false),
|
||||
users: { view: false, manage: false },
|
||||
@@ -183,6 +193,7 @@ export function defaultPermissionsForRole(
|
||||
tickets: true,
|
||||
logs: true,
|
||||
transcripts: false,
|
||||
rawYaml: false,
|
||||
settings: { view: true, update: false },
|
||||
configs: configMap(true, true),
|
||||
users: { view: false, manage: false },
|
||||
@@ -193,6 +204,7 @@ export function defaultPermissionsForRole(
|
||||
tickets: true,
|
||||
logs: true,
|
||||
transcripts: true,
|
||||
rawYaml: false,
|
||||
settings: { view: true, update: false },
|
||||
configs: configMap(true, false),
|
||||
users: { view: false, manage: false },
|
||||
|
||||
@@ -30,6 +30,12 @@ export interface SetupValidateResponse {
|
||||
|
||||
export interface SetupFormValues {
|
||||
botToken: string;
|
||||
dbDriver: "sqlite" | "mysql";
|
||||
dbHost: string;
|
||||
dbPort: string;
|
||||
dbUser: string;
|
||||
dbPassword: string;
|
||||
dbDatabase: string;
|
||||
secretKey: string;
|
||||
clientId: string;
|
||||
clientSecret: string;
|
||||
|
||||
Reference in new issue
Block a user