Manta Developers
GitHub
Menu

Plan limits

Let a person edit the values a plan's rules run within.

A plan’s limits are the numbers and dates inside its rules: a cap, a floor, a window. usePlanLimits reads them and saves a change in one step. PlanLimitsDialog shows them, one row per value, with Cancel and Save limits. PlanLimitsAction is the “Edit limits” button with the dialog behind it, for a plan page.

What it is

Saving stages a change for each edited rule, validates them together and commits them. If any step fails, the dialog clears what it staged, and says so if even that fails. A saved limit changes the plan’s recommended changes right away; Manta acts on them at the plan’s next run.

Some rules show read-only, and the dialog says why on each one. A rule Manta maintains stays read-only, because editing it would make it the person’s and Manta would stop updating it. A rule with a change already staged elsewhere stays read-only until that change is committed or cleared, so saving here never commits it by accident.

Import

import { PlanLimitsAction } from "@manta-eu/react/components/planning/PlanLimitsAction";
import { PlanLimitsDialog } from "@manta-eu/react/plan-limits";
import { usePlanLimits } from "@manta-eu/react/hooks/usePlanLimits";

Example

The button and dialog, placed in a plan page’s actions:

<PlanLimitsAction planGraphIri={planGraphIri} />

The dialog on its own, fed by the hook:

const limits = usePlanLimits({ planGraphIri });

return (
  <PlanLimitsDialog
    open={open}
    onOpenChange={setOpen}
    rules={limits.rules}
    isLoading={limits.isLoading}
    isSaving={limits.isSaving}
    error={limits.error}
    omittedRules={limits.omittedRules}
    onSave={limits.save}
  />
);

rules takes any list of { ruleIri, ruleText, ownedByManta, hasStagedChange }, so an app can feed the dialog from its own read. The dialog shows only rules with an editable value; onSave receives one { ruleIri, ruleText } per changed rule.

Request

A backend does the same with the rule mutations: stage a CHANGE, validate, then commit. See calling Manta from a backend.