Explain required price quarter and preserve chat wheel scrolling
This commit is contained in:
+46
-4
@@ -377,6 +377,8 @@ button { font-family: inherit; }
|
||||
.inline-basis-picker { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .35rem; padding: .2rem; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-card); max-width: 100%; }
|
||||
.inline-basis-picker select, .inline-basis-picker button, .inline-basis-picker input { max-width: 100%; min-width: 0; padding: .2rem .35rem; font: inherit; color: var(--text); background: var(--bg-card); border: 1px solid var(--border); border-radius: 5px; }
|
||||
.inline-basis-note { flex-basis: 100%; font-size: .78rem; color: var(--text-muted); }
|
||||
.inline-basis-note[role="alert"] { color: var(--danger); }
|
||||
.inline-basis-picker select[aria-invalid="true"] { border-color: var(--danger); }
|
||||
.inline-basis-picker .inline-norm-select { max-width: min(28rem, 100%); }
|
||||
.inline-basis-picker .inline-quantity { width: 6rem; }
|
||||
.inline-basis-picker .inline-basis-apply { color: var(--accent); cursor: pointer; }
|
||||
@@ -420,7 +422,7 @@ button { font-family: inherit; }
|
||||
/* Таблица живёт в своём окне с ограничением высоты: иначе её горизонтальная полоса
|
||||
оказывалась внизу длинной таблицы, и до неё надо было прокрутить всю ленту
|
||||
(сказал Хозяин 18.11). С max-height обе полосы всегда у края видимой рамки. */
|
||||
.msg-ai .table-wrap { overflow-y: auto; overflow-x: hidden; max-height: min(60vh, 560px); overscroll-behavior: contain; -webkit-overflow-scrolling: touch; margin: .5rem 0; border: 1px solid var(--border); border-radius: 8px; scrollbar-width: thin; scrollbar-color: var(--text-muted) transparent; }
|
||||
.msg-ai .table-wrap { overflow-y: auto; overflow-x: hidden; max-height: min(60vh, 560px); -webkit-overflow-scrolling: touch; margin: .5rem 0; border: 1px solid var(--border); border-radius: 8px; scrollbar-width: thin; scrollbar-color: var(--text-muted) transparent; }
|
||||
/* Полоса прокрутки у таблицы должна быть видна в обеих темах: общий «тихий»
|
||||
скроллбар в тёмной теме сливался с фоном, и казалось, что таблица обрезана
|
||||
(жалоба Хозяина 18.11). */
|
||||
@@ -1110,6 +1112,7 @@ function enhanceTables(container) {
|
||||
}
|
||||
const wrap = document.createElement('div');
|
||||
wrap.className = 'table-wrap';
|
||||
wrap.addEventListener('wheel', passTableWheelAtEdge, {passive: false});
|
||||
table.parentNode.insertBefore(wrap, table);
|
||||
wrap.appendChild(table);
|
||||
// панель с кнопкой выгрузки
|
||||
@@ -1127,6 +1130,26 @@ function enhanceTables(container) {
|
||||
});
|
||||
}
|
||||
|
||||
// Когда таблица дошла до края, прокручиваем саму ленту. Chromium иногда
|
||||
// оставляет колесо во вложенном скролле даже без overscroll-behavior: contain.
|
||||
function passTableWheelAtEdge(event) {
|
||||
if (event.shiftKey || Math.abs(event.deltaY) <= Math.abs(event.deltaX)) return;
|
||||
const table = event.currentTarget;
|
||||
const chat = document.getElementById('messages');
|
||||
if (!chat) return;
|
||||
const down = event.deltaY > 0;
|
||||
const tableAtEdge = down
|
||||
? table.scrollTop + table.clientHeight >= table.scrollHeight - 2
|
||||
: table.scrollTop <= 2;
|
||||
const chatCanScroll = down
|
||||
? chat.scrollTop + chat.clientHeight < chat.scrollHeight - 1
|
||||
: chat.scrollTop > 1;
|
||||
if (!tableAtEdge || !chatCanScroll) return;
|
||||
event.preventDefault();
|
||||
const factor = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? chat.clientHeight : 1;
|
||||
chat.scrollTop += event.deltaY * factor;
|
||||
}
|
||||
|
||||
// Обновляет подсказки у всех таблиц: нужна и после вставки, и после смены ширины окна —
|
||||
// иначе на узком окне таблица молча обрезается без объяснения (жалоба Хозяина 18.11).
|
||||
function updateTableHeights() {
|
||||
@@ -2321,6 +2344,7 @@ function bindFreeformBasis(host) {
|
||||
'Изменить объём для этого расчёта');
|
||||
}
|
||||
|
||||
let inlineBasisNoteSequence = 0;
|
||||
async function openFreeformBasis(button, host, label) {
|
||||
if (!host._messageId || viewOwner) return;
|
||||
const requestTab = tabId;
|
||||
@@ -2340,7 +2364,8 @@ async function openFreeformBasis(button, host, label) {
|
||||
if (currentZone) zoneSelect.value = String(currentZone.zone_id);
|
||||
const periodSelect = document.createElement('select'); periodSelect.setAttribute('aria-label', 'Квартал цен');
|
||||
const periodNote = document.createElement('span'); periodNote.className = 'inline-basis-note';
|
||||
periodNote.textContent = 'Квартал из ответа не загружен. Выберите доступный квартал для нового расчёта.';
|
||||
periodNote.id = 'inline-basis-period-note-' + ++inlineBasisNoteSequence;
|
||||
periodSelect.setAttribute('aria-describedby', periodNote.id);
|
||||
const quarterMention = (host._rawText || '').match(/\b(IV|III|II|I|[1-4])\s*квартал[а-яё]*\s+(20\d{2})/i);
|
||||
const roman = {I:1, II:2, III:3, IV:4};
|
||||
const mentionedPeriod = quarterMention
|
||||
@@ -2356,9 +2381,19 @@ async function openFreeformBasis(button, host, label) {
|
||||
const named = (zone ? zone.periods : []).find(p => p.name === mentionedPeriod)
|
||||
|| (zone ? zone.periods : []).find(p => (host._rawText || '').includes(p.name));
|
||||
if (named) periodSelect.value = String(named.period_id);
|
||||
periodNote.hidden = !quarterMention || !!named;
|
||||
periodSelect.removeAttribute('aria-invalid');
|
||||
periodNote.removeAttribute('role');
|
||||
periodNote.textContent = quarterMention && !named
|
||||
? 'Квартал из ответа не загружен. Выберите доступный квартал для нового расчёта.'
|
||||
: 'Выберите квартал цен для пересчёта.';
|
||||
periodNote.hidden = !!periodSelect.value;
|
||||
};
|
||||
fillPeriods(); zoneSelect.onchange = fillPeriods;
|
||||
periodSelect.onchange = () => {
|
||||
periodSelect.removeAttribute('aria-invalid');
|
||||
periodNote.removeAttribute('role');
|
||||
periodNote.hidden = !!periodSelect.value;
|
||||
};
|
||||
const normRows = options.norms || [];
|
||||
const position = options.position;
|
||||
const normSelect = document.createElement('select');
|
||||
@@ -2377,7 +2412,14 @@ async function openFreeformBasis(button, host, label) {
|
||||
const cancel = document.createElement('button'); cancel.type = 'button'; cancel.textContent = 'Отмена';
|
||||
cancel.onclick = () => picker.replaceWith(button);
|
||||
apply.onclick = async () => {
|
||||
if (!periodSelect.value) { periodSelect.focus(); return; }
|
||||
if (!periodSelect.value) {
|
||||
periodSelect.setAttribute('aria-invalid', 'true');
|
||||
periodNote.textContent = 'Выберите квартал цен перед пересчётом.';
|
||||
periodNote.hidden = false;
|
||||
periodNote.setAttribute('role', 'alert');
|
||||
periodSelect.focus();
|
||||
return;
|
||||
}
|
||||
if (normRows.length && (!quantity.value || !quantity.checkValidity()
|
||||
|| !Number.isFinite(Number(quantity.value)) || Number(quantity.value) <= 0)) {
|
||||
quantity.focus(); return;
|
||||
|
||||
@@ -167,6 +167,146 @@ def test_plain_answer_zone_changes_inside_its_bubble(browser, site):
|
||||
page.close()
|
||||
|
||||
|
||||
def test_plain_answer_explains_required_quarter_before_recalculate(browser, site):
|
||||
page = browser.new_page(viewport={"width": 980, "height": 700})
|
||||
page.goto(site)
|
||||
page.evaluate("""() => {
|
||||
window._basisPosts = [];
|
||||
const oldFetch = window.fetch;
|
||||
window.fetch = async (url, opts={}) => {
|
||||
if (String(url).includes('/api/messages/30/basis')) {
|
||||
if (opts.method === 'POST') {
|
||||
window._basisPosts.push(JSON.parse(opts.body));
|
||||
return new Response(JSON.stringify({answer:'Пересчитано: 280 ₽.'}),
|
||||
{status:200,headers:{'Content-Type':'application/json'}});
|
||||
}
|
||||
return new Response(JSON.stringify({revision:'old-hash',zones:[
|
||||
{zone_id:118,name:'Хабаровский край (1 зона)',periods:[
|
||||
{period_id:428,name:'4 квартал 2026'}]},
|
||||
{zone_id:225,name:'Хабаровский край (3 зона)',periods:[
|
||||
{period_id:428,name:'4 квартал 2026'}]}
|
||||
]}), {status:200,headers:{'Content-Type':'application/json'}});
|
||||
}
|
||||
return oldFetch(url,opts);
|
||||
};
|
||||
const answer = addMsg('ai','Норма ГЭСНм 10-08-002-02, объём работ = 100 шт.\\n'
|
||||
+ 'Период цен: III квартал 2025.\\nХабаровский край (1 зона)');
|
||||
answer._messageId = 30;
|
||||
bindFreeformBasis(answer);
|
||||
}""")
|
||||
page.locator(".inline-basis-trigger").first.click()
|
||||
page.locator('select[aria-label="Ценовая зона"]').select_option("225")
|
||||
quarter = page.locator('select[aria-label="Квартал цен"]')
|
||||
assert quarter.input_value() == ""
|
||||
page.locator(".inline-basis-apply").click()
|
||||
assert "Выберите квартал" in page.locator('.inline-basis-picker [role="alert"]').inner_text(timeout=2000)
|
||||
assert quarter.get_attribute("aria-invalid") == "true"
|
||||
assert quarter.evaluate("el => document.activeElement === el")
|
||||
assert page.evaluate("window._basisPosts.length") == 0
|
||||
screenshot_dir = os.environ.get("INLINE_CHAT_UX_SCREENSHOTS")
|
||||
if screenshot_dir:
|
||||
page.screenshot(path=str(Path(screenshot_dir) / "quarter-required.png"))
|
||||
quarter.select_option("428")
|
||||
assert quarter.get_attribute("aria-invalid") != "true"
|
||||
page.locator(".inline-basis-apply").click()
|
||||
page.locator(".msg-ai .ai-body", has_text="280 ₽").wait_for(timeout=10000)
|
||||
assert page.evaluate("window._basisPosts.length") == 1
|
||||
assert page.evaluate("window._basisPosts[0].zone_id") == 225
|
||||
assert page.locator("#messages .msg-ai").count() == 1
|
||||
page.close()
|
||||
|
||||
|
||||
def test_wheel_over_short_answer_table_scrolls_chat(browser, site):
|
||||
page = browser.new_page(viewport={"width": 980, "height": 700})
|
||||
page.goto(site)
|
||||
page.evaluate("""() => {
|
||||
const answer = addMsg('ai','Таблица');
|
||||
const table = document.createElement('table');
|
||||
table.innerHTML = '<tr><th>Работа</th><th>Цена</th></tr><tr><td>Монтаж</td><td>100</td></tr>';
|
||||
answer.appendChild(table);
|
||||
enhanceTables(answer);
|
||||
for (let i = 0; i < 24; i++) addMsg('system','Следующее сообщение ' + i);
|
||||
}""")
|
||||
table = page.locator(".msg-ai .table-wrap").first
|
||||
assert table.count() == 1
|
||||
assert table.evaluate("el => el.scrollHeight <= el.clientHeight")
|
||||
table.hover()
|
||||
page.evaluate("document.querySelector('#messages').scrollTop = 0")
|
||||
page.mouse.wheel(0, 360)
|
||||
page.wait_for_timeout(200)
|
||||
assert page.evaluate("document.querySelector('#messages').scrollTop") > 0
|
||||
page.close()
|
||||
|
||||
|
||||
def test_wheel_at_tall_answer_table_edge_scrolls_chat(browser, site):
|
||||
page = browser.new_page(viewport={"width": 980, "height": 700})
|
||||
page.goto(site)
|
||||
page.evaluate("""() => {
|
||||
const answer = addMsg('ai','Длинная таблица');
|
||||
const table = document.createElement('table');
|
||||
table.innerHTML = '<tr><th>Работа</th><th>Цена</th></tr>'
|
||||
+ Array.from({length:50}, (_,i) => `<tr><td>Позиция ${i}</td><td>100</td></tr>`).join('');
|
||||
answer.appendChild(table);
|
||||
enhanceTables(answer);
|
||||
for (let i = 0; i < 24; i++) addMsg('system','Следующее сообщение ' + i);
|
||||
}""")
|
||||
table = page.locator(".msg-ai .table-wrap").first
|
||||
table.hover()
|
||||
assert table.evaluate("el => el.scrollHeight > el.clientHeight")
|
||||
page.evaluate("""() => {
|
||||
document.querySelector('.msg-ai .table-wrap').scrollTop = 0;
|
||||
document.querySelector('#messages').scrollTop = 0;
|
||||
}""")
|
||||
box = table.bounding_box()
|
||||
x, y = box["x"] + 20, box["y"] + 20
|
||||
page.mouse.move(x, y)
|
||||
assert page.evaluate("([x,y]) => !!document.elementFromPoint(x,y)?.closest('.table-wrap')", [x,y])
|
||||
page.mouse.wheel(0, 160)
|
||||
page.wait_for_timeout(100)
|
||||
assert table.evaluate("el => el.scrollTop") > 0
|
||||
assert page.evaluate("document.querySelector('#messages').scrollTop") == 0
|
||||
page.evaluate("""() => {
|
||||
document.querySelector('.msg-ai .table-wrap').scrollTop = 100000;
|
||||
document.querySelector('#messages').scrollTop = 0;
|
||||
}""")
|
||||
box = table.bounding_box()
|
||||
x, y = box["x"] + 20, box["y"] + 20
|
||||
page.mouse.move(x, y)
|
||||
assert page.evaluate("([x,y]) => !!document.elementFromPoint(x,y)?.closest('.table-wrap')", [x,y])
|
||||
page.mouse.wheel(0, 360)
|
||||
page.wait_for_timeout(200)
|
||||
assert page.evaluate("document.querySelector('#messages').scrollTop") > 0
|
||||
page.close()
|
||||
|
||||
|
||||
def test_wheel_at_estimate_panel_edge_scrolls_chat(browser, site):
|
||||
page = browser.new_page(viewport={"width": 980, "height": 700})
|
||||
page.goto(site)
|
||||
page.evaluate("""() => {
|
||||
const answer = addMsg('ai','Смета');
|
||||
const panel = document.createElement('div'); panel.className = 'est-panel';
|
||||
const scroll = document.createElement('div'); scroll.className = 'est-scroll';
|
||||
scroll.innerHTML = Array.from({length:50}, (_,i) => `<p>Позиция ${i}: 100 ₽</p>`).join('');
|
||||
panel.appendChild(scroll); answer.appendChild(panel);
|
||||
for (let i = 0; i < 24; i++) addMsg('system','Следующее сообщение ' + i);
|
||||
}""")
|
||||
panel = page.locator(".msg-ai .est-scroll").first
|
||||
panel.hover()
|
||||
assert panel.evaluate("el => el.scrollHeight > el.clientHeight")
|
||||
page.evaluate("""() => {
|
||||
document.querySelector('.msg-ai .est-scroll').scrollTop = 100000;
|
||||
document.querySelector('#messages').scrollTop = 0;
|
||||
}""")
|
||||
box = panel.bounding_box()
|
||||
x, y = box["x"] + 20, box["y"] + 20
|
||||
page.mouse.move(x, y)
|
||||
assert page.evaluate("([x,y]) => !!document.elementFromPoint(x,y)?.closest('.est-scroll')", [x,y])
|
||||
page.mouse.wheel(0, 360)
|
||||
page.wait_for_timeout(200)
|
||||
assert page.evaluate("document.querySelector('#messages').scrollTop") > 0
|
||||
page.close()
|
||||
|
||||
|
||||
def test_plain_zone_without_calculable_position_has_no_dead_selector(browser, site):
|
||||
page = browser.new_page()
|
||||
page.goto(site)
|
||||
|
||||
Reference in New Issue
Block a user