Skip to content

Commit

Permalink
Added the Actions Icons on Cluster Detail Page (Azure#3051)
Browse files Browse the repository at this point in the history
* Added the Actions Icons on Cluster Detail Page

* Added Action Icon Button on Cluster Detail Page

* Added Action Icon Button on Cluster Detail Page
  • Loading branch information
rhamitarora authored and SrinivasAtmakuri committed Sep 18, 2023
1 parent d127db0 commit 3314060
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 109 deletions.
6 changes: 3 additions & 3 deletions pkg/portal/assets/v2/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"files": {
"main.js": "/static/js/main.f27c737c.js",
"main.js": "/static/js/main.f1999c11.js",
"index.html": "/index.html",
"main.f27c737c.js.map": "/static/js/main.f27c737c.js.map"
"main.f1999c11.js.map": "/static/js/main.f1999c11.js.map"
},
"entrypoints": [
"static/js/main.f27c737c.js"
"static/js/main.f1999c11.js"
]
}
2 changes: 1 addition & 1 deletion pkg/portal/assets/v2/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>ARO Portal</title><script defer="defer" src="/static/js/main.f27c737c.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>ARO Portal</title><script defer="defer" src="/static/js/main.f1999c11.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
3 changes: 3 additions & 0 deletions pkg/portal/assets/v2/build/static/js/main.f1999c11.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/portal/assets/v2/build/static/js/main.f1999c11.js.map

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions pkg/portal/assets/v2/build/static/js/main.f27c737c.js

This file was deleted.

1 change: 0 additions & 1 deletion pkg/portal/assets/v2/build/static/js/main.f27c737c.js.map

This file was deleted.

