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

feat(SerialConsole): Introduce SerialConsole component #160

Merged
merged 2 commits into from
May 2, 2018

Conversation

mareklibra
Copy link
Contributor

@mareklibra mareklibra commented Jan 11, 2018

What: Provide reusable component to access serial console of a server/virtual machine

Link to Storybook: https://mareklibra.github.io/patternfly-react/

Additional issues:

Description:
The SerialConsole component wraps access to the Terminal component [1].

The component can be used to access serial console (PTY) of a server
or a virtual machine.

[1] https://github.com/xtermjs/xterm.js

@mareklibra
Copy link
Contributor Author

Storybook and test will be written, so far looking for early comments.

Reuse within Cockpit works fine.
I will try in another project.

color: #f0f0f0;
background: #000;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This should be done in less and sass and added to the appropriate directories (we will need to add the converter to this repo soon).
Colors should be from the patternfly palette.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, css removed.

package.json Outdated
"build:scripts": "babel src --out-dir dist/js --ignore test*.js,__mocks__",
"build:less": "mkdir -p dist/less && cp -r less/* dist/less",
"build:sass": "mkdir -p dist/sass && cp -r sass/patternfly-react/* dist/sass && node-sass --output-style compressed --include-path sass $npm_package_sassIncludes_patternfly $npm_package_sassIncludes_bootstrap $npm_package_sassIncludes_fontAwesome -o dist/css sass/patternfly-react.scss",
"build:css": "mkdir -p dist/css && find ./src -name \\*.css -exec cp {} dist/css/ \\;",
Copy link
Member

Choose a reason for hiding this comment

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

we shouldn't have css in the components directories. We've standardized on both less and sass so that we can use variables which can then be overridden.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, done

