From f07dffab0770be196342d5ec446ef6f24cb2a91d Mon Sep 17 00:00:00 2001 From: Piyush Gupta <56182734+gupta-piyush19@users.noreply.github.com> Date: Fri, 12 Apr 2024 20:58:05 +0530 Subject: [PATCH] fix: OpenTextSummary no longer has "Show more" button (#2427) Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com> Co-authored-by: Johannes --- .../summary/components/AddressSummary.tsx | 70 ++++----- .../components/DateQuestionSummary.tsx | 80 ++++++---- .../summary/components/FileUploadSummary.tsx | 142 ++++++++++-------- .../components/HiddenFieldsSummary.tsx | 22 ++- .../summary/components/OpenTextSummary.tsx | 80 ++++++---- packages/lib/response/util.ts | 2 +- .../src/components/general/CalEmbed.tsx | 2 +- .../src/components/general/FileInput.tsx | 2 +- .../src/components/general/ThankYouCard.tsx | 2 +- .../src/components/general/WelcomeCard.tsx | 6 +- 10 files changed, 243 insertions(+), 165 deletions(-) diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/AddressSummary.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/AddressSummary.tsx index 6379a0aade..2183f432bf 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/AddressSummary.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/AddressSummary.tsx @@ -23,44 +23,46 @@ export const AddressSummary = ({ questionSummary, environmentId }: AddressSummar
Response
Time
- {questionSummary.samples.map((response) => { - return ( -
-
- {response.person ? ( - -
- +
+ {questionSummary.samples.map((response) => { + return ( +
+
+ {response.person ? ( + +
+ +
+

+ {getPersonIdentifier(response.person)} +

+ + ) : ( +
+
+ +
+

Anonymous

-

- {getPersonIdentifier(response.person)} -

- - ) : ( -
-
- -
-

Anonymous

-
- )} -
- { -
- + )}
- } + { +
+ +
+ } -
- {timeSince(new Date(response.updatedAt).toISOString())} +
+ {timeSince(new Date(response.updatedAt).toISOString())} +
-
- ); - })} + ); + })} +
); diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/DateQuestionSummary.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/DateQuestionSummary.tsx index 26d34bbe8e..7f992bf34c 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/DateQuestionSummary.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/DateQuestionSummary.tsx @@ -1,10 +1,12 @@ import Link from "next/link"; +import { useState } from "react"; import { getPersonIdentifier } from "@formbricks/lib/person/util"; import { timeSince } from "@formbricks/lib/time"; import { formatDateWithOrdinal } from "@formbricks/lib/utils/datetime"; import { TSurveyQuestionSummaryDate } from "@formbricks/types/surveys"; import { PersonAvatar } from "@formbricks/ui/Avatars"; +import { Button } from "@formbricks/ui/Button"; import { QuestionSummaryHeader } from "./QuestionSummaryHeader"; @@ -14,6 +16,15 @@ interface DateQuestionSummary { } export const DateQuestionSummary = ({ questionSummary, environmentId }: DateQuestionSummary) => { + const [visibleResponses, setVisibleResponses] = useState(10); + + const handleLoadMore = () => { + // Increase the number of visible responses by 10, not exceeding the total number of responses + setVisibleResponses((prevVisibleResponses) => + Math.min(prevVisibleResponses + 10, questionSummary.samples.length) + ); + }; + return (
@@ -23,39 +34,48 @@ export const DateQuestionSummary = ({ questionSummary, environmentId }: DateQues
Response
Time
- {questionSummary.samples.map((response) => ( -
-
- {response.person ? ( - -
- +
+ {questionSummary.samples.slice(0, visibleResponses).map((response) => ( +
+
+ {response.person ? ( + +
+ +
+

+ {getPersonIdentifier(response.person)} +

+ + ) : ( +
+
+ +
+

Anonymous

-

- {getPersonIdentifier(response.person)} -

- - ) : ( -
-
- -
-

Anonymous

-
- )} -
-
- {formatDateWithOrdinal(new Date(response.value as string))} -
-
- {timeSince(new Date(response.updatedAt).toISOString())} + )} +
+
+ {formatDateWithOrdinal(new Date(response.value as string))} +
+
+ {timeSince(new Date(response.updatedAt).toISOString())} +
+ ))} +
+ {visibleResponses < questionSummary.samples.length && ( +
+
- ))} + )}
); diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/FileUploadSummary.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/FileUploadSummary.tsx index 6ca143463e..6e6df046ca 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/FileUploadSummary.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/FileUploadSummary.tsx @@ -1,11 +1,13 @@ import { DownloadIcon, FileIcon } from "lucide-react"; import Link from "next/link"; +import { useState } from "react"; import { getPersonIdentifier } from "@formbricks/lib/person/util"; import { getOriginalFileNameFromUrl } from "@formbricks/lib/storage/utils"; import { timeSince } from "@formbricks/lib/time"; import { TSurveyQuestionSummaryFileUpload } from "@formbricks/types/surveys"; import { PersonAvatar } from "@formbricks/ui/Avatars"; +import { Button } from "@formbricks/ui/Button"; import { QuestionSummaryHeader } from "./QuestionSummaryHeader"; @@ -15,6 +17,15 @@ interface FileUploadSummaryProps { } export const FileUploadSummary = ({ questionSummary, environmentId }: FileUploadSummaryProps) => { + const [visibleResponses, setVisibleResponses] = useState(10); + + const handleLoadMore = () => { + // Increase the number of visible responses by 10, not exceeding the total number of responses + setVisibleResponses((prevVisibleResponses) => + Math.min(prevVisibleResponses + 10, questionSummary.files.length) + ); + }; + return (
@@ -24,72 +35,81 @@ export const FileUploadSummary = ({ questionSummary, environmentId }: FileUpload
Response
Time
- {questionSummary.files.map((response) => ( -
-
- {response.person ? ( - -
- -
-

- {getPersonIdentifier(response.person)} -

- - ) : ( -
-
- -
-

Anonymous

-
- )} -
- -
- {Array.isArray(response.value) && - (response.value.length > 0 ? ( - response.value.map((fileUrl, index) => { - const fileName = getOriginalFileNameFromUrl(fileUrl); - - return ( -
- -
-
- -
-
-
- -
- -

{fileName}

-
-
- ); - }) +
+ {questionSummary.files.slice(0, visibleResponses).map((response) => ( +
+
+ {response.person ? ( + +
+ +
+

+ {getPersonIdentifier(response.person)} +

+ ) : ( -
-

skipped

+
+
+ +
+

Anonymous

- ))} -
+ )} +
-
- {timeSince(new Date(response.updatedAt).toISOString())} +
+ {Array.isArray(response.value) && + (response.value.length > 0 ? ( + response.value.map((fileUrl, index) => { + const fileName = getOriginalFileNameFromUrl(fileUrl); + + return ( +
+ +
+
+ +
+
+
+ +
+ +

{fileName}

+
+
+ ); + }) + ) : ( +
+

skipped

+
+ ))} +
+ +
+ {timeSince(new Date(response.updatedAt).toISOString())} +
+ ))} +
+ {visibleResponses < questionSummary.files.length && ( +
+
- ))} + )}
); diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/HiddenFieldsSummary.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/HiddenFieldsSummary.tsx index e2adee2eb3..ac914ce227 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/HiddenFieldsSummary.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/HiddenFieldsSummary.tsx @@ -1,18 +1,27 @@ import { InboxIcon, Link, MessageSquareTextIcon } from "lucide-react"; -import { FC } from "react"; +import { useState } from "react"; import { getPersonIdentifier } from "@formbricks/lib/person/util"; import { timeSince } from "@formbricks/lib/time"; import { TEnvironment } from "@formbricks/types/environment"; import { TSurveyQuestionSummaryHiddenFields } from "@formbricks/types/surveys"; import { PersonAvatar } from "@formbricks/ui/Avatars"; +import { Button } from "@formbricks/ui/Button"; interface HiddenFieldsSummaryProps { environment: TEnvironment; questionSummary: TSurveyQuestionSummaryHiddenFields; } -export const HiddenFieldsSummary: FC = ({ environment, questionSummary }) => { +export const HiddenFieldsSummary = ({ environment, questionSummary }: HiddenFieldsSummaryProps) => { + const [visibleResponses, setVisibleResponses] = useState(10); + + const handleLoadMore = () => { + // Increase the number of visible responses by 10, not exceeding the total number of responses + setVisibleResponses((prevVisibleResponses) => + Math.min(prevVisibleResponses + 10, questionSummary.samples.length) + ); + }; return (
@@ -37,7 +46,7 @@ export const HiddenFieldsSummary: FC = ({ environment,
Response
Time
- {questionSummary.samples.map((response) => ( + {questionSummary.samples.slice(0, visibleResponses).map((response) => (
@@ -70,6 +79,13 @@ export const HiddenFieldsSummary: FC = ({ environment,
))} + {visibleResponses < questionSummary.samples.length && ( +
+ +
+ )}
); diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/OpenTextSummary.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/OpenTextSummary.tsx index 45bdf2fc77..45404ca380 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/OpenTextSummary.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/OpenTextSummary.tsx @@ -1,9 +1,11 @@ import Link from "next/link"; +import { useState } from "react"; import { getPersonIdentifier } from "@formbricks/lib/person/util"; import { timeSince } from "@formbricks/lib/time"; import { TSurveyQuestionSummaryOpenText } from "@formbricks/types/surveys"; import { PersonAvatar } from "@formbricks/ui/Avatars"; +import { Button } from "@formbricks/ui/Button"; import { QuestionSummaryHeader } from "./QuestionSummaryHeader"; @@ -13,6 +15,15 @@ interface OpenTextSummaryProps { } export const OpenTextSummary = ({ questionSummary, environmentId }: OpenTextSummaryProps) => { + const [visibleResponses, setVisibleResponses] = useState(10); + + const handleLoadMore = () => { + // Increase the number of visible responses by 10, not exceeding the total number of responses + setVisibleResponses((prevVisibleResponses) => + Math.min(prevVisibleResponses + 10, questionSummary.samples.length) + ); + }; + return (
@@ -22,39 +33,48 @@ export const OpenTextSummary = ({ questionSummary, environmentId }: OpenTextSumm
Response
Time
- {questionSummary.samples.map((response) => ( -
-
- {response.person ? ( - -
- +
+ {questionSummary.samples.slice(0, visibleResponses).map((response) => ( +
+
+ {response.person ? ( + +
+ +
+

+ {getPersonIdentifier(response.person)} +

+ + ) : ( +
+
+ +
+

Anonymous

-

- {getPersonIdentifier(response.person)} -

- - ) : ( -
-
- -
-

Anonymous

-
- )} -
-
- {response.value} -
-
- {timeSince(new Date(response.updatedAt).toISOString())} + )} +
+
+ {response.value} +
+
+ {timeSince(new Date(response.updatedAt).toISOString())} +
+ ))} +
+ {visibleResponses < questionSummary.samples.length && ( +
+
- ))} + )}
); diff --git a/packages/lib/response/util.ts b/packages/lib/response/util.ts index 0dc5eaa3cc..8e32d03162 100644 --- a/packages/lib/response/util.ts +++ b/packages/lib/response/util.ts @@ -685,7 +685,7 @@ export const getQuestionWiseSummary = ( survey: TSurvey, responses: TResponse[] ): TSurveySummary["summary"] => { - const VALUES_LIMIT = 10; + const VALUES_LIMIT = 50; let summary: TSurveySummary["summary"] = []; survey.questions.forEach((question) => { diff --git a/packages/surveys/src/components/general/CalEmbed.tsx b/packages/surveys/src/components/general/CalEmbed.tsx index ae1cdf5bbe..996d639078 100644 --- a/packages/surveys/src/components/general/CalEmbed.tsx +++ b/packages/surveys/src/components/general/CalEmbed.tsx @@ -50,7 +50,7 @@ export default function CalEmbed({ question, onSuccessfulBooking }: CalEmbedProp return (
-
+
); } diff --git a/packages/surveys/src/components/general/FileInput.tsx b/packages/surveys/src/components/general/FileInput.tsx index 071113cfbd..5aa0cc40f6 100644 --- a/packages/surveys/src/components/general/FileInput.tsx +++ b/packages/surveys/src/components/general/FileInput.tsx @@ -254,7 +254,7 @@ export default function FileInput({
{isUploading && (
-
diff --git a/packages/surveys/src/components/general/ThankYouCard.tsx b/packages/surveys/src/components/general/ThankYouCard.tsx index e5b3fb7ac2..a78f61f1fa 100644 --- a/packages/surveys/src/components/general/ThankYouCard.tsx +++ b/packages/surveys/src/components/general/ThankYouCard.tsx @@ -83,7 +83,7 @@ export default function ThankYouCard({ window.location.replace(buttonLink); }} /> -

Press Enter ↵

+

Press Enter ↵

)}
diff --git a/packages/surveys/src/components/general/WelcomeCard.tsx b/packages/surveys/src/components/general/WelcomeCard.tsx index 2380c9a133..4f6fd21f1b 100644 --- a/packages/surveys/src/components/general/WelcomeCard.tsx +++ b/packages/surveys/src/components/general/WelcomeCard.tsx @@ -125,21 +125,21 @@ export default function WelcomeCard({
{timeToFinish && !showResponseCount ? ( -
+

Takes {calculateTimeToComplete()}

) : showResponseCount && !timeToFinish && responseCount && responseCount > 3 ? ( -
+

{`${responseCount} people responded`}

) : timeToFinish && showResponseCount ? ( -
+

Takes {calculateTimeToComplete()}