-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3152 from quantified-uncertainty/export-page-lists
Show exports on front page
- Loading branch information
Showing
24 changed files
with
513 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/hub/prisma/migrations/20240405224331_model_export_is_current/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-- AlterTable | ||
ALTER TABLE "ModelExport" ADD COLUMN "isCurrent" BOOLEAN NOT NULL DEFAULT false; | ||
UPDATE "ModelExport" SET "isCurrent" = true WHERE "modelRevisionId" IN (SELECT "currentRevisionId" FROM "Model"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"use client"; | ||
|
||
import { FC } from "react"; | ||
import { graphql, usePaginationFragment } from "react-relay"; | ||
|
||
import { ModelExportList } from "@/modelExports/components/ModelExportList"; | ||
|
||
import { FrontPageModelExportList$key } from "@/__generated__/FrontPageModelExportList.graphql"; | ||
import { FrontPageModelExportListPaginationQuery } from "@/__generated__/FrontPageModelExportListPaginationQuery.graphql"; | ||
|
||
const Fragment = graphql` | ||
fragment FrontPageModelExportList on Query | ||
@argumentDefinitions( | ||
cursor: { type: "String" } | ||
count: { type: "Int", defaultValue: 20 } | ||
) | ||
@refetchable(queryName: "FrontPageModelExportListPaginationQuery") { | ||
modelExports(first: $count, after: $cursor) | ||
@connection(key: "FrontPageModelExportList_modelExports") { | ||
# necessary for Relay | ||
edges { | ||
__typename | ||
} | ||
...ModelExportList | ||
} | ||
} | ||
`; | ||
|
||
type Props = { | ||
dataRef: FrontPageModelExportList$key; | ||
}; | ||
|
||
export const FrontPageModelExportList: FC<Props> = ({ dataRef }) => { | ||
const { | ||
data: { modelExports }, | ||
loadNext, | ||
} = usePaginationFragment< | ||
FrontPageModelExportListPaginationQuery, | ||
FrontPageModelExportList$key | ||
>(Fragment, dataRef); | ||
|
||
return <ModelExportList connectionRef={modelExports} loadNext={loadNext} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/hub/src/app/users/[username]/exports/UserModelExportList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { FC } from "react"; | ||
import { usePaginationFragment } from "react-relay"; | ||
import { graphql } from "relay-runtime"; | ||
|
||
import { ModelExportList } from "@/modelExports/components/ModelExportList"; | ||
|
||
import { UserModelExportList$key } from "@/__generated__/UserModelExportList.graphql"; | ||
|
||
const Fragment = graphql` | ||
fragment UserModelExportList on User | ||
@argumentDefinitions( | ||
cursor: { type: "String" } | ||
count: { type: "Int", defaultValue: 20 } | ||
) | ||
@refetchable(queryName: "UserModelExportListPaginationQuery") { | ||
modelExports(first: $count, after: $cursor) | ||
@connection(key: "UserModelExportList_modelExports") { | ||
edges { | ||
__typename | ||
} | ||
...ModelExportList | ||
} | ||
} | ||
`; | ||
|
||
type Props = { | ||
dataRef: UserModelExportList$key; | ||
}; | ||
|
||
export const UserModelExportList: FC<Props> = ({ dataRef }) => { | ||
const { | ||
data: { modelExports }, | ||
loadNext, | ||
} = usePaginationFragment(Fragment, dataRef); | ||
|
||
return ( | ||
<div> | ||
{modelExports.edges.length ? ( | ||
<ModelExportList connectionRef={modelExports} loadNext={loadNext} /> | ||
) : ( | ||
<div className="text-slate-500">No modelExport to show.</div> | ||
)} | ||
</div> | ||
); | ||
}; |
32 changes: 32 additions & 0 deletions
32
packages/hub/src/app/users/[username]/exports/UserModelExportsPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"use client"; | ||
import { FC } from "react"; | ||
import { graphql } from "relay-runtime"; | ||
|
||
import { extractFromGraphqlErrorUnion } from "@/lib/graphqlHelpers"; | ||
import { SerializablePreloadedQuery } from "@/relay/loadPageQuery"; | ||
import { usePageQuery } from "@/relay/usePageQuery"; | ||
|
||
import { UserModelExportList } from "./UserModelExportList"; | ||
|
||
import { UserModelExportsPageQuery } from "@/__generated__/UserModelExportsPageQuery.graphql"; | ||
|
||
const Query = graphql` | ||
query UserModelExportsPageQuery($username: String!) { | ||
userByUsername(username: $username) { | ||
__typename | ||
... on User { | ||
...UserModelExportList | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export const UserModelExportsPage: FC<{ | ||
query: SerializablePreloadedQuery<UserModelExportsPageQuery>; | ||
}> = ({ query }) => { | ||
const [{ userByUsername: result }] = usePageQuery(Query, query); | ||
|
||
const user = extractFromGraphqlErrorUnion(result, "User"); | ||
|
||
return <UserModelExportList dataRef={user} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Metadata } from "next"; | ||
|
||
import { loadPageQuery } from "@/relay/loadPageQuery"; | ||
|
||
import { UserModelExportsPage } from "./UserModelExportsPage"; | ||
|
||
import QueryNode, { | ||
UserModelExportsPageQuery, | ||
} from "@/__generated__/UserModelExportsPageQuery.graphql"; | ||
|
||
type Props = { | ||
params: { username: string }; | ||
}; | ||
|
||
export default async function OuterUserModelExportsPage({ params }: Props) { | ||
const query = await loadPageQuery<UserModelExportsPageQuery>(QueryNode, { | ||
username: params.username, | ||
}); | ||
|
||
return <UserModelExportsPage query={query} />; | ||
} | ||
|
||
export function generateMetadata({ params }: Props): Metadata { | ||
return { title: params.username }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.