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

Add related pub button #973

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Conversation

allisonking
Copy link
Contributor

@allisonking allisonking commented Feb 12, 2025

Issue(s) Resolved

Closes #953

High-level Explanation of PR

TODO

  • TS error on slug for ConfigureRelatedValue
  • Adding a related pub currently replaces any current related value instead of appending—check if new update/upsert/create logic might address this?
  • Check file upload, member select, context editor and other tricky form values work ok
  • Refactor editorSpecifiers
  • Tests

Test Plan

  1. Add any related field (null should also work)
  2. Add the field to a pub type
  3. Create a pub with that pub type
  4. On the created pub page, click the "Add related pub" button
  5. You should get a modal that lets you choose a pubtype, relationship field, and relationship value
  6. Click "Create pub"
  7. This should bring you to the create pub page. Create a pub here
  8. Go back to the pub created in step 3 and verify that the pub created in step 7 is now in the "Related pubs" table. You should also see the field it was related on and the value.

Screenshots (if applicable)

image

Notes

@@ -59,7 +59,6 @@ export default async function Page(props: Props) {

const pubFields = await getPubFields({
communityId: community?.id as CommunitiesId,
includeRelations: true,
Copy link
Contributor Author

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} />
Copy link
Contributor Author

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) }
Copy link
Contributor Author

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

Copy link
Contributor Author

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?

Comment on lines 141 to 142
// @ts-ignore TODO: how best to fix this?
slug="relatedPub.value"
Copy link
Contributor Author

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)

Comment on lines +215 to +228
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]);
Copy link
Contributor Author

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

@allisonking allisonking marked this pull request as ready for review February 12, 2025 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Button to create new related pub on pub details page
1 participant