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 DIY widget #1546

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rafaellehmkuhl
Copy link
Member

@rafaellehmkuhl rafaellehmkuhl commented Jan 6, 2025

This allows the users to create their own widget, with custom HTML+JS+CSS code.

The widget has access to the data-lake and actions APIs (as shown in the video), so one can create rich widgets that interact with the entire Cockpit ecosystem.

I'm using the Monaco editor here (the one VSCode is based on), and the editor window can be dragged to facilitate editing.

In the video I show a simple widget that consists on the memory used by Cockpit (consumed from the data-lake) that changes its color based on a threshold.

diywidget.mp4

This is the editor behind VSCode. It will help with features that allow users to edit code.
This library makes it easy to add dragging and resizing on any component.
This is a widget that runs bare Javascript code created by the user. It does nothing this the user writes the code.

The idea with this widget is to allow people to add any type of functionality to Cockpit without actually knowing the Cockpit codebase previously.

We expect a lot of cool stuff to come from this!
@ArturoManzoli
Copy link
Contributor

Still reviewing the code, but for now, you can adjust some interface details:

  • Drag icon should be on the top-left corner, 8px from top, 8px from left edge. Not aligned the dialog title, otherwise it seems to be connected to the title, not to the window itself; (you could use negative margins here: e.g.: -mt-[5px])

  • The dialog title should be centered;

  • Dialog actions should all be in white text. Some dimmed white could be applied.

  • The footer is too tall, take 5px and 8px out as shown on the image;

image

@rafaellehmkuhl
Copy link
Member Author

Still reviewing the code, but for now, you can adjust some interface details:

  • Drag icon should be on the top-left corner, 8px from top, 8px from left edge. Not aligned the dialog title, otherwise it seems to be connected to the title, not to the window itself; (you could use negative margins here: e.g.: -mt-[5px])
  • The dialog title should be centered;
  • Dialog actions should all be in white text. Some dimmed white could be applied.
  • The footer is too tall, take 5px and 8px out as shown on the image;

Nice catches, thanks!

@ArturoManzoli
Copy link
Contributor

Some suggestions that could be implemented on this first version:

  • Add a hotkey to apply the changes (intuitively I was pressing ctrl+s to save and render like in VSCode 👀). Suggestion is ctrl+enter that is standard to form sending.
  • Swap the second frame (css) with the third (JS script) so it will be in the same order VueJS use on their files.

Some suggestions to be implemented in further versions of the DIY widget:

  • Expansible frames, so the user will have more space to the one he is working on at the moment, such as the JS script frame;
  • Question mark icon on the top-right that has some quick reference, both to the monaco-editor and to the dynamics of data sharing through data lake variables.

Comment on lines +19 to +21
<div ref="htmlEditorContainer" class="editor-container" />
<div ref="cssEditorContainer" class="editor-container" />
<div ref="jsEditorContainer" class="editor-container" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could switch the two last to match Vue pattern:

<div ref="htmlEditorContainer" class="editor-container" />
<div ref="jsEditorContainer" class="editor-container" />
<div ref="cssEditorContainer" class="editor-container" />

Comment on lines +142 to +148
const handleDialogOpen = async (): Promise<void> => {
await initEditor()
}

const handleDialogClose = async (): Promise<void> => {
finishEditor()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not wrong, but would be nice to have standardized function names such as: 'handleCloseDialog' and 'handleOpenDialog'

Copy link
Contributor

@ArturoManzoli ArturoManzoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, it works well. Just need to adjust some small interface stuff mentioned above.
Also would be nice to have a small guide on how to work with the data lake variables.

finishEditor()
}

const applyChanges = (): void => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned on the functionality review, a ctrl+enter shortcut for this apply function would be very handy.

@ES-Alexander ES-Alexander added the docs-needed Change needs to be documented label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-needed Change needs to be documented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants