Conversations page: pump, search, read the transcript; docs and the libredesk link
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3544f29d85
commit
45db86d1ff
8 files changed
+127
-16
No files matched your search
+4
-2
@@ -3,11 +3,12 @@ import {
|
||||
ActionIcon, AppShell, Burger, ColorSwatch, Group, Loader, NavLink, ScrollArea, Text, Tooltip, useComputedColorScheme, useMantineColorScheme,
|
||||
} from "@mantine/core";
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
import { IconChartLine, IconCircleCheck, IconCircleDashed, IconFolder, IconMoon, IconSatellite, IconSun } from "@tabler/icons-react";
|
||||
import { IconChartLine, IconCircleCheck, IconCircleDashed, IconFolder, IconMessages, IconMoon, IconSatellite, IconSun } from "@tabler/icons-react";
|
||||
|
||||
const Data = lazy(() => import("./pages/Data.jsx")); // Plotly, loaded only here
|
||||
const Stations = lazy(() => import("./pages/Stations.jsx"));
|
||||
const PAGES = [["data", "Data", IconChartLine], ["stations", "Stations", IconSatellite]];
|
||||
const Conversations = lazy(() => import("./pages/Conversations.jsx"));
|
||||
const PAGES = [["data", "Data", IconChartLine], ["stations", "Stations", IconSatellite], ["conversations", "Conversations", IconMessages]];
|
||||
|
||||
// The address: #/<page>?station=…&start=…&end=…; reloading keeps the page and the selection, Back works; without dates, the
|
||||
// last 5 UTC days, today included (end excluded: tomorrow)
|
||||
@@ -142,6 +143,7 @@ export default function App() {
|
||||
<AppShell.Main bg="var(--mantine-color-default-hover)">
|
||||
<Suspense fallback={<Loader m="xl" />}>
|
||||
{page === "stations" ? <Stations selection={selection} />
|
||||
: page === "conversations" ? <Conversations />
|
||||
: <Data selection={selection} choose={choose} analysis={analysis} setAnalysis={setAnalysis}
|
||||
support={support} setSupport={setSupport} />}
|
||||
</Suspense>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Button, Card, Group, Select, TextInput } from "@mantine/core";
|
||||
import { notifications } from "@mantine/notifications";
|
||||
|
||||
@@ -34,3 +34,11 @@ export function Selector({ selection, choose }) {
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
// A markdown rendered by the server (report, summary, transcript), at the height of its content once its images are loaded;
|
||||
// sandboxed: no script runs in it
|
||||
export function Page({ title, src }) {
|
||||
const frame = useRef();
|
||||
const fit = () => { const b = frame.current?.contentDocument?.body; if (b) frame.current.style.height = `${b.scrollHeight + 20}px`; };
|
||||
return <iframe ref={frame} title={title} sandbox="allow-same-origin" onLoad={fit} style={{ border: 0, width: "100%", height: 400 }} src={src} />;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Button, Card, Code, Group, ScrollArea, Stack, Table, Text, TextInput, Title, useComputedColorScheme } from "@mantine/core";
|
||||
import { IconSearch } from "@tabler/icons-react";
|
||||
import { call, Page } from "../common.jsx";
|
||||
|
||||
const when = t => (t ? t.slice(0, 16).replace("T", " ") : "");
|
||||
|
||||
// The LibreDesk conversations, pumped read-only by ~/aimsight-libredesk into labeling/auto/conversations/: a pumping (a range
|
||||
// of updates, or without dates what changed since the last one), its log read every 2 s; the pumped conversations, searched
|
||||
// on subject, contact and reference; a click shows the transcript (images inline, the client's text never run)
|
||||
export default function Conversations() {
|
||||
const [range, setRange] = useState({ start: "", end: "" }), [state, setState] = useState(null);
|
||||
const [list, setList] = useState([]), [search, setSearch] = useState(""), [open, setOpen] = useState(null);
|
||||
const dark = useComputedColorScheme("light") === "dark", wasRunning = useRef(false);
|
||||
const read = () => call("/api/conversations").then(l => l && setList(l));
|
||||
useEffect(() => { read(); }, []);
|
||||
useEffect(() => {
|
||||
const poll = () => fetch("/api/conversations/pump").then(r => r.ok && r.json()).then(p => {
|
||||
if (!p) return;
|
||||
if (wasRunning.current && !p.running) read(); // a pumping ended: the list again
|
||||
wasRunning.current = p.running;
|
||||
setState(p);
|
||||
}).catch(() => {}); // silently: every 2 s
|
||||
poll();
|
||||
const timer = setInterval(poll, 2000);
|
||||
return () => clearInterval(timer);
|
||||
}, []);
|
||||
const pump = () => call("/api/conversations/pump", "POST", range).then(p => { if (p) { wasRunning.current = p.running; setState(p); } });
|
||||
const q = search.trim().toLowerCase();
|
||||
const shown = list.filter(c => !q || [c.subject, c.contact, c.reference].some(x => x.toLowerCase().includes(q)));
|
||||
return (
|
||||
<Stack gap="lg" maw={1200}>
|
||||
<div>
|
||||
<Title order={2}>Conversations</Title>
|
||||
<Text c="dimmed">The LibreDesk conversations, pumped read-only into labeling/auto/conversations/: the thread, its images and
|
||||
attachments, for the support and as training data.</Text>
|
||||
</div>
|
||||
<Card shadow="sm" withBorder>
|
||||
<Stack gap="md">
|
||||
<Group align="flex-end" gap="md">
|
||||
<TextInput label="Updated from (UTC)" type="date" value={range.start} onChange={e => setRange({ ...range, start: e.currentTarget.value })} />
|
||||
<TextInput label="To (excluded)" type="date" value={range.end} onChange={e => setRange({ ...range, end: e.currentTarget.value })} />
|
||||
<Button onClick={pump} loading={!!state?.running}>Pump</Button>
|
||||
</Group>
|
||||
<Text size="xs" c="dimmed">Without dates: what changed since the last pumping; the first time, the whole history (a quiet
|
||||
hour). The key stays in ~/aimsight-libredesk/.env; nothing is ever written to LibreDesk.</Text>
|
||||
{state?.log?.length > 0 && (
|
||||
<ScrollArea h={200} viewportRef={v => v && (v.scrollTop = v.scrollHeight)}>
|
||||
<Code block>{state.log.join("\n")}</Code>
|
||||
</ScrollArea>
|
||||
)}
|
||||
</Stack>
|
||||
</Card>
|
||||
<Card shadow="sm" withBorder>
|
||||
<Stack gap="md">
|
||||
<TextInput placeholder="Search: subject, contact, reference" leftSection={<IconSearch size={16} />} value={search}
|
||||
onChange={e => setSearch(e.currentTarget.value)} maw={400} />
|
||||
{list.length ? (
|
||||
<ScrollArea.Autosize mah={400}>
|
||||
<Table highlightOnHover verticalSpacing={4} stickyHeader>
|
||||
<Table.Thead><Table.Tr><Table.Th>Ref.</Table.Th><Table.Th>Subject</Table.Th><Table.Th>Contact</Table.Th>
|
||||
<Table.Th>Status</Table.Th><Table.Th>Last message (UTC)</Table.Th><Table.Th>Messages</Table.Th><Table.Th>Attachments</Table.Th></Table.Tr></Table.Thead>
|
||||
<Table.Tbody>
|
||||
{shown.map(c => (
|
||||
<Table.Tr key={c.reference} onClick={() => setOpen(c.reference)} style={{ cursor: "pointer" }}
|
||||
bg={open === c.reference ? "var(--mantine-primary-color-light)" : undefined}>
|
||||
<Table.Td ff="monospace">{c.reference}</Table.Td><Table.Td>{c.subject}</Table.Td><Table.Td>{c.contact}</Table.Td>
|
||||
<Table.Td>{c.status}</Table.Td><Table.Td ff="monospace">{when(c.last)}</Table.Td>
|
||||
<Table.Td>{c.messages}</Table.Td><Table.Td>{c.attachments}</Table.Td>
|
||||
</Table.Tr>
|
||||
))}
|
||||
</Table.Tbody>
|
||||
</Table>
|
||||
</ScrollArea.Autosize>
|
||||
) : <Text c="dimmed" size="sm">No conversation pumped yet.</Text>}
|
||||
</Stack>
|
||||
</Card>
|
||||
{open && (
|
||||
<Card shadow="sm" withBorder>
|
||||
<Page key={`${open}-${dark}`} title="Transcript" src={`/api/conversations/${encodeURIComponent(open)}/report.html?dark=${dark}`} />
|
||||
</Card>
|
||||
)}
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
useComputedColorScheme,
|
||||
} from "@mantine/core";
|
||||
import { IconPlus, IconX } from "@tabler/icons-react";
|
||||
import { call, Selector } from "../common.jsx";
|
||||
import { call, Page, Selector } from "../common.jsx";
|
||||
import { StationImages } from "./Images.jsx";
|
||||
|
||||
// Data, the curve viewer and the labelling: one plot at the start, others to add or remove,
|
||||
@@ -515,12 +515,6 @@ function Thread({ lines }) {
|
||||
);
|
||||
}
|
||||
|
||||
// A markdown rendered by the server (report, summary), at the height of its content once its images are loaded
|
||||
function Page({ title, src }) {
|
||||
const frame = useRef();
|
||||
const fit = () => { const b = frame.current?.contentDocument?.body; if (b) frame.current.style.height = `${b.scrollHeight + 20}px`; };
|
||||
return <iframe ref={frame} title={title} sandbox="allow-same-origin" onLoad={fit} style={{ border: 0, width: "100%", height: 400 }} src={src} />;
|
||||
}
|
||||
|
||||
const STATE_COLOR = { running: "blue", done: "teal", error: "red", interrupted: "orange" };
|
||||
|
||||
|
||||
Reference in new issue
Block a user