mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
Audited all proxy()/useSnapshot() usage against the v1→v2 migration guide; no breaking changes apply (no reused proxy() inputs, no promise-valued state, all consumers already client components). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Updated the Valtio dependency to a newer version for improved compatibility. * **Bug Fixes** * Improved AI assistant persistence in IndexedDB so chat sessions reliably save (while keeping only the most recent 20 messages per chat). * Hardened tabs restoration from storage to fall back to fresh defaults when data is missing, invalid, or fails validation. * **Refactor** * Switched multiple studio panels to use fresh initial-state factories for initialization and reset reliability. * Updated advisor state so the derived notification filter count is no longer exposed. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
76 lines
2.6 KiB
TypeScript
76 lines
2.6 KiB
TypeScript
import { proxy, snapshot, useSnapshot } from 'valtio'
|
|
|
|
export type AdvisorTab = 'all' | 'security' | 'performance' | 'messages'
|
|
export type AdvisorSeverity = 'critical' | 'warning' | 'info'
|
|
export type AdvisorItemSource = 'lint' | 'notification' | 'signal'
|
|
|
|
const createInitialState = () => ({
|
|
activeTab: 'all' as AdvisorTab,
|
|
severityFilters: ['critical', 'warning'] as AdvisorSeverity[],
|
|
selectedItemId: undefined as string | undefined,
|
|
selectedItemSource: undefined as AdvisorItemSource | undefined,
|
|
// Notification filters
|
|
notificationFilterStatuses: [] as string[],
|
|
notificationFilterPriorities: [] as string[],
|
|
})
|
|
|
|
export const advisorState = proxy({
|
|
...createInitialState(),
|
|
setActiveTab(tab: AdvisorTab) {
|
|
advisorState.activeTab = tab
|
|
},
|
|
setSeverityFilters(severities: AdvisorSeverity[]) {
|
|
advisorState.severityFilters = severities
|
|
},
|
|
clearSeverityFilters() {
|
|
advisorState.severityFilters = []
|
|
},
|
|
setSelectedItem(id: string | undefined, source?: AdvisorItemSource) {
|
|
advisorState.selectedItemId = id
|
|
advisorState.selectedItemSource = source
|
|
},
|
|
focusItem({ id, tab, source }: { id: string; tab?: AdvisorTab; source?: AdvisorItemSource }) {
|
|
if (tab) {
|
|
advisorState.activeTab = tab
|
|
}
|
|
advisorState.selectedItemId = id
|
|
advisorState.selectedItemSource = source
|
|
},
|
|
setNotificationFilters: (value: string, type: 'status' | 'priority') => {
|
|
switch (type) {
|
|
case 'status':
|
|
if (advisorState.notificationFilterStatuses.includes(value)) {
|
|
advisorState.notificationFilterStatuses = advisorState.notificationFilterStatuses.filter(
|
|
(x) => x !== value
|
|
)
|
|
} else {
|
|
advisorState.notificationFilterStatuses = advisorState.notificationFilterStatuses.concat([
|
|
value,
|
|
])
|
|
}
|
|
break
|
|
case 'priority':
|
|
if (advisorState.notificationFilterPriorities.includes(value)) {
|
|
advisorState.notificationFilterPriorities =
|
|
advisorState.notificationFilterPriorities.filter((x) => x !== value)
|
|
} else {
|
|
advisorState.notificationFilterPriorities =
|
|
advisorState.notificationFilterPriorities.concat([value])
|
|
}
|
|
break
|
|
}
|
|
},
|
|
resetNotificationFilters() {
|
|
advisorState.notificationFilterStatuses = []
|
|
advisorState.notificationFilterPriorities = []
|
|
},
|
|
reset() {
|
|
Object.assign(advisorState, createInitialState())
|
|
},
|
|
})
|
|
|
|
export const getAdvisorStateSnapshot = () => snapshot(advisorState)
|
|
|
|
export const useAdvisorStateSnapshot = (options?: Parameters<typeof useSnapshot>[1]) =>
|
|
useSnapshot(advisorState, options)
|