Repository navigation
fix: show findings once and refresh the open rule detail after a Rule Editor save #378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -579,6 +579,9 @@ export async function renderAntiPatterns(container: HTMLElement, currentFilter: | |
|
|
||
| // Wire up rules section | ||
| wireRulesSection(container, rules, previewMap, currentFilter); | ||
|
|
||
| const openRuleId = container.querySelector<HTMLElement>('#rule-detail-panel')!.dataset.ruleId; | ||
| if (openRuleId) showRuleDetail(container, openRuleId, rules, previewMap, currentFilter); | ||
| } | ||
|
|
||
| /* ── Tab switching ── */ | ||
|
|
@@ -610,6 +613,7 @@ function renderFindings( | |
| ): void { | ||
| const detailsContainer = container.querySelector('#apDetails')!; | ||
| const allGroupKeys: PracticeGroup[] = ['prompt-quality', 'session-hygiene', 'code-review', 'tool-mastery']; | ||
| const sections: HTMLElement[] = []; | ||
|
|
||
| for (const groupKey of allGroupKeys) { | ||
| const gs = scores.find(s => s.group === groupKey); | ||
|
|
@@ -674,8 +678,9 @@ function renderFindings( | |
| section.appendChild(card); | ||
| } | ||
| } | ||
| detailsContainer.appendChild(section); | ||
| sections.push(section); | ||
| } | ||
| detailsContainer.replaceChildren(...sections); | ||
|
|
||
| const hint = consumeNavHint(); | ||
| if (hint) { | ||
|
|
@@ -1037,12 +1042,7 @@ function wireRulesSection( | |
| }, { signal }); | ||
|
|
||
| // Back button | ||
| container.querySelector('#rule-back-btn')?.addEventListener('click', () => { | ||
| container.querySelector<HTMLElement>('#rule-list')!.style.display = ''; | ||
| container.querySelector<HTMLElement>('#rule-detail-panel')!.style.display = 'none'; | ||
| container.querySelector<HTMLElement>('#rule-search-bar')!.style.display = ''; | ||
| container.querySelector<HTMLElement>('#ap-rules-header')!.style.display = ''; | ||
| }, { signal }); | ||
| container.querySelector('#rule-back-btn')?.addEventListener('click', () => hideRuleDetail(container), { signal }); | ||
|
|
||
| // Unified Rule Editor | ||
| wireRuleEditorModal(container, currentFilter, () => renderAntiPatterns(container, currentFilter), signal); | ||
|
|
@@ -1213,7 +1213,10 @@ function showRuleDetail( | |
| currentFilter: DateFilter, | ||
| ): void { | ||
| const rule = rules.find(r => r.id === ruleId); | ||
| if (!rule) return; | ||
| if (!rule) { | ||
| hideRuleDetail(container); | ||
| return; | ||
| } | ||
|
|
||
| const preview = previewMap.get(ruleId); | ||
| container.querySelector<HTMLElement>('#rule-list')!.style.display = 'none'; | ||
|
|
@@ -1222,6 +1225,7 @@ function showRuleDetail( | |
|
|
||
| const panel = container.querySelector<HTMLElement>('#rule-detail-panel')!; | ||
| panel.style.display = ''; | ||
| panel.dataset.ruleId = ruleId; | ||
|
|
||
| const content = container.querySelector<HTMLElement>('#rule-detail-content')!; | ||
| render(renderRuleDetailContent(rule, preview, ruleId), content); | ||
|
|
@@ -1237,6 +1241,15 @@ function showRuleDetail( | |
| wireRuleDetailExplainButtons(content, currentFilter); | ||
| } | ||
|
|
||
| function hideRuleDetail(container: HTMLElement): void { | ||
| const panel = container.querySelector<HTMLElement>('#rule-detail-panel')!; | ||
| panel.style.display = 'none'; | ||
| delete panel.dataset.ruleId; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is important: without it, opening a rule, pressing Back, then saving a new rule would bring the old detail back. Right now all the tests still pass if it's removed, though. Could we add a case next to your new ones? This passes with your change and fails without this line: it('the rule list, when the detail was closed with Back before a save', async () => {
const page = await renderPage();
showDetail(page, A);
click(page, '#rule-back-btn');
click(page, '#rule-new-btn');
click(page, '.rule-editor-tab[data-editor-tab="source"]');
el<HTMLTextAreaElement>(page, '#rule-editor-raw').value = SOURCES[C];
click(page, '#rule-editor-save');
await answer('saveRule', { ok: true });
expect(el(page, '#rule-detail-panel').style.display).toBe('none');
expect(el(page, '#rule-list').style.display).toBe('');
});
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you Sanjay Singh (@san360), great catch! Added your case as is, right after the other new ones in 744474c. I checked it the same way: it passes with the change and fails once |
||
| container.querySelector<HTMLElement>('#rule-list')!.style.display = ''; | ||
| container.querySelector<HTMLElement>('#rule-search-bar')!.style.display = ''; | ||
| container.querySelector<HTMLElement>('#ap-rules-header')!.style.display = ''; | ||
| } | ||
|
|
||
| function renderLayerStatus(layers: RuleLayerInfo[], layerName: string): ComponentChildren { | ||
| const info = layers.find(l => l.layer === layerName); | ||
| if (!info) return html`<span class="rule-help-status rule-help-na">Not applicable</span>`; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional, as you mentioned in the description: a group someone had expanded comes back collapsed after each save. If you'd like to keep it open, one idea is to remember the open groups before rebuilding:
We tried this locally with your tests plus one for an expanded group, and typecheck is clean. Happy for this to be a separate PR or skipped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for trying this out locally, the
openGroupsidea is really neat! I'd like to keep this PR focused on #352, so I'll open a small follow up PR with your change and a test for an expanded group as soon as this one lands.