Skip to content

Commit

Permalink
Tracker: Option to skip empty emails
Browse files Browse the repository at this point in the history
  • Loading branch information
PopDaph committed Dec 20, 2024
1 parent 3cc06b6 commit fbdece1
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 7 deletions.
28 changes: 28 additions & 0 deletions front/components/trackers/TrackerBuilder.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
Button,
Checkbox,
Chip,
DropdownMenu,
DropdownMenuContent,
Expand Down Expand Up @@ -79,6 +80,7 @@ export const TrackerBuilder = ({
promptError: null,
frequency: TRACKER_FREQUENCIES[0].value,
frequencyError: null,
skipEmptyEmails: true,
recipients: "",
recipientsError: null,
modelId: CLAUDE_3_5_SONNET_DEFAULT_MODEL_CONFIG.modelId,
Expand Down Expand Up @@ -178,6 +180,7 @@ export const TrackerBuilder = ({
providerId: tracker.providerId,
temperature: tracker.temperature,
frequency: tracker.frequency,
skipEmptyEmails: tracker.skipEmptyEmails,
recipients: tracker.recipients ? extractEmails(tracker.recipients) : [],
maintainedDataSources: Object.values(tracker.maintainedDataSources).map(
(ds) => dataSourceToPayload(ds, owner.sId)
Expand Down Expand Up @@ -536,6 +539,31 @@ export const TrackerBuilder = ({
/>
</div>
</div>
<div className="grid grid-cols-1 gap-4 md:grid-cols-3">
<div className="flex md:col-span-1">
<div className="flex flex-col space-y-2"></div>
</div>
<div className="md:col-span-2">
<div className="flex flex-row gap-2">
<Checkbox
label="Send me a copy of the email"
checked={tracker.skipEmptyEmails}
onCheckedChange={() => {
setTracker((t) => ({
...t,
skipEmptyEmails: !t.skipEmptyEmails,
}));
if (!edited) {
setEdited(true);
}
}}
/>
<div className="text-sm text-element-700">
Send the email only if there's suggested changes.
</div>
</div>
</div>
</div>
</div>

{/* DataSource Configurations Settings */}
Expand Down
16 changes: 9 additions & 7 deletions front/lib/api/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ export const processTrackerNotification = async ({

// Send the tracker email(s).
const generations = tracker.generations || [];
await sendTrackerEmail({
name: tracker.name,
recipients: tracker.recipients,
generations,
localLogger,
});
if (generations.length > 0 || !tracker.skipEmptyEmails) {
await sendTrackerEmail({
name: tracker.name,
recipients: tracker.recipients,
generations,
localLogger,
});
}

// Consume the tracker & associated generations.
await TrackerConfigurationResource.consumeGenerations({
Expand Down Expand Up @@ -108,7 +110,7 @@ const _sendTrackerDefaultEmail = async ({
subject: `[Dust] Tracker ${name} check complete: No updates required.`,
body: `
<p>Tracker: ${name}.</p>
<p>No changes detected in watched documents. All maintained documents are current</p>
<p>No changes detected in watched documents. All maintained documents are up to date.</p>
`,
});
};
Expand Down
6 changes: 6 additions & 0 deletions front/lib/models/doc_tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class TrackerConfigurationModel extends SoftDeletableModel<TrackerConfigu

declare frequency: string | null;
declare lastNotifiedAt: Date | null;
declare skipEmptyEmails: boolean;

declare recipients: string[] | null;

Expand Down Expand Up @@ -92,6 +93,11 @@ TrackerConfigurationModel.init(
type: DataTypes.STRING,
allowNull: true,
},
skipEmptyEmails: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true,
},
lastNotifiedAt: {
type: DataTypes.DATE,
allowNull: true,
Expand Down
1 change: 1 addition & 0 deletions front/lib/resources/tracker_resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ export class TrackerConfigurationResource extends ResourceWithSpace<TrackerConfi
temperature: this.temperature,
prompt: this.prompt,
frequency: this.frequency ?? "daily",
skipEmptyEmails: this.skipEmptyEmails,
recipients: this.recipients ?? [],
space: this.space.toJSON(),
maintainedDataSources: this.dataSourceConfigurations
Expand Down
1 change: 1 addition & 0 deletions front/migrations/db/migration_135.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "public"."tracker_configurations" ADD COLUMN "skipEmptyEmails" BOOLEAN NOT NULL DEFAULT true;
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ async function handler(
providerId: body.providerId,
temperature: body.temperature,
frequency: body.frequency,
skipEmptyEmails: body.skipEmptyEmails,
recipients: body.recipients,
},
body.maintainedDataSources,
Expand Down
2 changes: 2 additions & 0 deletions front/pages/api/w/[wId]/spaces/[spaceId]/trackers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const PostTrackersRequestBodySchema = t.type({
modelId: ModelIdCodec,
providerId: ModelProviderIdCodec,
frequency: t.string,
skipEmptyEmails: t.boolean,
temperature: t.number,
recipients: t.array(t.string),
maintainedDataSources: TrackerDataSourcesConfigurationBodySchema,
Expand Down Expand Up @@ -140,6 +141,7 @@ async function handler(
temperature: body.temperature,
status: body.status,
frequency: body.frequency,
skipEmptyEmails: body.skipEmptyEmails,
recipients: body.recipients,
},
body.maintainedDataSources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ const initializeTrackerBuilderState = async (
providerId: trackerToEdit.providerId,
temperature: trackerToEdit.temperature,
frequency: trackerToEdit.frequency ?? "daily",
skipEmptyEmails: true,
recipients: trackerToEdit.recipients?.join(",") || "",
maintainedDataSources,
watchedDataSources,
Expand Down
2 changes: 2 additions & 0 deletions types/src/front/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type TrackerConfigurationType = {
temperature: number;
prompt: string | null;
frequency: string;
skipEmptyEmails: boolean;
recipients: string[];
space: SpaceType;
maintainedDataSources: TrackerDataSourceConfigurationType[];
Expand Down Expand Up @@ -43,6 +44,7 @@ export type TrackerConfigurationStateType = {
promptError: string | null;
frequency: string;
frequencyError: string | null;
skipEmptyEmails: boolean;
recipients: string | null;
recipientsError: string | null;
modelId: ModelIdType;
Expand Down

0 comments on commit fbdece1

Please sign in to comment.