Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add trace stream toggle into preferences context #4035

Merged
merged 1 commit into from
Jul 27, 2024
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
4 changes: 3 additions & 1 deletion app/src/components/markdown/MarkdownDisplayContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export function useMarkdownMode(): MarkdownDisplayContextType {
}

export function MarkdownDisplayProvider(props: PropsWithChildren) {
const mode = usePreferencesContext((state) => state.markdownDisplayMode);
const mode = usePreferencesContext((state) => {
return state.markdownDisplayMode;
});
const setMarkdownDisplayMode = usePreferencesContext(
(state) => state.setMarkdownDisplayMode
);
Expand Down
9 changes: 8 additions & 1 deletion app/src/contexts/StreamStateContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import React, {
useState,
} from "react";

import { usePreferencesContext } from "./PreferencesContext";

export type StreamStateContextType = {
/**
* Whether or not streaming is enabled.
Expand Down Expand Up @@ -44,7 +46,12 @@ export function StreamStateProvider({
initialFetchKey = "initial",
children,
}: PropsWithChildren<{ initialFetchKey?: string }>) {
const [isStreaming, setIsStreaming] = useState<boolean>(true);
const isStreaming = usePreferencesContext(
(state) => state.traceStreamingEnabled
);
const setIsStreaming = usePreferencesContext(
(state) => state.setTraceStreamingEnabled
);
const [fetchKey, _setFetchKey] = useState<string>(initialFetchKey);

const setFetchKey = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion app/src/pages/project/StreamToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function StreamToggle(props: { project: StreamToggle_data$key }) {
return (
<Switch
labelPlacement="start"
defaultSelected
isSelected={isStreaming}
onChange={() => {
setIsStreaming(!isStreaming);
}}
Expand Down
15 changes: 15 additions & 0 deletions app/src/store/preferencesStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ export interface PreferencesState extends PreferencesProps {
* @param markdownDisplayMode
*/
setMarkdownDisplayMode: (markdownDisplayMode: MarkdownDisplayMode) => void;
/**
* Whether or not streaming is enabled for a projects traces
* @default true
*/
traceStreamingEnabled: boolean;
/**
* Setter for enabling/disabling trace streaming
* @param traceStreamingEnabled
* @returns
*/
setTraceStreamingEnabled: (traceStreamingEnabled: boolean) => void;
}

export const createPreferencesStore = (
Expand All @@ -28,6 +39,10 @@ export const createPreferencesStore = (
setMarkdownDisplayMode: (markdownDisplayMode) => {
set({ markdownDisplayMode });
},
traceStreamingEnabled: true,
setTraceStreamingEnabled: (traceStreamingEnabled) => {
set({ traceStreamingEnabled });
},
});
return create<PreferencesState>()(
persist(devtools(preferencesStore), {
Expand Down
Loading