5 changes: 3 additions & 2 deletions portal/v2/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ registerIcons({
version="1.1"
xmlns="http://www.w3.org/2000/svg"
width="22"
height="22"
height="16"
style={{ overflow: "visible" }}>
<g id="svgg" transform="translate(0.000000,18.000000) scale(0.05000000,-0.05000000)">
<path
Expand Down Expand Up @@ -331,6 +331,7 @@ function App(props: { params: any }) {
<Stack.Item grow>
<ClusterDetailPanel
csrfToken={csrfRef}
sshBox={sshRef}
loaded={fetching}
currentCluster={currentCluster}
onClose={_onCloseDetailPanel}
Expand All @@ -343,4 +344,4 @@ function App(props: { params: any }) {
)
}

export default App
export default App
12 changes: 8 additions & 4 deletions portal/v2/src/ClusterDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { AxiosResponse } from "axios"
import { fetchClusterInfo } from "./Request"
import { ICluster, headerStyles } from "./App"
import { Nav, INavLink, INavStyles } from "@fluentui/react/lib/Nav"
import { ToolIcons } from "./ToolIcons"
import { ClusterDetailComponent, MemoisedClusterDetailListComponent } from "./ClusterDetailList"
import React from "react"

Expand Down Expand Up @@ -79,6 +80,7 @@ const errorBarStyles: Partial<IMessageBarStyles> = { root: { marginBottom: 15 }
export function ClusterDetailPanel(props: {
csrfToken: MutableRefObject<string>
currentCluster: ICluster | null
sshBox: any
onClose: any
loaded: string
}) {
Expand Down Expand Up @@ -183,7 +185,8 @@ export function ClusterDetailPanel(props: {

const _dismissPanel = () => {
dismissPanel()
props.onClose() // useEffect?
props.sshBox.current.hidePopup()
props.onClose()
setData([])
setFetching("")
setDataLoaded(false)
Expand Down Expand Up @@ -261,7 +264,7 @@ export function ClusterDetailPanel(props: {
},
})
}

const onRenderHeader = (): ReactElement => {
return (
<>
Expand All @@ -280,7 +283,8 @@ export function ClusterDetailPanel(props: {
</Stack.Item>
<Stack.Item>
<div className={headerStyles.titleText}>{props.currentCluster?.name}</div>
<div className={headerStyles.subtitleText}>Cluster</div>
<div className={headerStyles.subtitleText}>Cluster</div>
<ToolIcons resourceId={props.currentCluster? props.currentCluster?.resourceId:""} version={Number(props.currentCluster?.version) !== undefined ? Number(props.currentCluster?.version) : 0} csrfToken={props.csrfToken} sshBox={props.sshBox}/>
</Stack.Item>
</Stack>
</>
Expand Down Expand Up @@ -321,4 +325,4 @@ export function ClusterDetailPanel(props: {
</Stack>
</Panel>
)
}
}
62 changes: 6 additions & 56 deletions portal/v2/src/ClusterList.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import React, { useState, useEffect, useRef, MutableRefObject, Component } from "react"
import {
Stack,
IconButton,
Stack,
MessageBarType,
MessageBar,
CommandBar,
ICommandBarItemProps,
Separator,
Text,
IMessageBarStyles,
mergeStyleSets,
TooltipHost,
mergeStyleSets,
TextField,
Link,
Layer,
Expand All @@ -27,7 +25,7 @@ import {
} from "@fluentui/react/lib/DetailsList"
import { useBoolean } from "@fluentui/react-hooks"
import { fetchClusters } from "./Request"
import { KubeconfigButton } from "./Kubeconfig"
import { ToolIcons } from "./ToolIcons"
import { AxiosResponse } from "axios"
import { ICluster, headerStyles } from "./App"

Expand Down Expand Up @@ -287,45 +285,8 @@ class ClusterListComponent extends Component<ClusterListComponentProps, ICluster
data: "string",
isPadded: true,
onRender: (item: ICluster) => (
<Stack horizontal verticalAlign="center" className={classNames.iconContainer}>
<TooltipHost content={`Copy Resource ID`}>
<IconButton
iconProps={{ iconName: "Copy" }}
aria-label="Copy Resource ID"
onClick={() => this._onCopyResourceID(item)}
/>
</TooltipHost>
<TooltipHost content={`Prometheus`}>
<IconButton
iconProps={{ iconName: "BIDashboard" }}
aria-label="Prometheus"
href={
item.resourceId + (+item.version >= 4.11 ? `/prometheus` : `/prometheus/graph`)
}
/>
</TooltipHost>
<TooltipHost content={`SSH`}>
<IconButton
iconProps={{ iconName: "CommandPrompt" }}
aria-label="SSH"
onClick={() => this._onSSHClick(item)}
/>
</TooltipHost>
<KubeconfigButton resourceId={item.resourceId} csrfToken={props.csrfToken} />
{/* <TooltipHost content={`Geneva`}>
<IconButton
iconProps={{iconName: "Health"}}
aria-label="Geneva"
href={item.resourceId + `/geneva`}
/>
</TooltipHost>
<TooltipHost content={`Feature Flags`}>
<IconButton
iconProps={{iconName: "IconSetsFlag"}}
aria-label="featureFlags"
href={item.resourceId + `/feature-flags`}
/>
</TooltipHost> */}
<Stack horizontal verticalAlign="center" className={classNames.iconContainer}>
<ToolIcons resourceId={item.resourceId} csrfToken={props.csrfToken} version={Number(item.version)} sshBox={props.sshModalRef}/>
</Stack>
),
},
Expand Down Expand Up @@ -380,17 +341,6 @@ class ClusterListComponent extends Component<ClusterListComponentProps, ICluster
})
}

private _onSSHClick(item: any): void {
const modal = this._sshModal
if (modal && modal.current) {
modal.current.LoadSSH(item.resourceId)
}
}

private _onCopyResourceID(item: any): void {
navigator.clipboard.writeText(item.resourceId)
}

private _onClusterInfoLinkClick(item: ICluster): void {
this.props.setCurrentCluster(item)
}
Expand Down Expand Up @@ -523,4 +473,4 @@ export function ClusterList(props: {
/>
</Stack>
)
}
}
80 changes: 45 additions & 35 deletions portal/v2/src/SSHModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useId, useBoolean } from "@fluentui/react-hooks"
import {
Modal,
Popup,
Layer,
getTheme,
mergeStyleSets,
FontWeights,
Expand Down Expand Up @@ -38,10 +39,15 @@ type SSHModalProps = {

const theme = getTheme()
const contentStyles = mergeStyleSets({
container: {
display: "flex",
flexFlow: "column nowrap",
alignItems: "stretch",
root: {
background: 'white',
left: '50%',
maxWidth: '500px',
position: 'absolute',
top: '50%',
transform: 'translate(-50%, -50%)',
border: '1px solid #CCC',
boxShadow: 'rgba(0, 0, 0, 0.22) 0px 25.6px 57.6px 0px, rgba(0, 0, 0, 0.18) 0px 4.8px 14.4px 0px',
},
header: [
{
Expand All @@ -67,6 +73,7 @@ const contentStyles = mergeStyleSets({
},
})


const iconButtonStyles = {
root: {
color: theme.palette.neutralPrimary,
Expand All @@ -83,8 +90,7 @@ const sshDocs: string =
"https://msazure.visualstudio.com/AzureRedHatOpenShift/_wiki/wikis/ARO.wiki/136823/ARO-SRE-portal?anchor=ssh-(elevated)"

export const SSHModal = forwardRef<any, SSHModalProps>(({ csrfToken }, ref) => {
const [isModalOpen, { setTrue: showModal, setFalse: hideModal }] = useBoolean(false)

const [isPopupVisible, { setTrue: showPopup, setFalse: hidePopup }] = useBoolean(false);
const titleId = useId("title")
const [update, { setTrue: requestSSH, setFalse: sshRequested }] = useBoolean(false)
const [resourceID, setResourceID] = useState("")
Expand All @@ -98,9 +104,9 @@ export const SSHModal = forwardRef<any, SSHModalProps>(({ csrfToken }, ref) => {
setUnrequestable()
setData(null)
setError(null)
showModal()
showPopup()
setResourceID(item)
},
},hidePopup
}))

useEffect(() => {
Expand Down Expand Up @@ -207,33 +213,37 @@ export const SSHModal = forwardRef<any, SSHModalProps>(({ csrfToken }, ref) => {

return (
<div>
<Modal
titleAriaId={titleId}
isOpen={isModalOpen}
onDismiss={hideModal}
isModeless={true}
containerClassName={contentStyles.container}>
<div className={contentStyles.header} id="sshModal">
<span id={titleId}>SSH Access</span>
<IconButton
styles={iconButtonStyles}
iconProps={cancelIcon}
ariaLabel="Close popup modal"
onClick={hideModal}
/>
</div>

<div className={contentStyles.body}>
<p>
Before requesting SSH access, please ensure you have read the{" "}
<a href={sshDocs}>SSH docs</a>.
</p>
{error && errorBar()}
{data ? dataResult() : selectionField()}
</div>
</Modal>
{isPopupVisible && (
<Layer>
<Popup
className={contentStyles.root}
role="dialog"
aria-modal="true"
onDismiss={hidePopup}
enableAriaHiddenSiblings={true}
>
<div className={contentStyles.header} id="sshModal">
<span id={titleId}>SSH Access</span>
<IconButton
styles={iconButtonStyles}
iconProps={cancelIcon}
ariaLabel="Close popup modal"
onClick={hidePopup}
/>
</div>
<div className={contentStyles.body}>
<p>
Before requesting SSH access, please ensure you have read the{" "}
<a href={sshDocs}>SSH docs</a>.
</p>
{error && errorBar()}
{data ? dataResult() : selectionField()}
</div>
</Popup>
</Layer>
)}
</div>
)
})

SSHModal.displayName = "sshmodal"
SSHModal.displayName = "sshmodal"
44 changes: 40 additions & 4 deletions portal/v2/src/Kubeconfig.tsx → portal/v2/src/ToolIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ import { useRef } from "react"
import { forwardRef } from "react"
import { parse as parseContentDisposition } from "content-disposition"

type KubeconfigButtonProps = {
type ToolIconsProps = {
csrfToken: MutableRefObject<string>
resourceId: string
version: number
sshBox: any
}

type FileDownload = {
name: string
content: string
}

export const KubeconfigButton = forwardRef<any, KubeconfigButtonProps>(
({ csrfToken, resourceId }) => {
export const ToolIcons = forwardRef<any, ToolIconsProps>(
({ csrfToken, resourceId, version, sshBox }) => {
const [data, setData] = useState<FileDownload>({ name: "", content: "" })
const [error, setError] = useState<AxiosResponse | null>(null)
const [fetching, setFetching] = useState("DONE")
Expand All @@ -44,6 +46,17 @@ export const KubeconfigButton = forwardRef<any, KubeconfigButtonProps>(
}
}, [fetching, error, data, resourceId, csrfToken])

const _onCopyResourceID = (resourceId: any) => {
navigator.clipboard.writeText(resourceId)
}

const _onSSHClick = (resourceId: any) => {
const modal = sshBox
if (modal && modal.current) {
modal.current.LoadSSH(resourceId)
}
}

useLayoutEffect(() => {
if (data.content && buttonRef && buttonRef.current) {
buttonRef.current.href = data.content
Expand All @@ -56,6 +69,29 @@ export const KubeconfigButton = forwardRef<any, KubeconfigButtonProps>(

return (
<>
<TooltipHost content={`Copy Resource ID`}>
<IconButton
iconProps={{ iconName: "Copy" }}
aria-label="Copy Resource ID"
onClick={_onCopyResourceID.bind({},resourceId)}
/>
</TooltipHost>
<TooltipHost content={`Prometheus`}>
<IconButton
iconProps={{ iconName: "BIDashboard" }}
aria-label="Prometheus"
href={
resourceId + (+(version) >= 4.11 ? `/prometheus` : `/prometheus/graph`)
}
/>
</TooltipHost>
<TooltipHost content={`SSH`}>
<IconButton
iconProps={{ iconName: "CommandPrompt" }}
aria-label="SSH"
onClick={() => _onSSHClick(resourceId)}
/>
</TooltipHost>
<TooltipHost content={`Download Kubeconfig`}>
<IconButton
iconProps={{ iconName: "kubernetes-svg" }}
Expand All @@ -72,4 +108,4 @@ export const KubeconfigButton = forwardRef<any, KubeconfigButtonProps>(
}
)

KubeconfigButton.displayName = "kubeconfigbutton"
ToolIcons.displayName = "toolicons"
Loading

0 comments on commit 3314060

Please sign in to comment.