Fix related pubs bug#1017
Conversation
| } | ||
| > | ||
| <div className="flex justify-center py-10"> | ||
| <div className="prose max-w-prose flex-1"> |
There was a problem hiding this comment.
this originally came from #980 but it seems like just the flex-1 is enough to keep the width. adding prose changes a bunch of styles, including making <hr/>s have huge margins
prose is used for markdown, but I believe the various markdown places already have prose on them, i.e. StructuralElement
https://github.com/pubpub/platform/blob/0711707979fe1bc51874d120e33d6626b3f7be32/core/app/components/FormBuilder/FormElement.tsx#L167
| {element.schemaName !== CoreSchemaType.Null && ( | ||
| <span>Please enter a value for this relationship.</span> | ||
| )} |
There was a problem hiding this comment.
I just noticed it was still saying to fill out a field if the schema was null (and then it wouldn't render an input to fill out)
|
|
||
| // For the Context, we want both the pubs from the initial pub query (which is limited) | ||
| // as well as the pubs related to this pub | ||
| const relatedPubs = pub ? pub.values.flatMap((v) => (v.relatedPub ? [v.relatedPub] : [])) : []; |
There was a problem hiding this comment.
TIL: you can use flatMap to get around how doing a .map(...).filter(value => !!value) doesn't let TS think you have Thing[] and TS will still think you have (Thing | null)[] even after the filter
There was a problem hiding this comment.
very hot tip, the .filter typing is so annoying!
There was a problem hiding this comment.
i think they did fix this in a recent release, if you do .filter(value=>value != null) specifically!
There was a problem hiding this comment.
oh no nvm, this only applies one level deep! they fixed the "simple" case in typescript 5.5
https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#inferred-type-predicates
Example (change to typescript <5.5 to see error in the simple case)
kalilsn
left a comment
There was a problem hiding this comment.
Works great! Tested and confirmed the bug on main (with limit 1) and that it works on your branch
* Remove prose class which added unwanted styling * Concat related pubs to pub context

Issue(s) Resolved
Closes #1003
High-level Explanation of PR
Our pub editor requires a list of pubs in a context so that it knows what pubs can be related to, and so it can render the titles of pubs that are already related. The problem is that when we query for pubs, we need to limit (in this case we limit to
30). So a pub might be related to another pub that is not in that initial 30, in which case the app can't render the pub's title since it wasn't returned with the query and breaks.This fixes this initial problem by concatenating an existing pub's related pubs to the pubs sent to the pub context.
Test Plan
limitto1https://github.com/pubpub/platform/blob/626e97e310537e74eeb8a77289514b7319d96d83/core/app/components/pubs/PubEditor/PubEditor.tsx#L166
Screenshots (if applicable)
Notes