Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7be62596c | ||
|
|
4d2f69408b | ||
|
|
f723a66021 | ||
|
|
be5faf380d |
@@ -7,15 +7,15 @@
|
||||
* tool list unchanged.
|
||||
*/
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import { useMemo, type ReactNode } from "react";
|
||||
|
||||
/** Whether the right rail should host the Policies section. False in core. */
|
||||
export function usePoliciesEnabled(): boolean {
|
||||
return false;
|
||||
return useMemo(() => false, []);
|
||||
}
|
||||
|
||||
/** Whether the Policies list should appear for the current user. False in core. */
|
||||
export function usePoliciesVisible(): boolean {
|
||||
export function usePoliciesVisible(_enabled = false): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ export default function RightSidebar() {
|
||||
} = useToolWorkflow();
|
||||
|
||||
const policiesEnabled = usePoliciesEnabled();
|
||||
const policiesVisible = usePoliciesVisible();
|
||||
const policiesVisible = usePoliciesVisible(policiesEnabled);
|
||||
const rawPolicyDetailActive = usePolicyDetailActive();
|
||||
const fullscreenExpanded = useIsFullscreenExpanded();
|
||||
const fullscreenGeometry = useToolPanelGeometry({
|
||||
|
||||
@@ -90,10 +90,10 @@ export function usePoliciesEnabled(): boolean {
|
||||
/**
|
||||
* Whether the right rail should show the Policies section.
|
||||
*/
|
||||
export function usePoliciesVisible(): boolean {
|
||||
const pol = usePolicies();
|
||||
export function usePoliciesVisible(enabled = POLICIES_ENABLED): boolean {
|
||||
const pol = usePolicies(enabled);
|
||||
const { categories } = usePolicyCatalog();
|
||||
if (!POLICIES_ENABLED) return false;
|
||||
if (!enabled) return false;
|
||||
return pol.canConfigure || categories.some((c) => !c.comingSoon);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,6 @@ if (typeof globalThis.crypto?.randomUUID !== "function") {
|
||||
const api = vi.hoisted(() => ({
|
||||
store: new Map<string, { id: string }>(),
|
||||
seq: 0,
|
||||
}));
|
||||
vi.mock("@app/services/policyApi", () => ({
|
||||
listPolicies: vi.fn(async () => [...api.store.values()]),
|
||||
savePolicy: vi.fn(async (p: { id?: string }) => {
|
||||
const id = p.id && p.id.length > 0 ? p.id : `be-${++api.seq}`;
|
||||
@@ -35,6 +33,15 @@ vi.mock("@app/services/policyApi", () => ({
|
||||
runPolicyPipeline: vi.fn(),
|
||||
getPolicyRun: vi.fn(),
|
||||
}));
|
||||
vi.mock("@app/services/policyApi", () => ({
|
||||
listPolicies: api.listPolicies,
|
||||
savePolicy: api.savePolicy,
|
||||
getPolicy: api.getPolicy,
|
||||
deletePolicy: api.deletePolicy,
|
||||
runStoredPolicy: api.runStoredPolicy,
|
||||
runPolicyPipeline: api.runPolicyPipeline,
|
||||
getPolicyRun: api.getPolicyRun,
|
||||
}));
|
||||
|
||||
import { usePolicies } from "@app/hooks/usePolicies";
|
||||
|
||||
@@ -65,6 +72,7 @@ const wizardResult = {
|
||||
|
||||
describe("usePolicies", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
localStorage.clear();
|
||||
api.store.clear();
|
||||
api.seq = 0;
|
||||
@@ -78,6 +86,12 @@ describe("usePolicies", () => {
|
||||
expect(result.current.policies.security.configured).toBe(false);
|
||||
});
|
||||
|
||||
it("skips the backend reconcile when disabled", async () => {
|
||||
renderHook(() => usePolicies(false));
|
||||
await act(async () => {});
|
||||
expect(api.listPolicies).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("enabling a policy persists it to the backend + marks it configured", async () => {
|
||||
const { result } = renderHook(() => usePolicies());
|
||||
await act(async () => {
|
||||
|
||||
@@ -73,7 +73,7 @@ function toStoreRequest(
|
||||
};
|
||||
}
|
||||
|
||||
export function usePolicies() {
|
||||
export function usePolicies(enabled = true) {
|
||||
const [policies, setPolicies] = useState<PoliciesByCategory>(loadPolicies);
|
||||
const { config, refetch: refetchAppConfig } = useAppConfig();
|
||||
const { isTeamLeader } = useSaaSTeam();
|
||||
@@ -88,6 +88,7 @@ export function usePolicies() {
|
||||
// locally-cached folderId; retry with backoff since the backend may not be up yet.
|
||||
// On recovery, also re-resolve app config in case its admin/team-leader flags settled false while down.
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
let cancelled = false;
|
||||
let attempt = 0;
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
@@ -127,7 +128,7 @@ export function usePolicies() {
|
||||
cancelled = true;
|
||||
if (timer) clearTimeout(timer);
|
||||
};
|
||||
}, []);
|
||||
}, [enabled]);
|
||||
|
||||
/**
|
||||
* Enable a new policy from the wizard result: persist it to the backend (the
|
||||
|
||||
Reference in New Issue
Block a user