Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/dev-guide/contributing-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ still be tested manually:
* Exporting all logs to a file
* Toggling tabbed panels in the sidebar
* Using keyboard shortcuts
* Toggling "Prettify" in both the status bar and the address bar
* Toggling "Prettify" via the status bar button, the address bar (URL hash), and the Monaco action

[gh-workflow-test]: https://github.com/y-scope/yscope-log-viewer/blob/main/.github/workflows/test.yaml
14 changes: 5 additions & 9 deletions src/components/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
CONFIG_KEY,
THEME_NAME,
} from "../../typings/config";
import {HASH_PARAM_NAMES} from "../../typings/url";
import {BeginLineNumToLogEventNumMap} from "../../typings/worker";
import {
ACTION_NAME,
Expand All @@ -33,7 +32,10 @@ import {
getMapValueWithNearestLessThanOrEqualKey,
} from "../../utils/data";
import {updateWindowUrlHashParams} from "../../utils/url";
import {updateViewHashParams} from "../../utils/url/urlHash";
import {
togglePrettify,
updateViewHashParams,
} from "../../utils/url/urlHash";
import MonacoInstance from "./MonacoInstance";
import {goToPositionAndCenter} from "./MonacoInstance/utils";

Expand Down Expand Up @@ -163,13 +165,7 @@ const handleEditorCustomAction = (
break;
}
case ACTION_NAME.TOGGLE_PRETTIFY: {
const {isPrettified, setIsPrettified} = useViewStore.getState();
const newIsPrettified = !isPrettified;
updateWindowUrlHashParams({
[HASH_PARAM_NAMES.IS_PRETTIFIED]: newIsPrettified,
});
setIsPrettified(newIsPrettified);
updateViewHashParams();
togglePrettify();
break;
}
case ACTION_NAME.TOGGLE_WORD_WRAP:
Expand Down
28 changes: 3 additions & 25 deletions src/components/StatusBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React, {useCallback} from "react";

import {
Button,
Divider,
Expand All @@ -15,14 +13,10 @@ import useLogFileStore from "../../stores/logFileStore";
import useUiStore from "../../stores/uiStore";
import useViewStore from "../../stores/viewStore";
import {UI_ELEMENT} from "../../typings/states";
import {HASH_PARAM_NAMES} from "../../typings/url";
import {ACTION_NAME} from "../../utils/actions";
import {isDisabled} from "../../utils/states";
import {
copyPermalinkToClipboard,
updateWindowUrlHashParams,
} from "../../utils/url";
import {updateViewHashParams} from "../../utils/url/urlHash";
import {copyPermalinkToClipboard} from "../../utils/url";
import {togglePrettify} from "../../utils/url/urlHash";
import LogLevelSelect from "./LogLevelSelect";
import StatusBarToggleButton from "./StatusBarToggleButton";

Expand All @@ -47,22 +41,6 @@ const StatusBar = () => {
const numEvents = useLogFileStore((state) => state.numEvents);
const uiState = useUiStore((state) => state.uiState);

const handleStatusButtonClick = useCallback((ev: React.MouseEvent<HTMLButtonElement>) => {
const {actionName} = ev.currentTarget.dataset;

switch (actionName) {
case ACTION_NAME.TOGGLE_PRETTIFY:
updateWindowUrlHashParams({
[HASH_PARAM_NAMES.IS_PRETTIFIED]: false === isPrettified,
});
updateViewHashParams();
break;
default:
console.error(`Unexpected action: ${actionName}`);
break;
}
}, [isPrettified]);

const isPrettifyButtonDisabled = isDisabled(uiState, UI_ELEMENT.PRETTIFY_BUTTON);

return (
Expand Down Expand Up @@ -104,7 +82,7 @@ const StatusBar = () => {
tooltipTitle={false === isPrettified ?
"Turn on Prettify" :
"Turn off Prettify"}
onClick={handleStatusButtonClick}/>
onClick={togglePrettify}/>
</Sheet>
);
};
Expand Down
11 changes: 11 additions & 0 deletions src/utils/url/urlHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {handleErrorWithNotification} from "../../stores/notificationStore";
import useQueryStore from "../../stores/queryStore";
import useViewStore from "../../stores/viewStore";
import {Nullable} from "../../typings/common";
import {HASH_PARAM_NAMES} from "../../typings/url";
import {
CURSOR_CODE,
CursorType,
Expand Down Expand Up @@ -153,7 +154,17 @@ const updateQueryHashParams = () => {
return isQueryModified;
};

/**
* Toggles the prettify state for formatted log viewing.
*/
const togglePrettify = () => {
const {isPrettified} = useViewStore.getState();
updateWindowUrlHashParams({[HASH_PARAM_NAMES.IS_PRETTIFIED]: !isPrettified});
updateViewHashParams();
};

export {
togglePrettify,
updateQueryHashParams,
updateViewHashParams,
};