fix(debug-logger): Fix PopOut component pattern and state management
- Change debugLoggerEnabledAtom from getter function to direct value atom to properly update UI - Convert PopOut components from children function to anchor-based pattern - Add click handlers for category and level filter menus - Fix TypeScript errors with entry.data unknown type checks - Filters should now display correctly when clicked
This commit is contained in:
1 parent
c647d561c1
commit
44029b6a5c
5 files changed
+2634
-72
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -1,6 +1,6 @@
|
||||
import { useEffect, useState, useCallback, useMemo } from 'react';
|
||||
import { useEffect, useState, useCallback, useMemo, MouseEventHandler } from 'react';
|
||||
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
|
||||
import { Box, Text, Button, color, config, Badge, Menu, MenuItem, PopOut } from 'folds';
|
||||
import { Box, Text, Button, color, config, Badge, Menu, MenuItem, PopOut, RectCords } from 'folds';
|
||||
import { SequenceCard } from '$components/sequence-card';
|
||||
|
||||
import {
|
||||
@@ -91,7 +91,7 @@ function LogEntryItem({ entry }: { entry: LogEntry }) {
|
||||
[{entry.namespace}]
|
||||
</Text>
|
||||
</Box>
|
||||
{entry.data && (
|
||||
{entry.data != null && (
|
||||
<Button
|
||||
variant="Secondary"
|
||||
fill="None"
|
||||
@@ -106,7 +106,7 @@ function LogEntryItem({ entry }: { entry: LogEntry }) {
|
||||
<Text size="T200" style={{ wordBreak: 'break-word' }}>
|
||||
{entry.message}
|
||||
</Text>
|
||||
{expanded && entry.data && (
|
||||
{expanded && entry.data != null && (
|
||||
<Box
|
||||
direction="Column"
|
||||
style={{
|
||||
@@ -142,6 +142,16 @@ export function DebugLogViewer() {
|
||||
const scrollRef = useState<HTMLDivElement | null>(null)[0];
|
||||
const [filterLevel, setFilterLevel] = useState<LogLevel | 'all'>('all');
|
||||
const [filterCategory, setFilterCategory] = useState<LogCategory | 'all'>('all');
|
||||
const [categoryAnchor, setCategoryAnchor] = useState<RectCords | undefined>();
|
||||
const [levelAnchor, setLevelAnchor] = useState<RectCords | undefined>();
|
||||
|
||||
const handleOpenCategoryMenu: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||
setCategoryAnchor(evt.currentTarget.getBoundingClientRect());
|
||||
};
|
||||
|
||||
const handleOpenLevelMenu: MouseEventHandler<HTMLButtonElement> = (evt) => {
|
||||
setLevelAnchor(evt.currentTarget.getBoundingClientRect());
|
||||
};
|
||||
|
||||
// Filter logs based on current filters
|
||||
const filteredLogs = useMemo(() => {
|
||||
@@ -281,6 +291,7 @@ export function DebugLogViewer() {
|
||||
Filters:
|
||||
</Text>
|
||||
<PopOut
|
||||
anchor={categoryAnchor}
|
||||
offset={4}
|
||||
alignOffset={-4}
|
||||
position="Bottom"
|
||||
@@ -290,7 +301,10 @@ export function DebugLogViewer() {
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={() => setFilterCategory('all')}
|
||||
onClick={() => {
|
||||
setFilterCategory('all');
|
||||
setCategoryAnchor(undefined);
|
||||
}}
|
||||
disabled={filterCategory === 'all'}
|
||||
>
|
||||
<Text size="T300">All Categories</Text>
|
||||
@@ -298,7 +312,10 @@ export function DebugLogViewer() {
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={() => setFilterCategory('sync')}
|
||||
onClick={() => {
|
||||
setFilterCategory('sync');
|
||||
setCategoryAnchor(undefined);
|
||||
}}
|
||||
disabled={filterCategory === 'sync'}
|
||||
>
|
||||
<Text size="T300">Sync</Text>
|
||||
@@ -306,7 +323,10 @@ export function DebugLogViewer() {
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={() => setFilterCategory('network')}
|
||||
onClick={() => {
|
||||
setFilterCategory('network');
|
||||
setCategoryAnchor(undefined);
|
||||
}}
|
||||
disabled={filterCategory === 'network'}
|
||||
>
|
||||
<Text size="T300">Network</Text>
|
||||
@@ -314,7 +334,10 @@ export function DebugLogViewer() {
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={() => setFilterCategory('notification')}
|
||||
onClick={() => {
|
||||
setFilterCategory('notification');
|
||||
setCategoryAnchor(undefined);
|
||||
}}
|
||||
disabled={filterCategory === 'notification'}
|
||||
>
|
||||
<Text size="T300">Notification</Text>
|
||||
@@ -322,7 +345,10 @@ export function DebugLogViewer() {
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={() => setFilterCategory('message')}
|
||||
onClick={() => {
|
||||
setFilterCategory('message');
|
||||
setCategoryAnchor(undefined);
|
||||
}}
|
||||
disabled={filterCategory === 'message'}
|
||||
>
|
||||
<Text size="T300">Message</Text>
|
||||
@@ -330,7 +356,10 @@ export function DebugLogViewer() {
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={() => setFilterCategory('call')}
|
||||
onClick={() => {
|
||||
setFilterCategory('call');
|
||||
setCategoryAnchor(undefined);
|
||||
}}
|
||||
disabled={filterCategory === 'call'}
|
||||
>
|
||||
<Text size="T300">Call</Text>
|
||||
@@ -338,7 +367,10 @@ export function DebugLogViewer() {
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={() => setFilterCategory('ui')}
|
||||
onClick={() => {
|
||||
setFilterCategory('ui');
|
||||
setCategoryAnchor(undefined);
|
||||
}}
|
||||
disabled={filterCategory === 'ui'}
|
||||
>
|
||||
<Text size="T300">UI</Text>
|
||||
@@ -346,7 +378,10 @@ export function DebugLogViewer() {
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={() => setFilterCategory('timeline')}
|
||||
onClick={() => {
|
||||
setFilterCategory('timeline');
|
||||
setCategoryAnchor(undefined);
|
||||
}}
|
||||
disabled={filterCategory === 'timeline'}
|
||||
>
|
||||
<Text size="T300">Timeline</Text>
|
||||
@@ -354,7 +389,10 @@ export function DebugLogViewer() {
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={() => setFilterCategory('general')}
|
||||
onClick={() => {
|
||||
setFilterCategory('general');
|
||||
setCategoryAnchor(undefined);
|
||||
}}
|
||||
disabled={filterCategory === 'general'}
|
||||
>
|
||||
<Text size="T300">General</Text>
|
||||
@@ -362,7 +400,10 @@ export function DebugLogViewer() {
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={() => setFilterCategory('error')}
|
||||
onClick={() => {
|
||||
setFilterCategory('error');
|
||||
setCategoryAnchor(undefined);
|
||||
}}
|
||||
disabled={filterCategory === 'error'}
|
||||
>
|
||||
<Text size="T300">Error</Text>
|
||||
@@ -370,22 +411,21 @@ export function DebugLogViewer() {
|
||||
</Menu>
|
||||
}
|
||||
>
|
||||
{(targetRef) => (
|
||||
<Button
|
||||
ref={targetRef}
|
||||
variant="Secondary"
|
||||
fill="Soft"
|
||||
size="300"
|
||||
radii="300"
|
||||
>
|
||||
<Text size="B300">
|
||||
Category: {filterCategory === 'all' ? 'All' : filterCategory}
|
||||
</Text>
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
onClick={handleOpenCategoryMenu}
|
||||
variant="Secondary"
|
||||
fill="Soft"
|
||||
size="300"
|
||||
radii="300"
|
||||
>
|
||||
<Text size="B300">
|
||||
Category: {filterCategory === 'all' ? 'All' : filterCategory}
|
||||
</Text>
|
||||
</Button>
|
||||
</PopOut>
|
||||
|
||||
<PopOut
|
||||
anchor={levelAnchor}
|
||||
offset={4}
|
||||
alignOffset={-4}
|
||||
position="Bottom"
|
||||
@@ -395,7 +435,10 @@ export function DebugLogViewer() {
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={() => setFilterLevel('all')}
|
||||
onClick={() => {
|
||||
setFilterLevel('all');
|
||||
setLevelAnchor(undefined);
|
||||
}}
|
||||
disabled={filterLevel === 'all'}
|
||||
>
|
||||
<Text size="T300">All Levels</Text>
|
||||
@@ -403,7 +446,10 @@ export function DebugLogViewer() {
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={() => setFilterLevel('debug')}
|
||||
onClick={() => {
|
||||
setFilterLevel('debug');
|
||||
setLevelAnchor(undefined);
|
||||
}}
|
||||
disabled={filterLevel === 'debug'}
|
||||
>
|
||||
<Text size="T300">Debug</Text>
|
||||
@@ -411,7 +457,10 @@ export function DebugLogViewer() {
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={() => setFilterLevel('info')}
|
||||
onClick={() => {
|
||||
setFilterLevel('info');
|
||||
setLevelAnchor(undefined);
|
||||
}}
|
||||
disabled={filterLevel === 'info'}
|
||||
>
|
||||
<Text size="T300">Info</Text>
|
||||
@@ -419,7 +468,10 @@ export function DebugLogViewer() {
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={() => setFilterLevel('warn')}
|
||||
onClick={() => {
|
||||
setFilterLevel('warn');
|
||||
setLevelAnchor(undefined);
|
||||
}}
|
||||
disabled={filterLevel === 'warn'}
|
||||
>
|
||||
<Text size="T300">Warning</Text>
|
||||
@@ -427,7 +479,10 @@ export function DebugLogViewer() {
|
||||
<MenuItem
|
||||
size="300"
|
||||
radii="300"
|
||||
onClick={() => setFilterLevel('error')}
|
||||
onClick={() => {
|
||||
setFilterLevel('error');
|
||||
setLevelAnchor(undefined);
|
||||
}}
|
||||
disabled={filterLevel === 'error'}
|
||||
>
|
||||
<Text size="T300">Error</Text>
|
||||
@@ -435,19 +490,17 @@ export function DebugLogViewer() {
|
||||
</Menu>
|
||||
}
|
||||
>
|
||||
{(targetRef) => (
|
||||
<Button
|
||||
ref={targetRef}
|
||||
variant="Secondary"
|
||||
fill="Soft"
|
||||
size="300"
|
||||
radii="300"
|
||||
>
|
||||
<Text size="B300">
|
||||
Level: {filterLevel === 'all' ? 'All' : filterLevel}
|
||||
</Text>
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
onClick={handleOpenLevelMenu}
|
||||
variant="Secondary"
|
||||
fill="Soft"
|
||||
size="300"
|
||||
radii="300"
|
||||
>
|
||||
<Text size="B300">
|
||||
Level: {filterLevel === 'all' ? 'All' : filterLevel}
|
||||
</Text>
|
||||
</Button>
|
||||
</PopOut>
|
||||
|
||||
{(filterLevel !== 'all' || filterCategory !== 'all') && (
|
||||
|
||||
@@ -11,9 +11,10 @@ const debugLogger = getDebugLogger();
|
||||
* Atom for enabling/disabling debug logging
|
||||
*/
|
||||
export const debugLoggerEnabledAtom = atom(
|
||||
() => debugLogger.isEnabled(),
|
||||
(_, set, enabled: boolean) => {
|
||||
debugLogger.isEnabled(),
|
||||
(get, set, enabled: boolean) => {
|
||||
debugLogger.setEnabled(enabled);
|
||||
set(debugLoggerEnabledAtom, enabled);
|
||||
set(debugLogsAtom);
|
||||
}
|
||||
);
|
||||
|
||||
+23
-20
@@ -298,7 +298,10 @@ export const initClient = async (session: Session): Promise<MatrixClient> => {
|
||||
};
|
||||
|
||||
let mx: MatrixClient;
|
||||
try {{
|
||||
try {
|
||||
mx = await buildClient(session);
|
||||
} catch (err) {
|
||||
if (!isMismatch(err)) {
|
||||
debugLog.error('sync', 'Failed to build client', { error: err });
|
||||
throw err;
|
||||
}
|
||||
@@ -316,10 +319,7 @@ export const initClient = async (session: Session): Promise<MatrixClient> => {
|
||||
throw err;
|
||||
}
|
||||
log.warn('initClient: mismatch on initRustCrypto — wiping and retrying:', err);
|
||||
debugLog.warn('sync', 'Crypto init mismatch - wiping stores and retrying', { error: err };
|
||||
} catch (err) {
|
||||
if (!isMismatch(err)) throw err;
|
||||
log.warn('initClient: mismatch on initRustCrypto — wiping and retrying:', err);
|
||||
debugLog.warn('sync', 'Crypto init mismatch - wiping stores and retrying', { error: err });
|
||||
mx.stopClient();
|
||||
await wipeAllStores();
|
||||
mx = await buildClient(session);
|
||||
@@ -348,7 +348,16 @@ const disposeSlidingSync = (mx: MatrixClient): void => {
|
||||
slidingSyncByClient.delete(mx);
|
||||
};
|
||||
|
||||
expebugLog.info('sync', 'Starting Matrix client', { userId: mx.getUserId() });
|
||||
export const getSlidingSyncManager = (mx: MatrixClient): SlidingSyncManager | undefined => {
|
||||
return slidingSyncByClient.get(mx);
|
||||
};
|
||||
|
||||
|
||||
export const startClient = async (
|
||||
mx: MatrixClient,
|
||||
config?: StartClientConfig
|
||||
): Promise<void> => {
|
||||
debugLog.info('sync', 'Starting Matrix client', { userId: mx.getUserId() });
|
||||
disposeSlidingSync(mx);
|
||||
const slidingConfig = config?.slidingSync;
|
||||
const slidingEnabledOnServer = resolveSlidingEnabled(slidingConfig?.enabled);
|
||||
@@ -370,20 +379,6 @@ expebugLog.info('sync', 'Starting Matrix client', { userId: mx.getUserId() });
|
||||
hasProxy: hasSlidingProxy,
|
||||
});
|
||||
|
||||
const startClassicSync = async (fallbackFromSliding: boolean, reason: SyncTransportReason) => {
|
||||
debugLog.info('sync', `Starting classic sync (reason: ${reason})`, {
|
||||
fallback: fallbackFromSliding,
|
||||
reason,
|
||||
});
|
||||
userId: mx.getUserId(),
|
||||
enabled: slidingConfig?.enabled,
|
||||
enabledOnServer: slidingEnabledOnServer,
|
||||
sessionOptIn: config?.sessionSlidingSyncOptIn === true,
|
||||
requestedEnabled: slidingRequested,
|
||||
proxyBaseUrl,
|
||||
hasSlidingProxy,
|
||||
});
|
||||
|
||||
const startClassicSync = async (fallbackFromSliding: boolean, reason: SyncTransportReason) => {
|
||||
syncTransportByClient.set(mx, {
|
||||
transport: 'classic',
|
||||
@@ -494,6 +489,14 @@ expebugLog.info('sync', 'Starting Matrix client', { userId: mx.getUserId() });
|
||||
}
|
||||
};
|
||||
|
||||
export const stopClient = (mx: MatrixClient): void => {
|
||||
log.log('stopClient', mx.getUserId());
|
||||
debugLog.info('sync', 'Stopping client', { userId: mx.getUserId() });
|
||||
disposeSlidingSync(mx);
|
||||
mx.stopClient();
|
||||
syncTransportByClient.delete(mx);
|
||||
};
|
||||
|
||||
export const clearCacheAndReload = async (mx: MatrixClient) => {
|
||||
log.log('clearCacheAndReload', mx.getUserId());
|
||||
stopClient(mx);
|
||||
|
||||
@@ -14,12 +14,7 @@ import {
|
||||
MSC3575_STATE_KEY_ME,
|
||||
EventType,
|
||||
User,
|
||||
import {
|
||||
MatrixClient,
|
||||
SlidingSync,
|
||||
SlidingSyncEvent,
|
||||
SlidingSyncEventHandlerMap,
|
||||
SlidingSyncState,
|
||||
} from '$types/matrix-sdk';
|
||||
import { createLogger } from '$utils/debug';
|
||||
import { createDebugLogger } from '$utils/debugLogger';
|
||||
|
||||
Reference in new issue
Block a user