feat(quick-access): expose effective preference provenance
This commit is contained in:
@@ -32,6 +32,11 @@ type Draft = {
|
||||
tools: Record<string, QuickAccessPreference>;
|
||||
};
|
||||
type AvailabilityMode = "inherit" | "available" | "blocked" | "forced";
|
||||
type EffectiveProvenance = {
|
||||
state: "available" | "forced" | "blocked";
|
||||
availabilitySource: "module" | "system" | "tenant" | "user";
|
||||
orderSource: "module" | "system" | "tenant" | "user";
|
||||
};
|
||||
|
||||
const EMPTY_DRAFT: Draft = { categories: {}, tools: {} };
|
||||
|
||||
@@ -186,6 +191,14 @@ export default function QuickAccessSettingsPanel({
|
||||
const lockedTools = new Map(
|
||||
(effective?.categories ?? []).flatMap((category) => category.tools).filter((item) => item.locked_by).map((item) => [item.id, item.locked_by])
|
||||
);
|
||||
const categoryProvenance = new Map(
|
||||
(effective?.categories ?? []).map((item) => [item.id, effectiveProvenance(item)])
|
||||
);
|
||||
const toolProvenance = new Map(
|
||||
(effective?.categories ?? []).flatMap((category) =>
|
||||
category.tools.map((item) => [item.id, effectiveProvenance(item)] as const)
|
||||
)
|
||||
);
|
||||
const categoryIds = categories.map((item) => item.id);
|
||||
|
||||
return (
|
||||
@@ -219,6 +232,7 @@ export default function QuickAccessSettingsPanel({
|
||||
preference={draft.categories[category.id]}
|
||||
isPersonal={isPersonal}
|
||||
lockedBy={editableConstraintSource(scope, lockedCategories.get(category.id))}
|
||||
provenance={categoryProvenance.get(category.id)}
|
||||
disabled={!canWrite || saving}
|
||||
onChange={(value) => setPreference("categories", category.id, value)}
|
||||
onMoveUp={() => move("categories", categoryIds, category.id, -1)}
|
||||
@@ -243,6 +257,7 @@ export default function QuickAccessSettingsPanel({
|
||||
defaultEnabled={tool.default_enabled}
|
||||
isPersonal={isPersonal}
|
||||
lockedBy={editableConstraintSource(scope, lockedTools.get(tool.id))}
|
||||
provenance={toolProvenance.get(tool.id)}
|
||||
disabled={!canWrite || saving}
|
||||
onChange={(value) => setPreference("tools", tool.id, value)}
|
||||
onMoveUp={() => move("tools", toolIds, tool.id, -1)}
|
||||
@@ -268,6 +283,7 @@ function PreferenceRow({
|
||||
defaultEnabled = true,
|
||||
isPersonal,
|
||||
lockedBy,
|
||||
provenance,
|
||||
disabled,
|
||||
onChange,
|
||||
onMoveUp,
|
||||
@@ -282,6 +298,7 @@ function PreferenceRow({
|
||||
defaultEnabled?: boolean;
|
||||
isPersonal: boolean;
|
||||
lockedBy?: string | null;
|
||||
provenance?: EffectiveProvenance;
|
||||
disabled: boolean;
|
||||
onChange: (value: QuickAccessPreference | null) => void;
|
||||
onMoveUp: () => void;
|
||||
@@ -303,6 +320,15 @@ function PreferenceRow({
|
||||
})}
|
||||
</small>
|
||||
) : null}
|
||||
{provenance ? (
|
||||
<small>
|
||||
{i18nMessage("i18n:govoplan-quick-access.effective_provenance", {
|
||||
value0: provenance.state,
|
||||
value1: provenance.availabilitySource,
|
||||
value2: provenance.orderSource
|
||||
})}
|
||||
</small>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="quick-access-preference-controls">
|
||||
{isPersonal ? (
|
||||
@@ -338,6 +364,18 @@ function PreferenceRow({
|
||||
);
|
||||
}
|
||||
|
||||
function effectiveProvenance(item: {
|
||||
availability_state: "available" | "forced" | "blocked";
|
||||
availability_source: "module" | "system" | "tenant" | "user";
|
||||
order_source: "module" | "system" | "tenant" | "user";
|
||||
}): EffectiveProvenance {
|
||||
return {
|
||||
state: item.availability_state,
|
||||
availabilitySource: item.availability_source,
|
||||
orderSource: item.order_source
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function preferenceMode(preference?: QuickAccessPreference): AvailabilityMode {
|
||||
if (!preference || preference.enabled === null || preference.enabled === undefined) return "inherit";
|
||||
|
||||
Reference in New Issue
Block a user