Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(review): keep inherited rules out of the set to restore

rebelicef9f15c9553c4
diff --git a/frontend/src/components/sql-review/StandardRuleSwitches.test.tsx b/frontend/src/components/sql-review/StandardRuleSwitches.test.tsx
index 34826ef86b..564f06c2a6 100644
--- a/frontend/src/components/sql-review/StandardRuleSwitches.test.tsx
+++ b/frontend/src/components/sql-review/StandardRuleSwitches.test.tsx
@@ -120,6 +120,23 @@ describe("StandardRuleSwitches", () => {
);
});
+ test("the read-only view does not replace the rules to restore", () => {
+ const own = [ReviewRuleType.SYNTAX, ReviewRuleType.DISALLOW_RENAME];
+ const inherited = [ReviewRuleType.SYNTAX, ReviewRuleType.REQUIRE_WHERE];
+ const onChange = vi.fn();
+ const { rerender } = render(
+ <StandardRuleSwitches rules={own} onChange={onChange} />
+ );
+ rerender(<StandardRuleSwitches rules={[]} onChange={onChange} />);
+ rerender(
+ <StandardRuleSwitches rules={inherited} onChange={onChange} readOnly />
+ );
+ rerender(<StandardRuleSwitches rules={[]} onChange={onChange} />);
+
+ fireEvent.click(ruleSwitch("syntax"));
+ expect(onChange).toHaveBeenLastCalledWith(own);
+ });
+
test("disabled locks every switch", () => {
render(
<StandardRuleSwitches
diff --git a/frontend/src/components/sql-review/StandardRuleSwitches.tsx b/frontend/src/components/sql-review/StandardRuleSwitches.tsx
index 25f97b040c..ed7ac6ab87 100644
--- a/frontend/src/components/sql-review/StandardRuleSwitches.tsx
+++ b/frontend/src/components/sql-review/StandardRuleSwitches.tsx
@@ -30,11 +30,12 @@ export function StandardRuleSwitches({
// SYNTAX gates the rest, and the backend reads a list without it as empty,
// so switching it off saves an empty list. Switching it back on restores
- // the rules from before it went off in this session, else every rule.
+ // the rules from before it went off in this session, else every rule. The
+ // read-only view shows rules set elsewhere, so it does not count.
const rulesWithSyntax = useRef<readonly ReviewRuleType[] | undefined>(
undefined
);
- if (reviewOn) {
+ if (reviewOn && !readOnly) {
rulesWithSyntax.current = rules;
}
const toggle = (rule: ReviewRuleType, on: boolean) => {
diff --git a/frontend/src/routes/project/ProjectSQLReviewPage.test.tsx b/frontend/src/routes/project/ProjectSQLReviewPage.test.tsx
index 54110d1034..6688b2e602 100644
--- a/frontend/src/routes/project/ProjectSQLReviewPage.test.tsx
+++ b/frontend/src/routes/project/ProjectSQLReviewPage.test.tsx
@@ -501,6 +501,23 @@ describe("ProjectSQLReviewPage", () => {
).toBeInTheDocument();
});
+ test("following the workspace in between keeps the project's own rules to restore", async () => {
+ seedCustomized();
+ const customize = await renderLoaded();
+
+ fireEvent.click(ruleSwitch("syntax"));
+ fireEvent.click(customize);
+ expect(screen.getAllByText("sql-review.standard-rules.on")).toHaveLength(2);
+ fireEvent.click(customize);
+ fireEvent.click(ruleSwitch("syntax"));
+
+ expect(ruleSwitch("syntax")).toHaveAttribute("aria-checked", "true");
+ expect(ruleSwitch("require-where")).toHaveAttribute(
+ "aria-checked",
+ "false"
+ );
+ });
+
test("undoing an unsaved switch needs no permission", async () => {
mocks.permissions = { "bb.policies.delete": false };
const customize = await renderLoaded();