refactor: refs #8406 simplified code
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Pau Rovira 2025-04-23 11:19:55 +02:00
parent 10d8db6de3
commit aedcda4799
1 changed files with 11 additions and 25 deletions

View File

@ -131,9 +131,7 @@ async function fetch(data) {
const rows = keyData ? data[keyData] : data; const rows = keyData ? data[keyData] : data;
resetData(rows); resetData(rows);
emit('onFetch', rows); emit('onFetch', rows);
if ($props.insertOnLoad) { $props.insertOnLoad && await insert();
await insert();
}
return rows; return rows;
} }
@ -231,7 +229,7 @@ async function insert(pushData = { ...$props.dataRequired, ...$props.dataDefault
const lastRow = formData.value.at(-1); const lastRow = formData.value.at(-1);
const isLastRowEmpty = lastRow ? isRowEmpty(lastRow) : false; const isLastRowEmpty = lastRow ? isRowEmpty(lastRow) : false;
if (formData.value.length > 0 && isLastRowEmpty) return; if (formData.value.length && isLastRowEmpty) return;
const $index = formData.value.length ? formData.value.at(-1).$index + 1 : 0; const $index = formData.value.length ? formData.value.at(-1).$index + 1 : 0;
const nRow = Object.assign({ $index }, pushData); const nRow = Object.assign({ $index }, pushData);
@ -335,33 +333,21 @@ function removeIndexField(data) {
async function handleTab(event) { async function handleTab(event) {
event.preventDefault(); event.preventDefault();
const { shiftKey, target } = event;
const focusableSelector = `tbody tr td:not(:first-child) :is(a, button, input, textarea, select, details):not([disabled])`; const focusableSelector = `tbody tr td:not(:first-child) :is(a, button, input, textarea, select, details):not([disabled])`;
const focusableElements = rowsContainer.value?.querySelectorAll(focusableSelector); const focusableElements = rowsContainer.value?.querySelectorAll(focusableSelector);
const currentIndex = Array.prototype.indexOf.call(focusableElements, event.target); const currentIndex = Array.prototype.indexOf.call(focusableElements, target);
const isLast = event.target === focusableElements[focusableElements.length - 1]; const index = shiftKey ? currentIndex - 1 : currentIndex + 1;
const isLast = target === focusableElements[focusableElements.length - 1];
const isFirst = currentIndex === 0; const isFirst = currentIndex === 0;
if (event.shiftKey) { if ((shiftKey && !isFirst) || (!shiftKey && !isLast))
if (!isFirst) { focusableElements[index]?.focus();
focusableElements[currentIndex - 1].focus(); else if (isLast) {
} else {
const prevRow = event.target.closest('tr')?.previousElementSibling;
const lastFocusable = prevRow?.querySelector(
'td:not(:first-child) :is(input, select, textarea):not([disabled])'
);
lastFocusable?.focus();
}
} else {
if (isLast) {
await insert(); await insert();
await nextTick(); await nextTick();
} else {
focusableElements[currentIndex + 1]?.focus();
} }
} }
}
async function reload(params) { async function reload(params) {
const data = await vnPaginateRef.value.fetch(params); const data = await vnPaginateRef.value.fetch(params);