Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show total unused fields #5878

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/web/app/src/pages/target-explorer-unused.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Subtitle, Title } from '@/components/ui/page';
import { QueryError } from '@/components/ui/query-error';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
import { FragmentType, graphql, useFragment } from '@/gql';
import { GraphQlInputObjectType, GraphQlInterfaceType, GraphQlObjectType } from '@/gql/graphql';
import { useDateRangeController } from '@/lib/hooks/use-date-range-controller';
import { cn } from '@/lib/utils';
import { TypeRenderer, TypeRenderFragment } from './target-explorer-type';
Expand Down Expand Up @@ -97,8 +98,29 @@ const UnusedSchemaView = memo(function _UnusedSchemaView(props: {
return null;
}

const unusedTypes = types.length ?? 0;
const unusedFields = types.reduce((a, b) => {
if (b.__typename === 'GraphQLObjectType') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this counts all fields, not just unused?

return a + (b as GraphQlObjectType).fields.length;
}
if (b.__typename === 'GraphQLInterfaceType') {
return a + (b as GraphQlInterfaceType).fields.length;
}
if (b.__typename === 'GraphQLInputObjectType') {
return a + (b as GraphQlInputObjectType).fields.length;
}

return a;
}, 0);

return (
<div className="space-y-6">
<div>
<p className="text-sm text-gray-500">
You have a total of {unusedFields} unused fields within {unusedTypes} different types in
the selected time period
</p>
</div>
<div>
<TooltipProvider>
{letters.map(letter => (
Expand Down