-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add related pub button #973
base: main
Are you sure you want to change the base?
Conversation
@@ -59,7 +59,6 @@ export default async function Page(props: Props) { | |||
|
|||
const pubFields = await getPubFields({ | |||
communityId: community?.id as CommunitiesId, | |||
includeRelations: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
includeRelations
was originally meant to hide relationship fields while we were still building them out. now that they are being used everywhere (I think) I've removed the param in favor of an isRelated: boolean
which can filter for only relations (or non-relations)
</p> | ||
</div> | ||
<div className="mb-2"> | ||
<CreatePubButton text="Add New Pub" communityId={community.id} parentId={pub.id} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this ticket wasn't to remove the add children button, but since it's getting removed anyway I did it now so that CreatePubButton
didn't have to keep working with children
|
||
const onSubmit = async (values: FieldValues) => { | ||
const related = values.relatedPub | ||
? { ...values.relatedPub, value: JSON.stringify(values.relatedPub.value) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not totally sure that this is safe—basically the problem is that our "create pub" flow is split across two views. The first view selects the pub type, and now also the relation definition. Then it redirects to the full create pub page, passing along its info via query parameters.
Is there any reason we wouldn't want the value
field of the relation to be passed via query param to the other page? I think perhaps it could get long? or in the case of file upload, the path to the s3 file would end up in the query param i.e. http://localhost:3000/c/croccroc/pubs/create?pubTypeId=c8be5cf7-3fd0-47f1-8ddc-eb954526efa3&relatedPubId=1a5a3582-01b6-45b1-8ad5-1bd6019289ab&slug=croccroc%3Arelated-file&value=%5B%7B%22id%22%3A%22relatedPub.value-test%2Ffile%2Ftxt-1d-1e-text%2Fplain-11-1722373001847%22%2C%22fileName%22%3A%22test-file.txt%22%2C%22fileSource%22%3A%22dashboard-relatedPub.value%22%2C%22fileType%22%3A%22text%2Fplain%22%2C%22fileSize%22%3A11%2C%22fileMeta%22%3A%7B%22relativePath%22%3Anull%2C%22name%22%3A%22test-file.txt%22%2C%22type%22%3A%22text%2Fplain%22%7D%2C%22fileUploadUrl%22%3A%22https%3A%2F%2Fs3.us-east-1.amazonaws.com%2Fassets.v7.pubpub.org%2F1a5a3582-01b6-45b1-8ad5-1bd6019289ab%2Ftest-file.txt%22%7D%5D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the alternative would be to store the value in something like local storage, or maybe a context?
// @ts-ignore TODO: how best to fix this? | ||
slug="relatedPub.value" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could use some TS suggestions here—right now ConfigureRelatedValue
is typed such that it expects to be part of an array field, but that's not the case here, where it's actually the only field (slug is expected to be i.e. field.0.value
when really this one is just field.value
. the strict field.0.value
typing in ConfigureRelatedValue
is to help render field array error states)
const path = usePathname(); | ||
const searchParams = useSearchParams(); | ||
const router = useRouter(); | ||
const community = useCommunity(); | ||
|
||
const pathWithoutFormParam = useMemo(() => { | ||
const urlSearchParams = new URLSearchParams(searchParams ?? undefined); | ||
urlSearchParams.delete("create-pub-form"); | ||
return `${path}?${urlSearchParams.toString()}`; | ||
}, [path, searchParams]); | ||
|
||
const closeForm = useCallback(() => { | ||
router.replace(pathWithoutFormParam); | ||
}, [pathWithoutFormParam]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all of this is from the original PubTypeFormClient
which I renamed since this does more than just pub type now
Issue(s) Resolved
Closes #953
High-level Explanation of PR
TODO
slug
forConfigureRelatedValue
editorSpecifiers
Test Plan
Screenshots (if applicable)
Notes