componentWillMount() {
const term = new Terminal({
cols: this.props.cols || 80,
rows: this.props.rows || 25,
Copy link
Member

Choose a reason for hiding this comment

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

This could be done using defaultProps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

textDisconnect = 'Disconnect',
textDisconnected = 'Disconnected from serial console. Click the Reconnect button.',
textLoading = 'Loading ...',
textReconnect = 'Reconnect',
Copy link
Member

Choose a reason for hiding this comment

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

These need to be override-able by applications using I18N. See https://github.com/patternfly/patternfly-react/pull/162/files#diff-9694875e1ead42ed0c55964e603992b1R6 as an example on how to do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was the point here as well. Anyway, wrapped into the messages prop to be consistent.

@@ -1,3 +1,62 @@
/**
Patternfly React Specific Extensions
*/
@import '~patternfly/dist/less/variables';

/** Following is used by SerialConsole */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about introducing .less files local to the component? Means like src/SerialConsole/styles.less .
They would be listed in less/patternfly-react.less for import.

Copy link
Member

Choose a reason for hiding this comment

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

I'd be ok with that if that's what we all agree on. Still need the sass version too though.

Copy link
Member

Choose a reason for hiding this comment

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

Could you use a separate file here as well? Add this to serialConsole.less and import the file here.

@mareklibra mareklibra force-pushed the serialConsole branch 2 times, most recently from b62feef to 4f28d65 Compare January 17, 2018 08:10
@mareklibra
Copy link
Contributor Author

Sass added

@@ -21,3 +21,61 @@ $icon-font-path: '~patternfly/dist/fonts/';
*/

@import 'patternfly-react/patternfly-react';

/** Following is used by SerialConsole */
Copy link
Member

Choose a reason for hiding this comment

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

This should go in sass/patternfly-react/_serialConsole.sass and then add @import 'serialConsole' to sass/patternfly-react/_patternfly-react.scss

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@mareklibra mareklibra force-pushed the serialConsole branch 2 times, most recently from 06a80f6 to f8177b7 Compare January 17, 2018 14:34
@mareklibra
Copy link
Contributor Author

less/serialConsole.less added

@mareklibra mareklibra force-pushed the serialConsole branch 3 times, most recently from 61e1b17 to 46c7821 Compare January 18, 2018 12:44
@jeff-phillips-18
Copy link
Member

Looking at this more closely, I'm not really sure it fits in this repository. There is no Patternfly pattern for this and no existing Patternfly styling for this.

Might this be better as its own standalone component? react-serial-console for instance?

@ohadlevy
Copy link
Member

@jeff-phillips-18 - we have discussed that components that are common to many patternfly users - we would like to keep under the patternfly organization, since this is the first one, we also agreed that initially we would keep it in this repo, and over time, extract to separate npm packages, so that users can upgrade as needed. /cc @serenamarie125

constructor(props) {
super(props);

this.focusTerminal = this.focusTerminal.bind(this);
Copy link
Member

Choose a reason for hiding this comment

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

can we use:
import { bindMethods } from '../../common/helpers';

instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, nice helper function :-)

this.props.onDisconnect();
}

msg(key) {
Copy link
Member

@priley86 priley86 Jan 19, 2018

Choose a reason for hiding this comment

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

I don't really get it... why not just use defaultProps and specify the value? Maybe someone can explain this...

Copy link
Contributor Author

@mareklibra mareklibra Jan 20, 2018

Choose a reason for hiding this comment

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

Based on a previous review comment, I expect this is a pattern in this project. If not, the former direct use of props seems to me more straightforward.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, defaultProps used instead

let terminal;
let disconnectDisabled = 'disabled'; // CSS class name
switch (status) {
case 'connected':
Copy link
Member

@priley86 priley86 Jan 19, 2018

Choose a reason for hiding this comment

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

maybe break out the statuses into a constants.js or SerialConsoleConstants.js?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

SerialConsole styles
*/

.console-ct > .terminal {
Copy link
Member

Choose a reason for hiding this comment

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

What is the -ct? It should likely be -pf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a leftover from original code. The .console-ct is used for the top-most div of the component, like a container.
The console-pf in this case sounds good to me as well.

line-height: normal;
}

@media (min-width: 568px) {
Copy link
Member

Choose a reason for hiding this comment

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

Would it still work if we used one of the bootstrap variables @screen-sm or @screen-xs or is there a reason for using 568?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@screen-tablet used instead due to deprecation of the others. Just verified, still works well.


@media (min-width: 568px) {
.console-ct {
font-size: 12px;
Copy link
Member

Choose a reason for hiding this comment

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

@font-size-small

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@serenamarie125
Copy link
Member

@mareklibra from a design pattern perspective, what does this feature consist of ? Are the Disconnect/Reconnect buttons a part of the pattern? Since we don't have an existing PatternFly design, I'd like to make sure that I understand the use case and design of the pattern itself. Thanks!

@mareklibra
Copy link
Contributor Author

@serenamarie125 , the component is planed to be part of a higher level one - serving all consoles. For better understanding, please have a look at screenshots in later comments of cockpit-project/cockpit#8234 .

Regarding the Serial Console, it consists of

  • terminal (receiving input from keyboard and rendering output produced by server's serial console)
  • control buttons Disconnect, Reconnect

I would keep the control buttons in the pattern, they server common use cases:

  • disconnect from the console to free it for anyone else
  • reconnect to either take it back or re-establish the connection

@sharvit
Copy link
Contributor

sharvit commented Jan 28, 2018

Thanks @mareklibra Looks good!

Wondering...

  • shouldn't the css part of it need to live under patternfly core?
  • should it live in a separate npm package (under patternfly namespace) since most of patternfly-react consumers are not going to use it? (It adds another dependency)

@martinpitt
Copy link

I just want to reiterate that the cockpit fork of term.js is not meant to be proliferated like that. As soon as xterm.js becomes suitable for Cockpit, we are going to move to that. So putting it as-is into PatternFly seems a bit ambitious to me.

@mareklibra : For your purposes of sharing the component between software, wouldn't a new NPM project be more suitable?

@mareklibra
Copy link
Contributor Author

Rebased.
xterm version increased to 3.3.0.

@mareklibra
Copy link
Contributor Author

Since implementation of the "monorepo" will still take some time plus additional will be needed to settle-down, can this PR be unblocked on it?

The xterm dependency is peerDependency only.
Repeated rebasing can introduce dummy bugs and costs additional effort.
The functionality is blocked in related projects.

@mareklibra
Copy link
Contributor Author

Approvals are received prior a couple of last rebases.

@serenamarie125
Copy link
Member

@jgiardino this still has the cssreview tag on it. Can you take a look please?

@jeff-phillips-18
Copy link
Member

@mareklibra with the merge of #311, we've updated where the consoles code should live. Can you please update your code to be under https://github.com/patternfly/patternfly-react/tree/master/packages/console ?

@mareklibra
Copy link
Contributor Author

mareklibra commented Apr 25, 2018

Rebased and basically verified in Cockpit.

Some of the original code was already copied from here to #311 .

@mareklibra mareklibra force-pushed the serialConsole branch 2 times, most recently from 2b975e1 to 4a08e43 Compare April 25, 2018 15:06
@@ -1,6 +1,9 @@
/**
Patternfly React Specific Extensions
*/
@import "~bootstrap/less/variables";
@import "~patternfly/dist/less/variables";

Copy link
Member

Choose a reason for hiding this comment

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

We don't want to do this here. Patternfly is a dependency and we assume that these are already included if the project is building with the less files. If we do this here, it will overwrite any variables the application might have already overridden (which would likely be the reason to include the less files rather than the CSS).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -1,6 +1,9 @@
/**
+ Styling shared by both VncConsole and SerialConsole.
+*/
@import "~bootstrap/less/variables";
@import "~patternfly/dist/less/variables";
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@jeff-phillips-18
Copy link
Member

Please add the sass counterpart to the less styling.

@mareklibra
Copy link
Contributor Author

mareklibra commented Apr 26, 2018

@jeff-phillips-18 , sass was one of the parts which was copied from this PR to #311 and committed there, track seems to be lost by this step. But should be up-to-date. Please correct me.

Or do you suggest to extend the packages/console/README.md ? I can extend it, but the way sass is handled here seems to be self-enclosing to me - dependencies (like variables from bootstrap or patternfly) are imported by patternfly-react's .scss. So this looks like consistent across whole patternfly-react.

@jeff-phillips-18
Copy link
Member

Ok, sorry @mareklibra , I didn't realize it was included with content in #311

constructor(props) {
super(props);

bindMethods(this, ['focusTerminal', 'onResetClick', 'onDisconnectClick']);
Copy link
Member

Choose a reason for hiding this comment

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

We have deprecated bindMethods in favor of class properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

The SerialConsole component wraps the Terminal component [1]
to access serial console (PTY) of a server
or a virtual machine.

Part of the code (like styling) was already committed within #4a69ebd806.

[1] https://github.com/xtermjs/xterm.js
Copy link
Member

@jeff-phillips-18 jeff-phillips-18 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @mareklibra !

@mareklibra
Copy link
Contributor Author

Thanks.
Is there anything missing to have this merged, please?

Copy link
Member

@serenamarie125 serenamarie125 left a comment

Choose a reason for hiding this comment

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

Thanks @mareklibra trying to get another maintainer to review today

@priley86
Copy link
Member

priley86 commented May 2, 2018

this looks great! thanks @mareklibra

can #288 be closed now? or are you planning to revisit Vnc console after?

@mareklibra
Copy link
Contributor Author

can #288 be closed now?

No, it's follow-up for this adding VncConsole component.
Once this is merged, I'll rebase there.

FYI., on top of the VncConsole PR, there will be others - for

  • external clients
  • switching among console types
  • console configuration
  • probably RDP
  • maybe SPICE

@jeff-phillips-18 jeff-phillips-18 merged commit 466a5d8 into patternfly:master May 2, 2018
@mareklibra
Copy link
Contributor Author

Nice to see this merged :-)
What is the process for publishing @patternfly-react/console, please?

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.