-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web: clear logs functionality (#4170)
New button in the resource bar to clear logs. On the all view, this will clear logs for all resources. On an individual resource, it will just clear that resource's logs. Alerts for non-existent spans (i.e. because they've been removed) will be ignored to prevent showing counts on the filters that won't actually have any content.
- Loading branch information
Showing
14 changed files
with
453 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { mount } from "enzyme" | ||
import React from "react" | ||
import ClearLogs from "./ClearLogs" | ||
import { logLinesToString } from "./logs" | ||
import LogStore, { LogStoreProvider } from "./LogStore" | ||
import { oneResource } from "./testdata" | ||
import { appendLinesForManifestAndSpan } from "./testlogs" | ||
|
||
describe("ClearLogs", () => { | ||
const createPopulatedLogStore = (): LogStore => { | ||
const logStore = new LogStore() | ||
appendLinesForManifestAndSpan(logStore, "", "", [ | ||
"global 1\n", | ||
"global 2\n", | ||
]) | ||
appendLinesForManifestAndSpan(logStore, "vigoda", "build:m1:1", [ | ||
"m1:1 build line 1\n", | ||
]) | ||
appendLinesForManifestAndSpan(logStore, "vigoda", "pod:m1-abc123", [ | ||
"m1:1 runtime line 1\n", | ||
]) | ||
appendLinesForManifestAndSpan(logStore, "manifest2", "build:m2", [ | ||
"m2 build line 1\n", | ||
]) | ||
appendLinesForManifestAndSpan(logStore, "vigoda", "build:m1:2", [ | ||
"m1:2 build line 1\n", | ||
"m1:2 build line 2\n", | ||
]) | ||
appendLinesForManifestAndSpan(logStore, "manifest2", "pod:m2-def456", [ | ||
"m2 runtime line 1\n", | ||
]) | ||
return logStore | ||
} | ||
|
||
it("clears all resources", () => { | ||
const logStore = createPopulatedLogStore() | ||
const root = mount( | ||
<LogStoreProvider value={logStore}> | ||
<ClearLogs /> | ||
</LogStoreProvider> | ||
) | ||
root.find(ClearLogs).simulate("click") | ||
expect(logStore.spans).toEqual({}) | ||
expect(logStore.allLog()).toHaveLength(0) | ||
}) | ||
|
||
it("clears a specific resource", () => { | ||
const logStore = createPopulatedLogStore() | ||
const resource = oneResource() | ||
const root = mount( | ||
<LogStoreProvider value={logStore}> | ||
<ClearLogs resource={resource} /> | ||
</LogStoreProvider> | ||
) | ||
root.find(ClearLogs).simulate("click") | ||
expect(Object.keys(logStore.spans).sort()).toEqual([ | ||
"_", | ||
"build:m2", | ||
"pod:m2-def456", | ||
]) | ||
expect(logLinesToString(logStore.allLog(), false)).toEqual( | ||
"global 1\nglobal 2\nm2 build line 1\nm2 runtime line 1" | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from "react" | ||
import styled from "styled-components" | ||
import { useLogStore } from "./LogStore" | ||
import { | ||
AnimDuration, | ||
Color, | ||
FontSize, | ||
mixinResetButtonStyle, | ||
} from "./style-helpers" | ||
|
||
const ClearLogsButton = styled.button` | ||
${mixinResetButtonStyle} | ||
margin-left: auto; | ||
font-size: ${FontSize.small}; | ||
color: ${Color.white}; | ||
transition: color ${AnimDuration.default} ease; | ||
&:hover { | ||
color: ${Color.blue}; | ||
} | ||
` | ||
|
||
export interface ClearLogsProps { | ||
resource?: Proto.webviewResource | ||
} | ||
|
||
const ClearLogs: React.FC<ClearLogsProps> = ({ resource }) => { | ||
const logStore = useLogStore() | ||
const label = resource?.name ? "Clear Logs" : "Clear All Logs" | ||
|
||
const clearLogs = () => { | ||
let spans: { [key: string]: Proto.webviewLogSpan } | ||
if (resource) { | ||
const manifestName = resource.name ?? "" | ||
spans = logStore.spansForManifest(manifestName) | ||
} else { | ||
spans = logStore.allSpans() | ||
} | ||
|
||
logStore.removeSpans(Object.keys(spans)) | ||
} | ||
|
||
return <ClearLogsButton onClick={() => clearLogs()}>{label}</ClearLogsButton> | ||
} | ||
|
||
export default ClearLogs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.