-
Notifications
You must be signed in to change notification settings - Fork 30
Add UI for dynamic code block to execute Assistant wp-cli commands #214
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
Conversation
…block
<div className="mt-1 p-4 bg-[#2D3337]"> | ||
<div className="flex justify-between mb-2 font-sans"> | ||
<span className={ status === 'success' ? 'text-[#63CE68]' : 'text-[#E66D6C]' }> | ||
{ status === 'success' ? 'Success' : 'Error' } |
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.
Likely no need to repeat the status
logic here once integrated with wp-cli -- this logic is just for demonstration, and could be refactored into separate states.
interface InlineCLIProps { | ||
output: string; | ||
status: 'success' | 'error'; | ||
time: 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.
This interface is likely to change based on the final shape of the wp-cli implementation in #203 -- just chose some probable params for UI demonstration purposes.
This approach is at ~85% polish, but marking as "Ready for Review" to get feedback.
Edit: Markdown |
@@ -107,6 +120,7 @@ export default function ButtonComponent( { | |||
baseStyles, | |||
variant === 'primary' && primaryStyles, | |||
variant === 'secondary' && secondaryStyles, | |||
variant === 'tertiary' && tertiaryStyles, |
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.
Leverage tertiary
for InlineCLI ActionButtons. (tertiary
is currently unused as a <Button />
variant in trunk
.)
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 noted these new tertiary styles modified the existing usage of tertiary in the add site modal. We might consider consolidating button styles (i.e., ask the design team if we can reduce the number of button styles used) or rename this new style. WDYT?
Before | After |
---|---|
![]() |
![]() |
studio/src/components/add-site.tsx
Line 140 in 216154a
<Button onClick={ closeModal } disabled={ isAddingSite } variant="tertiary"> |
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.
@dcalhoun Good catch! I think we should use a different name for the buttons in code blocks as they're a bit of a special use case. I don't anticipate on re-using those dark styles anywhere else in the app at the moment.
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.
On second thought, let's update these buttons to use the same styling as the Add site
button in the sidebar (outlined, not filled). That helps bring more consistency to the button styles in the app. (Figma)
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.
For posterity, I drafted #243 addressing the button styling.
Hi @derekblank - I did not have time to take a look at this one today but I will review tomorrow and probably create a new PR against this one that connects to whatever we implemented in #203 |
…e-block
@katinthehatsite No worries -- I updated the PR description with a visual example of the JSX tree for the components introduced in this PR, if it's helpful. I also merged the latest from Under the current UI structure proposed in this PR, the Run button handler in this PR would be replaced by the |
Prevents DOM validation warning: Warning: validateDOMNesting(...): <div> cannot appear as a descendant of <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.
@derekblank , thanks for creating all the UI elements.
I replaced the spinner to use the default from WordPress components here 65313ac
We'll merge this PR and @katinthehatsite will create a new PR for the integration with wp-cli.
We commented the Run
button for now.
Thank you!
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 work! We made a couple of minor changes and disabled the "Run" button for now.
@derekblank I think it might be good to also add the tests for the code block. We can handle it as a part of a different PR after we implemented the execution part. |
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.
@@ -107,6 +120,7 @@ export default function ButtonComponent( { | |||
baseStyles, | |||
variant === 'primary' && primaryStyles, | |||
variant === 'secondary' && secondaryStyles, | |||
variant === 'tertiary' && tertiaryStyles, |
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 noted these new tertiary styles modified the existing usage of tertiary in the add site modal. We might consider consolidating button styles (i.e., ask the design team if we can reduce the number of button styles used) or rename this new style. WDYT?
Before | After |
---|---|
![]() |
![]() |
studio/src/components/add-site.tsx
Line 140 in 216154a
<Button onClick={ closeModal } disabled={ isAddingSite } variant="tertiary"> |
Noting the unexpected spacing for inline code was addressed in #235. 🎉 However, it appears an error regarding invalid HTML remains. HTML error
|
Resolves Automattic/dotcom-forge#7526
Proposed Changes
Adds dynamic code block to display output of wp-cli commands, to be integrated with output of
add/execute-cli-inline
implemented in #203.dynamic-code-block.mov
JSX Example
A visual example of the dynamic code block JSX tree, and some of the components introduced in this PR. Open to feedback/ideas (and I would expect this tree to change somewhat as we integrate the wp-cli commands).
The general flow:
<Message role="assistant" />
Assistant API response is parsed using react-markdown.<CodeBlock />
as a subcomponent of react-markdown to display the command to the user using basic syntax highlighting.<ActionButton />
components is appended to the bottom of each<CodeBlock />
. containing the Copy and Run buttons.<ActionButton />
button is clicked, the command starts executing. Display the<Spinner />
while the command executes.<InlineCLI />
component.Testing Instructions
STUDIO_AI=true npm start
Pre-merge Checklist
Todo