Skip to content

Commit

Permalink
Merge pull request #54 from relferreira/dev
Browse files Browse the repository at this point in the history
New Shortcuts and improving arrows navigation
  • Loading branch information
relferreira committed Sep 25, 2020
2 parents 0e378a7 + 8f2f0fa commit 9ac6748
Show file tree
Hide file tree
Showing 27 changed files with 944 additions and 801 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,25 @@ kubectl apply -f deploy-in-cluster.yaml -n <NAMESPACE>

## Shortcuts

| Keys | Shortcut |
| --------------- | --------------- |
| cmd + k | Global Search |
| cmd + shift + k | Command Pallete |
| cmd + shift + y | Command History |
| cmd + shift + f | Table Search |
| Keys | Shortcut |
| --------------- | ------------------ |
| cmd + k | Global Search |
| cmd + shift + k | Command Pallete |
| cmd + shift + y | Command History |
| cmd + shift + f | Table Search |
| g + n | Namespace Selector |
| g + s | Go to services |
| g + d | Go to deployments |
| g + j | Go to jobs |
| g + c | Go to cronjobs |
| g + t | Go to statefulsets |
| g + h | Go to hpa |
| g + v | Go to pvc |
| g + p | Go to pods |
| g + i | Go to ingress |
| g + m | Go to configmaps |
| g + r | Go to secrets |
| g + f | Go to port-forward |

## Development

Expand Down
13 changes: 3 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,9 @@ func main() {
from := c.Param("from")
to := c.Param("to")

fullCommand := []string{}

fullCommand = append(fullCommand, "-n")
fullCommand = append(fullCommand, namespace)
fullCommand = append(fullCommand, "port-forward")
fullCommand = append(fullCommand, fmt.Sprintf("%s/%s", resourceType, name))
fullCommand = append(fullCommand, fmt.Sprintf("%s:%s", from, to))

fmt.Printf("%#v\n", fullCommand)
cmd := exec.Command("kubectl", fullCommand...)
command := fmt.Sprintf("while true; do kubectl -n %s port-forward %s/%s %s:%s; done", namespace, resourceType, name, from, to)
fmt.Printf("%s\n", command)
cmd := exec.Command("bash", "-c", command)
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}

