From b35b82f4ee183c0a945cdf51cddcf0909dd838cb Mon Sep 17 00:00:00 2001 From: Anshuman Pandey <54475686+pandeymangg@users.noreply.github.com> Date: Mon, 11 Nov 2024 18:39:58 +0530 Subject: [PATCH] fix: restricting archived attributes in the survey and segment editor (#4269) Co-authored-by: Piyush Gupta --- .../[environmentId]/surveys/[surveyId]/edit/page.tsx | 2 +- .../attributes/components/AttributeClassesTable.tsx | 12 ++++++++++-- .../[environmentId]/(people)/segments/page.tsx | 2 +- .../actions/components/ActionActivityTab.tsx | 1 - packages/lib/attributeClass/service.ts | 7 ++++++- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/page.tsx b/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/page.tsx index f3f573d0eb..e3fe659a25 100644 --- a/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/page.tsx +++ b/apps/web/app/(app)/(survey-editor)/environments/[environmentId]/surveys/[surveyId]/edit/page.tsx @@ -48,7 +48,7 @@ const Page = async ({ params, searchParams }) => { getProductByEnvironmentId(params.environmentId), getEnvironment(params.environmentId), getActionClasses(params.environmentId), - getAttributeClasses(params.environmentId), + getAttributeClasses(params.environmentId, undefined, { skipArchived: true }), getResponseCountBySurveyId(params.surveyId), getOrganizationByEnvironmentId(params.environmentId), getServerSession(authOptions), diff --git a/apps/web/app/(app)/environments/[environmentId]/(people)/attributes/components/AttributeClassesTable.tsx b/apps/web/app/(app)/environments/[environmentId]/(people)/attributes/components/AttributeClassesTable.tsx index e1ff46aac3..bf8e175189 100644 --- a/apps/web/app/(app)/environments/[environmentId]/(people)/attributes/components/AttributeClassesTable.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/(people)/attributes/components/AttributeClassesTable.tsx @@ -4,6 +4,7 @@ import { useTranslations } from "next-intl"; import { useMemo, useState } from "react"; import { TAttributeClass } from "@formbricks/types/attribute-classes"; import { TUserLocale } from "@formbricks/types/user"; +import { Label } from "@formbricks/ui/components/Label"; import { Switch } from "@formbricks/ui/components/Switch"; import { AttributeDetailModal } from "./AttributeDetailModal"; import { AttributeClassDataRow } from "./AttributeRowData"; @@ -49,8 +50,15 @@ export const AttributeClassesTable = ({ {hasArchived && (
- {t("environments.attributes.show_archived")} - + +
)} diff --git a/apps/web/app/(app)/environments/[environmentId]/(people)/segments/page.tsx b/apps/web/app/(app)/environments/[environmentId]/(people)/segments/page.tsx index 29b1ed80f7..d2d504d72c 100644 --- a/apps/web/app/(app)/environments/[environmentId]/(people)/segments/page.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/(people)/segments/page.tsx @@ -24,7 +24,7 @@ const Page = async ({ params }) => { const [environment, segments, attributeClasses, organization, product] = await Promise.all([ getEnvironment(params.environmentId), getSegments(params.environmentId), - getAttributeClasses(params.environmentId), + getAttributeClasses(params.environmentId, undefined, { skipArchived: true }), getOrganizationByEnvironmentId(params.environmentId), getProductByEnvironmentId(params.environmentId), ]); diff --git a/apps/web/app/(app)/environments/[environmentId]/actions/components/ActionActivityTab.tsx b/apps/web/app/(app)/environments/[environmentId]/actions/components/ActionActivityTab.tsx index a1f6feef52..c8dc0b95c5 100644 --- a/apps/web/app/(app)/environments/[environmentId]/actions/components/ActionActivityTab.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/actions/components/ActionActivityTab.tsx @@ -32,7 +32,6 @@ export const ActionActivityTab = ({ actionClass, environmentId }: ActivityTabPro const getActiveInactiveSurveysResponse = await getActiveInactiveSurveysAction({ actionClassId: actionClass.id, }); - console.log(getActiveInactiveSurveysResponse, "randike"); if (getActiveInactiveSurveysResponse?.data) { setActiveSurveys(getActiveInactiveSurveysResponse.data.activeSurveys); setInactiveSurveys(getActiveInactiveSurveysResponse.data.inactiveSurveys); diff --git a/packages/lib/attributeClass/service.ts b/packages/lib/attributeClass/service.ts index 1317349c96..e5b13d7fde 100644 --- a/packages/lib/attributeClass/service.ts +++ b/packages/lib/attributeClass/service.ts @@ -48,7 +48,11 @@ export const getAttributeClass = reactCache( ); export const getAttributeClasses = reactCache( - async (environmentId: string, page?: number): Promise => + async ( + environmentId: string, + page?: number, + options?: { skipArchived: boolean } + ): Promise => cache( async () => { validateInputs([environmentId, ZId], [page, ZOptionalNumber]); @@ -57,6 +61,7 @@ export const getAttributeClasses = reactCache( const attributeClasses = await prisma.attributeClass.findMany({ where: { environmentId: environmentId, + ...(options?.skipArchived ? { archived: false } : {}), }, orderBy: { createdAt: "asc",