mirror of
https://github.com/docmost/docmost.git
synced 2026-08-26 00:07:04 +08:00
Merge branch 'main' into feat/lightbox-media-display
This commit is contained in:
@@ -18,6 +18,15 @@ RUN apt-get update \
|
|||||||
&& apt-get install -y --no-install-recommends curl bash \
|
&& apt-get install -y --no-install-recommends curl bash \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# drop npm and corepack
|
||||||
|
RUN rm -rf /usr/local/lib/node_modules/npm \
|
||||||
|
&& rm -rf /usr/local/lib/node_modules/corepack \
|
||||||
|
&& rm -rf /usr/local/bin/npm \
|
||||||
|
&& rm -rf /usr/local/bin/npx \
|
||||||
|
&& rm -rf /usr/local/bin/corepack \
|
||||||
|
&& rm -rf /root/.npm \
|
||||||
|
&& rm -rf /root/.node-gyp
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy apps
|
# Copy apps
|
||||||
|
|||||||
@@ -696,7 +696,7 @@
|
|||||||
"Upgrade your plan": "Upgrade Ihres Plans",
|
"Upgrade your plan": "Upgrade Ihres Plans",
|
||||||
"Available with a paid license": "Verfügbar mit einer kostenpflichtigen Lizenz",
|
"Available with a paid license": "Verfügbar mit einer kostenpflichtigen Lizenz",
|
||||||
"Upgrade your license tier.": "Stufen Sie Ihre Lizenz hoch.",
|
"Upgrade your license tier.": "Stufen Sie Ihre Lizenz hoch.",
|
||||||
"AI is only available in the Docmost enterprise edition. Contact sales@docmost.com.": "KI ist nur in der Docmost Enterprise-Edition verfügbar. Kontaktieren Sie sales@docmost.com.",
|
"AI is available in the Docmost paid editions. Contact sales@docmost.com.": "KI ist in den kostenpflichtigen Docmost-Editionen verfügbar. Kontaktieren Sie sales@docmost.com.",
|
||||||
"AI & MCP": "KI & MCP",
|
"AI & MCP": "KI & MCP",
|
||||||
"AI": "KI",
|
"AI": "KI",
|
||||||
"MCP": "MCP",
|
"MCP": "MCP",
|
||||||
|
|||||||
@@ -701,7 +701,7 @@
|
|||||||
"Upgrade your plan": "Upgrade your plan",
|
"Upgrade your plan": "Upgrade your plan",
|
||||||
"Available with a paid license": "Available with a paid license",
|
"Available with a paid license": "Available with a paid license",
|
||||||
"Upgrade your license tier.": "Upgrade your license tier.",
|
"Upgrade your license tier.": "Upgrade your license tier.",
|
||||||
"AI is only available in the Docmost enterprise edition. Contact sales@docmost.com.": "AI is only available in the Docmost enterprise edition. Contact sales@docmost.com.",
|
"AI is available in the Docmost paid editions. Contact sales@docmost.com.": "AI is available in the Docmost paid editions. Contact sales@docmost.com.",
|
||||||
"AI & MCP": "AI & MCP",
|
"AI & MCP": "AI & MCP",
|
||||||
"AI": "AI",
|
"AI": "AI",
|
||||||
"MCP": "MCP",
|
"MCP": "MCP",
|
||||||
@@ -1305,5 +1305,13 @@
|
|||||||
"Error loading attachments.": "Error loading attachments.",
|
"Error loading attachments.": "Error loading attachments.",
|
||||||
"No attachments on this page yet.": "No attachments on this page yet.",
|
"No attachments on this page yet.": "No attachments on this page yet.",
|
||||||
"Uploaded by {{name}}": "Uploaded by {{name}}",
|
"Uploaded by {{name}}": "Uploaded by {{name}}",
|
||||||
"Download {{name}}": "Download {{name}}"
|
"Download {{name}}": "Download {{name}}",
|
||||||
|
"Workspace knowledge only": "Workspace knowledge only",
|
||||||
|
"Restrict AI Chat to answering from your workspace pages and uploaded files only. It will not use outside knowledge.": "Restrict AI Chat to answering from your workspace pages and uploaded files only. It will not use outside knowledge.",
|
||||||
|
"Toggle workspace knowledge only": "Toggle workspace knowledge only",
|
||||||
|
"Read-only mode": "Read-only mode",
|
||||||
|
"AI Chat can search and read workspace content, but cannot create or edit pages.": "AI Chat can search and read workspace content, but cannot create or edit pages.",
|
||||||
|
"Toggle AI Chat read-only mode": "Toggle AI Chat read-only mode",
|
||||||
|
"Title only": "Title only",
|
||||||
|
"you": "you"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -696,7 +696,7 @@
|
|||||||
"Upgrade your plan": "Mejora tu plan",
|
"Upgrade your plan": "Mejora tu plan",
|
||||||
"Available with a paid license": "Disponible con una licencia de pago",
|
"Available with a paid license": "Disponible con una licencia de pago",
|
||||||
"Upgrade your license tier.": "Mejora el nivel de tu licencia.",
|
"Upgrade your license tier.": "Mejora el nivel de tu licencia.",
|
||||||
"AI is only available in the Docmost enterprise edition. Contact sales@docmost.com.": "La IA solo está disponible en la edición empresarial de Docmost. Contacte con sales@docmost.com.",
|
"AI is available in the Docmost paid editions. Contact sales@docmost.com.": "La IA está disponible en las ediciones de pago de Docmost. Contacte con sales@docmost.com.",
|
||||||
"AI & MCP": "IA y MCP",
|
"AI & MCP": "IA y MCP",
|
||||||
"AI": "IA",
|
"AI": "IA",
|
||||||
"MCP": "MCP",
|
"MCP": "MCP",
|
||||||
|
|||||||
@@ -696,7 +696,7 @@
|
|||||||
"Upgrade your plan": "Mettez à niveau votre forfait",
|
"Upgrade your plan": "Mettez à niveau votre forfait",
|
||||||
"Available with a paid license": "Disponible avec une licence payante",
|
"Available with a paid license": "Disponible avec une licence payante",
|
||||||
"Upgrade your license tier.": "Mettez à niveau votre niveau de licence.",
|
"Upgrade your license tier.": "Mettez à niveau votre niveau de licence.",
|
||||||
"AI is only available in the Docmost enterprise edition. Contact sales@docmost.com.": "L'IA n'est disponible que dans l'édition Entreprise de Docmost. Contactez sales@docmost.com.",
|
"AI is available in the Docmost paid editions. Contact sales@docmost.com.": "L'IA est disponible dans les éditions payantes de Docmost. Contactez sales@docmost.com.",
|
||||||
"AI & MCP": "IA & MCP",
|
"AI & MCP": "IA & MCP",
|
||||||
"AI": "IA",
|
"AI": "IA",
|
||||||
"MCP": "MCP",
|
"MCP": "MCP",
|
||||||
|
|||||||
@@ -696,7 +696,7 @@
|
|||||||
"Upgrade your plan": "Aggiorna il tuo piano",
|
"Upgrade your plan": "Aggiorna il tuo piano",
|
||||||
"Available with a paid license": "Disponibile con una licenza a pagamento",
|
"Available with a paid license": "Disponibile con una licenza a pagamento",
|
||||||
"Upgrade your license tier.": "Aggiorna il livello della tua licenza.",
|
"Upgrade your license tier.": "Aggiorna il livello della tua licenza.",
|
||||||
"AI is only available in the Docmost enterprise edition. Contact sales@docmost.com.": "L'IA è disponibile solo nell'edizione Enterprise di Docmost. Contatta sales@docmost.com.",
|
"AI is available in the Docmost paid editions. Contact sales@docmost.com.": "L'IA è disponibile nelle edizioni a pagamento di Docmost. Contatta sales@docmost.com.",
|
||||||
"AI & MCP": "IA e MCP",
|
"AI & MCP": "IA e MCP",
|
||||||
"AI": "IA",
|
"AI": "IA",
|
||||||
"MCP": "MCP",
|
"MCP": "MCP",
|
||||||
|
|||||||
@@ -696,7 +696,7 @@
|
|||||||
"Upgrade your plan": "プランをアップグレードする",
|
"Upgrade your plan": "プランをアップグレードする",
|
||||||
"Available with a paid license": "有料ライセンスで利用可能",
|
"Available with a paid license": "有料ライセンスで利用可能",
|
||||||
"Upgrade your license tier.": "ライセンスタイアをアップグレードしてください。",
|
"Upgrade your license tier.": "ライセンスタイアをアップグレードしてください。",
|
||||||
"AI is only available in the Docmost enterprise edition. Contact sales@docmost.com.": "AI は Docmost のエンタープライズ版でのみ利用可能です。sales@docmost.com までお問い合わせください。",
|
"AI is available in the Docmost paid editions. Contact sales@docmost.com.": "AI は Docmost の有料版で利用可能です。sales@docmost.com までお問い合わせください。",
|
||||||
"AI & MCP": "AI と MCP",
|
"AI & MCP": "AI と MCP",
|
||||||
"AI": "AI",
|
"AI": "AI",
|
||||||
"MCP": "MCP",
|
"MCP": "MCP",
|
||||||
|
|||||||
@@ -696,7 +696,7 @@
|
|||||||
"Upgrade your plan": "요금제를 업그레이드하세요",
|
"Upgrade your plan": "요금제를 업그레이드하세요",
|
||||||
"Available with a paid license": "유료 라이선스에서만 사용 가능합니다",
|
"Available with a paid license": "유료 라이선스에서만 사용 가능합니다",
|
||||||
"Upgrade your license tier.": "라이선스 등급을 업그레이드하세요.",
|
"Upgrade your license tier.": "라이선스 등급을 업그레이드하세요.",
|
||||||
"AI is only available in the Docmost enterprise edition. Contact sales@docmost.com.": "AI는 Docmost 엔터프라이즈 에디션에서만 제공됩니다. sales@docmost.com으로 문의하세요.",
|
"AI is available in the Docmost paid editions. Contact sales@docmost.com.": "AI는 Docmost 유료 에디션에서 제공됩니다. sales@docmost.com으로 문의하세요.",
|
||||||
"AI & MCP": "AI 및 MCP",
|
"AI & MCP": "AI 및 MCP",
|
||||||
"AI": "AI",
|
"AI": "AI",
|
||||||
"MCP": "MCP",
|
"MCP": "MCP",
|
||||||
|
|||||||
@@ -696,7 +696,7 @@
|
|||||||
"Upgrade your plan": "Upgrade je abonnement",
|
"Upgrade your plan": "Upgrade je abonnement",
|
||||||
"Available with a paid license": "Beschikbaar met een betaalde licentie",
|
"Available with a paid license": "Beschikbaar met een betaalde licentie",
|
||||||
"Upgrade your license tier.": "Upgrade je licentieniveau.",
|
"Upgrade your license tier.": "Upgrade je licentieniveau.",
|
||||||
"AI is only available in the Docmost enterprise edition. Contact sales@docmost.com.": "AI is alleen beschikbaar in de Docmost Enterprise-editie. Neem contact op met sales@docmost.com.",
|
"AI is available in the Docmost paid editions. Contact sales@docmost.com.": "AI is beschikbaar in de betaalde edities van Docmost. Neem contact op met sales@docmost.com.",
|
||||||
"AI & MCP": "AI & MCP",
|
"AI & MCP": "AI & MCP",
|
||||||
"AI": "AI",
|
"AI": "AI",
|
||||||
"MCP": "MCP",
|
"MCP": "MCP",
|
||||||
|
|||||||
@@ -696,7 +696,7 @@
|
|||||||
"Upgrade your plan": "Faça upgrade do seu plano",
|
"Upgrade your plan": "Faça upgrade do seu plano",
|
||||||
"Available with a paid license": "Disponível com uma licença paga",
|
"Available with a paid license": "Disponível com uma licença paga",
|
||||||
"Upgrade your license tier.": "Faça upgrade do seu nível de licença.",
|
"Upgrade your license tier.": "Faça upgrade do seu nível de licença.",
|
||||||
"AI is only available in the Docmost enterprise edition. Contact sales@docmost.com.": "A IA está disponível apenas na edição empresarial do Docmost. Contate sales@docmost.com.",
|
"AI is available in the Docmost paid editions. Contact sales@docmost.com.": "A IA está disponível nas edições pagas do Docmost. Contate sales@docmost.com.",
|
||||||
"AI & MCP": "IA e MCP",
|
"AI & MCP": "IA e MCP",
|
||||||
"AI": "IA",
|
"AI": "IA",
|
||||||
"MCP": "MCP",
|
"MCP": "MCP",
|
||||||
|
|||||||
@@ -696,7 +696,7 @@
|
|||||||
"Upgrade your plan": "Обновите свой тарифный план",
|
"Upgrade your plan": "Обновите свой тарифный план",
|
||||||
"Available with a paid license": "Доступно с платной лицензией",
|
"Available with a paid license": "Доступно с платной лицензией",
|
||||||
"Upgrade your license tier.": "Обновите уровень вашей лицензии.",
|
"Upgrade your license tier.": "Обновите уровень вашей лицензии.",
|
||||||
"AI is only available in the Docmost enterprise edition. Contact sales@docmost.com.": "ИИ доступен только в корпоративной версии Docmost. Свяжитесь по адресу sales@docmost.com.",
|
"AI is available in the Docmost paid editions. Contact sales@docmost.com.": "ИИ доступен в платных версиях Docmost. Свяжитесь по адресу sales@docmost.com.",
|
||||||
"AI & MCP": "ИИ и MCP",
|
"AI & MCP": "ИИ и MCP",
|
||||||
"AI": "ИИ",
|
"AI": "ИИ",
|
||||||
"MCP": "MCP",
|
"MCP": "MCP",
|
||||||
|
|||||||
@@ -696,7 +696,7 @@
|
|||||||
"Upgrade your plan": "Оновіть свій тарифний план",
|
"Upgrade your plan": "Оновіть свій тарифний план",
|
||||||
"Available with a paid license": "Доступно за платною ліцензією",
|
"Available with a paid license": "Доступно за платною ліцензією",
|
||||||
"Upgrade your license tier.": "Оновіть рівень своєї ліцензії.",
|
"Upgrade your license tier.": "Оновіть рівень своєї ліцензії.",
|
||||||
"AI is only available in the Docmost enterprise edition. Contact sales@docmost.com.": "ШІ доступний лише в корпоративній редакції Docmost. Зверніться до sales@docmost.com.",
|
"AI is available in the Docmost paid editions. Contact sales@docmost.com.": "ШІ доступний у платних редакціях Docmost. Зверніться до sales@docmost.com.",
|
||||||
"AI & MCP": "ШІ та MCP",
|
"AI & MCP": "ШІ та MCP",
|
||||||
"AI": "ШІ",
|
"AI": "ШІ",
|
||||||
"MCP": "MCP",
|
"MCP": "MCP",
|
||||||
|
|||||||
@@ -696,7 +696,7 @@
|
|||||||
"Upgrade your plan": "升级您的方案",
|
"Upgrade your plan": "升级您的方案",
|
||||||
"Available with a paid license": "需付费许可才可用",
|
"Available with a paid license": "需付费许可才可用",
|
||||||
"Upgrade your license tier.": "升级您的许可等级。",
|
"Upgrade your license tier.": "升级您的许可等级。",
|
||||||
"AI is only available in the Docmost enterprise edition. Contact sales@docmost.com.": "AI 仅在 Docmost 企业版中提供。请联系 sales@docmost.com。",
|
"AI is available in the Docmost paid editions. Contact sales@docmost.com.": "AI 在 Docmost 付费版中提供。请联系 sales@docmost.com。",
|
||||||
"AI & MCP": "AI 与 MCP",
|
"AI & MCP": "AI 与 MCP",
|
||||||
"AI": "AI",
|
"AI": "AI",
|
||||||
"MCP": "MCP",
|
"MCP": "MCP",
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { UnstyledButton } from "@mantine/core";
|
||||||
|
import { type ComponentPropsWithoutRef, forwardRef } from "react";
|
||||||
|
|
||||||
|
// Menu.Item hard-codes role="menuitem"; use as its `component` to restore role="menuitemcheckbox" so aria-checked works.
|
||||||
|
export const CheckboxMenuItem = forwardRef<
|
||||||
|
HTMLButtonElement,
|
||||||
|
ComponentPropsWithoutRef<"button">
|
||||||
|
>((props, ref) => (
|
||||||
|
<UnstyledButton ref={ref} {...props} role="menuitemcheckbox" />
|
||||||
|
));
|
||||||
|
|
||||||
|
CheckboxMenuItem.displayName = "CheckboxMenuItem";
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
import { Badge, Group, Text, Switch, Tooltip } from "@mantine/core";
|
||||||
|
import { useAtom } from "jotai";
|
||||||
|
import { workspaceAtom } from "@/features/user/atoms/current-user-atom.ts";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { updateWorkspace } from "@/features/workspace/services/workspace-service.ts";
|
||||||
|
import { notifications } from "@mantine/notifications";
|
||||||
|
import { useHasFeature } from "@/ee/hooks/use-feature";
|
||||||
|
import { Feature } from "@/ee/features";
|
||||||
|
import { useUpgradeLabel } from "@/ee/hooks/use-upgrade-label";
|
||||||
|
|
||||||
|
export default function AiChatReadOnly() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const hasAccess = useHasFeature(Feature.AI_CONTROLS);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Group justify="space-between" wrap="nowrap" gap="xl">
|
||||||
|
<div>
|
||||||
|
<Group gap="xs" align="center">
|
||||||
|
<Text size="md">{t("Read-only mode")}</Text>
|
||||||
|
{!hasAccess && (
|
||||||
|
<Badge variant="light" size="sm" radius="sm">
|
||||||
|
{t("Enterprise")}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</Group>
|
||||||
|
<Text size="sm" c="dimmed">
|
||||||
|
{t(
|
||||||
|
"AI Chat can search and read workspace content, but cannot create or edit pages.",
|
||||||
|
)}
|
||||||
|
</Text>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<AiChatReadOnlyToggle />
|
||||||
|
</Group>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AiChatReadOnlyToggle() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [workspace, setWorkspace] = useAtom(workspaceAtom);
|
||||||
|
const [checked, setChecked] = useState(
|
||||||
|
workspace?.settings?.ai?.chatReadOnly,
|
||||||
|
);
|
||||||
|
const hasAccess = useHasFeature(Feature.AI_CONTROLS);
|
||||||
|
const upgradeLabel = useUpgradeLabel();
|
||||||
|
|
||||||
|
const handleChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const value = event.currentTarget.checked;
|
||||||
|
try {
|
||||||
|
const updatedWorkspace = await updateWorkspace({
|
||||||
|
aiChatReadOnly: value,
|
||||||
|
});
|
||||||
|
setChecked(value);
|
||||||
|
setWorkspace(updatedWorkspace);
|
||||||
|
} catch (err: any) {
|
||||||
|
notifications.show({
|
||||||
|
message: err?.response?.data?.message,
|
||||||
|
color: "red",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tooltip label={upgradeLabel} disabled={hasAccess} refProp="rootRef">
|
||||||
|
<Switch
|
||||||
|
defaultChecked={checked}
|
||||||
|
onChange={handleChange}
|
||||||
|
disabled={!hasAccess}
|
||||||
|
aria-label={t("Toggle AI Chat read-only mode")}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
import { Badge, Group, Text, Switch, Tooltip } from "@mantine/core";
|
||||||
|
import { useAtom } from "jotai";
|
||||||
|
import { workspaceAtom } from "@/features/user/atoms/current-user-atom.ts";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { updateWorkspace } from "@/features/workspace/services/workspace-service.ts";
|
||||||
|
import { notifications } from "@mantine/notifications";
|
||||||
|
import { useHasFeature } from "@/ee/hooks/use-feature";
|
||||||
|
import { Feature } from "@/ee/features";
|
||||||
|
import { useUpgradeLabel } from "@/ee/hooks/use-upgrade-label";
|
||||||
|
|
||||||
|
export default function AiChatWorkspaceKnowledgeOnly() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const hasAccess = useHasFeature(Feature.AI_CONTROLS);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Group justify="space-between" wrap="nowrap" gap="xl">
|
||||||
|
<div>
|
||||||
|
<Group gap="xs" align="center">
|
||||||
|
<Text size="md">{t("Workspace knowledge only")}</Text>
|
||||||
|
{!hasAccess && (
|
||||||
|
<Badge variant="light" size="sm" radius="sm">
|
||||||
|
{t("Enterprise")}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</Group>
|
||||||
|
<Text size="sm" c="dimmed">
|
||||||
|
{t(
|
||||||
|
"Restrict AI Chat to answering from your workspace pages and uploaded files only. It will not use outside knowledge.",
|
||||||
|
)}
|
||||||
|
</Text>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<AiChatWorkspaceKnowledgeOnlyToggle />
|
||||||
|
</Group>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AiChatWorkspaceKnowledgeOnlyToggle() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [workspace, setWorkspace] = useAtom(workspaceAtom);
|
||||||
|
const [checked, setChecked] = useState(
|
||||||
|
workspace?.settings?.ai?.chatWorkspaceKnowledgeOnly,
|
||||||
|
);
|
||||||
|
const hasAccess = useHasFeature(Feature.AI_CONTROLS);
|
||||||
|
const upgradeLabel = useUpgradeLabel();
|
||||||
|
|
||||||
|
const handleChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const value = event.currentTarget.checked;
|
||||||
|
try {
|
||||||
|
const updatedWorkspace = await updateWorkspace({
|
||||||
|
aiChatWorkspaceKnowledgeOnly: value,
|
||||||
|
});
|
||||||
|
setChecked(value);
|
||||||
|
setWorkspace(updatedWorkspace);
|
||||||
|
} catch (err: any) {
|
||||||
|
notifications.show({
|
||||||
|
message: err?.response?.data?.message,
|
||||||
|
color: "red",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tooltip label={upgradeLabel} disabled={hasAccess} refProp="rootRef">
|
||||||
|
<Switch
|
||||||
|
defaultChecked={checked}
|
||||||
|
onChange={handleChange}
|
||||||
|
disabled={!hasAccess}
|
||||||
|
aria-label={t("Toggle workspace knowledge only")}
|
||||||
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -6,7 +6,10 @@ import {
|
|||||||
IconFileText,
|
IconFileText,
|
||||||
} from "@tabler/icons-react";
|
} from "@tabler/icons-react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import ChatInput from "./chat-input";
|
import { useAtomValue } from "jotai";
|
||||||
|
import { workspaceAtom } from "@/features/user/atoms/current-user-atom.ts";
|
||||||
|
import { useRef } from "react";
|
||||||
|
import ChatInput, { ChatInputHandle } from "./chat-input";
|
||||||
import type { ChatAttachment, PageMention } from "../types/ai-chat.types";
|
import type { ChatAttachment, PageMention } from "../types/ai-chat.types";
|
||||||
import classes from "../styles/ai-chat.module.css";
|
import classes from "../styles/ai-chat.module.css";
|
||||||
|
|
||||||
@@ -14,6 +17,7 @@ type Suggestion = {
|
|||||||
icon: React.ReactNode;
|
icon: React.ReactNode;
|
||||||
text: string;
|
text: string;
|
||||||
prompt: string;
|
prompt: string;
|
||||||
|
write?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const SUGGESTIONS: Suggestion[] = [
|
const SUGGESTIONS: Suggestion[] = [
|
||||||
@@ -26,6 +30,7 @@ const SUGGESTIONS: Suggestion[] = [
|
|||||||
icon: <IconFilePlus size={16} />,
|
icon: <IconFilePlus size={16} />,
|
||||||
text: "Create a new page",
|
text: "Create a new page",
|
||||||
prompt: "Create a new page titled ",
|
prompt: "Create a new page titled ",
|
||||||
|
write: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: <IconFileText size={16} />,
|
icon: <IconFileText size={16} />,
|
||||||
@@ -36,6 +41,7 @@ const SUGGESTIONS: Suggestion[] = [
|
|||||||
icon: <IconEdit size={16} />,
|
icon: <IconEdit size={16} />,
|
||||||
text: "Update page content",
|
text: "Update page content",
|
||||||
prompt: "Update the page @",
|
prompt: "Update the page @",
|
||||||
|
write: true,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -47,9 +53,13 @@ type Props = {
|
|||||||
|
|
||||||
export default function ChatEmptyState({ isStreaming, onSend, onStop }: Props) {
|
export default function ChatEmptyState({ isStreaming, onSend, onStop }: Props) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const workspace = useAtomValue(workspaceAtom);
|
||||||
|
const writesDisabled = workspace?.settings?.ai?.chatReadOnly === true;
|
||||||
|
|
||||||
|
const inputRef = useRef<ChatInputHandle>(null);
|
||||||
|
|
||||||
const handleSuggestionClick = (prompt: string) => {
|
const handleSuggestionClick = (prompt: string) => {
|
||||||
onSend(prompt, [], []);
|
inputRef.current?.prefill(prompt);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -62,6 +72,7 @@ export default function ChatEmptyState({ isStreaming, onSend, onStop }: Props) {
|
|||||||
|
|
||||||
<div className={classes.emptyStateInput}>
|
<div className={classes.emptyStateInput}>
|
||||||
<ChatInput
|
<ChatInput
|
||||||
|
ref={inputRef}
|
||||||
isStreaming={isStreaming}
|
isStreaming={isStreaming}
|
||||||
onSend={onSend}
|
onSend={onSend}
|
||||||
onStop={onStop}
|
onStop={onStop}
|
||||||
@@ -73,7 +84,7 @@ export default function ChatEmptyState({ isStreaming, onSend, onStop }: Props) {
|
|||||||
<div className={classes.suggestionsSection}>
|
<div className={classes.suggestionsSection}>
|
||||||
<h2 className={classes.suggestionsLabel}>{t("Get started")}</h2>
|
<h2 className={classes.suggestionsLabel}>{t("Get started")}</h2>
|
||||||
<div className={classes.suggestionsGrid}>
|
<div className={classes.suggestionsGrid}>
|
||||||
{SUGGESTIONS.map((s) => (
|
{SUGGESTIONS.filter((s) => !writesDisabled || !s.write).map((s) => (
|
||||||
<button
|
<button
|
||||||
key={s.text}
|
key={s.text}
|
||||||
type="button"
|
type="button"
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
import { useCallback, useId, useRef, useEffect, useState } from "react";
|
import {
|
||||||
|
forwardRef,
|
||||||
|
useCallback,
|
||||||
|
useId,
|
||||||
|
useImperativeHandle,
|
||||||
|
useRef,
|
||||||
|
useEffect,
|
||||||
|
useState,
|
||||||
|
} from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { IconArrowUp, IconPaperclip, IconPlayerStopFilled, IconX, IconFile, IconPhoto, IconPlus, IconAt, IconFileText } from "@tabler/icons-react";
|
import { IconArrowUp, IconPaperclip, IconPlayerStopFilled, IconX, IconFile, IconPhoto, IconPlus, IconAt, IconFileText } from "@tabler/icons-react";
|
||||||
import { Popover } from "@mantine/core";
|
import { Popover } from "@mantine/core";
|
||||||
@@ -35,6 +43,10 @@ type Props = {
|
|||||||
chatId?: string;
|
chatId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ChatInputHandle = {
|
||||||
|
prefill: (text: string) => void;
|
||||||
|
};
|
||||||
|
|
||||||
function extractMentions(json: any): PageMention[] {
|
function extractMentions(json: any): PageMention[] {
|
||||||
const mentions: PageMention[] = [];
|
const mentions: PageMention[] = [];
|
||||||
const seen = new Set<string>();
|
const seen = new Set<string>();
|
||||||
@@ -89,7 +101,7 @@ function editorJsonToText(json: any): string {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ChatInput({
|
const ChatInput = forwardRef<ChatInputHandle, Props>(function ChatInput({
|
||||||
isStreaming,
|
isStreaming,
|
||||||
onSend,
|
onSend,
|
||||||
onStop,
|
onStop,
|
||||||
@@ -100,7 +112,7 @@ export default function ChatInput({
|
|||||||
variant = "card",
|
variant = "card",
|
||||||
showDisclaimer = true,
|
showDisclaimer = true,
|
||||||
chatId,
|
chatId,
|
||||||
}: Props) {
|
}: Props, ref) {
|
||||||
const chatIdRef = useRef(chatId);
|
const chatIdRef = useRef(chatId);
|
||||||
chatIdRef.current = chatId;
|
chatIdRef.current = chatId;
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -270,6 +282,19 @@ export default function ChatInput({
|
|||||||
}
|
}
|
||||||
}, [editor]);
|
}, [editor]);
|
||||||
|
|
||||||
|
useImperativeHandle(
|
||||||
|
ref,
|
||||||
|
() => ({
|
||||||
|
prefill: (text: string) => {
|
||||||
|
if (!editor || editor.isDestroyed) return;
|
||||||
|
editor.commands.clearContent();
|
||||||
|
editor.commands.insertContent(text);
|
||||||
|
editor.commands.focus();
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
[editor],
|
||||||
|
);
|
||||||
|
|
||||||
const hasContent = !isEmpty || pendingAttachments.some((a) => !a.uploading) || (contextPages?.length ?? 0) > 0;
|
const hasContent = !isEmpty || pendingAttachments.some((a) => !a.uploading) || (contextPages?.length ?? 0) > 0;
|
||||||
|
|
||||||
const wrapperClass = variant === "flat" ? classes.inputWrapperFlat : classes.inputWrapper;
|
const wrapperClass = variant === "flat" ? classes.inputWrapperFlat : classes.inputWrapper;
|
||||||
@@ -429,4 +454,6 @@ export default function ChatInput({
|
|||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
|
|
||||||
|
export default ChatInput;
|
||||||
|
|||||||
@@ -5,8 +5,10 @@ import { useTranslation } from "react-i18next";
|
|||||||
import EnableAiSearch from "@/ee/ai/components/enable-ai-search.tsx";
|
import EnableAiSearch from "@/ee/ai/components/enable-ai-search.tsx";
|
||||||
import EnableGenerativeAi from "@/ee/ai/components/enable-generative-ai.tsx";
|
import EnableGenerativeAi from "@/ee/ai/components/enable-generative-ai.tsx";
|
||||||
import EnableAiChat from "@/ee/ai-chat/components/enable-ai-chat.tsx";
|
import EnableAiChat from "@/ee/ai-chat/components/enable-ai-chat.tsx";
|
||||||
|
import AiChatReadOnly from "@/ee/ai-chat/components/ai-chat-read-only.tsx";
|
||||||
|
import AiChatWorkspaceKnowledgeOnly from "@/ee/ai-chat/components/ai-chat-workspace-knowledge-only.tsx";
|
||||||
import McpSettings from "@/ee/ai/components/mcp-settings.tsx";
|
import McpSettings from "@/ee/ai/components/mcp-settings.tsx";
|
||||||
import { Alert, Stack, Tabs } from "@mantine/core";
|
import { Alert, Collapse, Stack, Tabs } from "@mantine/core";
|
||||||
import { IconInfoCircle } from "@tabler/icons-react";
|
import { IconInfoCircle } from "@tabler/icons-react";
|
||||||
import { useHasFeature } from "@/ee/hooks/use-feature";
|
import { useHasFeature } from "@/ee/hooks/use-feature";
|
||||||
import { Feature } from "@/ee/features";
|
import { Feature } from "@/ee/features";
|
||||||
@@ -14,12 +16,16 @@ import { useUpgradeLabel } from "@/ee/hooks/use-upgrade-label";
|
|||||||
import { isCloud } from "@/lib/config.ts";
|
import { isCloud } from "@/lib/config.ts";
|
||||||
import { useLocation, useNavigate } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
import { DocumentTitle } from "@/components/ui/document-title.tsx";
|
import { DocumentTitle } from "@/components/ui/document-title.tsx";
|
||||||
|
import { useAtomValue } from "jotai";
|
||||||
|
import { workspaceAtom } from "@/features/user/atoms/current-user-atom.ts";
|
||||||
|
|
||||||
export default function AiSettings() {
|
export default function AiSettings() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { isAdmin } = useUserRole();
|
const { isAdmin } = useUserRole();
|
||||||
const hasAccess = useHasFeature(Feature.AI);
|
const hasAccess = useHasFeature(Feature.AI);
|
||||||
const upgradeLabel = useUpgradeLabel();
|
const upgradeLabel = useUpgradeLabel();
|
||||||
|
const workspace = useAtomValue(workspaceAtom);
|
||||||
|
const aiChatEnabled = workspace?.settings?.ai?.chat === true;
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
@@ -61,7 +67,7 @@ export default function AiSettings() {
|
|||||||
mb="lg"
|
mb="lg"
|
||||||
>
|
>
|
||||||
{t(
|
{t(
|
||||||
"AI is only available in the Docmost enterprise edition. Contact sales@docmost.com.",
|
"AI is available in the Docmost paid editions. Contact sales@docmost.com.",
|
||||||
)}
|
)}
|
||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
@@ -70,6 +76,20 @@ export default function AiSettings() {
|
|||||||
{!isCloud() && <EnableAiSearch />}
|
{!isCloud() && <EnableAiSearch />}
|
||||||
<EnableGenerativeAi />
|
<EnableGenerativeAi />
|
||||||
<EnableAiChat />
|
<EnableAiChat />
|
||||||
|
<Collapse expanded={aiChatEnabled}>
|
||||||
|
<Stack
|
||||||
|
gap="md"
|
||||||
|
pl="md"
|
||||||
|
ml="xs"
|
||||||
|
style={{
|
||||||
|
borderLeft:
|
||||||
|
"2px solid light-dark(var(--mantine-color-gray-3), var(--mantine-color-dark-4))",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<AiChatReadOnly />
|
||||||
|
<AiChatWorkspaceKnowledgeOnly />
|
||||||
|
</Stack>
|
||||||
|
</Collapse>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Tabs.Panel>
|
</Tabs.Panel>
|
||||||
|
|
||||||
|
|||||||
@@ -22,4 +22,5 @@ export const Feature = {
|
|||||||
PERSONAL_SPACES: 'spaces:personal',
|
PERSONAL_SPACES: 'spaces:personal',
|
||||||
DOCX_EXPORT: 'export:docx',
|
DOCX_EXPORT: 'export:docx',
|
||||||
BASES: 'bases',
|
BASES: 'bases',
|
||||||
|
AI_CONTROLS: 'ai:controls',
|
||||||
} as const;
|
} as const;
|
||||||
|
|||||||
@@ -13,14 +13,17 @@ import {
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { sortPositionKeys } from "@/features/page/tree/utils/utils";
|
import { sortPositionKeys } from "@/features/page/tree/utils/utils";
|
||||||
import { useSharedPageSubpages } from "@/features/share/hooks/use-shared-page-subpages";
|
import { useSharedPageSubpages } from "@/features/share/hooks/use-shared-page-subpages";
|
||||||
|
import { extractPageSlugId } from "@/lib";
|
||||||
|
|
||||||
export default function SubpagesView(props: NodeViewProps) {
|
export default function SubpagesView(props: NodeViewProps) {
|
||||||
const { editor } = props;
|
const { editor } = props;
|
||||||
const { spaceSlug, shareId } = useParams();
|
const { spaceSlug, shareId, pageSlug } = useParams();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
//@ts-ignore
|
// @ts-ignore
|
||||||
const currentPageId = editor.storage.pageId;
|
const storagePageId = editor.storage.pageId;
|
||||||
|
const routePageId = extractPageSlugId(pageSlug);
|
||||||
|
const currentPageId = storagePageId ?? routePageId;
|
||||||
|
|
||||||
// Get subpages from shared tree if we're in a shared context
|
// Get subpages from shared tree if we're in a shared context
|
||||||
const sharedSubpages = useSharedPageSubpages(currentPageId);
|
const sharedSubpages = useSharedPageSubpages(currentPageId);
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export function useWorkspaceLabelsQuery(query: string, enabled: boolean) {
|
|||||||
queryFn: () => getWorkspaceLabels({ type: "page", query, limit: 50 }),
|
queryFn: () => getWorkspaceLabels({ type: "page", query, limit: 50 }),
|
||||||
enabled,
|
enabled,
|
||||||
staleTime: 30 * 1000,
|
staleTime: 30 * 1000,
|
||||||
|
placeholderData: keepPreviousData
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
import { ReactNode, useMemo, useState } from "react";
|
||||||
|
import { Divider, Group, Menu, ScrollArea, Text, TextInput } from "@mantine/core";
|
||||||
|
import { useDebouncedValue } from "@mantine/hooks";
|
||||||
|
import { IconCheck, IconSearch } from "@tabler/icons-react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useSearchSuggestionsQuery } from "@/features/search/queries/search-query";
|
||||||
|
import { RadioMenuItem } from "@/components/ui/radio-menu-item";
|
||||||
|
import { CustomAvatar } from "@/components/ui/custom-avatar.tsx";
|
||||||
|
import { IUser } from "@/features/user/types/user.types.ts";
|
||||||
|
import { useAtomValue } from "jotai";
|
||||||
|
import { userAtom } from "@/features/user/atoms/current-user-atom.ts";
|
||||||
|
|
||||||
|
type CreatorFilterMenuProps = {
|
||||||
|
value: string | null;
|
||||||
|
onChange: (user: IUser | null) => void;
|
||||||
|
children: ReactNode;
|
||||||
|
width?: number;
|
||||||
|
position?:
|
||||||
|
| "bottom-start"
|
||||||
|
| "bottom-end"
|
||||||
|
| "bottom"
|
||||||
|
| "top-start"
|
||||||
|
| "top-end"
|
||||||
|
| "top";
|
||||||
|
zIndex?: number;
|
||||||
|
opened?: boolean;
|
||||||
|
onOpenChange?: (opened: boolean) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function CreatorFilterMenu({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
children,
|
||||||
|
width = 280,
|
||||||
|
position = "bottom-end",
|
||||||
|
zIndex,
|
||||||
|
opened,
|
||||||
|
onOpenChange,
|
||||||
|
}: CreatorFilterMenuProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [searchQuery, setSearchQuery] = useState("");
|
||||||
|
const [debouncedQuery] = useDebouncedValue(searchQuery, 300);
|
||||||
|
|
||||||
|
const { data: suggestion, isLoading } = useSearchSuggestionsQuery({
|
||||||
|
query: debouncedQuery,
|
||||||
|
includeUsers: true,
|
||||||
|
includeGroups: false,
|
||||||
|
includePages: false,
|
||||||
|
preload: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const users: IUser[] = (suggestion?.users as IUser[]) ?? [];
|
||||||
|
const currentUser = useAtomValue(userAtom);
|
||||||
|
|
||||||
|
// pin the signed-in user on top so they never have to search themselves
|
||||||
|
const displayUsers = useMemo(() => {
|
||||||
|
if (!currentUser) return users;
|
||||||
|
const others = users.filter((user) => user.id !== currentUser.id);
|
||||||
|
const q = debouncedQuery.trim().toLowerCase();
|
||||||
|
const matchesQuery =
|
||||||
|
!q ||
|
||||||
|
currentUser.name?.toLowerCase().includes(q) ||
|
||||||
|
currentUser.email?.toLowerCase().includes(q);
|
||||||
|
return matchesQuery ? [currentUser as IUser, ...others] : users;
|
||||||
|
}, [users, currentUser, debouncedQuery]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Menu
|
||||||
|
shadow="md"
|
||||||
|
width={width}
|
||||||
|
position={position}
|
||||||
|
zIndex={zIndex}
|
||||||
|
opened={opened}
|
||||||
|
onChange={onOpenChange}
|
||||||
|
>
|
||||||
|
<Menu.Target>{children}</Menu.Target>
|
||||||
|
<Menu.Dropdown>
|
||||||
|
<TextInput
|
||||||
|
placeholder={t("Find a user")}
|
||||||
|
data-autofocus
|
||||||
|
autoFocus
|
||||||
|
leftSection={<IconSearch size={16} />}
|
||||||
|
value={searchQuery}
|
||||||
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
|
size="sm"
|
||||||
|
variant="filled"
|
||||||
|
radius="sm"
|
||||||
|
styles={{ input: { marginBottom: 8 } }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ScrollArea.Autosize mah={280}>
|
||||||
|
<Menu.Item
|
||||||
|
component={RadioMenuItem}
|
||||||
|
aria-checked={!value}
|
||||||
|
onClick={() => onChange(null)}
|
||||||
|
>
|
||||||
|
<Group flex="1" gap="xs">
|
||||||
|
<div style={{ flex: 1 }}>
|
||||||
|
<Text size="sm" fw={500}>
|
||||||
|
{t("Anyone")}
|
||||||
|
</Text>
|
||||||
|
</div>
|
||||||
|
{!value && <IconCheck size={20} aria-hidden />}
|
||||||
|
</Group>
|
||||||
|
</Menu.Item>
|
||||||
|
|
||||||
|
<Divider my="xs" />
|
||||||
|
|
||||||
|
{displayUsers.length === 0 && (
|
||||||
|
<Text size="xs" c="dimmed" px="xs" py="sm">
|
||||||
|
{isLoading ? t("Loading...") : t("No users found")}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{displayUsers.map((user) => (
|
||||||
|
<Menu.Item
|
||||||
|
key={user.id}
|
||||||
|
component={RadioMenuItem}
|
||||||
|
aria-checked={value === user.id}
|
||||||
|
onClick={() => onChange(user)}
|
||||||
|
>
|
||||||
|
<Group flex="1" gap="xs">
|
||||||
|
<CustomAvatar
|
||||||
|
avatarUrl={user.avatarUrl}
|
||||||
|
size={20}
|
||||||
|
name={user.name}
|
||||||
|
/>
|
||||||
|
<div style={{ flex: 1, minWidth: 0 }}>
|
||||||
|
<Text size="sm" fw={500} truncate>
|
||||||
|
{user.name}
|
||||||
|
{user.id === currentUser?.id && (
|
||||||
|
<Text span size="sm" c="dimmed" fw={400}>
|
||||||
|
{" "}
|
||||||
|
({t("you")})
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</Text>
|
||||||
|
{user.email && (
|
||||||
|
<Text size="xs" c="dimmed" truncate>
|
||||||
|
{user.email}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
{value === user.id && <IconCheck size={20} aria-hidden />}
|
||||||
|
</Group>
|
||||||
|
</Menu.Item>
|
||||||
|
))}
|
||||||
|
</ScrollArea.Autosize>
|
||||||
|
</Menu.Dropdown>
|
||||||
|
</Menu>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
import { ReactNode, useMemo, useState } from "react";
|
||||||
|
import {
|
||||||
|
Group,
|
||||||
|
Menu,
|
||||||
|
ScrollArea,
|
||||||
|
Text,
|
||||||
|
TextInput,
|
||||||
|
useComputedColorScheme,
|
||||||
|
} from "@mantine/core";
|
||||||
|
import { useDebouncedValue } from "@mantine/hooks";
|
||||||
|
import { IconCheck, IconSearch } from "@tabler/icons-react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useWorkspaceLabelsQuery } from "@/features/label/queries/label-query.ts";
|
||||||
|
import { getLabelColor } from "@/features/label/utils/label-colors.ts";
|
||||||
|
import { CheckboxMenuItem } from "@/components/ui/checkbox-menu-item";
|
||||||
|
|
||||||
|
type LabelFilterMenuProps = {
|
||||||
|
value: string[];
|
||||||
|
onChange: (labelIds: string[]) => void;
|
||||||
|
children: ReactNode;
|
||||||
|
width?: number;
|
||||||
|
position?:
|
||||||
|
| "bottom-start"
|
||||||
|
| "bottom-end"
|
||||||
|
| "bottom"
|
||||||
|
| "top-start"
|
||||||
|
| "top-end"
|
||||||
|
| "top";
|
||||||
|
zIndex?: number;
|
||||||
|
opened?: boolean;
|
||||||
|
onOpenChange?: (opened: boolean) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function LabelFilterMenu({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
children,
|
||||||
|
width = 280,
|
||||||
|
position = "bottom-end",
|
||||||
|
zIndex,
|
||||||
|
opened,
|
||||||
|
onOpenChange,
|
||||||
|
}: LabelFilterMenuProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const scheme = useComputedColorScheme("light");
|
||||||
|
const [searchQuery, setSearchQuery] = useState("");
|
||||||
|
const [debouncedQuery] = useDebouncedValue(searchQuery, 300);
|
||||||
|
|
||||||
|
const { data, isLoading } = useWorkspaceLabelsQuery(debouncedQuery, true);
|
||||||
|
const labels = data?.items ?? [];
|
||||||
|
|
||||||
|
const selectedSet = useMemo(() => new Set(value), [value]);
|
||||||
|
|
||||||
|
const toggleLabel = (labelId: string) => {
|
||||||
|
if (selectedSet.has(labelId)) {
|
||||||
|
onChange(value.filter((id) => id !== labelId));
|
||||||
|
} else {
|
||||||
|
onChange([...value, labelId]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Menu
|
||||||
|
shadow="md"
|
||||||
|
width={width}
|
||||||
|
position={position}
|
||||||
|
zIndex={zIndex}
|
||||||
|
opened={opened}
|
||||||
|
onChange={onOpenChange}
|
||||||
|
closeOnItemClick={false}
|
||||||
|
>
|
||||||
|
<Menu.Target>{children}</Menu.Target>
|
||||||
|
<Menu.Dropdown>
|
||||||
|
<TextInput
|
||||||
|
placeholder={t("Find a label")}
|
||||||
|
data-autofocus
|
||||||
|
autoFocus
|
||||||
|
leftSection={<IconSearch size={16} />}
|
||||||
|
value={searchQuery}
|
||||||
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
|
size="sm"
|
||||||
|
variant="filled"
|
||||||
|
radius="sm"
|
||||||
|
styles={{ input: { marginBottom: 8 } }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ScrollArea.Autosize mah={280}>
|
||||||
|
{labels.length === 0 && (
|
||||||
|
<Text size="xs" c="dimmed" px="xs" py="sm">
|
||||||
|
{isLoading ? t("Loading...") : t("No labels found")}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{labels.map((label) => {
|
||||||
|
const isChecked = selectedSet.has(label.id);
|
||||||
|
const color = getLabelColor(label.name, scheme);
|
||||||
|
return (
|
||||||
|
<Menu.Item
|
||||||
|
key={label.id}
|
||||||
|
type="button"
|
||||||
|
component={CheckboxMenuItem}
|
||||||
|
aria-checked={isChecked}
|
||||||
|
onClick={() => toggleLabel(label.id)}
|
||||||
|
>
|
||||||
|
<Group flex="1" gap="xs">
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
width: 8,
|
||||||
|
height: 8,
|
||||||
|
borderRadius: "50%",
|
||||||
|
background: color.dot,
|
||||||
|
flexShrink: 0,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Text size="sm" fw={500} style={{ flex: 1 }} truncate>
|
||||||
|
{label.name}
|
||||||
|
</Text>
|
||||||
|
{isChecked && <IconCheck size={20} aria-hidden />}
|
||||||
|
</Group>
|
||||||
|
</Menu.Item>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ScrollArea.Autosize>
|
||||||
|
</Menu.Dropdown>
|
||||||
|
</Menu>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
} from "@/features/search/types/search.types";
|
} from "@/features/search/types/search.types";
|
||||||
import DOMPurify from "dompurify";
|
import DOMPurify from "dompurify";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { timeAgo } from "@/lib/time.ts";
|
||||||
|
|
||||||
interface SearchResultItemProps {
|
interface SearchResultItemProps {
|
||||||
result: IPageSearch | IAttachmentSearch;
|
result: IPageSearch | IAttachmentSearch;
|
||||||
@@ -26,6 +27,14 @@ interface SearchResultItemProps {
|
|||||||
showSpace?: boolean;
|
showSpace?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Spotlight hardcodes tabIndex={-1} after spreading props; a ref wins and
|
||||||
|
// React never writes -1 back because the prop value never changes
|
||||||
|
const makeActionTabbable = (el: HTMLElement | null) => {
|
||||||
|
if (el) {
|
||||||
|
el.tabIndex = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export function SearchResultItem({
|
export function SearchResultItem({
|
||||||
result,
|
result,
|
||||||
isAttachmentResult,
|
isAttachmentResult,
|
||||||
@@ -46,6 +55,7 @@ export function SearchResultItem({
|
|||||||
return (
|
return (
|
||||||
<Spotlight.Action
|
<Spotlight.Action
|
||||||
component={Link}
|
component={Link}
|
||||||
|
ref={makeActionTabbable}
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
to={buildPageUrl(
|
to={buildPageUrl(
|
||||||
attachmentResult.space.slug,
|
attachmentResult.space.slug,
|
||||||
@@ -59,8 +69,13 @@ export function SearchResultItem({
|
|||||||
<IconFile size={16} />
|
<IconFile size={16} />
|
||||||
</Center>
|
</Center>
|
||||||
|
|
||||||
<div style={{ flex: 1 }}>
|
<div style={{ flex: 1, minWidth: 0 }}>
|
||||||
<Text>{attachmentResult.fileName}</Text>
|
<Group justify="space-between" wrap="nowrap" gap="xs">
|
||||||
|
<Text truncate>{attachmentResult.fileName}</Text>
|
||||||
|
<Text size="xs" c="dimmed" style={{ flexShrink: 0 }}>
|
||||||
|
{timeAgo(attachmentResult.updatedAt)}
|
||||||
|
</Text>
|
||||||
|
</Group>
|
||||||
<Text size="xs" opacity={0.6}>
|
<Text size="xs" opacity={0.6}>
|
||||||
{attachmentResult.space.name} • {attachmentResult.page.title}
|
{attachmentResult.space.name} • {attachmentResult.page.title}
|
||||||
</Text>
|
</Text>
|
||||||
@@ -96,6 +111,7 @@ export function SearchResultItem({
|
|||||||
return (
|
return (
|
||||||
<Spotlight.Action
|
<Spotlight.Action
|
||||||
component={Link}
|
component={Link}
|
||||||
|
ref={makeActionTabbable}
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
to={buildPageUrl(
|
to={buildPageUrl(
|
||||||
pageResult.space.slug,
|
pageResult.space.slug,
|
||||||
@@ -107,8 +123,13 @@ export function SearchResultItem({
|
|||||||
<Group wrap="nowrap" w="100%">
|
<Group wrap="nowrap" w="100%">
|
||||||
<Center>{getPageIcon(pageResult?.icon)}</Center>
|
<Center>{getPageIcon(pageResult?.icon)}</Center>
|
||||||
|
|
||||||
<div style={{ flex: 1 }}>
|
<div style={{ flex: 1, minWidth: 0 }}>
|
||||||
<Text>{pageResult.title}</Text>
|
<Group justify="space-between" wrap="nowrap" gap="xs">
|
||||||
|
<Text truncate>{pageResult.title || t("Untitled")}</Text>
|
||||||
|
<Text size="xs" c="dimmed" style={{ flexShrink: 0 }}>
|
||||||
|
{timeAgo(pageResult.updatedAt)}
|
||||||
|
</Text>
|
||||||
|
</Group>
|
||||||
|
|
||||||
{showSpace && pageResult.space && (
|
{showSpace && pageResult.space && (
|
||||||
<Badge variant="light" size="xs" color="gray">
|
<Badge variant="light" size="xs" color="gray">
|
||||||
|
|||||||
@@ -17,3 +17,10 @@
|
|||||||
color: light-dark(var(--mantine-color-gray-7), var(--mantine-color-gray-6));
|
color: light-dark(var(--mantine-color-gray-7), var(--mantine-color-gray-6));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.filterButtonActive {
|
||||||
|
color: var(--mantine-color-blue-light-color);
|
||||||
|
&:hover {
|
||||||
|
color: var(--mantine-color-blue-light-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
|
import cx from "clsx";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Menu,
|
Menu,
|
||||||
@@ -11,18 +12,24 @@ import {
|
|||||||
import {
|
import {
|
||||||
IconChevronDown,
|
IconChevronDown,
|
||||||
IconBuilding,
|
IconBuilding,
|
||||||
|
IconPlus,
|
||||||
IconFileDescription,
|
IconFileDescription,
|
||||||
IconCheck,
|
IconCheck,
|
||||||
|
IconUser,
|
||||||
|
IconTag,
|
||||||
|
IconLetterCase,
|
||||||
} from "@tabler/icons-react";
|
} from "@tabler/icons-react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useGetSpacesQuery } from "@/features/space/queries/space-query";
|
import { useGetSpacesQuery } from "@/features/space/queries/space-query";
|
||||||
import { SpaceFilterMenu } from "@/features/space/components/space-filter-menu";
|
import { SpaceFilterMenu } from "@/features/space/components/space-filter-menu";
|
||||||
|
import { CreatorFilterMenu } from "@/features/search/components/creator-filter-menu";
|
||||||
import { RadioMenuItem } from "@/components/ui/radio-menu-item";
|
import { RadioMenuItem } from "@/components/ui/radio-menu-item";
|
||||||
import { useHasFeature } from "@/ee/hooks/use-feature";
|
import { useHasFeature } from "@/ee/hooks/use-feature";
|
||||||
import { Feature } from "@/ee/features";
|
import { Feature } from "@/ee/features";
|
||||||
import classes from "./search-spotlight-filters.module.css";
|
import classes from "./search-spotlight-filters.module.css";
|
||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import { workspaceAtom } from "@/features/user/atoms/current-user-atom.ts";
|
import { workspaceAtom } from "@/features/user/atoms/current-user-atom.ts";
|
||||||
|
import { LabelFilterMenu } from "./label-filter-menu";
|
||||||
|
|
||||||
interface SearchSpotlightFiltersProps {
|
interface SearchSpotlightFiltersProps {
|
||||||
onFiltersChange?: (filters: any) => void;
|
onFiltersChange?: (filters: any) => void;
|
||||||
@@ -40,9 +47,17 @@ export function SearchSpotlightFilters({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const hasAttachmentIndexing = useHasFeature(Feature.ATTACHMENT_INDEXING);
|
const hasAttachmentIndexing = useHasFeature(Feature.ATTACHMENT_INDEXING);
|
||||||
const [selectedSpaceId, setSelectedSpaceId] = useState<string | null>(
|
const [selectedSpaceId, setSelectedSpaceId] = useState<string | null>(
|
||||||
spaceId || null,
|
spaceId || null
|
||||||
);
|
);
|
||||||
const [contentType, setContentType] = useState<string | null>("page");
|
const [contentType, setContentType] = useState<string | null>("page");
|
||||||
|
const [selectedCreatorId, setSelectedCreatorId] = useState<string | null>(null);
|
||||||
|
const [selectedCreatorName, setSelectedCreatorName] = useState<string | null>(
|
||||||
|
null
|
||||||
|
);
|
||||||
|
const [selectedLabelIds, setSelectedLabelIds] = useState<string[]>([]);
|
||||||
|
const [titleOnly, setTitleOnly] = useState(false);
|
||||||
|
const [openedFilter, setOpenedFilter] = useState<string | null>(null);
|
||||||
|
const [visibleFilters, setVisibleFilters] = useState<string[]>([]);
|
||||||
const [workspace] = useAtom(workspaceAtom);
|
const [workspace] = useAtom(workspaceAtom);
|
||||||
|
|
||||||
const { data: spacesData } = useGetSpacesQuery({ limit: 100 });
|
const { data: spacesData } = useGetSpacesQuery({ limit: 100 });
|
||||||
@@ -50,15 +65,6 @@ export function SearchSpotlightFilters({
|
|||||||
? spacesData?.items.find((space) => space.id === selectedSpaceId)
|
? spacesData?.items.find((space) => space.id === selectedSpaceId)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (onFiltersChange) {
|
|
||||||
onFiltersChange({
|
|
||||||
spaceId: selectedSpaceId,
|
|
||||||
contentType,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const contentTypeOptions = [
|
const contentTypeOptions = [
|
||||||
{ value: "page", label: t("Pages") },
|
{ value: "page", label: t("Pages") },
|
||||||
{
|
{
|
||||||
@@ -68,38 +74,70 @@ export function SearchSpotlightFilters({
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onFiltersChange?.({
|
||||||
|
spaceId: selectedSpaceId,
|
||||||
|
contentType,
|
||||||
|
creatorId: selectedCreatorId,
|
||||||
|
labelIds: selectedLabelIds,
|
||||||
|
titleOnly,
|
||||||
|
});
|
||||||
|
}, [
|
||||||
|
selectedSpaceId,
|
||||||
|
contentType,
|
||||||
|
selectedCreatorId,
|
||||||
|
selectedLabelIds,
|
||||||
|
titleOnly,
|
||||||
|
onFiltersChange,
|
||||||
|
]);
|
||||||
|
|
||||||
const handleSpaceSelect = (spaceId: string | null) => {
|
const handleSpaceSelect = (spaceId: string | null) => {
|
||||||
setSelectedSpaceId(spaceId);
|
setSelectedSpaceId(spaceId);
|
||||||
|
};
|
||||||
|
|
||||||
if (onFiltersChange) {
|
const handleCreatorSelect = (user: { id: string; name: string } | null) => {
|
||||||
onFiltersChange({
|
setSelectedCreatorId(user?.id ?? null);
|
||||||
spaceId: spaceId,
|
setSelectedCreatorName(user?.name ?? null);
|
||||||
contentType,
|
};
|
||||||
});
|
|
||||||
|
const handleLabelsSelect = (labelIds: string[]) => {
|
||||||
|
setSelectedLabelIds(labelIds);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChangeContentType = (value: string) => {
|
||||||
|
setContentType(value);
|
||||||
|
|
||||||
|
if (value === "attachment") {
|
||||||
|
setSelectedLabelIds([]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFilterChange = (filterType: string, value: any) => {
|
const onDemandFilters = [
|
||||||
let newSelectedSpaceId = selectedSpaceId;
|
{ key: "creator", label: t("Created by"), icon: IconUser, available: true },
|
||||||
let newContentType = contentType;
|
{
|
||||||
|
key: "labels",
|
||||||
|
label: t("Labels"),
|
||||||
|
icon: IconTag,
|
||||||
|
available: contentType !== "attachment",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
switch (filterType) {
|
const isFilterVisible = (key: string) => {
|
||||||
case "spaceId":
|
if (openedFilter === key) return true;
|
||||||
newSelectedSpaceId = value;
|
if (key === "creator") return !!selectedCreatorId;
|
||||||
setSelectedSpaceId(value);
|
if (key === "labels")
|
||||||
break;
|
return contentType !== "attachment" && selectedLabelIds.length > 0;
|
||||||
case "contentType":
|
return false;
|
||||||
newContentType = value;
|
};
|
||||||
setContentType(value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (onFiltersChange) {
|
const orderedVisibleFilters = visibleFilters.filter(isFilterVisible);
|
||||||
onFiltersChange({
|
const addableFilters = onDemandFilters.filter(
|
||||||
spaceId: newSelectedSpaceId,
|
(filter) => filter.available && !isFilterVisible(filter.key),
|
||||||
contentType: newContentType,
|
);
|
||||||
});
|
|
||||||
}
|
const revealFilter = (key: string) => {
|
||||||
|
setVisibleFilters((prev) => [...prev.filter((k) => k !== key), key]);
|
||||||
|
setOpenedFilter(key);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -122,8 +160,17 @@ export function SearchSpotlightFilters({
|
|||||||
color="blue"
|
color="blue"
|
||||||
labelPosition="left"
|
labelPosition="left"
|
||||||
styles={{
|
styles={{
|
||||||
root: { display: "flex", alignItems: "center" },
|
root: {
|
||||||
label: { paddingRight: "8px", fontSize: "13px", fontWeight: 500 },
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
flexShrink: 0,
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
paddingRight: "8px",
|
||||||
|
fontSize: "13px",
|
||||||
|
fontWeight: 500,
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -181,7 +228,7 @@ export function SearchSpotlightFilters({
|
|||||||
onClick={() =>
|
onClick={() =>
|
||||||
!option.disabled &&
|
!option.disabled &&
|
||||||
contentType !== option.value &&
|
contentType !== option.value &&
|
||||||
handleFilterChange("contentType", option.value)
|
handleChangeContentType(option.value)
|
||||||
}
|
}
|
||||||
disabled={
|
disabled={
|
||||||
option.disabled || (isAiMode && option.value === "attachment")
|
option.disabled || (isAiMode && option.value === "attachment")
|
||||||
@@ -195,9 +242,7 @@ export function SearchSpotlightFilters({
|
|||||||
{t("Enterprise")}
|
{t("Enterprise")}
|
||||||
</Badge>
|
</Badge>
|
||||||
)}
|
)}
|
||||||
{!option.disabled &&
|
{!option.disabled && isAiMode && option.value === "attachment" && (
|
||||||
isAiMode &&
|
|
||||||
option.value === "attachment" && (
|
|
||||||
<Text size="xs" mt={4}>
|
<Text size="xs" mt={4}>
|
||||||
{t("AI Answers not available for attachments")}
|
{t("AI Answers not available for attachments")}
|
||||||
</Text>
|
</Text>
|
||||||
@@ -209,6 +254,126 @@ export function SearchSpotlightFilters({
|
|||||||
))}
|
))}
|
||||||
</Menu.Dropdown>
|
</Menu.Dropdown>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
|
||||||
|
{!isAiMode && (
|
||||||
|
<Button
|
||||||
|
variant={titleOnly ? "light" : "subtle"}
|
||||||
|
color={titleOnly ? "blue" : "gray"}
|
||||||
|
size="sm"
|
||||||
|
radius="xl"
|
||||||
|
leftSection={<IconLetterCase size={16} />}
|
||||||
|
className={cx(
|
||||||
|
classes.filterButton,
|
||||||
|
titleOnly && classes.filterButtonActive,
|
||||||
|
)}
|
||||||
|
fw={500}
|
||||||
|
aria-pressed={titleOnly}
|
||||||
|
onClick={() => setTitleOnly(!titleOnly)}
|
||||||
|
>
|
||||||
|
{t("Title only")}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!isAiMode &&
|
||||||
|
orderedVisibleFilters.map((filterKey) => {
|
||||||
|
if (filterKey === "creator") {
|
||||||
|
return (
|
||||||
|
<CreatorFilterMenu
|
||||||
|
key="creator"
|
||||||
|
value={selectedCreatorId}
|
||||||
|
onChange={handleCreatorSelect}
|
||||||
|
position="bottom-start"
|
||||||
|
width={250}
|
||||||
|
zIndex={getDefaultZIndex("max")}
|
||||||
|
opened={openedFilter === "creator"}
|
||||||
|
onOpenChange={(opened) =>
|
||||||
|
setOpenedFilter(opened ? "creator" : null)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
variant="subtle"
|
||||||
|
color="gray"
|
||||||
|
size="sm"
|
||||||
|
rightSection={<IconChevronDown size={14} />}
|
||||||
|
leftSection={<IconUser size={16} />}
|
||||||
|
className={classes.filterButton}
|
||||||
|
fw={500}
|
||||||
|
>
|
||||||
|
{selectedCreatorId
|
||||||
|
? `${t("Created by")}: ${selectedCreatorName || t("Unknown")}`
|
||||||
|
: `${t("Created by")}: ${t("Anyone")}`}
|
||||||
|
</Button>
|
||||||
|
</CreatorFilterMenu>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filterKey === "labels") {
|
||||||
|
return (
|
||||||
|
<LabelFilterMenu
|
||||||
|
key="labels"
|
||||||
|
value={selectedLabelIds}
|
||||||
|
onChange={handleLabelsSelect}
|
||||||
|
position="bottom-start"
|
||||||
|
width={250}
|
||||||
|
zIndex={getDefaultZIndex("max")}
|
||||||
|
opened={openedFilter === "labels"}
|
||||||
|
onOpenChange={(opened) =>
|
||||||
|
setOpenedFilter(opened ? "labels" : null)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
variant="subtle"
|
||||||
|
color="gray"
|
||||||
|
size="sm"
|
||||||
|
rightSection={<IconChevronDown size={14} />}
|
||||||
|
leftSection={<IconTag size={16} />}
|
||||||
|
className={classes.filterButton}
|
||||||
|
fw={500}
|
||||||
|
>
|
||||||
|
{selectedLabelIds.length > 0
|
||||||
|
? `${t("Labels")} (${selectedLabelIds.length})`
|
||||||
|
: t("Labels")}
|
||||||
|
</Button>
|
||||||
|
</LabelFilterMenu>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
})}
|
||||||
|
|
||||||
|
{!isAiMode && addableFilters.length > 0 && (
|
||||||
|
<Menu
|
||||||
|
shadow="md"
|
||||||
|
width={200}
|
||||||
|
position="bottom-end"
|
||||||
|
zIndex={getDefaultZIndex("max")}
|
||||||
|
>
|
||||||
|
<Menu.Target>
|
||||||
|
<Button
|
||||||
|
variant="subtle"
|
||||||
|
color="gray"
|
||||||
|
size="sm"
|
||||||
|
leftSection={<IconPlus size={16} />}
|
||||||
|
className={classes.filterButton}
|
||||||
|
style={{ marginLeft: "auto" }}
|
||||||
|
fw={500}
|
||||||
|
>
|
||||||
|
{t("Filter")}
|
||||||
|
</Button>
|
||||||
|
</Menu.Target>
|
||||||
|
<Menu.Dropdown>
|
||||||
|
{addableFilters.map((filter) => (
|
||||||
|
<Menu.Item
|
||||||
|
key={filter.key}
|
||||||
|
leftSection={<filter.icon size={16} />}
|
||||||
|
onClick={() => revealFilter(filter.key)}
|
||||||
|
>
|
||||||
|
{filter.label}
|
||||||
|
</Menu.Item>
|
||||||
|
))}
|
||||||
|
</Menu.Dropdown>
|
||||||
|
</Menu>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Spotlight } from "@mantine/spotlight";
|
import { Spotlight } from "@mantine/spotlight";
|
||||||
import { IconSearch, IconSparkles } from "@tabler/icons-react";
|
import { IconSearch, IconSparkles } from "@tabler/icons-react";
|
||||||
import { Group, Button, VisuallyHidden } from "@mantine/core";
|
import { Group, Button, VisuallyHidden, Text } from "@mantine/core";
|
||||||
import React, { useState, useMemo, useEffect } from "react";
|
import React, { useState, useMemo, useEffect, useCallback } from "react";
|
||||||
import { useDebouncedValue } from "@mantine/hooks";
|
import { useDebouncedValue } from "@mantine/hooks";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { notifications } from "@mantine/notifications";
|
import { notifications } from "@mantine/notifications";
|
||||||
@@ -31,6 +31,9 @@ export function SearchSpotlight({ spaceId }: SearchSpotlightProps) {
|
|||||||
const [filters, setFilters] = useState<{
|
const [filters, setFilters] = useState<{
|
||||||
spaceId?: string | null;
|
spaceId?: string | null;
|
||||||
contentType?: string;
|
contentType?: string;
|
||||||
|
creatorId?: string | null;
|
||||||
|
labelIds?: string[];
|
||||||
|
titleOnly?: boolean;
|
||||||
}>({
|
}>({
|
||||||
contentType: "page",
|
contentType: "page",
|
||||||
});
|
});
|
||||||
@@ -48,10 +51,25 @@ export function SearchSpotlight({ spaceId }: SearchSpotlightProps) {
|
|||||||
params.spaceId = filters.spaceId;
|
params.spaceId = filters.spaceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (filters.creatorId) {
|
||||||
|
params.creatorId = filters.creatorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filters.labelIds?.length) {
|
||||||
|
params.labelIds = filters.labelIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filters.titleOnly) {
|
||||||
|
params.titleOnly = true;
|
||||||
|
}
|
||||||
|
|
||||||
return params;
|
return params;
|
||||||
}, [debouncedSearchQuery, filters]);
|
}, [debouncedSearchQuery, filters]);
|
||||||
|
|
||||||
const { data: searchResults, isLoading } = useUnifiedSearch(
|
const {
|
||||||
|
data: searchResults,
|
||||||
|
isFetching,
|
||||||
|
} = useUnifiedSearch(
|
||||||
searchParams,
|
searchParams,
|
||||||
!isAiMode // Disable regular search when in AI mode
|
!isAiMode // Disable regular search when in AI mode
|
||||||
);
|
);
|
||||||
@@ -88,6 +106,11 @@ export function SearchSpotlight({ spaceId }: SearchSpotlightProps) {
|
|||||||
}
|
}
|
||||||
}, [aiSearchError, t]);
|
}, [aiSearchError, t]);
|
||||||
|
|
||||||
|
const isFilterBrowse =
|
||||||
|
(filters.labelIds?.length ?? 0) > 0 || !!filters.creatorId;
|
||||||
|
// while the debounce is pending the empty list is not a settled "no results"
|
||||||
|
const isQuerySettled = query === debouncedSearchQuery;
|
||||||
|
|
||||||
// Determine result type for rendering
|
// Determine result type for rendering
|
||||||
const isAttachmentSearch =
|
const isAttachmentSearch =
|
||||||
filters.contentType === "attachment" && hasAttachmentIndexing;
|
filters.contentType === "attachment" && hasAttachmentIndexing;
|
||||||
@@ -110,9 +133,9 @@ export function SearchSpotlight({ spaceId }: SearchSpotlightProps) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFiltersChange = (newFilters: any) => {
|
const handleFiltersChange = useCallback((newFilters: any) => {
|
||||||
setFilters(newFilters);
|
setFilters(newFilters);
|
||||||
};
|
}, [setFilters]);
|
||||||
|
|
||||||
const handleAskClick = () => {
|
const handleAskClick = () => {
|
||||||
setIsAiMode(!isAiMode);
|
setIsAiMode(!isAiMode);
|
||||||
@@ -182,7 +205,7 @@ export function SearchSpotlight({ spaceId }: SearchSpotlightProps) {
|
|||||||
? query.length > 0 && !isAiLoading && !aiSearchResult
|
? query.length > 0 && !isAiLoading && !aiSearchResult
|
||||||
? t("No answer available")
|
? t("No answer available")
|
||||||
: ""
|
: ""
|
||||||
: query.length > 0 && !isLoading
|
: (query.length > 0 || isFilterBrowse) && !isFetching
|
||||||
? resultItems.length === 0
|
? resultItems.length === 0
|
||||||
? t("No results found")
|
? t("No results found")
|
||||||
: t("{{count}} results found", { count: resultItems.length })
|
: t("{{count}} results found", { count: resultItems.length })
|
||||||
@@ -209,15 +232,28 @@ export function SearchSpotlight({ spaceId }: SearchSpotlightProps) {
|
|||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{query.length === 0 && resultItems.length === 0 && (
|
{query.length === 0 && !isFilterBrowse && resultItems.length === 0 && (
|
||||||
<Spotlight.Empty>{t("Start typing to search...")}</Spotlight.Empty>
|
<Spotlight.Empty>{t("Start typing to search...")}</Spotlight.Empty>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{query.length > 0 && !isLoading && resultItems.length === 0 && (
|
{(query.length > 0 || isFilterBrowse) &&
|
||||||
|
!isFetching &&
|
||||||
|
isQuerySettled &&
|
||||||
|
resultItems.length === 0 && (
|
||||||
<Spotlight.Empty>{t("No results found...")}</Spotlight.Empty>
|
<Spotlight.Empty>{t("No results found...")}</Spotlight.Empty>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{resultItems.length > 0 && <>{resultItems}</>}
|
{resultItems.length > 0 && <>{resultItems}</>}
|
||||||
|
|
||||||
|
{(query.length > 0 || isFilterBrowse) &&
|
||||||
|
isFetching &&
|
||||||
|
resultItems.length === 0 && (
|
||||||
|
<Spotlight.Empty>
|
||||||
|
<Text size="sm" style={{ marginTop: 10 }}>
|
||||||
|
{t("Searching...")}
|
||||||
|
</Text>
|
||||||
|
</Spotlight.Empty>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Spotlight.ActionsList>
|
</Spotlight.ActionsList>
|
||||||
|
|||||||
@@ -39,6 +39,20 @@ export function useUnifiedSearch(
|
|||||||
return await searchPage(backendParams);
|
return await searchPage(backendParams);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
enabled: !!params.query && enabled,
|
enabled:
|
||||||
|
(!!params.query ||
|
||||||
|
(params.labelIds?.length ?? 0) > 0 ||
|
||||||
|
!!params.creatorId) &&
|
||||||
|
enabled,
|
||||||
|
// keep previous results only within the same search type; page results
|
||||||
|
// rendered as attachments (or vice versa) crash on missing fields
|
||||||
|
placeholderData: (previousData, previousQuery) => {
|
||||||
|
if (!params.query && !params.labelIds?.length && !params.creatorId)
|
||||||
|
return undefined;
|
||||||
|
if (previousQuery && previousQuery.queryKey[1] !== searchType) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return previousData;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ export interface IPageSearchParams {
|
|||||||
query: string;
|
query: string;
|
||||||
spaceId?: string;
|
spaceId?: string;
|
||||||
shareId?: string;
|
shareId?: string;
|
||||||
|
creatorId?: string;
|
||||||
|
labelIds?: string[];
|
||||||
|
titleOnly?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IAttachmentSearch {
|
export interface IAttachmentSearch {
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ export interface IWorkspace {
|
|||||||
generativeAi?: boolean;
|
generativeAi?: boolean;
|
||||||
disablePublicSharing?: boolean;
|
disablePublicSharing?: boolean;
|
||||||
mcpEnabled?: boolean;
|
mcpEnabled?: boolean;
|
||||||
|
aiChatReadOnly?: boolean;
|
||||||
|
aiChatWorkspaceKnowledgeOnly?: boolean;
|
||||||
trashRetentionDays?: number;
|
trashRetentionDays?: number;
|
||||||
restrictApiToAdmins?: boolean;
|
restrictApiToAdmins?: boolean;
|
||||||
allowMemberTemplates?: boolean;
|
allowMemberTemplates?: boolean;
|
||||||
@@ -51,6 +53,8 @@ export interface IWorkspaceAiSettings {
|
|||||||
generative?: boolean;
|
generative?: boolean;
|
||||||
mcp?: boolean;
|
mcp?: boolean;
|
||||||
chat?: boolean;
|
chat?: boolean;
|
||||||
|
chatReadOnly?: boolean;
|
||||||
|
chatWorkspaceKnowledgeOnly?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IWorkspaceSharingSettings {
|
export interface IWorkspaceSharingSettings {
|
||||||
|
|||||||
@@ -33,3 +33,31 @@
|
|||||||
color: var(--mantine-color-dimmed);
|
color: var(--mantine-color-dimmed);
|
||||||
-webkit-text-fill-color: var(--mantine-color-dimmed);
|
-webkit-text-fill-color: var(--mantine-color-dimmed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Spotlight's selected action ships as primary-filled blue with white text,
|
||||||
|
* but our custom action children (gray badge, dimmed snippet, gray icons)
|
||||||
|
* keep their light-surface colors on it and drop below WCAG AA 4.5:1
|
||||||
|
* (WCAG 1.4.3). Use a gray selection one step above the gray-0/dark-6
|
||||||
|
* hover instead - it matches the app's selection styling (we use no blue
|
||||||
|
* fills) and keeps every child at its already-passing resting contrast.
|
||||||
|
*/
|
||||||
|
.mantine-Spotlight-action[data-selected] {
|
||||||
|
background-color: light-dark(
|
||||||
|
var(--mantine-color-gray-1),
|
||||||
|
var(--mantine-color-dark-5)
|
||||||
|
);
|
||||||
|
color: var(--mantine-color-text);
|
||||||
|
--action-description-color: var(--mantine-color-dimmed);
|
||||||
|
--action-description-opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Result actions are tab stops (tabIndex restored via ref); give keyboard
|
||||||
|
* focus the same gray treatment as arrow-key selection so both navigation
|
||||||
|
* modes read identically (WCAG 2.4.7 focus visible).
|
||||||
|
*/
|
||||||
|
.mantine-Spotlight-action:focus-visible {
|
||||||
|
background-color: light-dark(
|
||||||
|
var(--mantine-color-gray-1),
|
||||||
|
var(--mantine-color-dark-5)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export const Feature = {
|
|||||||
PERSONAL_SPACES: 'spaces:personal',
|
PERSONAL_SPACES: 'spaces:personal',
|
||||||
DOCX_EXPORT: 'export:docx',
|
DOCX_EXPORT: 'export:docx',
|
||||||
BASES: 'bases',
|
BASES: 'bases',
|
||||||
|
AI_CONTROLS: 'ai:controls',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type FeatureKey = (typeof Feature)[keyof typeof Feature];
|
export type FeatureKey = (typeof Feature)[keyof typeof Feature];
|
||||||
|
|||||||
@@ -116,8 +116,8 @@ export class AttachmentService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only index PDFs and DOCX files
|
// Only index PDF, DOCX and TXT files
|
||||||
if (['.pdf', '.docx'].includes(attachment.fileExt.toLowerCase())) {
|
if (['.pdf', '.docx', '.txt'].includes(attachment.fileExt.toLowerCase())) {
|
||||||
await this.attachmentQueue.add(
|
await this.attachmentQueue.add(
|
||||||
QueueJob.ATTACHMENT_INDEX_CONTENT,
|
QueueJob.ATTACHMENT_INDEX_CONTENT,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ export class CommentController {
|
|||||||
@AuthWorkspace() workspace: Workspace,
|
@AuthWorkspace() workspace: Workspace,
|
||||||
) {
|
) {
|
||||||
const page = await this.pageRepo.findById(createCommentDto.pageId);
|
const page = await this.pageRepo.findById(createCommentDto.pageId);
|
||||||
if (!page || page.deletedAt) {
|
if (!page || page.workspaceId !== workspace.id || page.deletedAt) {
|
||||||
throw new NotFoundException('Page not found');
|
throw new NotFoundException('Page not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,9 +89,10 @@ export class CommentController {
|
|||||||
@Body()
|
@Body()
|
||||||
pagination: PaginationOptions,
|
pagination: PaginationOptions,
|
||||||
@AuthUser() user: User,
|
@AuthUser() user: User,
|
||||||
|
@AuthWorkspace() workspace: Workspace,
|
||||||
) {
|
) {
|
||||||
const page = await this.pageRepo.findById(input.pageId);
|
const page = await this.pageRepo.findById(input.pageId);
|
||||||
if (!page) {
|
if (!page || page.workspaceId !== workspace.id || page.deletedAt) {
|
||||||
throw new NotFoundException('Page not found');
|
throw new NotFoundException('Page not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,14 +103,18 @@ export class CommentController {
|
|||||||
|
|
||||||
@HttpCode(HttpStatus.OK)
|
@HttpCode(HttpStatus.OK)
|
||||||
@Post('info')
|
@Post('info')
|
||||||
async findOne(@Body() input: CommentIdDto, @AuthUser() user: User) {
|
async findOne(
|
||||||
|
@Body() input: CommentIdDto,
|
||||||
|
@AuthUser() user: User,
|
||||||
|
@AuthWorkspace() workspace: Workspace,
|
||||||
|
) {
|
||||||
const comment = await this.commentRepo.findById(input.commentId);
|
const comment = await this.commentRepo.findById(input.commentId);
|
||||||
if (!comment) {
|
if (!comment) {
|
||||||
throw new NotFoundException('Comment not found');
|
throw new NotFoundException('Comment not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const page = await this.pageRepo.findById(comment.pageId);
|
const page = await this.pageRepo.findById(comment.pageId);
|
||||||
if (!page) {
|
if (!page || page.workspaceId !== workspace.id || page.deletedAt) {
|
||||||
throw new NotFoundException('Page not found');
|
throw new NotFoundException('Page not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +135,7 @@ export class CommentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const page = await this.pageRepo.findById(comment.pageId);
|
const page = await this.pageRepo.findById(comment.pageId);
|
||||||
if (!page) {
|
if (!page || page.workspaceId !== workspace.id || page.deletedAt) {
|
||||||
throw new NotFoundException('Page not found');
|
throw new NotFoundException('Page not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +153,7 @@ export class CommentController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const page = await this.pageRepo.findById(comment.pageId);
|
const page = await this.pageRepo.findById(comment.pageId);
|
||||||
if (!page) {
|
if (!page || page.workspaceId !== workspace.id || page.deletedAt) {
|
||||||
throw new NotFoundException('Page not found');
|
throw new NotFoundException('Page not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,15 @@ import { executeTx } from '@docmost/db/utils';
|
|||||||
import { PaginationOptions } from '@docmost/db/pagination/pagination-options';
|
import { PaginationOptions } from '@docmost/db/pagination/pagination-options';
|
||||||
import { PagePermissionRepo } from '@docmost/db/repos/page/page-permission.repo';
|
import { PagePermissionRepo } from '@docmost/db/repos/page/page-permission.repo';
|
||||||
import { normalizeLabelName } from './utils';
|
import { normalizeLabelName } from './utils';
|
||||||
|
import { EventEmitter2 } from "@nestjs/event-emitter";
|
||||||
|
import { EventName } from "src/common/events/event.contants";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LabelService {
|
export class LabelService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly labelRepo: LabelRepo,
|
private readonly labelRepo: LabelRepo,
|
||||||
private readonly pagePermissionRepo: PagePermissionRepo,
|
private readonly pagePermissionRepo: PagePermissionRepo,
|
||||||
|
private readonly eventEmitter: EventEmitter2,
|
||||||
@InjectKysely() private readonly db: KyselyDB,
|
@InjectKysely() private readonly db: KyselyDB,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -34,6 +37,12 @@ export class LabelService {
|
|||||||
attached.push(label);
|
attached.push(label);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.eventEmitter.emit(EventName.PAGE_UPDATED, {
|
||||||
|
pageIds: [pageId],
|
||||||
|
workspaceId: workspaceId,
|
||||||
|
});
|
||||||
|
|
||||||
return attached;
|
return attached;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,6 +73,11 @@ export class LabelService {
|
|||||||
await this.labelRepo.deleteLabel(labelId, workspaceId, trx);
|
await this.labelRepo.deleteLabel(labelId, workspaceId, trx);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.eventEmitter.emit(EventName.PAGE_UPDATED, {
|
||||||
|
pageIds: [pageId],
|
||||||
|
workspaceId: workspaceId,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPageLabels(pageId: string, pagination: PaginationOptions) {
|
async getPageLabels(pageId: string, pagination: PaginationOptions) {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
IsArray,
|
||||||
IsBoolean,
|
IsBoolean,
|
||||||
IsNotEmpty,
|
IsNotEmpty,
|
||||||
IsNumber,
|
IsNumber,
|
||||||
@@ -8,9 +9,9 @@ import {
|
|||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
|
|
||||||
export class SearchDTO {
|
export class SearchDTO {
|
||||||
@IsNotEmpty()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
query: string;
|
query?: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsUUID()
|
@IsUUID()
|
||||||
@@ -24,6 +25,15 @@ export class SearchDTO {
|
|||||||
@IsUUID()
|
@IsUUID()
|
||||||
creatorId?: string;
|
creatorId?: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsArray()
|
||||||
|
@IsUUID('all', { each: true })
|
||||||
|
labelIds?: string[];
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsBoolean()
|
||||||
|
titleOnly?: boolean;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
limit?: number;
|
limit?: number;
|
||||||
|
|||||||
@@ -29,12 +29,36 @@ export class SearchService {
|
|||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
},
|
},
|
||||||
): Promise<{ items: SearchResponseDto[] }> {
|
): Promise<{ items: SearchResponseDto[] }> {
|
||||||
const { query } = searchParams;
|
const query = searchParams.query?.trim() ?? '';
|
||||||
|
const labelIds = [...new Set(searchParams.labelIds ?? [])];
|
||||||
|
// selected filters (labels, creator) are browsable without a query
|
||||||
|
const browseByFilters =
|
||||||
|
query.length < 1 &&
|
||||||
|
(labelIds.length > 0 || Boolean(searchParams.creatorId));
|
||||||
|
|
||||||
if (query.length < 1) {
|
if (query.length < 1 && !browseByFilters) {
|
||||||
return { items: [] };
|
return { items: [] };
|
||||||
}
|
}
|
||||||
const searchQuery = tsquery(query.trim() + '*');
|
const searchQuery = tsquery(query + '*');
|
||||||
|
const titleOnly = searchParams.titleOnly === true;
|
||||||
|
const titleQuery = query;
|
||||||
|
// escape LIKE wildcards; ranking keeps the raw query
|
||||||
|
const titleLikeQuery = query.replace(/[\\%_]/g, '\\$&');
|
||||||
|
|
||||||
|
const rankColumn = browseByFilters
|
||||||
|
? sql<number>`0`.as('rank')
|
||||||
|
: titleOnly
|
||||||
|
? sql<number>`word_similarity(lower(f_unaccent(${titleQuery})), lower(f_unaccent(pages.title)))`.as(
|
||||||
|
'rank',
|
||||||
|
)
|
||||||
|
: sql<number>`ts_rank(tsv, to_tsquery('english', f_unaccent(${searchQuery})))`.as(
|
||||||
|
'rank',
|
||||||
|
);
|
||||||
|
const highlightColumn = browseByFilters || titleOnly
|
||||||
|
? sql<string>`''`.as('highlight')
|
||||||
|
: sql<string>`ts_headline('english', text_content, to_tsquery('english', f_unaccent(${searchQuery})),'MinWords=9, MaxWords=10, MaxFragments=3')`.as(
|
||||||
|
'highlight',
|
||||||
|
);
|
||||||
|
|
||||||
let queryResults = this.db
|
let queryResults = this.db
|
||||||
.selectFrom('pages')
|
.selectFrom('pages')
|
||||||
@@ -47,23 +71,41 @@ export class SearchService {
|
|||||||
'creatorId',
|
'creatorId',
|
||||||
'createdAt',
|
'createdAt',
|
||||||
'updatedAt',
|
'updatedAt',
|
||||||
sql<number>`ts_rank(tsv, to_tsquery('english', f_unaccent(${searchQuery})))`.as(
|
rankColumn,
|
||||||
'rank',
|
highlightColumn,
|
||||||
),
|
|
||||||
sql<string>`ts_headline('english', text_content, to_tsquery('english', f_unaccent(${searchQuery})),'MinWords=9, MaxWords=10, MaxFragments=3')`.as(
|
|
||||||
'highlight',
|
|
||||||
),
|
|
||||||
])
|
])
|
||||||
.where(
|
.$if(!browseByFilters && !titleOnly, (qb) =>
|
||||||
|
qb.where(
|
||||||
'tsv',
|
'tsv',
|
||||||
'@@',
|
'@@',
|
||||||
sql<string>`to_tsquery('english', f_unaccent(${searchQuery}))`,
|
sql<string>`to_tsquery('english', f_unaccent(${searchQuery}))`,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.$if(!browseByFilters && titleOnly, (qb) =>
|
||||||
|
qb.where((eb) =>
|
||||||
|
eb(
|
||||||
|
sql`lower(f_unaccent(pages.title))`,
|
||||||
|
'like',
|
||||||
|
sql`lower(f_unaccent(${`%${titleLikeQuery}%`}))`,
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
.$if(Boolean(searchParams.creatorId), (qb) =>
|
.$if(Boolean(searchParams.creatorId), (qb) =>
|
||||||
qb.where('creatorId', '=', searchParams.creatorId),
|
qb.where('creatorId', '=', searchParams.creatorId),
|
||||||
)
|
)
|
||||||
|
.$if(labelIds?.length > 0, (qb) =>
|
||||||
|
qb.where(
|
||||||
|
'id',
|
||||||
|
'in',
|
||||||
|
this.db
|
||||||
|
.selectFrom('pageLabels')
|
||||||
|
.select('pageId')
|
||||||
|
.where('labelId', 'in', labelIds),
|
||||||
|
),
|
||||||
|
)
|
||||||
.where('deletedAt', 'is', null)
|
.where('deletedAt', 'is', null)
|
||||||
.orderBy('rank', 'desc')
|
.$if(browseByFilters, (qb) => qb.orderBy('updatedAt', 'desc'))
|
||||||
|
.$if(!browseByFilters, (qb) => qb.orderBy('rank', 'desc'))
|
||||||
.limit(searchParams.limit || 25)
|
.limit(searchParams.limit || 25)
|
||||||
.offset(searchParams.offset || 0);
|
.offset(searchParams.offset || 0);
|
||||||
|
|
||||||
@@ -71,8 +113,7 @@ export class SearchService {
|
|||||||
queryResults = queryResults.select((eb) => this.pageRepo.withSpace(eb));
|
queryResults = queryResults.select((eb) => this.pageRepo.withSpace(eb));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (searchParams.spaceId) {
|
if (searchParams.spaceId && opts.userId) {
|
||||||
// search by spaceId
|
|
||||||
queryResults = queryResults.where('spaceId', '=', searchParams.spaceId);
|
queryResults = queryResults.where('spaceId', '=', searchParams.spaceId);
|
||||||
} else if (opts.userId && !searchParams.spaceId) {
|
} else if (opts.userId && !searchParams.spaceId) {
|
||||||
// only search spaces the user is a member of
|
// only search spaces the user is a member of
|
||||||
|
|||||||
@@ -46,8 +46,9 @@ export class ShareService {
|
|||||||
throw new NotFoundException('Share not found');
|
throw new NotFoundException('Share not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const isRestricted =
|
const isRestricted = await this.pagePermissionRepo.hasRestrictedAncestor(
|
||||||
await this.pagePermissionRepo.hasRestrictedAncestor(share.pageId);
|
share.pageId,
|
||||||
|
);
|
||||||
if (isRestricted) {
|
if (isRestricted) {
|
||||||
throw new NotFoundException('Share not found');
|
throw new NotFoundException('Share not found');
|
||||||
}
|
}
|
||||||
@@ -110,6 +111,9 @@ export class ShareService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getSharedPage(dto: ShareInfoDto, workspaceId: string) {
|
async getSharedPage(dto: ShareInfoDto, workspaceId: string) {
|
||||||
|
//TODO: we should resolve the page from the share id
|
||||||
|
if (!dto.pageId) throw new NotFoundException('Shared page not found');
|
||||||
|
|
||||||
const share = await this.getShareForPage(dto.pageId, workspaceId);
|
const share = await this.getShareForPage(dto.pageId, workspaceId);
|
||||||
|
|
||||||
if (!share) {
|
if (!share) {
|
||||||
@@ -126,8 +130,9 @@ export class ShareService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Block access to restricted pages
|
// Block access to restricted pages
|
||||||
const isRestricted =
|
const isRestricted = await this.pagePermissionRepo.hasRestrictedAncestor(
|
||||||
await this.pagePermissionRepo.hasRestrictedAncestor(page.id);
|
page.id,
|
||||||
|
);
|
||||||
if (isRestricted) {
|
if (isRestricted) {
|
||||||
throw new NotFoundException('Shared page not found');
|
throw new NotFoundException('Shared page not found');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,4 +68,12 @@ export class UpdateWorkspaceDto extends PartialType(CreateWorkspaceDto) {
|
|||||||
@IsString()
|
@IsString()
|
||||||
@IsIn(['read', 'edit'])
|
@IsIn(['read', 'edit'])
|
||||||
defaultPageEditMode: string;
|
defaultPageEditMode: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsBoolean()
|
||||||
|
aiChatReadOnly: boolean;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsBoolean()
|
||||||
|
aiChatWorkspaceKnowledgeOnly: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -334,7 +334,9 @@ export class WorkspaceService {
|
|||||||
typeof updateWorkspaceDto.restrictApiToAdmins !== 'undefined' ||
|
typeof updateWorkspaceDto.restrictApiToAdmins !== 'undefined' ||
|
||||||
typeof updateWorkspaceDto.allowMemberTemplates !== 'undefined' ||
|
typeof updateWorkspaceDto.allowMemberTemplates !== 'undefined' ||
|
||||||
typeof updateWorkspaceDto.isScimEnabled !== 'undefined' ||
|
typeof updateWorkspaceDto.isScimEnabled !== 'undefined' ||
|
||||||
typeof updateWorkspaceDto.allowPersonalSpaces !== 'undefined'
|
typeof updateWorkspaceDto.allowPersonalSpaces !== 'undefined' ||
|
||||||
|
typeof updateWorkspaceDto.aiChatReadOnly !== 'undefined' ||
|
||||||
|
typeof updateWorkspaceDto.aiChatWorkspaceKnowledgeOnly !== 'undefined'
|
||||||
) {
|
) {
|
||||||
const ws = await this.db
|
const ws = await this.db
|
||||||
.selectFrom('workspaces')
|
.selectFrom('workspaces')
|
||||||
@@ -374,6 +376,21 @@ export class WorkspaceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof updateWorkspaceDto.aiChatReadOnly !== 'undefined' ||
|
||||||
|
typeof updateWorkspaceDto.aiChatWorkspaceKnowledgeOnly !== 'undefined'
|
||||||
|
) {
|
||||||
|
if (
|
||||||
|
!this.licenseCheckService.hasFeature(
|
||||||
|
ws.licenseKey,
|
||||||
|
Feature.AI_CONTROLS,
|
||||||
|
ws.plan,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
throw new ForbiddenException('This feature requires a valid license');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof updateWorkspaceDto.disablePublicSharing !== 'undefined' ||
|
typeof updateWorkspaceDto.disablePublicSharing !== 'undefined' ||
|
||||||
typeof updateWorkspaceDto.trashRetentionDays !== 'undefined' ||
|
typeof updateWorkspaceDto.trashRetentionDays !== 'undefined' ||
|
||||||
@@ -516,6 +533,34 @@ export class WorkspaceService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof updateWorkspaceDto.aiChatReadOnly !== 'undefined') {
|
||||||
|
const prev = settingsBefore?.ai?.chatReadOnly ?? false;
|
||||||
|
if (prev !== updateWorkspaceDto.aiChatReadOnly) {
|
||||||
|
before.aiChatReadOnly = prev;
|
||||||
|
after.aiChatReadOnly = updateWorkspaceDto.aiChatReadOnly;
|
||||||
|
}
|
||||||
|
await this.workspaceRepo.updateAiSettings(
|
||||||
|
workspaceId,
|
||||||
|
'chatReadOnly',
|
||||||
|
updateWorkspaceDto.aiChatReadOnly,
|
||||||
|
trx,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof updateWorkspaceDto.aiChatWorkspaceKnowledgeOnly !== 'undefined') {
|
||||||
|
const prev = settingsBefore?.ai?.chatWorkspaceKnowledgeOnly ?? false;
|
||||||
|
if (prev !== updateWorkspaceDto.aiChatWorkspaceKnowledgeOnly) {
|
||||||
|
before.aiChatWorkspaceKnowledgeOnly = prev;
|
||||||
|
after.aiChatWorkspaceKnowledgeOnly = updateWorkspaceDto.aiChatWorkspaceKnowledgeOnly;
|
||||||
|
}
|
||||||
|
await this.workspaceRepo.updateAiSettings(
|
||||||
|
workspaceId,
|
||||||
|
'chatWorkspaceKnowledgeOnly',
|
||||||
|
updateWorkspaceDto.aiChatWorkspaceKnowledgeOnly,
|
||||||
|
trx,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof updateWorkspaceDto.allowPersonalSpaces !== 'undefined') {
|
if (typeof updateWorkspaceDto.allowPersonalSpaces !== 'undefined') {
|
||||||
const prev = settingsBefore?.spaces?.allowPersonal ?? false;
|
const prev = settingsBefore?.spaces?.allowPersonal ?? false;
|
||||||
if (prev !== updateWorkspaceDto.allowPersonalSpaces) {
|
if (prev !== updateWorkspaceDto.allowPersonalSpaces) {
|
||||||
@@ -553,6 +598,8 @@ export class WorkspaceService {
|
|||||||
delete updateWorkspaceDto.aiChat;
|
delete updateWorkspaceDto.aiChat;
|
||||||
delete updateWorkspaceDto.allowPersonalSpaces;
|
delete updateWorkspaceDto.allowPersonalSpaces;
|
||||||
delete updateWorkspaceDto.defaultPageEditMode;
|
delete updateWorkspaceDto.defaultPageEditMode;
|
||||||
|
delete updateWorkspaceDto.aiChatReadOnly;
|
||||||
|
delete updateWorkspaceDto.aiChatWorkspaceKnowledgeOnly;
|
||||||
|
|
||||||
await this.workspaceRepo.updateWorkspace(
|
await this.workspaceRepo.updateWorkspace(
|
||||||
updateWorkspaceDto,
|
updateWorkspaceDto,
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { type Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
|
export async function up(db: Kysely<any>): Promise<void> {
|
||||||
|
await sql`CREATE INDEX IF NOT EXISTS pages_title_trgm_idx ON pages USING gin (lower(f_unaccent(title)) gin_trgm_ops)`.execute(
|
||||||
|
db,
|
||||||
|
);
|
||||||
|
|
||||||
|
// separators normalized to spaces so space-typed queries match How_to_export.pdf
|
||||||
|
await sql`CREATE INDEX IF NOT EXISTS attachments_file_name_trgm_idx ON attachments USING gin (lower(f_unaccent(translate(file_name, '_.-', ' '))) gin_trgm_ops)`.execute(
|
||||||
|
db,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(db: Kysely<any>): Promise<void> {
|
||||||
|
await sql`DROP INDEX IF EXISTS attachments_file_name_trgm_idx`.execute(db);
|
||||||
|
await sql`DROP INDEX IF EXISTS pages_title_trgm_idx`.execute(db);
|
||||||
|
}
|
||||||
+1
-1
Submodule apps/server/src/ee updated: e13af0ce05...b51a46ef10
Reference in New Issue
Block a user