reshape search
This commit is contained in:
@@ -193,14 +193,14 @@ function truncateForDisplay(value, max = 80) {
|
||||
return `${value.slice(0, max)}… (${value.length} chars)`;
|
||||
}
|
||||
|
||||
function formatListRow(row, steuerklassen) {
|
||||
const stock = row.fBestand ?? '—';
|
||||
const price = formatPrice(row, steuerklassen);
|
||||
const name = row.cName ?? '—';
|
||||
return `${row.cArtNr ?? '—'} ${stock} ${price} ${name}`;
|
||||
function formatListRow(row) {
|
||||
const stock = row.stock ?? '—';
|
||||
const price = row.price == null ? '—' : eur(row.price);
|
||||
const name = row.name ?? '—';
|
||||
return `${row.sku ?? '—'} ${stock} ${price} ${name}`;
|
||||
}
|
||||
|
||||
const ResultList = ({ rows, onSelect, onBack, steuerklassen }) => {
|
||||
const ResultList = ({ rows, onSelect, onBack }) => {
|
||||
const [selected, setSelected] = useState(0);
|
||||
const windowStart = Math.max(0, Math.min(selected - Math.floor(VISIBLE_ROWS / 2), rows.length - VISIBLE_ROWS));
|
||||
const visible = rows.slice(windowStart, windowStart + VISIBLE_ROWS);
|
||||
@@ -227,9 +227,9 @@ const ResultList = ({ rows, onSelect, onBack, steuerklassen }) => {
|
||||
const absoluteIndex = windowStart + index;
|
||||
const prefix = absoluteIndex === selected ? chalk.cyan('> ') : ' ';
|
||||
const label = absoluteIndex === selected
|
||||
? chalk.cyan.bold(formatListRow(row, steuerklassen))
|
||||
: formatListRow(row, steuerklassen);
|
||||
return e(Text, { key: row.kArtikel ?? absoluteIndex }, prefix, label);
|
||||
? chalk.cyan.bold(formatListRow(row))
|
||||
: formatListRow(row);
|
||||
return e(Text, { key: row.id ?? absoluteIndex }, prefix, label);
|
||||
}),
|
||||
rows.length > VISIBLE_ROWS
|
||||
? e(Text, null, chalk.gray(`Showing ${windowStart + 1}-${windowStart + visible.length} of ${rows.length}`))
|
||||
@@ -296,7 +296,7 @@ const App = ({ steuerklassen }) => {
|
||||
return;
|
||||
}
|
||||
if (recordset.length === 1) {
|
||||
await loadArticle(recordset[0].cArtNr);
|
||||
await loadArticle(recordset[0].sku);
|
||||
return;
|
||||
}
|
||||
setRows(recordset);
|
||||
@@ -334,9 +334,8 @@ const App = ({ steuerklassen }) => {
|
||||
if (mode === MODES.LIST) {
|
||||
return e(ResultList, {
|
||||
rows,
|
||||
onSelect: (row) => loadArticle(row.cArtNr),
|
||||
onSelect: (row) => loadArticle(row.sku),
|
||||
onBack: backToSearch,
|
||||
steuerklassen,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user