feat(czat): tabela pod odpowiedzia - szersza niz tekst, 5 kolumn, karty na telefonie
- tabela wychodzi poza kolumne tekstu do szerokosci rozmowy (max 1200 px), wysrodkowana - lista pilnych: Rodzaj pod Pozycja, Stan pod data w kolumnie Termin, Odpowiada znika gdy wszedzie ta sama osoba; zestawienie umow: dni do konca pod data konca - dane wierszy bez zmian (z nich jest historia dla modelu); uklad to dane w table.view, wiec przetrwa zapis rozmowy w sessionStorage - ponizej 640 px kazdy wiersz to karta z etykietami, bez poziomego przewijania Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016uwxqJbh3fPYdfdLG3MU6f
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4d122cb481
commit
b22ee09828
@@ -64,7 +64,7 @@ def test_each_urgent_row_links_to_its_record_and_the_list_to_sygna() -> None:
|
||||
assert "rec: { slug: 'sygna', kind: 'zestawienie', key: 'atrium:pilne'" in pick
|
||||
table = _fn("function chatTableEl(")
|
||||
# A link only to this origin or an in-app hash, and the cell text set as text, never as markup.
|
||||
assert "href.startsWith('#') || sameOrigin(href)" in table and "a.textContent = r[linkCol]" in table
|
||||
assert "href.startsWith('#') || sameOrigin(href)" in table and "const a = el('a', null, r[i])" in table
|
||||
assert "innerHTML" not in table
|
||||
|
||||
|
||||
@@ -91,3 +91,42 @@ def test_quotes_come_from_the_models_words_once_not_from_the_appended_table() ->
|
||||
r = subprocess.run([NODE, "-e", script], capture_output=True, text=True, timeout=60, encoding="utf-8")
|
||||
assert r.returncode == 0, r.stderr
|
||||
assert [x["q"] for x in json.loads(r.stdout)] == ["Konstrukta-Bud — zapłata", "Remedium — kontrola UODO"]
|
||||
|
||||
|
||||
# The smallest DOM chatTableEl needs: elements that keep their children, text and class.
|
||||
_DOM = """
|
||||
const mk = (tag) => ({ tag, children: [], dataset: {}, className: '', textContent: '',
|
||||
appendChild(c) { this.children.push(c); return c; }, append(...c) { this.children.push(...c); } });
|
||||
const document = { createElement: mk };
|
||||
const sameOrigin = () => false;
|
||||
const text = (e) => [e.textContent, ...e.children.map(text)].filter(Boolean).join('/');
|
||||
"""
|
||||
|
||||
|
||||
def _draw(table: dict, view: dict) -> dict:
|
||||
script = _DOM + _fn("function chatTableEl(") + f"""
|
||||
const w = chatTableEl({{ ...{json.dumps(table, ensure_ascii=False)}, view: {json.dumps(view)} }});
|
||||
const [th, tb] = w.children[0].children;
|
||||
const cells = tb.children[0].children;
|
||||
const a = cells.map((c) => c.children[0]).find((x) => x && x.tag === 'a');
|
||||
console.log(JSON.stringify({{ head: th.children[0].children.map((c) => c.textContent), first: cells.map(text), link: a && a.href }}));"""
|
||||
r = subprocess.run([NODE, "-e", script], capture_output=True, text=True, timeout=60, encoding="utf-8")
|
||||
assert r.returncode == 0, r.stderr
|
||||
return json.loads(r.stdout)
|
||||
|
||||
|
||||
@pytest.mark.skipif(NODE is None, reason="needs node on PATH")
|
||||
def test_the_urgent_table_draws_five_columns_with_kind_and_state_underneath() -> None:
|
||||
view = {"sub": {"1": 2, "3": 4}, "head": {"3": "Termin"}, "dropSame": [6]}
|
||||
head = ["Lp.", "Pozycja", "Rodzaj", "Data", "Stan", "Sprawa / umowa", "Odpowiada", "Następny krok"]
|
||||
rows = [["1", "Odpowiedź na pozew", "procesowy", "2026-11-04", "po terminie od 2 dni", "sprawa 2026/0001", "Ala", "sprawdzić"],
|
||||
["2", "Rozprawa", "rozprawa", "2026-11-10", "za 4 dni", "sprawa 2026/0002", "Ala", "przygotować się"]]
|
||||
t = {"head": head, "rows": rows, "links": ["#/m/sygna/a", "#/m/sygna/b"], "linkCol": 5}
|
||||
compact = _draw(t, view)
|
||||
assert compact["head"] == ["Lp.", "Pozycja", "Termin", "Sprawa / umowa", "Następny krok"]
|
||||
assert compact["first"][1:3] == ["Odpowiedź na pozew/procesowy", "2026-11-04/po terminie od 2 dni"]
|
||||
assert compact["link"] == "#/m/sygna/a"
|
||||
assert _draw(t, {})["head"] == head # no view: drawn as it is
|
||||
# Different owners stay: the column is left out only when it says nothing.
|
||||
rows[1][6] = "Ola"
|
||||
assert "Odpowiada" in _draw(t, view)["head"]
|
||||
|
||||
+14
-2
@@ -145,9 +145,9 @@
|
||||
.ha-table th, .ha-table td { text-align: left; vertical-align: top; padding: 4px 8px; border-bottom: 1px solid var(--at-border); }
|
||||
.ha-table th { color: var(--at-text-muted); font-weight: 500; }
|
||||
.ha-table th, .ha-table td { overflow-wrap: normal; }
|
||||
.ha-table td:nth-child(2) { min-width: 12em; }
|
||||
.ha-table td:first-child { white-space: nowrap; }
|
||||
.ha-table td:last-child { min-width: 16em; }
|
||||
.ha-table td:nth-child(1), .ha-table td:nth-child(3), .ha-table td:nth-child(4), .ha-table td:nth-child(5) { white-space: nowrap; }
|
||||
.ha-sub { display: block; margin-top: 2px; font-size: 12px; color: var(--at-text-muted); }
|
||||
.ha-trace { margin-top: 8px; white-space: normal; overflow-wrap: anywhere; }
|
||||
.ha-trace summary { cursor: pointer; }
|
||||
/* A conversation open: the greeting and the figures step aside, the history reads downwards and the composer
|
||||
@@ -168,6 +168,10 @@
|
||||
padding: 24px 16px 16px; border: 0; border-radius: 0; background: none;
|
||||
}
|
||||
.home.chatting .home-answer > *, .home.chatting .home-box { width: 100%; max-width: 800px; margin-inline: auto; }
|
||||
/* A table needs more room than a line of text: it leaves the 800px column, up to the conversation's whole
|
||||
width (1200px at most), centred on the column. Never narrower than the column. */
|
||||
.home.chatting .home-answer { container-type: inline-size; }
|
||||
.home.chatting .ha-table { --tw: max(100%, min(100cqw, 1200px)); width: var(--tw); margin-left: calc((100% - var(--tw)) / 2); }
|
||||
.home.chatting .home-box { flex: none; margin-top: 0; padding: 8px 16px 16px; box-sizing: border-box; max-width: 832px; }
|
||||
.home.chatting .home-new { display: inline-flex; }
|
||||
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
|
||||
@@ -273,6 +277,14 @@ pre.diff {
|
||||
.home-model { flex: 1; min-width: 0; }
|
||||
.home-model > span:first-child { display: none; }
|
||||
.home-model select { width: 100%; max-width: none; }
|
||||
/* A phone: every row is a card, each cell under its own label; nothing scrolls sideways. */
|
||||
.ha-table thead { display: none; }
|
||||
.ha-table table, .ha-table tbody, .ha-table tr, .ha-table td { display: block; }
|
||||
.ha-table tr { padding: 10px 12px; margin-bottom: 8px; border: 1px solid var(--at-border); border-radius: var(--at-radius-lg); }
|
||||
.ha-table td { border: 0; padding: 2px 0; min-width: 0; white-space: normal; }
|
||||
.ha-table td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--at-text-muted); }
|
||||
.ha-table td:first-child::before { content: none; }
|
||||
.ha-table td:first-child { font-weight: 600; }
|
||||
.home.chatting .home-box { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
|
||||
.hr-kind { display: none; }
|
||||
|
||||
|
||||
+33
-17
@@ -1314,21 +1314,36 @@ function chatRender(toEnd) {
|
||||
box.scrollTop = toEnd && asked ? box.scrollTop + asked.getBoundingClientRect().top - box.getBoundingClientRect().top - 16 : keep;
|
||||
}
|
||||
|
||||
function chatTableEl({ head, rows, links = [], linkCol = -1 }) {
|
||||
const wrap = document.createElement('div');
|
||||
wrap.className = 'ha-table';
|
||||
const table = document.createElement('table');
|
||||
const tr = (cells, tag) => { const r = document.createElement('tr'); for (const c of cells) { const x = document.createElement(tag); x.textContent = c; r.appendChild(x); } return r; };
|
||||
const th = document.createElement('thead'); th.appendChild(tr(head, 'th'));
|
||||
const tb = document.createElement('tbody');
|
||||
rows.forEach((r, i) => {
|
||||
const row = tr(r, 'td');
|
||||
const href = links[i];
|
||||
if (href && row.children[linkCol] && (href.startsWith('#') || sameOrigin(href))) {
|
||||
const a = document.createElement('a');
|
||||
a.href = href;
|
||||
a.textContent = r[linkCol];
|
||||
row.children[linkCol].replaceChildren(a);
|
||||
/* The rows stay whole (the history the model reads next turn is built from them); `view` only says how to draw
|
||||
them, as plain data so it survives the conversation's storage: `sub` puts one column as a small second line
|
||||
under another ("procesowy" under the item, the state under the date), `head` renames a column, `dropSame`
|
||||
leaves out a column whose every row says the same (one owner for all). On a phone each row is a card. */
|
||||
function chatTableEl({ head, rows, links = [], linkCol = -1, view = {} }) {
|
||||
const sub = view.sub || {};
|
||||
const under = new Set(Object.values(sub).map(Number));
|
||||
const same = (c) => rows.every((r) => r[c] === rows[0][c]);
|
||||
const cols = head.map((_, i) => i).filter((i) => !under.has(i) && !((view.dropSame || []).includes(i) && rows.length > 1 && same(i)));
|
||||
const label = (i) => (view.head || {})[i] || head[i];
|
||||
const el = (tag, cls, text) => { const x = document.createElement(tag); if (cls) x.className = cls; if (text != null) x.textContent = text; return x; };
|
||||
const wrap = el('div', 'ha-table');
|
||||
const table = el('table');
|
||||
const hr = el('tr');
|
||||
for (const i of cols) hr.appendChild(el('th', null, label(i)));
|
||||
const th = el('thead'); th.appendChild(hr);
|
||||
const tb = el('tbody');
|
||||
rows.forEach((r, n) => {
|
||||
const row = el('tr');
|
||||
for (const i of cols) {
|
||||
const td = el('td');
|
||||
td.dataset.label = label(i);
|
||||
const href = links[n];
|
||||
if (i === linkCol && href && (href.startsWith('#') || sameOrigin(href))) {
|
||||
const a = el('a', null, r[i]);
|
||||
a.href = href;
|
||||
td.appendChild(a);
|
||||
} else td.textContent = r[i];
|
||||
if (sub[i] != null && r[sub[i]]) td.appendChild(el('span', 'ha-sub', r[sub[i]]));
|
||||
row.appendChild(td);
|
||||
}
|
||||
tb.appendChild(row);
|
||||
});
|
||||
@@ -2611,13 +2626,14 @@ function chatPick(question, index) {
|
||||
// read as "no links to the sources" (Tobiasz, 2026-11-06). The list itself opens Sygna's deadlines.
|
||||
const links = items.map((d) => { const r = index.byKey.get(d.key); return r && r.inner ? moduleHref(r.slug, r.inner) : ''; });
|
||||
return { empty, rec: { slug: 'sygna', kind: 'zestawienie', key: 'atrium:pilne', title: 'Pilne: pozycje wybrane do odpowiedzi', inner: 'deadlines', text,
|
||||
members: items.map((d) => d.key) }, table: { head, rows, links, linkCol: 5 } };
|
||||
members: items.map((d) => d.key) }, table: { head, rows, links, linkCol: 5, view: { sub: { 1: 2, 3: 4 }, head: { 3: en ? 'Due' : 'Termin' }, dropSame: [6] } } };
|
||||
}
|
||||
const chatIsEn = (question) => !/[ąćęłńóśźż]/i.test(question) && /(?:^|\W)(?:the|what|which|is|are|how|english)(?!\w)/i.test(question);
|
||||
function chatContractTable(cs, today, en) {
|
||||
const head = en ? ['No.', 'Contract', 'Counterparty', 'Ends', 'Days left', 'Status', 'Value'] : ['Lp.', 'Umowa', 'Kontrahent', 'Koniec', 'Zostało dni', 'Status', 'Wartość'];
|
||||
return { head, rows: cs.map((c, i) => [String(i + 1), `${c.number} ${c.name}`, c.counterparty || '-', c.ends_on || '-',
|
||||
c.ends_on ? String(chatDays(c.ends_on, today)) : '-', c.status, c.value_amount ? `${chatMoney(c.value_amount)} ${c.value_currency}` : '-']) };
|
||||
c.ends_on ? String(chatDays(c.ends_on, today)) : '-', c.status, c.value_amount ? `${chatMoney(c.value_amount)} ${c.value_currency}` : '-']),
|
||||
view: { sub: { 3: 4 } } };
|
||||
}
|
||||
const chatTableText = (t) => [t.head, ...t.rows].map((r) => '| ' + r.join(' | ') + ' |').join('\n');
|
||||
function chatListFor(sources, question) {
|
||||
|
||||
Reference in New Issue
Block a user