fix: allow Edit only on Available assets
The builder only allows the Asset details activity in Available, so the runtime rejected Edit in Assigned and Under Repair. Disable the button outside Available with a hint to return the asset first, and keep the closed-asset notice keyed to the open states. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
96718d173c
commit
72cdae3d1c
@ -168,18 +168,21 @@ export default function AssetDetails() {
|
||||
const isAssigned = isAssetState(row, ASSET_STATE.ASSIGNED)
|
||||
const isAvailable = isAssetState(row, ASSET_STATE.AVAILABLE)
|
||||
const isUnderRepair = isAssetState(row, ASSET_STATE.UNDER_REPAIR)
|
||||
// ASSIGNED and Send for Repair run in Available; Reassigned in Assigned; Lost
|
||||
// in either; Repair Completed in Under Repair; Edit in all three. RETURNED
|
||||
// runs in any state but Closed, and the runtime says if the state doesn't
|
||||
// allow it. If the view sends no state, let the runtime decide rather than
|
||||
// hiding the buttons.
|
||||
// ASSIGNED, Send for Repair and Edit (Asset details) run in Available;
|
||||
// Reassigned in Assigned; Lost in either; Repair Completed in Under Repair.
|
||||
// The builder has Asset details in Available only, so the runtime rejects it
|
||||
// elsewhere ("Asset details" is not allowed in "Assigned"). RETURNED runs in
|
||||
// any state but Closed, and the runtime says if the state doesn't allow it.
|
||||
// If the view sends no state, let the runtime decide rather than hiding the
|
||||
// buttons.
|
||||
const isOpen = !state || isAvailable || isAssigned || isUnderRepair
|
||||
const canAssign = !state || isAvailable
|
||||
const canReassign = !state || isAssigned
|
||||
const canReturn = !isAssetState(row, ASSET_STATE.CLOSED) && !isEndState(row)
|
||||
const canReportLost = !state || isAvailable || isAssigned
|
||||
const canSendForRepair = !state || isAvailable
|
||||
const canCompleteRepair = !state || isUnderRepair
|
||||
const canEdit = !state || isAvailable || isAssigned || isUnderRepair
|
||||
const canEdit = !state || isAvailable
|
||||
|
||||
// Assigned or reassigned, whichever is newer, is who has it now.
|
||||
const current = currentAssignment(row)
|
||||
@ -251,7 +254,12 @@ export default function AssetDetails() {
|
||||
<Button icon="history" onClick={load} disabled={loading}>
|
||||
{loading ? 'Refreshing…' : 'Refresh'}
|
||||
</Button>
|
||||
<Button icon="edit" onClick={() => openActivity('edit')} disabled={!canEdit}>
|
||||
<Button
|
||||
icon="edit"
|
||||
onClick={() => openActivity('edit')}
|
||||
disabled={!canEdit}
|
||||
title={canEdit ? undefined : 'Only an Available asset can be edited. Return it first.'}
|
||||
>
|
||||
Edit
|
||||
</Button>
|
||||
<Button
|
||||
@ -289,7 +297,7 @@ export default function AssetDetails() {
|
||||
}
|
||||
/>
|
||||
|
||||
{!canEdit && (
|
||||
{!isOpen && (
|
||||
<div className="notice notice--warning" role="status">
|
||||
<Icon name="alert" size={15} />
|
||||
<span>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user