-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli-terminal): Create cli-terminal
- Loading branch information
1 parent
a5bc8fc
commit 5e91d37
Showing
16 changed files
with
274 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
frontend/packages/console-app/src/components/terminal/CloudshellResource.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as React from 'react'; | ||
import * as _ from 'lodash'; | ||
import { LoadingBox } from '@console/internal/components/utils'; | ||
|
||
const CloudshellResource: React.FC = (props) => { | ||
const cloudShell = _.get(props, ['resources', 'cloudShell', 'data']); | ||
const phase = _.get(cloudShell, ['status', 'phase']); | ||
const ideUrl = _.get(cloudShell, ['status', 'ideUrl']); | ||
if (phase === 'Running' && ideUrl) | ||
return <iframe title="cloudshell" style={{ width: '100%', height: '100%' }} src={ideUrl} />; | ||
return <LoadingBox />; | ||
}; | ||
|
||
export default CloudshellResource; |
63 changes: 63 additions & 0 deletions
63
frontend/packages/console-app/src/components/terminal/CloudshellTerminal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as React from 'react'; | ||
import { referenceForModel, k8sCreate, k8sList } from '@console/internal/module/k8s'; | ||
import { LoadingBox, Firehose, FirehoseResource } from '@console/internal/components/utils'; | ||
|
||
import { WorkspaceModel } from '../../models'; | ||
import CloudshellResource from './CloudshellResource'; | ||
import { newCloudShellWorkSpace } from '../../utils/cloudshell-resource'; | ||
|
||
type CloudShellTerminalProps = {}; | ||
|
||
const CloudShellTerminal: React.FC<CloudShellTerminalProps> = () => { | ||
/* Change dedicated name and namespace as per update */ | ||
const namespace = 'che-workspace-controller'; | ||
const name = 'cloudshell-userID'; | ||
const [cloudShell, setCloudShell] = React.useState(null); | ||
|
||
const createCloudShell = () => { | ||
k8sCreate(WorkspaceModel, newCloudShellWorkSpace(name, namespace)) | ||
.then((newShell) => { | ||
setCloudShell(newShell); | ||
}) | ||
.catch((error) => { | ||
// eslint-disable-next-line no-console | ||
console.warn('Cloudshell creation Error', error); | ||
}); | ||
}; | ||
|
||
React.useEffect(() => { | ||
k8sList(WorkspaceModel, { ns: namespace }) | ||
.then((existingShells) => { | ||
if (!existingShells || existingShells.length === 0) { | ||
createCloudShell(); | ||
} else { | ||
setCloudShell(existingShells[0]); | ||
} | ||
}) | ||
.catch((error) => { | ||
// eslint-disable-next-line no-console | ||
console.warn('Cloud Shell resuming error', error); | ||
}); | ||
}, []); | ||
|
||
if (cloudShell && cloudShell.metadata) { | ||
const resources: FirehoseResource[] = [ | ||
{ | ||
kind: referenceForModel(WorkspaceModel), | ||
name: cloudShell.metadata.name, | ||
namespace, | ||
prop: `cloudShell`, | ||
isList: false, | ||
}, | ||
]; | ||
|
||
return ( | ||
<Firehose resources={resources}> | ||
<CloudshellResource /> | ||
</Firehose> | ||
); | ||
} | ||
return <LoadingBox />; | ||
}; | ||
|
||
export default CloudShellTerminal; |
31 changes: 31 additions & 0 deletions
31
frontend/packages/console-app/src/components/terminal/Terminal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { RootState } from '@console/internal/redux'; | ||
import * as UIActions from '@console/internal/actions/ui'; | ||
import CloudShellDrawer from '../cloud-shell/CloudShellDrawer'; | ||
import CloudShellBody from '../cloud-shell/CloudShellBody'; | ||
|
||
type TerminalContentProps = { | ||
isTerminalExpanded: boolean; | ||
toggleTerminal: any; | ||
}; | ||
|
||
const TerminalContent: React.FC<TerminalContentProps> = ({ | ||
isTerminalExpanded, | ||
toggleTerminal, | ||
}) => ( | ||
<CloudShellDrawer open={isTerminalExpanded} onClose={() => toggleTerminal()}> | ||
<CloudShellBody /> | ||
</CloudShellDrawer> | ||
); | ||
|
||
const terminalStateToProps = ({ UI }: RootState) => ({ | ||
isTerminalExpanded: !!UI.getIn(['terminal', 'isExpanded']), | ||
}); | ||
|
||
const connecttoTerminalIcon = connect((state: RootState) => terminalStateToProps(state), { | ||
toggleTerminal: UIActions.terminalDrawerToggleExpanded, | ||
}); | ||
const ConnectedTerminal = connecttoTerminalIcon(TerminalContent); | ||
|
||
export default ConnectedTerminal; |
24 changes: 24 additions & 0 deletions
24
frontend/packages/console-app/src/components/terminal/TerminalToolicon.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as React from 'react'; | ||
import { TerminalIcon } from '@patternfly/react-icons'; | ||
import { Button, ToolbarItem } from '@patternfly/react-core'; | ||
import { connectToFlags } from '@console/internal/reducers/features'; | ||
import { FLAG_DEVWORKSPACE } from '../../consts'; | ||
|
||
type TerminalTooliconProps = { | ||
flags: Record<string, any>; | ||
terminalToggle: any; | ||
}; | ||
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 ConnectedTerminalToolicon = connectToFlags(FLAG_DEVWORKSPACE)(TerminalToolicon); | ||
|
||
export default ConnectedTerminalToolicon; |
13 changes: 13 additions & 0 deletions
13
frontend/packages/console-app/src/components/terminal/redux/action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { action, ActionType } from 'typesafe-actions'; | ||
|
||
export enum Actions { | ||
TerminalDrawerToggleExpanded = 'terminalDrawerExpanded', | ||
} | ||
|
||
export const terminalDrawerToggleExpanded = () => action(Actions.TerminalDrawerToggleExpanded); | ||
|
||
const actions = { | ||
terminalDrawerToggleExpanded, | ||
}; | ||
|
||
export type TerminalAction = ActionType<typeof actions>; |
16 changes: 16 additions & 0 deletions
16
frontend/packages/console-app/src/components/terminal/redux/reducer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Map } from 'immutable'; | ||
import { TerminalAction, Actions } from './action'; | ||
|
||
export type State = Map<string, any>; | ||
|
||
export default (state: State, action: TerminalAction) => { | ||
if (!state) { | ||
return Map({ | ||
terminal: () => {}, | ||
}); | ||
} | ||
if (action.type === Actions.TerminalDrawerToggleExpanded) | ||
return state.setIn(['terminal', 'isExpanded'], !state.getIn(['terminal', 'isExpanded'])); | ||
|
||
return state; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const FLAG_DEVWORKSPACE = 'DEVWORKSPACE'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { K8sKind } from '@console/internal/module/k8s'; | ||
|
||
export const WorkspaceModel: K8sKind = { | ||
kind: 'Workspace', | ||
label: 'Workspace', | ||
labelPlural: 'workspaces', | ||
apiGroup: 'workspace.che.eclipse.org', | ||
apiVersion: 'v1alpha1', | ||
abbr: 'WS', | ||
namespaced: true, | ||
crd: true, | ||
plural: 'workspaces', | ||
propagationPolicy: 'Foreground', | ||
}; | ||
|
||
export const DevWorkspaceModel: K8sKind = { | ||
kind: 'DevWorkspace', | ||
label: 'Devworkspace', | ||
labelPlural: 'workspaces', | ||
apiGroup: 'apiextensions.k8s.io', | ||
apiVersion: 'v1alpha1', | ||
abbr: 'DW', | ||
namespaced: true, | ||
crd: true, | ||
plural: 'devworkspaces', | ||
propagationPolicy: 'Foreground', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
frontend/packages/console-app/src/utils/cloudshell-resource.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export const newCloudShellWorkSpace = (name: string, namespace: string) => ({ | ||
apiVersion: 'workspace.che.eclipse.org/v1alpha1', | ||
kind: 'Workspace', | ||
metadata: { | ||
name, | ||
namespace, | ||
}, | ||
spec: { | ||
started: true, | ||
devfile: { | ||
apiVersion: '0.0.1', | ||
metadata: { | ||
name: 'cloud-shell', | ||
}, | ||
components: [ | ||
{ | ||
alias: 'cloud-shell', | ||
type: 'cheEditor', | ||
id: 'eclipse/cloud-shell/nightly', | ||
}, | ||
{ | ||
type: 'dockerimage', | ||
memoryLimit: '256Mi', | ||
alias: 'dev', | ||
image: 'quay.io/eclipse/che-sidecar-openshift-connector:0.1.2-2601509', | ||
args: ['tail', '-f', '/dev/null'], | ||
env: [ | ||
{ | ||
value: '\\[\\e[34m\\]>\\[\\e[m\\]\\[\\e[33m\\]>\\[\\e[m\\]', | ||
name: 'PS1', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { combineReducers } from 'redux'; | ||
import terminalReducer from '../components/terminal/redux/reducer'; | ||
|
||
export default combineReducers({ | ||
terminal: terminalReducer, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters