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(cli-terminal): Create cli-terminal #4762

Merged
merged 1 commit into from Apr 7, 2020

Conversation

abhinandan13jan
Copy link
Contributor

@abhinandan13jan abhinandan13jan commented Mar 18, 2020

Feature:

https://issues.redhat.com/browse/ODC-3055

Analysis / Root cause:

Create Cloudshell Terminal Component, Icon & Feature Flag it

Solution Description:

Creates a set of components in console/app to create and launch a Terminal component integrated to Workspace component to start a cloudshell session.
Also, feature flags the whole setup to the presence of DevWorkspace CRD

Current Namespace Setting
Currently implementation creates and reads Workspace resource from dedicated namespace che-controller-operator, which needs to be updated as per final discussion.

ScreenShots

( might take time to load )...
Cloudshell__modal

CloudShel__terminal

Unit tests:

  • packages/console-app/src/components/cloud-shell/tests/cloudshell-resource.spec.ts
  • packages/console-app/src/components/cloud-shell/tests/CloudShellTerminalFrame.spec.tsx

Browser conformance:

Chrome 73

How to Review:

After pulling the code changes to local follow instructions at

https://github.com/che-incubator/che-workspace-operator

**Step 2: Add Icon **
TerminalIcon is commented out in masthead-toolbar... Bring the icon in by removing the comments

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 18, 2020
@openshift-ci-robot openshift-ci-robot added the component/core Related to console core functionality label Mar 18, 2020
@andrewballantyne
Copy link
Contributor

/kind feature

@openshift-ci-robot openshift-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Mar 19, 2020
@abhinandan13jan abhinandan13jan changed the title WIP: feat(cli-terminal): Create cli-terminal Feat(cli-terminal): Create cli-terminal Mar 26, 2020
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 26, 2020
Copy link
Contributor

@sahil143 sahil143 left a comment

Choose a reason for hiding this comment

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

I know there is still some work left to be done, But few redux comments that need attention. Also Need proper typings.

toggleTerminal,
}) => (
<CloudShellDrawer open={isTerminalExpanded} onClose={() => toggleTerminal()}>
<CloudShellBody />
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this and use CloudShellTerminal here. This was just a dummy component

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

);

const terminalStateToProps = ({ UI }: RootState) => ({
isTerminalExpanded: !!UI.getIn(['terminal', 'isExpanded']),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why double !!? isExpanded should be a boolean value or have open, close state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Comment on lines 26 to 31
const connecttoTerminalIcon = connect((state: RootState) => terminalStateToProps(state), {
toggleTerminal: UIActions.terminalDrawerToggleExpanded,
});
const ConnectedTerminal = connecttoTerminalIcon(TerminalContent);

export default ConnectedTerminal;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const connecttoTerminalIcon = connect((state: RootState) => terminalStateToProps(state), {
toggleTerminal: UIActions.terminalDrawerToggleExpanded,
});
const ConnectedTerminal = connecttoTerminalIcon(TerminalContent);
export default ConnectedTerminal;
const terminalPropsToState = {
toggleTerminal: UIActions.terminalDrawerToggleExpanded,
};
export default connect(terminalStateToProps, terminalPropsToState)(TerminalContent);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

export default (state: State, action: TerminalAction) => {
if (!state) {
return Map({
terminal: () => {},
Copy link
Contributor

Choose a reason for hiding this comment

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

currently your state looks like this

temrinal: {
       terminal: () => {}
}

change

Suggested change
terminal: () => {},
isExpanded: false,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

});
}
if (action.type === Actions.TerminalDrawerToggleExpanded)
return state.setIn(['terminal', 'isExpanded'], !state.getIn(['terminal', 'isExpanded']));
Copy link
Contributor

Choose a reason for hiding this comment

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

change this according to the above state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

toggleTerminal: any;
};

const TerminalContent: React.FC<TerminalContentProps> = ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename this to CloudShell

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

flags: Record<string, any>;
terminalToggle: any;
};
const TerminalToolicon: React.FC<TerminalTooliconProps> = ({ flags, terminalToggle }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename CloudShellIcon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Comment on lines 22 to 24
const ConnectedTerminalToolicon = connectToFlags(FLAG_DEVWORKSPACE)(TerminalToolicon);

export default ConnectedTerminalToolicon;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const ConnectedTerminalToolicon = connectToFlags(FLAG_DEVWORKSPACE)(TerminalToolicon);
export default ConnectedTerminalToolicon;
export default connectToFlags(FLAG_DEVWORKSPACE)(TerminalToolicon);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Copy link
Contributor

@sahil143 sahil143 left a comment

Choose a reason for hiding this comment

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

@abhinandan13jan The background should be black even in the loading state and your loading state is different from the one in the UX designs.
Screenshot from 2020-03-28 01-02-27

);
type CloudshellContentProps = {
isTerminalExpanded: boolean;
toggleTerminal: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

remove any, type should be () => void

type terminalToggle = () => void;

type TerminalTooliconProps = {
flags: Record<string, any>;
Copy link
Contributor

Choose a reason for hiding this comment

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

add proper type in place of any


type TerminalTooliconProps = {
flags: Record<string, any>;
terminalToggle: terminalToggle;
Copy link
Contributor

Choose a reason for hiding this comment

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

terminalToggle is not reusable type so use directly () => void

Comment on lines 14 to 23
const TerminalToolicon: React.FC<TerminalTooliconProps> = ({ flags, terminalToggle }) => {
if (!flags[FLAG_DEVWORKSPACE]) return null;
return (
<ToolbarItem>
<Button variant="plain" aria-label="Terminal" onClick={terminalToggle}>
<TerminalIcon className="co-masthead-icon" />
</Button>
</ToolbarItem>
);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

can be simplified

Suggested change
const TerminalToolicon: React.FC<TerminalTooliconProps> = ({ flags, terminalToggle }) => {
if (!flags[FLAG_DEVWORKSPACE]) return null;
return (
<ToolbarItem>
<Button variant="plain" aria-label="Terminal" onClick={terminalToggle}>
<TerminalIcon className="co-masthead-icon" />
</Button>
</ToolbarItem>
);
};
const TerminalToolicon: React.FC<TerminalTooliconProps> = ({ flags, terminalToggle }) => ( flags[FLAG_DEVWORKSPACE] ? (
<ToolbarItem>
<Button variant="plain" aria-label="Terminal" onClick={terminalToggle}>
<TerminalIcon className="co-masthead-icon" />
</Button>
</ToolbarItem>
) : null );

if (!flags[FLAG_DEVWORKSPACE]) return null;
return (
<ToolbarItem>
<Button variant="plain" aria-label="Terminal" onClick={terminalToggle}>
Copy link
Contributor

Choose a reason for hiding this comment

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

aria-label should be Command Line Terminal and there should be tooltip for this button. Please, check the UX design doc for the content of tooltip.

export default (state: State, action: TerminalAction) => {
if (!state) {
return Map({
terminal: { isExpanded: false },
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be

Suggested change
terminal: { isExpanded: false },
isExpanded: false,

because you already have terminal property in the combineReducer.

});
}
if (action.type === Actions.TerminalDrawerToggleExpanded)
return state.setIn(['terminal', 'isExpanded'], !state.getIn(['terminal', 'isExpanded']));
Copy link
Contributor

Choose a reason for hiding this comment

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

we are using cloud-shell name everywhere. We should look to rename terminal to cloudShell here as well.

value: string;
name: string;
};
type Component = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Component is very generic name. It would be good idea to rename this to something else like DevFileComponents.

isTerminalExpanded,
toggleTerminal,
}) => (
<CloudShellDrawer open={isTerminalExpanded} onClose={() => toggleTerminal()}>
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be a confirmation modal before closing the cloud shell.
Screenshot from 2020-03-28 01-04-20

terminalToggle: terminalToggle;
};

const TerminalToolicon: React.FC<TerminalTooliconProps> = ({ flags, terminalToggle }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

rename this to CloudShellIcon


const dispatchToProps = (dispatch: Dispatch): DispatchProps => ({
onClose: () =>
confirmModal({
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be part of redux callbacks, create a sperate callback for modal something like this

const closeCloudShellConfirmationModal = (callback) => {confirmModal({    
      title: 'Close Terminal?',
      message: (
        <>
          This will close the terminal session. Content in the terminal will not be resolved in the
          next seesion.
        </>
      ),
      btnText: 'Yes',
      submitDanger: true,

      cancelText: 'No',
      executeFn: callback,
    })};

you can use the same in CloudShellMastheadButton as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated this

<CloudShellBody />
</CloudShellDrawer>
</>
<CloudShellDrawer open={open} onClose={onClose}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<CloudShellDrawer open={open} onClose={onClose}>
<CloudShellDrawer open={open} onClose={() => closeTerminalConfirmationModal(onClose)}>

export type CloudShellDrawerProps = {
open: boolean;
type CloudShellDrawerProps = {
open?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure, why this is optional. We don't provide a default value for open also if this is omitted from the props then we would have no way to render the drawer component.


const toggleTerminal = () => {
if (open) {
return confirmModal({
Copy link
Contributor

Choose a reason for hiding this comment

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

use a common utility for this, same as above closeCloudShellConfirmationModal

}

return (
<Tooltip content={open ? 'Close Terminal' : 'Open Terminal'}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Tooltip content Open command line terminal. Check design doc.
Also, the tooltip should be on the button instead of ToolbarItem.

@@ -2,10 +2,12 @@ import * as _ from 'lodash-es';
import * as React from 'react';
import { render } from 'react-dom';
import { Helmet } from 'react-helmet';

Copy link
Contributor

Choose a reason for hiding this comment

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

remove this extra line

@parvathyvr
Copy link

@abhinandan13jan From the GIF i see that the 'Close' modal message is not correct and there is a typo in the 2nd line for the word 'session'...Please refer the design doc for the proposed message in the modal-https://docs.google.com/document/d/1UsyTYm67FXtcprku6F3L0WD48FjwTlgpDnC5Dj9kUGg/edit?ts=5df25614#heading=h.yy8m94syjcx2

@abhinandan13jan
Copy link
Contributor Author

abhinandan13jan commented Mar 31, 2020

@parvathyvr I've updated the message to this

      <>
        This will close the terminal session. Content in the terminal will not be restored on
        next session.
      </>

Comment on lines 7 to 12
message: (
<>
This will close the terminal session. Content in the terminal will not be restored on next
session.
</>
),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
message: (
<>
This will close the terminal session. Content in the terminal will not be restored on next
session.
</>
),
message: 'This will close the terminal session. Content in the terminal will not be restored on next session.',

With this change, remove the React import and rename file to use .ts suffix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@@ -40,7 +40,7 @@ describe('CloudShellDrawerComponent', () => {
.find(Drawer)
.shallow()
.find(Button);
expect(buttons.at(1).props()['aria-label']).toEqual('Close Terminal');
expect(buttons.at(1).props()['aria-label']).toEqual('Close terminal');
Copy link
Contributor

Choose a reason for hiding this comment

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

This is where having a data-test-id would be beneficial.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

using data-test-id

@@ -572,6 +573,7 @@ class MastheadToolbarContents_ extends React.Component {
<PlusCircleIcon className="co-masthead-icon" />
</Button>
</ToolbarItem>
<CloudShellMastheadButton />
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's comment this out before merging because we need to fix the workspace namespace and resource name before it can be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

commented out

});
};

export default cloudshellConfirmationModal;
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename file to not be uppercase because this does not export a react component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed

@abhinandan13jan abhinandan13jan force-pushed the terminal branch 2 times, most recently from cb73eff to 4f6a624 Compare April 2, 2020 10:01
@abhinandan13jan
Copy link
Contributor Author

/test e2e-gcp-console

);
};

export default CloudShellTerminal;
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is incorrectly named CloudshellTerminal.tsx where it should be named CloudShellTerminal.tsx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed

@abhinandan13jan
Copy link
Contributor Author

/test e2e-gcp-console

Copy link
Contributor

@sahil143 sahil143 left a comment

Choose a reason for hiding this comment

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

@abhinandan13jan cloud shell is not minimizing properly
Screenshot from 2020-04-06 14-06-31

@abhinandan13jan
Copy link
Contributor Author

@abhinandan13jan cloud shell is not minimizing properly
Screenshot from 2020-04-06 14-06-31

I wasnt able to see them, when I last tested....Let's take these as bugs related to CSS... as we have lot of Pending work in the epic...
It is crucial to get this PR in as we have dependant stories waiting. @sahil143

@sahil143
Copy link
Contributor

sahil143 commented Apr 6, 2020

/lgtm

I wasnt able to see them, when I last tested....Let's take these as bugs related to CSS... as we have lot of Pending work in the epic...
It is crucial to get this PR in as we have dependant stories waiting. @sahil143

Please raise a Jira ticket for this

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 6, 2020
@abhinandan13jan
Copy link
Contributor Author

https://issues.redhat.com/browse/ODC-3495 Added this for CSS refinement

@christianvogt
Copy link
Contributor

/approve

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: abhinandan13jan, christianvogt, sahil143

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 6, 2020
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

2 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit 4bbaa7e into openshift:master Apr 7, 2020
@spadgett spadgett added this to the v4.5 milestone Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. component/core Related to console core functionality component/olm Related to OLM component/shared Related to console-shared kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants