Skip to content

Commit

Permalink
Tracker: display status when editing and allow to deactivate/reactiva…
Browse files Browse the repository at this point in the history
…te a tracker
  • Loading branch information
PopDaph committed Dec 19, 2024
1 parent 18bdec2 commit 3c3d841
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 12 deletions.
67 changes: 60 additions & 7 deletions front/components/trackers/TrackerBuilder.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Button,
Chip,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
Expand All @@ -8,6 +9,7 @@ import {
Label,
Page,
TextArea,
TrashIcon,
useSendNotification,
} from "@dust-tt/sparkle";
import type {
Expand All @@ -24,6 +26,8 @@ import {
CLAUDE_3_5_SONNET_DEFAULT_MODEL_CONFIG,
TRACKER_FREQUENCIES,
} from "@dust-tt/types";
import { capitalize } from "lodash";
import { LockIcon } from "lucide-react";
import { useRouter } from "next/router";
import { useContext, useMemo, useState } from "react";

Expand Down Expand Up @@ -66,6 +70,7 @@ export const TrackerBuilder = ({

const [tracker, setTracker] = useState<TrackerConfigurationStateType>(
initialTrackerState ?? {
status: "active",
name: null,
nameError: null,
description: null,
Expand Down Expand Up @@ -165,6 +170,7 @@ export const TrackerBuilder = ({
const res = await fetch(route, {
method,
body: JSON.stringify({
status: tracker.status,
name: tracker.name,
description: tracker.description,
prompt: tracker.prompt,
Expand Down Expand Up @@ -338,13 +344,36 @@ export const TrackerBuilder = ({
<div className="flex flex-grow" />
<div className="flex flex-shrink-0 gap-2">
{initialTrackerId && (
<Button
label={"Delete"}
variant="warning"
onClick={onDelete}
isLoading={isDeleting}
disabled={isSubmitting || isDeleting}
/>
<DropdownMenu>
<DropdownMenuTrigger>
<Chip
size="sm"
color={tracker.status === "active" ? "emerald" : "warning"}
className="capitalize"
icon={tracker.status === "active" ? undefined : LockIcon}
>
{capitalize(tracker.status)}
</Chip>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem
key={tracker.status}
label={
tracker.status === "active" ? "Deactivate" : "Activate"
}
onClick={() => {
setTracker((t) => ({
...t,
status:
tracker.status === "active" ? "inactive" : "active",
}));
if (!edited) {
setEdited(true);
}
}}
/>
</DropdownMenuContent>
</DropdownMenu>
)}
<AdvancedSettings
owner={owner}
Expand All @@ -371,9 +400,21 @@ export const TrackerBuilder = ({
}
}}
/>
{initialTrackerId && (
<Button
icon={TrashIcon}
tooltip="Delete Tracker"
variant="outline"
onClick={onDelete}
isLoading={isDeleting}
disabled={isSubmitting || isDeleting}
/>
)}
</div>
</div>

{/* Tracker Settings */}

<div className="flex flex-col gap-8">
<div>
<Page.SectionHeader title="Naming" />
Expand All @@ -400,6 +441,7 @@ export const TrackerBuilder = ({
placeholder="Descriptive name."
message={tracker.nameError}
messageStatus={tracker.nameError ? "error" : undefined}
disabled={tracker.status === "inactive"}
/>
</div>
<div className="md:col-span-2">
Expand All @@ -419,11 +461,14 @@ export const TrackerBuilder = ({
placeholder="Brief description of what you're tracking and why."
message={tracker.descriptionError}
messageStatus={tracker.descriptionError ? "error" : undefined}
disabled={tracker.status === "inactive"}
/>
</div>
</div>
</div>

{/* Notification Settings */}

<div className="flex flex-col gap-8">
<div>
<Page.SectionHeader title="Notification Settings" />
Expand All @@ -447,6 +492,7 @@ export const TrackerBuilder = ({
}
variant="outline"
isSelect
disabled={tracker.status === "inactive"}
/>
</DropdownMenuTrigger>
<DropdownMenuContent>
Expand Down Expand Up @@ -486,10 +532,14 @@ export const TrackerBuilder = ({
}}
message={tracker.recipientsError}
messageStatus={tracker.recipientsError ? "error" : undefined}
disabled={tracker.status === "inactive"}
/>
</div>
</div>
</div>

{/* DataSource Configurations Settings */}

<div className="flex flex-col gap-8">
<div>
<Page.SectionHeader title="Tracker Settings" />
Expand All @@ -516,6 +566,7 @@ export const TrackerBuilder = ({
}}
error={tracker.promptError}
showErrorLabel={!!tracker.promptError}
disabled={tracker.status === "inactive"}
/>
</div>
<div className="grid grid-cols-1 gap-4 md:grid-cols-3">
Expand All @@ -528,6 +579,7 @@ export const TrackerBuilder = ({
setShowMaintainedDsModal(true);
}}
className="w-fit"
disabled={tracker.status === "inactive"}
/>
</div>
</div>
Expand Down Expand Up @@ -558,6 +610,7 @@ export const TrackerBuilder = ({
setShowWatchedDataSourcesModal(true);
}}
className="w-fit"
disabled={tracker.status === "inactive"}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ async function handler(
const updatedTrackerRes = await tracker.updateConfig(
auth,
{
status: body.status,
name: body.name,
description: body.description,
prompt: body.prompt,
modelId: body.modelId,
providerId: body.providerId,
temperature: body.temperature,
status: "active",
frequency: body.frequency,
recipients: body.recipients,
},
Expand Down
3 changes: 2 additions & 1 deletion front/pages/api/w/[wId]/spaces/[spaceId]/trackers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const TrackerDataSourcesConfigurationBodySchema = t.array(
);

export const PostTrackersRequestBodySchema = t.type({
status: t.union([t.literal("active"), t.literal("inactive")]),
name: t.string,
description: t.union([t.string, t.null]),
prompt: t.union([t.string, t.null]),
Expand Down Expand Up @@ -137,7 +138,7 @@ async function handler(
modelId: body.modelId,
providerId: body.providerId,
temperature: body.temperature,
status: "active",
status: body.status,
frequency: body.frequency,
recipients: body.recipients,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const initializeTrackerBuilderState = async (
);

return {
status: trackerToEdit.status,
name: trackerToEdit.name,
description: trackerToEdit.description,
prompt: trackerToEdit.prompt,
Expand Down
13 changes: 10 additions & 3 deletions types/src/front/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { DataSourceViewSelectionConfigurations } from "./data_source_view";
import { ModelIdType, ModelProviderIdType } from "./lib/assistant";
import { SpaceType } from "./space";

type TrackerStatus = "active" | "inactive";

export type TrackerConfigurationType = {
id: ModelId;
sId: string;
name: string;
status: "active" | "inactive";
status: TrackerStatus;
description: string | null;
modelId: ModelIdType;
providerId: ModelProviderIdType;
Expand All @@ -33,6 +35,7 @@ export type TrackerDataSourceConfigurationType = {

export type TrackerConfigurationStateType = {
name: string | null;
status: TrackerStatus;
nameError: string | null;
description: string | null;
descriptionError: string | null;
Expand All @@ -50,8 +53,12 @@ export type TrackerConfigurationStateType = {
};

export const TRACKER_FREQUENCIES = [
{ label: "Daily", value: "0 17 * * 1-5" },
{ label: "Weekly", value: "0 17 * * 5" },
{ label: "Daily (Mon-Fri)", value: "0 17 * * 1-5" },
{ label: "Weekly on Monday", value: "0 17 * * 1" },
{ label: "Weekly on Tuesday", value: "0 17 * * 2" },
{ label: "Weekly on Wednesday", value: "0 17 * * 3" },
{ label: "Weekly on Thursday", value: "0 17 * * 4" },
{ label: "Weekly on Friday", value: "0 17 * * 5" },
];

export type TrackerIdWorkspaceId = {
Expand Down

0 comments on commit 3c3d841

Please sign in to comment.