if err := cmd.Start(); err != nil {
Expand Down
1 change: 1 addition & 0 deletions ui/components/DeleteButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Button from './Button';
const DialogButtons = styled.div`
display: flex;
justify-content: flex-end;
padding: 16px;
button {
margin-left: 16px;
Expand Down
73 changes: 53 additions & 20 deletions ui/components/Dialog.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import React from 'react';
import styled from '@emotion/styled';
import { Dialog, DialogOverlay, DialogContent } from '@reach/dialog';
import { useSpring, animated, useTransition } from 'react-spring';

const StyledDialog = styled(Dialog)`
const AnimatedDialogContent = animated(DialogContent);
const AnimatedDialogOverlay = animated(DialogOverlay);

const StyledDialog = styled(AnimatedDialogContent)`
width: ${props => props.width};
background: ${props => props.theme.background};
background: ${props => props.theme.header};
color: ${props => props.theme.containerFont};
border-radius: 5px;
padding: 0px;
overflow: hidden;
`;

const DialogHeader = styled.div`
display: flex;
align-items: center;
padding: 16px;
border-bottom: 1px solid ${props => props.theme.controllerBorder};
span {
flex: 1;
Expand All @@ -19,32 +29,55 @@ const DialogHeader = styled.div`
background: transparent;
border: none;
cursor: pointer;
font-size: 16px;
font-size: 20px;
color: ${props => props.theme.containerFont};
}
`;

const DialogContainer = styled.div`
display: flex;
flex-direction: column;
margin-top: 32px;
`;

const CustomDialog = ({ title, isOpen, onDismiss, children, width }) => (
<StyledDialog
isOpen={isOpen}
onDismiss={onDismiss}
width={width}
aria-label="Modal content"
>
<DialogHeader>
<span>{title}</span>
<button className="close-button" onClick={onDismiss} tabIndex="-1">
<span aria-hidden>×</span>
</button>
</DialogHeader>
<DialogContainer>{children}</DialogContainer>
</StyledDialog>
);
const CustomDialog = ({ title, isOpen, onDismiss, children, width }) => {
const transitions = useTransition(isOpen, null, {
from: { opacity: 0, y: 50 },
enter: {
opacity: 1,
y: 0,
boxShadow: '0px 10px 20px 0px rgba(0,0,0,0.4)'
},
leave: { opacity: 0, y: 50 },
config: { tension: 250 }
});
return transitions.map(
({ item, key, props: styles }) =>
item && (
<AnimatedDialogOverlay
key={key}
style={{ background: 'transparent', opacity: styles.opacity }}
onDismiss={onDismiss}
>
<StyledDialog
style={styles}
width={width}
aria-label="Dialog content"
>
<DialogHeader>
<span>{title}</span>
{/* <button
className="close-button"
onClick={onDismiss}
tabIndex="-1"
>
<span aria-hidden>×</span>
</button> */}
</DialogHeader>
<DialogContainer>{children}</DialogContainer>
</StyledDialog>
</AnimatedDialogOverlay>
)
);
};

export default CustomDialog;
4 changes: 2 additions & 2 deletions ui/components/LocationHistoryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const LocationHistoryController = () => {

return (
<HistoryButtons>
<ReversedHistoryButton onClick={handleBackward}>
<ReversedHistoryButton onClick={handleBackward} aria-label="Go Back">
<svg
xmlns="http://www.w3.org/2000/svg"
width="18"
Expand All @@ -48,7 +48,7 @@ const LocationHistoryController = () => {
</svg>
</ReversedHistoryButton>
<span />
<HistoryButton onClick={handleForward}>
<HistoryButton onClick={handleForward} aria-label="Go Forward">
<svg
xmlns="http://www.w3.org/2000/svg"
width="18"
Expand Down
8 changes: 5 additions & 3 deletions ui/components/PageHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const PageHeader = ({
showToggleList,
onSearch,
onRefresh,
onBlur,
children
}) => {
const { config, changeConfig } = useConfigContext();
Expand All @@ -57,13 +58,14 @@ const PageHeader = ({
ref={inputRef}
onChange={event => onSearch(event.target.value)}
onKeyDown={event => {
if (event.key === 'Escape') {
if (event.key === 'Escape' || event.key === 'ArrowDown') {
inputRef.current.blur();
}
}}
onBlur={onBlur}
/>
</Hotkeys>
<CustomTooltip label="Change Layout">
{/* <CustomTooltip label="Change Layout">
<RefreshIcon onClick={handleListStyleChange}>
<svg
xmlns="http://www.w3.org/2000/svg"
Expand All @@ -75,7 +77,7 @@ const PageHeader = ({
<path d="M0 0h24v24H0z" fill="none" />
</svg>
</RefreshIcon>
</CustomTooltip>
</CustomTooltip> */}
{showToggleList && (
<CustomTooltip label="Refresh">
<RefreshIcon onClick={onRefresh}>
Expand Down
138 changes: 138 additions & 0 deletions ui/components/SearchDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import React from 'react';
import styled from '@emotion/styled';
import Downshift from 'downshift';

import Dialog from './Dialog';
import Input from './Input';
import { primaryDark, fontColorWhite } from '../util/colors';
import { useNavigate } from '@reach/router';

const DialogContainer = styled.div`
display: flex;
flex-direction: column;
button {
width: 100%;
}
a {
margin-bottom: 16px;
}
`;

const ModalSearch = styled(Input)`
width: 100%;
`;

const ModalList = styled.ul`
margin: 0;
padding: 0;
max-height: 500px;
list-style: none;
cursor: pointer;
overflow: auto;
`;

const ModalListItem = styled.li`
padding: 16px;
background: ${props =>
props.highlighted ? primaryDark : props.theme.background};
color: ${props =>
props.highlighted ? fontColorWhite : props.theme.sidebarFontColor};
font-size: 14px;
`;

function SearchDialog({
isOpen,
dialogItems,
selected,
loading,
data,
onDismiss
}) {
const navigate = useNavigate();

const handleOnSelect = selection => {
if (selection && selection.callback) {
let selectedItem = null;
if (data) {
const { items } = data;
selectedItem = items.find(({ metadata }) => metadata.name === selected);
}
selection.callback(selection, selectedItem);
} else if (selection && !selection.type) {
navigate(`${selection.href}`);
onDismiss();
} else if (selection) {
navigate(`${selection.type}/${selected}/${selection.href}`);
onDismiss();
} else {
onDismiss();
}
};

return (
<Dialog
isOpen={isOpen}
onDismiss={onDismiss}
title={selected}
width="500px"
>
<DialogContainer>
<Downshift
key={JSON.stringify(dialogItems)}
onChange={handleOnSelect}
itemToString={item => (item ? item.value : '')}
>
{({
getInputProps,
getItemProps,
getLabelProps,
getMenuProps,
inputValue,
highlightedIndex
}) => (
<div>
<label {...getLabelProps()}></label>
<ModalSearch
{...getInputProps({
placeholder: loading ? 'Loading...' : 'Search',
onKeyDown: event => {
if (event.key === 'Escape') {
event.nativeEvent.preventDownshiftDefault = true;
}
}
})}
/>
<ModalList {...getMenuProps()}>
{!loading &&
dialogItems
.filter(
item =>
!inputValue ||
item.value
.toLowerCase()
.includes(inputValue.toLowerCase())
)
.map((item, index) => (
<ModalListItem
{...getItemProps({
key: item.value,
index,
item,
highlighted: highlightedIndex === index
})}
>
{item.value}
</ModalListItem>
))}
</ModalList>
</div>
)}
</Downshift>
</DialogContainer>
</Dialog>
);
}

export default SearchDialog;
Loading

0 comments on commit 9ac6748

Please sign in to comment.