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(ui): add the ability to turn off auto-refresh of projects #4414

Merged
merged 3 commits into from
Aug 28, 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
10 changes: 8 additions & 2 deletions app/src/hooks/useInterval.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { useEffect, useRef } from "react";

type Callback = () => void;
export function useInterval(callback: Callback, delay: number) {

/**
* Custom hook to use setInterval with React hooks
* @param callback
* @param {number | null} delay - if set to null, no interval will be set
*/
export function useInterval(callback: Callback, delay: number | null) {
const savedCallback = useRef<Callback | null>(null);

// Remember the latest callback.
Expand All @@ -14,7 +20,7 @@ export function useInterval(callback: Callback, delay: number) {
function tick() {
savedCallback.current && savedCallback.current();
}
if (delay !== null) {
if (typeof delay === "number") {
const id = setInterval(tick, delay);
return () => clearInterval(id);
}
Expand Down
29 changes: 29 additions & 0 deletions app/src/pages/projects/ProjectsAutoRefreshToggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from "react";

import { Switch } from "@arizeai/components";

import { usePreferencesContext } from "@phoenix/contexts/PreferencesContext";

/**
* Enable / Disable auto refresh for projects
*/
export function ProjectsAutoRefreshToggle() {
const autoRefreshEnabled = usePreferencesContext(
(state) => state.projectsAutoRefreshEnabled
);
const setAutoRefreshEnabled = usePreferencesContext(
(state) => state.setProjectAutoRefreshEnabled
);

return (
<Switch
labelPlacement="start"
isSelected={autoRefreshEnabled}
onChange={() => {
setAutoRefreshEnabled(!autoRefreshEnabled);
}}
>
Auto-Refresh
</Switch>
);
}
30 changes: 22 additions & 8 deletions app/src/pages/projects/ProjectsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
useLastNTimeRange,
} from "@phoenix/components/datetime";
import { LatencyText } from "@phoenix/components/trace/LatencyText";
import { usePreferencesContext } from "@phoenix/contexts/PreferencesContext";
import { useInterval } from "@phoenix/hooks/useInterval";
import { intFormatter } from "@phoenix/utils/numberFormatUtils";

Expand All @@ -34,9 +35,10 @@ import { ProjectsPageProjectsQuery } from "./__generated__/ProjectsPageProjectsQ
import { ProjectsPageQuery } from "./__generated__/ProjectsPageQuery.graphql";
import { NewProjectButton } from "./NewProjectButton";
import { ProjectActionMenu } from "./ProjectActionMenu";
import { ProjectsAutoRefreshToggle } from "./ProjectsAutoRefreshToggle";

const REFRESH_INTERVAL_MS = 10000;
const PAGE_SIZE = 100;
const PAGE_SIZE = 50;

export function ProjectsPage() {
const { timeRange } = useLastNTimeRange();
Expand All @@ -49,6 +51,9 @@ export function ProjectsPage() {
}

export function ProjectsPageContent({ timeRange }: { timeRange: TimeRange }) {
const autoRefreshEnabled = usePreferencesContext(
(state) => state.projectsAutoRefreshEnabled
);
const [notify, holder] = useNotification();
// Convert the time range to a variable that can be used in the query
const timeRangeVariable = useMemo(() => {
Expand Down Expand Up @@ -83,7 +88,7 @@ export function ProjectsPageContent({ timeRange }: { timeRange: TimeRange }) {
@refetchable(queryName: "ProjectsPageProjectsQuery")
@argumentDefinitions(
after: { type: "String", defaultValue: null }
first: { type: "Int", defaultValue: 100 }
first: { type: "Int", defaultValue: 50 }
) {
projects(first: $first, after: $after)
@connection(key: "ProjectsPage_projects") {
Expand Down Expand Up @@ -127,11 +132,14 @@ export function ProjectsPageContent({ timeRange }: { timeRange: TimeRange }) {
[hasNext, isLoadingNext, loadNext]
);

useInterval(() => {
startTransition(() => {
refetch({}, { fetchPolicy: "store-and-network" });
});
}, REFRESH_INTERVAL_MS);
useInterval(
() => {
startTransition(() => {
refetch({}, { fetchPolicy: "store-and-network" });
});
},
autoRefreshEnabled ? REFRESH_INTERVAL_MS : null
);

const onDelete = useCallback(
(projectName: string) => {
Expand Down Expand Up @@ -195,7 +203,13 @@ export function ProjectsPageContent({ timeRange }: { timeRange: TimeRange }) {
borderBottomColor="grey-200"
borderBottomWidth="thin"
>
<Flex direction="row" justifyContent="end" gap="size-100">
<Flex
direction="row"
justifyContent="end"
alignItems="center"
gap="size-100"
>
<ProjectsAutoRefreshToggle />
<NewProjectButton />
<ConnectedLastNTimeRangePicker />
</Flex>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion app/src/store/preferencesStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export interface PreferencesProps {
* @default true
*/
traceStreamingEnabled: boolean;
/**
* Whether or not to automatically refresh projects
* @default true
*/
projectsAutoRefreshEnabled: boolean;
/**
* Whether or not to show the span aside that contains details about timing, status, etc.
* @default true
Expand All @@ -34,9 +39,13 @@ export interface PreferencesState extends PreferencesProps {
/**
* Setter for enabling/disabling trace streaming
* @param traceStreamingEnabled
* @returns
*/
setTraceStreamingEnabled: (traceStreamingEnabled: boolean) => void;
/**
* Setter for enabling/disabling project auto refresh
* @param projectsAutoRefreshEnabled
*/
setProjectAutoRefreshEnabled: (projectsAutoRefreshEnabled: boolean) => void;
/**
* Setter for enabling/disabling the span aside
* @param showSpanAside
Expand All @@ -61,6 +70,10 @@ export const createPreferencesStore = (
setTraceStreamingEnabled: (traceStreamingEnabled) => {
set({ traceStreamingEnabled });
},
projectsAutoRefreshEnabled: true,
setProjectAutoRefreshEnabled: (projectsAutoRefreshEnabled) => {
set({ projectsAutoRefreshEnabled });
},
showSpanAside: true,
setShowSpanAside: (showSpanAside) => {
set({ showSpanAside });
Expand Down
Loading