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

Manage dashboard with css grid #27

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
tmp
__pycache__

.env

# Logs
logs
*.log
Expand Down
35 changes: 35 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,38 @@
.read-the-docs {
color: #888;
} */
* {
box-sizing: border-box;
}

#main-window {
display: grid;
grid-template-areas: "a a a"
"b c c"
"b c c";

grid-template-rows: auto 1fr;
grid-template-columns: auto 1fr;
width: 100vw;
height: 100vh;
}

.main {
grid-area: c;
width: 100%;
height: 100%;
overflow: hidden;
display: flex;
flex-direction: column;
}

.splitterChild {
width: min-content;
border-right: gray 1px solid;
}

.splitterChild:last-child {
flex-grow: 1;
min-width: 50%;
border-right: none;
}
2 changes: 1 addition & 1 deletion src/ApplicationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const ApplicationBar: FunctionComponent<Props> = () => {
}, [])

return (
<span>
<span style={{ gridArea: 'a'}}>
<AppBar position="static" style={{height: applicationBarHeight - 10, color: 'black', background: applicationBarColor}}>
<Toolbar style={{minHeight: applicationBarHeight - 10}}>
<img src="/dendro.png" alt="logo" height={30} style={{paddingBottom: 3, cursor: 'pointer'}} onClick={onHome} />
Expand Down
64 changes: 28 additions & 36 deletions src/MainWindow.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { FunctionComponent } from "react";
import ApplicationBar, { applicationBarHeight } from "./ApplicationBar";
import ApplicationBar from "./ApplicationBar";
import AboutPage from "./pages/AboutPage/AboutPage";
import HomePage from "./pages/HomePage/HomePage";
import useRoute from "./useRoute";
import useWindowDimensions from "./useWindowDimensions";
import DandiBrowser from "./pages/DandiBrowser/DandiBrowser";
import ProjectPage from "./pages/ProjectPage/ProjectPage";
import RegisterComputeResourcePage from "./pages/RegisterComputeResourcePage/RegisterComputeResourcePage";
Expand All @@ -18,41 +17,34 @@ type Props = {

const MainWindow: FunctionComponent<Props> = () => {
const {route} = useRoute()
const {width, height} = useWindowDimensions()
return (
<div style={{position: 'absolute', width, height, overflow: 'hidden'}}>
<div style={{position: 'absolute', width, height: applicationBarHeight}}>
<ApplicationBar />
</div>
<div style={{position: 'absolute', top: applicationBarHeight, width, height: height - applicationBarHeight}}>
{
route.page === 'home' ? (
<HomePage width={width} height={height - applicationBarHeight} />
) : (route.page === 'dandisets' || route.page === 'dandiset') ? (
<DandiBrowser width={width} height={height - applicationBarHeight} />
) : route.page === 'project' ? (
<ProjectPage width={width} height={height - applicationBarHeight} />
) : route.page === 'about' ? (
<AboutPage width={width} height={height - applicationBarHeight} />
) : route.page === 'compute-resource' ? (
<ComputeResourcePage
width={width}
height={height - applicationBarHeight}
computeResourceId={route.computeResourceId}
/>
) : route.page === 'compute-resources' ? (
<ComputeResourcesPage width={width} height={height} />
) : route.page === 'projects' ? (
<ProjectsPage width={width} height={height} />
) : route.page === 'register-compute-resource' ? (
<RegisterComputeResourcePage />
) : route.page === 'github-auth' ? (
<GitHubAuthPage />
) : (
<div>404</div>
)
}
</div>
<div id="main-window">
<ApplicationBar />
{
route.page === 'home' ? (
<HomePage />
) : (route.page === 'dandisets' || route.page === 'dandiset') ? (
<DandiBrowser/>
) : route.page === 'project' ? (
<ProjectPage/>
) : route.page === 'about' ? (
<AboutPage/>
) : route.page === 'compute-resource' ? (
<ComputeResourcePage
computeResourceId={route.computeResourceId}
/>
) : route.page === 'compute-resources' ? (
<ComputeResourcesPage />
) : route.page === 'projects' ? (
<ProjectsPage />
) : route.page === 'register-compute-resource' ? (
<RegisterComputeResourcePage />
) : route.page === 'github-auth' ? (
<GitHubAuthPage />
) : (
<div>404</div>
)
}
</div>
)
}
Expand Down
15 changes: 5 additions & 10 deletions src/TabWidget/TabWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ type Props = {
currentTabId: string | undefined
setCurrentTabId: (id: string) => void
onCloseTab: (id: string) => void
width: number
height: number
}

const tabBarHeight = 30

const TabWidget: FunctionComponent<PropsWithChildren<Props>> = ({children, tabs, currentTabId, setCurrentTabId, onCloseTab, width, height}) => {
const TabWidget: FunctionComponent<PropsWithChildren<Props>> = ({children, tabs, currentTabId, setCurrentTabId, onCloseTab}) => {
const currentTabIndex = useMemo(() => {
if (!currentTabId) return undefined
const index = tabs.findIndex(t => t.id === currentTabId)
Expand All @@ -28,10 +26,7 @@ const TabWidget: FunctionComponent<PropsWithChildren<Props>> = ({children, tabs,
if ((children2 || []).length !== tabs.length) {
throw Error(`TabWidget: incorrect number of tabs ${(children2 || []).length} <> ${tabs.length}`)
}
const hMargin = 8
const vMargin = 8
const W = (width || 300) - hMargin * 2
const H = height - vMargin * 2

const [hasBeenVisible, setHasBeenVisible] = useState<number[]>([])
useEffect(() => {
if (currentTabIndex === undefined) return
Expand All @@ -45,10 +40,10 @@ const TabWidget: FunctionComponent<PropsWithChildren<Props>> = ({children, tabs,
}, [setCurrentTabId, tabs])
return (
<div
style={{position: 'absolute', left: hMargin, top: vMargin, width: W, height: H, overflow: 'hidden'}}
style={{overflow: 'hidden'}}
className="TabWidget"
>
<div key="tabwidget-bar" style={{position: 'absolute', left: 0, top: 0, width: W, height: tabBarHeight }}>
<div key="tabwidget-bar" style={{ height: tabBarHeight }}>
<TabWidgetTabBar
tabs={tabs}
currentTabIndex={currentTabIndex}
Expand All @@ -62,7 +57,7 @@ const TabWidget: FunctionComponent<PropsWithChildren<Props>> = ({children, tabs,
return (
<div key={`child-${i}`} style={{visibility: visible ? undefined : 'hidden', overflowY: 'hidden', overflowX: 'hidden', position: 'absolute', left: 0, top: tabBarHeight, width: W, height: H, background: 'white'}}>
{(visible || hasBeenVisible.includes(i)) && (
<c.type {...c.props} width={W} height={H - tabBarHeight}/>
<c.type {...c.props}/>
)}
</div>
)
Expand Down
4 changes: 2 additions & 2 deletions src/components/HBoxLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const HBoxLayout: React.FunctionComponent<PropsWithChildren<HBoxLayoutProps>> =
const totalWidth = widths.reduce((a, b) => (a + b), 0)
const children2 = React.Children.toArray(children).map(ch => (ch as any as ReactElement))
return (
<div style={{position: 'relative', width: totalWidth, height}}>
<div id="hbox" style={{position: 'relative', width: totalWidth, height}}>
{
children2.map((child: ReactElement, i) => {
return child ? (
<div key={i} style={{position: 'absolute', left: widths.slice(0, i).reduce((a, b) => (a + b), 0), top: 0, width: widths[i], height}}>
<div key={i} style={{}}>
<child.type {...child.props} width={widths[i]} height={height} />
</div>
) : <span />
Expand Down
65 changes: 22 additions & 43 deletions src/components/Splitter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React, { FunctionComponent, PropsWithChildren, ReactElement, useEffect, u
import Draggable, { DraggableData, DraggableEvent } from 'react-draggable';

interface Props {
width: number
height: number
initialPosition: number
// width: number
// height: number
initialPosition: number // Ratio?
positionFromRight?: boolean
onChange?: (newPosition: number) => void
gripThickness?: number
Expand All @@ -23,13 +23,14 @@ const defaultGripMargin = 2
const Draggable1: any = Draggable

const Splitter: FunctionComponent<PropsWithChildren<Props>> = (props) => {
const {width, height, initialPosition, onChange, adjustable=true, positionFromRight=false, direction='horizontal', hideSecondChild} = props
const { width, height, initialPosition, onChange, adjustable=true, positionFromRight=false, direction='horizontal', hideSecondChild} = props

const size1 = direction === 'horizontal' ? width : height
// const size2 = direction === 'horizontal' ? height : width

const [gripPosition, setGripPosition] = useState<number>(initialPosition)
useEffect(() => {

if (gripPosition > size1 - 4) {
setGripPosition(size1 - 4)
}
Expand Down Expand Up @@ -65,7 +66,7 @@ const Splitter: FunctionComponent<PropsWithChildren<Props>> = (props) => {
}

if (!child2) {
return <child1.type {...child1.props} width={width} height={height} />
return <child1.type {...child1.props}/>
}

let gripPositionFromLeft = positionFromRight ? size1 - gripPosition : gripPosition
Expand All @@ -79,53 +80,22 @@ const Splitter: FunctionComponent<PropsWithChildren<Props>> = (props) => {
const size1A = gripPositionFromLeft - gripThickness / 2 - gripMargin
const size1B = size1 - size1A - gripThickness - 2 * gripMargin

const style0: React.CSSProperties = {
top: 0,
left: 0,
width: width,
height: height,
overflow: 'hidden'
};
const style1: React.CSSProperties = {
left: 0,
top: 0,
width: direction === 'horizontal' ? size1A : width,
height: direction === 'horizontal' ? height : size1A,
zIndex: 0,
overflowY: direction === 'horizontal' ? 'auto' : 'hidden',
overflowX: direction === 'horizontal' ? 'hidden' : 'auto'
};
const style2: React.CSSProperties = {
left: direction === 'horizontal' ? size1A + gripThickness + 2 * gripMargin : 0,
top: direction === 'horizontal' ? 0 : size1A + gripThickness + 2 * gripMargin,
width: direction === 'horizontal' ? size1B : width,
height: direction === 'horizontal' ? height : size1B,
zIndex: 0,
overflowY: direction === 'horizontal' ? 'auto' : 'hidden',
overflowX: direction === 'horizontal' ? 'hidden' : 'auto'
};
const styleGripOuter: React.CSSProperties = {
left: 0,
top: 0,
width: direction === 'horizontal' ? gripThickness + 2 * gripMargin : width,
height: direction === 'horizontal' ? height : gripThickness + 2 * gripMargin,
backgroundColor: 'transparent',
cursor: direction === 'horizontal' ? 'col-resize' : 'row-resize',
zIndex: 9998
};
const styleGrip: React.CSSProperties = {
left: direction === 'horizontal' ? gripMargin : 0,
top: direction === 'horizontal' ? 0 : gripMargin,
width: direction === 'horizontal' ? gripThickness : width,
height: direction === 'horizontal' ? height : gripThickness,
background: 'rgb(230, 230, 230)',
cursor: direction === 'horizontal' ? 'col-resize' : 'row-resize'
};
const styleGripInner: React.CSSProperties = {
top: direction === 'horizontal' ? 0 : (gripThickness - gripInnerThickness) / 2,
left: direction === 'horizontal' ? (gripThickness - gripInnerThickness) / 2 : 0,
width: direction === 'horizontal' ? gripInnerThickness : width,
height: direction === 'horizontal' ? height : gripInnerThickness,
background: 'gray',
cursor: direction === 'horizontal' ? 'col-resize' : 'row-resize'
};
Expand All @@ -140,10 +110,17 @@ const Splitter: FunctionComponent<PropsWithChildren<Props>> = (props) => {
setGripPosition(newGripPosition)
onChange && onChange(newGripPosition)
}

console.log('HIEE!', hideSecondChild)
return (
<div className="splitter" style={{...style0, position: 'relative'}}>
<div key="child1" style={{...style1, position: 'absolute'}} className="SplitterChild">
<child1.type {...child1.props} width={direction === 'horizontal' ? size1A : width} height={direction === 'horizontal' ? height : size1A} />
<div style={{
position: 'relative',
display: 'flex',
height: '100%',
overflow: 'hidden'
}}>
<div key="child1" className="splitterChild" style={{ overflow: 'auto' }}>
<child1.type {...child1.props} />
</div>
{
adjustable && !hideSecondChild && (
Expand All @@ -164,10 +141,12 @@ const Splitter: FunctionComponent<PropsWithChildren<Props>> = (props) => {
)
}

<div key="child2" style={{...style2, position: 'absolute'}} className="SplitterChild">
{/* <child2.type ref={ref} {...child2.props} width={direction === 'horizontal' ? size1B : width} height={direction === 'horizontal' ? height : size1B} /> */}
<child2.type {...child2.props} width={direction === 'horizontal' ? size1B : width} height={direction === 'horizontal' ? height : size1B} />
</div>
{
!hideSecondChild && <div key="child2" className="splitterChild" style={{ overflow: 'auto' }}>
{/* <child2.type ref={ref} {...child2.props} width={direction === 'horizontal' ? size1B : width} height={direction === 'horizontal' ? height : size1B} /> */}
<child2.type {...child2.props} />
</div>
}
</div>
)
}
Expand Down
10 changes: 4 additions & 6 deletions src/pages/ComputeResourcePage/ComputeResourceAppsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import ComputeResourceAppsTableMenuBar from "./ComputeResourceAppsTableMenuBar"
import NewAppWindow from "./NewAppWindow"

type Props = {
width: number
height: number
computeResource: DendroComputeResource
onNewApp: (name: string, specUri: string, absBatch?: ComputeResourceAwsBatchOpts, slurm?: ComputeResourceSlurmOpts) => void
Expand All @@ -20,7 +19,7 @@ const menuBarHeight = 30
const hPadding = 20
const vPadding = 5

const ComputeResourceAppsTable: FunctionComponent<Props> = ({width, height, computeResource, onNewApp, onEditApp, onDeleteApps}) => {
const ComputeResourceAppsTable: FunctionComponent<Props> = ({ height, computeResource, onNewApp, onEditApp, onDeleteApps}) => {
const [selectedAppNames, selectedAppNamesDispatch] = useReducer(selectedStringsReducer, new Set<string>())

const {visible: newAppWindowVisible, handleOpen: openNewAppWindow, handleClose: closeNewAppWindow} = useModalDialog()
Expand All @@ -39,18 +38,17 @@ const ComputeResourceAppsTable: FunctionComponent<Props> = ({width, height, comp
}, [selectedAppNames, computeResource])

return (
<div style={{position: 'relative', width, height}}>
<div style={{position: 'absolute', width: width - hPadding * 2, height: menuBarHeight - vPadding * 2, paddingLeft: hPadding, paddingRight: hPadding, paddingTop: vPadding, paddingBottom: vPadding}}>
<div style={{position: 'relative', height}}>
<div style={{ height: menuBarHeight - vPadding * 2, paddingLeft: hPadding, paddingRight: hPadding, paddingTop: vPadding, paddingBottom: vPadding}}>
<ComputeResourceAppsTableMenuBar
width={width - hPadding * 2}
height={menuBarHeight - vPadding * 2}
selectedAppNames={Array.from(selectedAppNames)}
onAddApp={openNewAppWindow}
onDeleteApps={onDeleteApps}
onEditApp={openEditAppWindow}
/>
</div>
<div style={{position: 'absolute', width: width - hPadding * 2, height: height - menuBarHeight - vPadding * 2, top: menuBarHeight, overflowY: 'scroll', paddingLeft: hPadding, paddingRight: hPadding, paddingTop: vPadding, paddingBottom: vPadding}}>
<div style={{height: height - menuBarHeight - vPadding * 2, top: menuBarHeight, overflowY: 'scroll', paddingLeft: hPadding, paddingRight: hPadding, paddingTop: vPadding, paddingBottom: vPadding}}>
<table className="scientific-table" style={{fontSize: 12}}>
<thead>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ import SmallIconButton from "../../components/SmallIconButton"
import { confirm } from "../../confirm_prompt_alert"

type ComputeResourceAppsTableMenuBarProps = {
width: number
height: number
selectedAppNames: string[]
onDeleteApps: (appNames: string[]) => void
onAddApp: () => void
onEditApp: () => void
}

const ComputeResourceAppsTableMenuBar: FunctionComponent<ComputeResourceAppsTableMenuBarProps> = ({width, height, selectedAppNames, onAddApp, onDeleteApps, onEditApp}) => {
const ComputeResourceAppsTableMenuBar: FunctionComponent<ComputeResourceAppsTableMenuBarProps> = ({ selectedAppNames, onAddApp, onDeleteApps, onEditApp}) => {
const handleDelete = useCallback(async () => {
const okay = await confirm(`Are you sure you want to delete these ${selectedAppNames.length} apps?`)
if (!okay) return
Expand Down
Loading