Pulse/scripts/history-clear-browser-fixture.mjs
pulse-triage[bot] 07ad2a8ea3 fix(alerts): discard pending history reads after clearing
A history request started before a successful clear can return deleted rows afterwards and repopulate the view. Invalidate those reads and settle loading only after the clear succeeds, preserving history on failure and allowing later refreshes.

Change-source: pulse-maintainer
2026-09-10 06:44:37 +01:00

22 lines
1.3 KiB
JavaScript

export const historyFixture = `
import { render } from 'solid-js/web';
import { Router, Route } from '@solidjs/router';
import { AlertsAPI } from '/src/api/alerts';
import { useAlertHistoryState } from '/src/features/alerts/useAlertHistoryState';
import { AlertHistoryAdministrationCard } from '/src/features/alerts/AlertHistoryAdministrationCard';
import '/src/index.css';
const row = {id:'old',type:'cpu',level:'warning',startTime:new Date().toISOString(),lastSeen:new Date().toISOString(),resourceId:'host',resourceName:'Fixture host',message:'Old history',acknowledged:false};
let calls = 0;
AlertsAPI.getHistory = () => ++calls === 1 ? Promise.resolve([row]) : new Promise(resolve => { window.finishHistory = () => resolve([row]); });
AlertsAPI.clearHistory = async () => {};
function Fixture() {
const state = useAlertHistoryState({activeAlerts:()=>({}),getResource:()=>undefined,allResources:()=>[]});
window.snapshot = () => ({rows:state.alertHistory().length,loading:state.loading()});
return <main class="p-4">
<button onClick={()=>state.setTimeFilter('24h')}>Refresh range</button>
<p>Rows: {state.alertHistory().length}</p>
<AlertHistoryAdministrationCard state={state}/>
</main>;
}
render(() => <Router><Route path="*" component={Fixture}/></Router>, document.getElementById('root'));
`;