Skip to content

Commit

Permalink
feat: Make past drill plan revisions read-only
Browse files Browse the repository at this point in the history
  • Loading branch information
strogonoff committed Mar 19, 2020
1 parent 71bc3c7 commit 61a3f6b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/renderer/plans/edit-drill-plan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export const EditDrillPlan: React.FC<EditDrillPlanProps> = function ({ planID })
const [sanitizedPlanRevision, updateSanitizedPlanRevision] =
useState<BCDrillPlanRevision | undefined>(undefined);

// TODO: Get max ID instead.
// Could theoretically fail, mixes up index in array and revision ID:
const isLatestRevision = selectedRevisionID === revisions.length;
const canAmendRevision =
selectedRevisionID === revisions.length && selectedRevisionID > 0;

Expand Down Expand Up @@ -248,6 +251,7 @@ export const EditDrillPlan: React.FC<EditDrillPlanProps> = function ({ planID })
onClick={commitInProgress ? undefined : () => commitChanges()}
active={commitInProgress}
disabled={
!isLatestRevision ||
sanitizedPlanRevision === undefined ||
bcPlan.isUpdating ||
!revision ||
Expand All @@ -263,10 +267,10 @@ export const EditDrillPlan: React.FC<EditDrillPlanProps> = function ({ planID })

<PlanForm
plan={revision}
onItemDelete={handleItemDeletion}
onReqEdit={handleRequirementEdit}
onPrepEdit={handlePrepStepEdit}
onStepEdit={handleStepEdit}
onItemDelete={isLatestRevision ? handleItemDeletion : undefined}
onReqEdit={isLatestRevision ? handleRequirementEdit : undefined}
onPrepEdit={isLatestRevision ? handlePrepStepEdit : undefined}
onStepEdit={isLatestRevision ? handleStepEdit : undefined}
/>
</div>
);
Expand Down

0 comments on commit 61a3f6b

Please sign in to comment.