Skip to content

Scheduling infrastructure for absolutely everyone.

fix: Insights team filter behavior (#18084)

Anik Dhabal Babudd3505ad8b8d
diff --git a/packages/features/insights/filters/TeamAndSelfList.tsx b/packages/features/insights/filters/TeamAndSelfList.tsx
index ce302d2c12b..064d38ddec3 100644
--- a/packages/features/insights/filters/TeamAndSelfList.tsx
+++ b/packages/features/insights/filters/TeamAndSelfList.tsx
@@ -79,18 +79,19 @@ export const TeamAndSelfList = ({ omitOrg = false }: { omitOrg?: boolean }) => {
};
const text = getTextPopover();
+ const isOrgDataAvailable = !!data && data.length > 0 && !!data[0].isOrg;
return (
<AnimatedPopover text={text}>
<FilterCheckboxFieldsContainer>
- {isSuccess && data?.length > 0 && data[0].isOrg && (
+ {isOrgDataAvailable && (
<FilterCheckboxField
id="all"
icon={<Icon name="layers" className="h-4 w-4" />}
checked={isAll}
onChange={(e) => {
setConfigFilters({
- selectedTeamId: data[0].isOrg ? data[0].id : null,
+ selectedTeamId: data[0].id,
selectedUserId: null,
selectedTeamName: null,
isAll: true,
@@ -123,7 +124,7 @@ export const TeamAndSelfList = ({ omitOrg = false }: { omitOrg?: boolean }) => {
});
} else if (!e.target.checked) {
setConfigFilters({
- selectedTeamId: null,
+ selectedTeamId: isOrgDataAvailable ? data[0].id : null,
selectedTeamName: null,
isAll: true,
});
@@ -154,8 +155,10 @@ export const TeamAndSelfList = ({ omitOrg = false }: { omitOrg?: boolean }) => {
});
} else if (!e.target.checked) {
setConfigFilters({
+ selectedTeamId: isOrgDataAvailable ? data[0].id : null,
selectedUserId: null,
- isAll: false,
+ selectedTeamName: null,
+ isAll: isOrgDataAvailable,
});
}
}}
diff --git a/packages/features/insights/server/trpc-router.ts b/packages/features/insights/server/trpc-router.ts
index 4a71a873f07..640ba9525b1 100644
--- a/packages/features/insights/server/trpc-router.ts
+++ b/packages/features/insights/server/trpc-router.ts
@@ -914,7 +914,7 @@ export const insightsRouter = router({
};
// Validate if user belongs to org as admin/owner
- if (user.organizationId) {
+ if (user.organizationId && user.organization.isOrgAdmin) {
const teamsFromOrg = await ctx.insightsDb.team.findMany({
where: {
parentId: user.organizationId,