fix: restricting archived attributes in the survey and segment editor (#4269)

Co-authored-by: Piyush Gupta <piyushguptaa2z123@gmail.com>
This commit is contained in:
Anshuman Pandey
2024-11-11 18:39:58 +05:30
committed by GitHub
parent ea52624ab2
commit b35b82f4ee
5 changed files with 18 additions and 6 deletions

View File

@@ -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),

View File

@@ -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 && (
<div className="my-4 flex items-center justify-end text-right">
<div className="flex items-center text-sm font-medium">
{t("environments.attributes.show_archived")}
<Switch className="mx-3" checked={showArchived} onCheckedChange={toggleShowArchived} />
<Label htmlFor="showArchivedToggle" className="cursor-pointer">
{t("environments.attributes.show_archived")}
</Label>
<Switch
id="showArchivedToggle"
className="mx-3"
checked={showArchived}
onCheckedChange={toggleShowArchived}
/>
</div>
</div>
)}

View File

@@ -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),
]);

View File

@@ -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);

View File

@@ -48,7 +48,11 @@ export const getAttributeClass = reactCache(
);
export const getAttributeClasses = reactCache(
async (environmentId: string, page?: number): Promise<TAttributeClass[]> =>
async (
environmentId: string,
page?: number,
options?: { skipArchived: boolean }
): Promise<TAttributeClass[]> =>
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",