Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

✨ Record each poll setting change in the activity feed (#3414)

Luke Velladf0f6c73c98b
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 79febe1e5..ba4ecdb8b 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -719,12 +719,16 @@
"planRenewsOn": "Renews on {date}",
"planResumedToast": "Your plan will renew",
"poll": "Poll",
+ "pollActivityCommentsTurnedOff": "Comments turned off",
+ "pollActivityCommentsTurnedOn": "Comments turned on",
"pollActivityConferencingAdded": "Video call added",
"pollActivityConferencingChanged": "Video call changed from <b>{from}</b>",
"pollActivityConferencingRemoved": "Video call <b>{from}</b> removed",
"pollActivityDescriptionAdded": "Description added",
"pollActivityDescriptionChanged": "Description changed",
"pollActivityDescriptionRemoved": "Description removed",
+ "pollActivityIfNeedBeTurnedOff": "“If need be” answers turned off",
+ "pollActivityIfNeedBeTurnedOn": "“If need be” answers turned on",
"pollActivityInviteOpened": "<b>{email}</b> opened their invite",
"pollActivityInviteReminded": "Reminder sent to <b>{email}</b>",
"pollActivityInviteRevoked": "Invite to <b>{email}</b> revoked",
@@ -738,6 +742,10 @@
"pollActivityOptionsAdded": "{count, plural, one {Date added} other {# dates added}}",
"pollActivityOptionsDeleted": "{count, plural, one {Date removed} other {# dates removed}}",
"pollActivityPageEmptyDescription": "Activity on this poll will show up here.",
+ "pollActivityParticipantEmailOptional": "Participant email optional",
+ "pollActivityParticipantEmailRequired": "Participant email required",
+ "pollActivityParticipantNamesHidden": "Participant names hidden",
+ "pollActivityParticipantNamesShown": "Participant names shown",
"pollActivityPollClosed": "Poll closed",
"pollActivityPollClosedAuto": "Poll closed automatically",
"pollActivityPollCreated": "Poll created",
@@ -751,6 +759,8 @@
"pollActivitySettingsChanged": "Settings changed",
"pollActivityTimeZoneChanged": "Time zone changed",
"pollActivityTitleChanged": "Title changed from <b>{from}</b>",
+ "pollActivityVotesHidden": "Votes hidden",
+ "pollActivityVotesShown": "Votes shown",
"pollAdminMenu": "Poll options",
"pollAutoClosedBadge": "Automatically closed",
"pollAutoClosedDescription": "This poll was closed automatically because all of its dates have passed. No more responses are being accepted.",
diff --git a/apps/web/src/features/activity/components/poll-activity-list.tsx b/apps/web/src/features/activity/components/poll-activity-list.tsx
index 9c64a2674..1a8e77991 100644
--- a/apps/web/src/features/activity/components/poll-activity-list.tsx
+++ b/apps/web/src/features/activity/components/poll-activity-list.tsx
@@ -4,16 +4,19 @@ import { cn } from "@rallly/ui";
import type { LucideIcon } from "lucide-react";
import {
AlignLeftIcon,
+ BarChart2Icon,
BellIcon,
CalendarCheckIcon,
CalendarMinusIcon,
CalendarPlusIcon,
CircleStopIcon,
GlobeIcon,
+ ListChecksIcon,
MailIcon,
MailOpenIcon,
MailXIcon,
MapPinIcon,
+ MessageCircleIcon,
PencilIcon,
PlayIcon,
PlusIcon,
@@ -23,6 +26,7 @@ import {
UserMinusIcon,
UserPenIcon,
UserPlusIcon,
+ VenetianMaskIcon,
VideoIcon,
} from "lucide-react";
import type { PollActivityEvent, PollChange } from "@/features/activity/schema";
@@ -156,6 +160,11 @@ const iconByChange: Record<PollChange["field"], LucideIcon> = {
location: MapPinIcon,
conferencing: VideoIcon,
timeZone: GlobeIcon,
+ hideParticipants: VenetianMaskIcon,
+ hideScores: BarChart2Icon,
+ disableComments: MessageCircleIcon,
+ allowTentativeVotes: ListChecksIcon,
+ requireParticipantEmail: MailIcon,
settings: Settings2Icon,
};
@@ -167,7 +176,19 @@ function toneOfChange(change: PollChange): keyof typeof toneClassName {
? "removed"
: "changed";
}
- return "changed";
+ switch (change.field) {
+ // Tinted by what participants gain or lose: hiding something or
+ // requiring an email takes something away.
+ case "hideParticipants":
+ case "hideScores":
+ case "disableComments":
+ case "requireParticipantEmail":
+ return change.from ? "added" : "removed";
+ case "allowTentativeVotes":
+ return change.from ? "removed" : "added";
+ default:
+ return "changed";
+ }
}
const conferencingName = (conferencing: PollConferencing) =>
@@ -250,6 +271,60 @@ function ChangeDescription({ change }: { change: PollChange }) {
defaults="Time zone changed"
/>
);
+ case "hideParticipants":
+ return change.from ? (
+ <Trans
+ i18nKey="pollActivityParticipantNamesShown"
+ defaults="Participant names shown"
+ />
+ ) : (
+ <Trans
+ i18nKey="pollActivityParticipantNamesHidden"
+ defaults="Participant names hidden"
+ />
+ );
+ case "hideScores":
+ return change.from ? (
+ <Trans i18nKey="pollActivityVotesShown" defaults="Votes shown" />
+ ) : (
+ <Trans i18nKey="pollActivityVotesHidden" defaults="Votes hidden" />
+ );
+ case "disableComments":
+ return change.from ? (
+ <Trans
+ i18nKey="pollActivityCommentsTurnedOn"
+ defaults="Comments turned on"
+ />
+ ) : (
+ <Trans
+ i18nKey="pollActivityCommentsTurnedOff"
+ defaults="Comments turned off"
+ />
+ );
+ case "allowTentativeVotes":
+ return change.from ? (
+ <Trans
+ i18nKey="pollActivityIfNeedBeTurnedOff"
+ defaults="“If need be” answers turned off"
+ />
+ ) : (
+ <Trans
+ i18nKey="pollActivityIfNeedBeTurnedOn"
+ defaults="“If need be” answers turned on"
+ />
+ );
+ case "requireParticipantEmail":
+ return change.from ? (
+ <Trans
+ i18nKey="pollActivityParticipantEmailOptional"
+ defaults="Participant email optional"
+ />
+ ) : (
+ <Trans
+ i18nKey="pollActivityParticipantEmailRequired"
+ defaults="Participant email required"
+ />
+ );
case "settings":
return (
<Trans
diff --git a/apps/web/src/features/activity/schema.test.ts b/apps/web/src/features/activity/schema.test.ts
index 8d7d5701c..63bb9d6e5 100644
--- a/apps/web/src/features/activity/schema.test.ts
+++ b/apps/web/src/features/activity/schema.test.ts
@@ -85,6 +85,21 @@ describe("pollActivitySchema", () => {
expect(event?.type).toBe("poll_scheduled");
});
+ it("reads itemized setting changes alongside the earlier collapsed one", () => {
+ const result = pollActivitySchema.safeParse({
+ type: "poll_updated",
+ userId: "u1",
+ payload: {
+ changes: [
+ { field: "disableComments", from: false },
+ { field: "settings" },
+ ],
+ },
+ });
+
+ expect(result.success).toBe(true);
+ });
+
it("requires the subject ref of a response event", () => {
const result = pollActivitySchema.safeParse({
type: "response_created",
diff --git a/apps/web/src/features/activity/schema.ts b/apps/web/src/features/activity/schema.ts
index 8d9e10b78..7d6673863 100644
--- a/apps/web/src/features/activity/schema.ts
+++ b/apps/web/src/features/activity/schema.ts
@@ -70,6 +70,12 @@ export const pollChangeSchema = z.discriminatedUnion("field", [
from: pollConferencingSchema.nullable(),
}),
z.object({ field: z.literal("timeZone"), from: z.string().nullable() }),
+ z.object({ field: z.literal("hideParticipants"), from: z.boolean() }),
+ z.object({ field: z.literal("hideScores"), from: z.boolean() }),
+ z.object({ field: z.literal("disableComments"), from: z.boolean() }),
+ z.object({ field: z.literal("allowTentativeVotes"), from: z.boolean() }),
+ z.object({ field: z.literal("requireParticipantEmail"), from: z.boolean() }),
+ // Written before settings changes were itemized. Still read for that history.
z.object({ field: z.literal("settings") }),
]);
diff --git a/apps/web/src/features/activity/utils.test.ts b/apps/web/src/features/activity/utils.test.ts
index 19f327658..79007f400 100644
--- a/apps/web/src/features/activity/utils.test.ts
+++ b/apps/web/src/features/activity/utils.test.ts
@@ -7,9 +7,14 @@ const prior = {
location: "Cafe",
conferencing: null,
timeZone: "Europe/London",
+ hideParticipants: false,
+ hideScores: false,
+ disableComments: false,
+ allowTentativeVotes: true,
+ requireParticipantEmail: false,
};
-const unchanged = { timeZone: "Europe/London", settingsChanged: false };
+const unchanged = { timeZone: "Europe/London" };
describe("getPollChanges", () => {
it("records nothing when the edit leaves every field as it was", () => {
@@ -59,15 +64,61 @@ describe("getPollChanges", () => {
]);
});
- it("records time zone and settings changes", () => {
+ it("records a time zone change", () => {
+ expect(getPollChanges({ prior, next: { timeZone: null } })).toEqual([
+ { field: "timeZone", from: "Europe/London" },
+ ]);
+ });
+
+ it("records each setting turned on with its previous value", () => {
expect(
getPollChanges({
prior,
- next: { timeZone: null, settingsChanged: true },
+ next: {
+ ...unchanged,
+ hideParticipants: true,
+ hideScores: true,
+ disableComments: true,
+ requireParticipantEmail: true,
+ },
}),
).toEqual([
- { field: "timeZone", from: "Europe/London" },
- { field: "settings" },
+ { field: "hideParticipants", from: false },
+ { field: "hideScores", from: false },
+ { field: "disableComments", from: false },
+ { field: "requireParticipantEmail", from: false },
]);
});
+
+ it("records a setting turned off with its previous value", () => {
+ expect(
+ getPollChanges({
+ prior: { ...prior, disableComments: true },
+ next: {
+ ...unchanged,
+ allowTentativeVotes: false,
+ disableComments: false,
+ },
+ }),
+ ).toEqual([
+ { field: "disableComments", from: true },
+ { field: "allowTentativeVotes", from: true },
+ ]);
+ });
+
+ it("records no setting change when a save resends the current values", () => {
+ expect(
+ getPollChanges({
+ prior,
+ next: {
+ ...unchanged,
+ hideParticipants: false,
+ hideScores: false,
+ disableComments: false,
+ allowTentativeVotes: true,
+ requireParticipantEmail: false,
+ },
+ }),
+ ).toEqual([]);
+ });
});
diff --git a/apps/web/src/features/activity/utils.ts b/apps/web/src/features/activity/utils.ts
index 5970724ff..d8fe284d7 100644
--- a/apps/web/src/features/activity/utils.ts
+++ b/apps/web/src/features/activity/utils.ts
@@ -3,6 +3,16 @@ import type { PollChange } from "./schema";
type ChangeAction = "added" | "changed" | "removed";
+const settingFields = [
+ "hideParticipants",
+ "hideScores",
+ "disableComments",
+ "allowTentativeVotes",
+ "requireParticipantEmail",
+] as const;
+
+type PollSettings = Record<(typeof settingFields)[number], boolean>;
+
const getChangeAction = (from: unknown, to: unknown): ChangeAction =>
from === null ? "added" : to === null ? "removed" : "changed";
@@ -21,15 +31,14 @@ export function getPollChanges({
location: string | null;
conferencing: PollConferencing | null;
timeZone: string | null;
- };
+ } & PollSettings;
next: {
title?: string;
description?: string;
location?: string;
conferencing?: PollConferencing | null;
timeZone: string | null;
- settingsChanged: boolean;
- };
+ } & Partial<PollSettings>;
}): PollChange[] {
const changes: PollChange[] = [];
@@ -64,8 +73,11 @@ export function getPollChanges({
changes.push({ field: "timeZone", from: prior.timeZone });
}
- if (next.settingsChanged) {
- changes.push({ field: "settings" });
+ for (const field of settingFields) {
+ const value = next[field];
+ if (value !== undefined && value !== prior[field]) {
+ changes.push({ field, from: prior[field] });
+ }
}
return changes;
diff --git a/apps/web/src/trpc/routers/polls.ts b/apps/web/src/trpc/routers/polls.ts
index 036f40793..dfc1ae650 100644
--- a/apps/web/src/trpc/routers/polls.ts
+++ b/apps/web/src/trpc/routers/polls.ts
@@ -701,6 +701,11 @@ export const polls = router({
pollId,
}),
timeZone: prior.timeZone,
+ hideParticipants: prior.hideParticipants,
+ hideScores: prior.hideScores,
+ disableComments: prior.disableComments,
+ allowTentativeVotes: prior.allowTentativeVotes,
+ requireParticipantEmail: prior.requireParticipantEmail,
},
next: {
title: input.title,
@@ -708,18 +713,11 @@ export const polls = router({
location: input.location,
conferencing,
timeZone: nextTimeZone,
- settingsChanged:
- (input.hideParticipants !== undefined &&
- input.hideParticipants !== prior.hideParticipants) ||
- (input.disableComments !== undefined &&
- input.disableComments !== prior.disableComments) ||
- (input.allowTentativeVotes !== undefined &&
- input.allowTentativeVotes !== prior.allowTentativeVotes) ||
- (input.hideScores !== undefined &&
- input.hideScores !== prior.hideScores) ||
- (input.requireParticipantEmail !== undefined &&
- input.requireParticipantEmail !==
- prior.requireParticipantEmail),
+ hideParticipants: input.hideParticipants,
+ hideScores: input.hideScores,
+ disableComments: input.disableComments,
+ allowTentativeVotes: input.allowTentativeVotes,
+ requireParticipantEmail: input.requireParticipantEmail,
},
});