Skip to content

Commit

Permalink
feat: add trace stream toggle into preferences context (#4035)
Browse files Browse the repository at this point in the history
  • Loading branch information
Parker-Stafford authored Jul 27, 2024
1 parent 09a5765 commit bc3be3e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
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

0 comments on commit bc3be3e

Please sign in to comment.