Skip to content

Commit

Permalink
Refactor fundraising resource naming and update related components fo…
Browse files Browse the repository at this point in the history
…r consistency
  • Loading branch information
jthoward64 committed Jan 8, 2025
1 parent 1907fc6 commit fde8a1e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
16 changes: 12 additions & 4 deletions packages/portal/src/config/refine/graphql/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,22 @@ export const dataProvider: Required<DataProvider> = {
if (meta?.gqlQuery) {
query = meta.gqlQuery;
} else if (meta?.gqlFragment) {
const fragmentDefinition = (meta.gqlFragment as Partial<DocumentNode>)
.definitions?.[0];
if (fragmentDefinition?.kind === Kind.FRAGMENT_DEFINITION) {
const gqlDefinitions =
(meta.gqlFragment as Partial<DocumentNode>).definitions ?? [];
const fragmentDefinition = gqlDefinitions.find(
(def) => def.kind === Kind.FRAGMENT_DEFINITION
);
if (fragmentDefinition) {
const pascalResource = camelcase(singular(resource), {
pascalCase: true,
});

query = makeListDocument(pascalResource, resource, fragmentDefinition);
query = makeListDocument(
pascalResource,
resource,
fragmentDefinition.name.value,
gqlDefinitions
);
}
}

Expand Down
9 changes: 5 additions & 4 deletions packages/portal/src/config/refine/graphql/makeListDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
AbstractSortItem,
} from "@ukdanceblue/common";
import type { ResultOf, TadaDocumentNode } from "gql.tada";
import type { FragmentDefinitionNode } from "graphql";
import type { DefinitionNode } from "graphql";
import { Kind, OperationTypeNode } from "graphql";
import pluralize from "pluralize";

Expand All @@ -13,7 +13,8 @@ import { PaginationFragment } from "#documents/shared.ts";
export function makeListDocument(
pascalResource: string,
resource: string,
fragmentDefinition: FragmentDefinitionNode
fragmentName: string,
definitions: readonly DefinitionNode[]
): TadaDocumentNode<
{
data: unknown;
Expand Down Expand Up @@ -170,7 +171,7 @@ export function makeListDocument(
kind: Kind.FRAGMENT_SPREAD,
name: {
kind: Kind.NAME,
value: fragmentDefinition.name.value,
value: fragmentName,
},
},
],
Expand All @@ -182,7 +183,7 @@ export function makeListDocument(
],
},
},
fragmentDefinition,
...definitions,
...PaginationFragment.definitions,
],
};
Expand Down
2 changes: 1 addition & 1 deletion packages/portal/src/config/refine/resources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const refineResources = [
list: "/fundraising/dbfunds",
},
{
name: "fundraising",
name: "fundraisingEntry",
meta: {
label: "Entries",
modelName: "FundraisingEntryNode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function FundraisingEntriesTable<T extends Record<string, unknown>>({
} = useTypedTable({
fragment: FundraisingEntryTableFragment,
props: {
resource: "fundraising",
resource: "fundraisingEntry",
sorters: {
initial: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function ViewTeamFundraising() {
const { data } = useTypedOne({
fragment: TeamFundraisingFragment,
props: {
resource: "fundraising",
resource: "fundraisingEntry",
id: useParams({ from: "/teams/$teamId/_layout/fundraising" }).teamId,
},
});
Expand Down

0 comments on commit fde8a1e

Please sign in to comment.