Reported: the warranty page cannot be searched by machine number. It was there to be found. _related_machine puts the machine's number in the payload, and it does so for a stated reason - a shopfloor PC is bought, warranted and replaced as a PC, but it is FOUND by the machine it drives, and nobody walks the floor looking for an asset number. The table renders it as a chip. The filter looked at vendor, service level, service tag and asset number, and never at the machine. So the one identifier the feature was designed around was the one thing the search box could not match. This is how a field list goes wrong: a column was added to the table and not to the filter, and nothing connects the two. Moved the field list into warrantySearch.js so a test can see it, following controllingPc.js and labelPages.js. Machine name is searched as well - somebody who knows the bay by "the Makino" should not have to look up its number to find its warranty. The specs also pin the case that made the old inline version fragile: a covered asset whose machine is null, which is every printer and any PC nobody has linked yet, must not throw. And a missing field must not match: String(undefined) is 'undefined', so a naive coercion makes a search for "und" hit every row with an empty vendor. Not changed, worth knowing: the covered asset's NAME is still not searched, only its number. That looks like the same omission, but it is a wider change than the report - the placeholder has always said "asset" without saying which half - so it is left for a deliberate decision rather than folded in here.
45 lines
1.8 KiB
JavaScript
45 lines
1.8 KiB
JavaScript
// What the warranty list's search box matches against.
|
|
//
|
|
// Pulled out of WarrantiesList.vue so the field list is somewhere a test can
|
|
// see it. It went wrong the way a field list usually does: silently, by a
|
|
// column being added to the table and not to the filter.
|
|
//
|
|
// THE MACHINE NUMBER IS THE POINT. _related_machine in the warranty API exists
|
|
// precisely because "a shopfloor PC is bought, warranted and replaced as a PC,
|
|
// but it is FOUND by the machine it drives - nobody walks the floor looking for
|
|
// an asset number". The payload carries it, the table renders it in a chip, and
|
|
// the filter did not look at it - so the one identifier the feature was built
|
|
// around was the one thing the search box could not find.
|
|
|
|
/**
|
|
* Does this warranty match the search term?
|
|
*
|
|
* @param {object} warranty - a row from GET /api/warranties
|
|
* @param {string} term - the raw search box contents
|
|
* @returns {boolean} true when the term is empty or any searched field contains it
|
|
*/
|
|
export function matchesWarrantySearch(warranty, term) {
|
|
const needle = (term || '').trim().toLowerCase()
|
|
if (!needle) return true
|
|
if (!warranty) return false
|
|
|
|
const has = (value) => String(value ?? '').toLowerCase().includes(needle)
|
|
|
|
if (has(warranty.vendor) || has(warranty.servicelevel) || has(warranty.servicetag)) {
|
|
return true
|
|
}
|
|
|
|
return (warranty.assets || []).some((asset) => {
|
|
if (has(asset?.assetnumber)) return true
|
|
// The related machine is optional: a warranty on something that drives no
|
|
// machine has none, and a machine that was never linked leaves it null.
|
|
const machine = asset?.machine
|
|
return !!machine && (has(machine.machinenumber) || has(machine.name))
|
|
})
|
|
}
|
|
|
|
/** The fields above, in the order the placeholder should name them. */
|
|
export const WARRANTY_SEARCH_FIELDS = [
|
|
'vendor', 'service level', 'tag', 'asset number', 'machine',
|
|
]
|