-
Notifications
You must be signed in to change notification settings - Fork 85
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 generateApiComponents.ts
and tests
#1074
Conversation
Thanks for contributing to Qiskit documentation! Before your PR can be merged, it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. Thanks! 🙌 |
Thanks for contributing to Qiskit documentation! Before your PR can be merged, it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. Thanks! 🙌 |
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.
Nice!
* That's because the owning class will already have a link to the relevant file; it's | ||
* noisy and not helpful to repeat the same link without line numbers for the individual methods. | ||
*/ | ||
export function prepareGitHubLink( |
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.
Not a big deal if this is going to be annoying to implement, but you can switch processHtml.md to use this now, along with findByText
. That way we don't duplicate. And you could move the tests too if it's too hard.
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.
Actually, it probably would be good to do this if isn't too much of a pain because it may take a few days to land the follow up PR since it's blocked by the Docker image being updated for staging.
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.
Done!
componentProps.extraRawSignatures = [ | ||
...extraRawSignatures.flatMap((sigProps) => sigProps.rawSignature ?? []), | ||
]; |
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.
Using flatMap
surprises me because rawSignature
is a string. Should this be
componentProps.extraRawSignatures = Array.from(
extraRawSignatures.map((x) => x.signature).filter((sig) => sig !== undefined)
)
Also can extraRawSignatures
have a more precise type like string[]
or Array<string | undefined>
? Seems weird to have all the ComponentProps if we're going to discard them.
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.
In reality, rawSignature
is a string
but could be undefined
given that we have API types without it. The problem with using the filter
is that we get the type (string | undefined)[]
instead of string[] | undefined
as in the flatMap
.
Also can
extraRawSignatures
have a more precise type
This is a good idea. I think we could remove the flatMap
or the map
+ filter
entirely, but I would like to do it in #1026 as a follow-up because we can simplify the main function by only storing the overloaded signature and not all props. The function addExtraSignatures
will make all the work as a black box
return ""; | ||
} | ||
|
||
const html = `<span class="target" id=''/><p><code>${signatureHtml}</code></p>`; |
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.
Why is id
an empty string?
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.
It's empty because it's not needed, but I was able to remove the span and the paragraph too 👍 . Apparently, we only need to add the code tag. Without the code tag, the signature has an extra apostrophe at the beginning and at the end
Part of Qiskit#1008 This PR is a precursor of Qiskit#1026, and it creates a new script named `generateApiComponents.ts` with some tests. This script will have all the logic to generate the MDX components, but, in the meantime, this PR adds some functions that can be tested independently by just receiving, as parameters, a list of props or HTML code. It also copies over the functions `prepareGitHubLink` and `findByText` from `processHtml.ts`
Part of #1008
This PR is a precursor of #1026, and it creates a new script named
generateApiComponents.ts
with some tests. This script will have all the logic to generate the MDX components, but, in the meantime, this PR adds some functions that can be tested independently by just receiving, as parameters, a list of props or HTML code.It also copies over the functions
prepareGitHubLink
andfindByText
fromprocessHtml.ts