feat(striker-ui): add initial drag functions

main
Tsu-ba-me 2 years ago
parent fe8eaa44e3
commit d1977a59c5
  1. 80
      striker-ui/pages/init/index.tsx

@ -1,8 +1,10 @@
import { FC } from 'react'; import { FC, useState } from 'react';
import { import {
Box as MUIBox, Box as MUIBox,
BoxProps as MUIBoxProps,
iconButtonClasses as muiIconButtonClasses, iconButtonClasses as muiIconButtonClasses,
} from '@mui/material'; } from '@mui/material';
import { DragHandle as MUIDragHandleIcon } from '@mui/icons-material';
import { import {
DataGrid as MUIDataGrid, DataGrid as MUIDataGrid,
DataGridProps as MUIDataGridProps, DataGridProps as MUIDataGridProps,
@ -10,7 +12,7 @@ import {
} from '@mui/x-data-grid'; } from '@mui/x-data-grid';
import API_BASE_URL from '../../lib/consts/API_BASE_URL'; import API_BASE_URL from '../../lib/consts/API_BASE_URL';
import { TEXT } from '../../lib/consts/DEFAULT_THEME'; import { GREY, TEXT } from '../../lib/consts/DEFAULT_THEME';
import Decorator from '../../components/Decorator'; import Decorator from '../../components/Decorator';
import { Panel, PanelHeader } from '../../components/Panels'; import { Panel, PanelHeader } from '../../components/Panels';
@ -65,7 +67,34 @@ const DataGridCellText: FC<BodyTextProps> = ({
/> />
); );
const NETWORK_INTERFACE_COLUMNS: MUIDataGridProps['columns'] = [ const createNetworkInterfaceTableColumns = (
onMouseDownDragHandle: (
row: NetworkInterfaceOverviewMetadata,
...eventArgs: Parameters<Exclude<MUIBoxProps['onMouseDown'], undefined>>
) => void,
): MUIDataGridProps['columns'] => [
{
align: 'center',
field: '',
renderCell: ({ row }) => (
<MUIBox
onMouseDown={(...eventArgs) => {
onMouseDownDragHandle(row, ...eventArgs);
}}
sx={{
alignItems: 'center',
display: 'flex',
flexDirection: 'row',
'&:hover': { cursor: 'grab' },
}}
>
<MUIDragHandleIcon />
</MUIBox>
),
sortable: false,
width: 1,
},
{ {
field: 'networkInterfaceName', field: 'networkInterfaceName',
flex: 1, flex: 1,
@ -122,6 +151,10 @@ const NETWORK_INTERFACE_COLUMNS: MUIDataGridProps['columns'] = [
]; ];
const NetworkInterfaceList: FC = () => { const NetworkInterfaceList: FC = () => {
const [networkInterfaceHeld, setNetworkInterfaceHeld] = useState<
NetworkInterfaceOverviewMetadata | undefined
>();
const { data: networkInterfaces = MOCK_NICS, isLoading } = periodicFetch< const { data: networkInterfaces = MOCK_NICS, isLoading } = periodicFetch<
NetworkInterfaceOverviewMetadata[] NetworkInterfaceOverviewMetadata[]
>(`${API_BASE_URL}/network-interface`, { >(`${API_BASE_URL}/network-interface`, {
@ -136,16 +169,28 @@ const NetworkInterfaceList: FC = () => {
{isLoading ? ( {isLoading ? (
<Spinner /> <Spinner />
) : ( ) : (
<MUIBox
sx={{
display: 'flex',
flexDirection: 'column',
'& > :not(:first-child)': {
marginTop: '1em',
},
}}
>
<MUIDataGrid <MUIDataGrid
autoHeight autoHeight
columns={NETWORK_INTERFACE_COLUMNS} columns={createNetworkInterfaceTableColumns((row) => {
setNetworkInterfaceHeld(row);
})}
disableColumnMenu disableColumnMenu
disableSelectionOnClick disableSelectionOnClick
getRowId={({ networkInterfaceUUID }) => networkInterfaceUUID} getRowId={({ networkInterfaceUUID }) => networkInterfaceUUID}
hideFooter hideFooter
rows={networkInterfaces} rows={networkInterfaces}
sx={{ sx={{
color: TEXT, color: GREY,
[`& .${muiIconButtonClasses.root}`]: { [`& .${muiIconButtonClasses.root}`]: {
color: 'inherit', color: 'inherit',
@ -156,13 +201,36 @@ const NetworkInterfaceList: FC = () => {
}, },
}} }}
/> />
<BodyText
text={`Network interface held: ${
networkInterfaceHeld?.networkInterfaceName || 'none'
}`}
/>
<MUIBox
onMouseUp={() => {
setNetworkInterfaceHeld(undefined);
}}
sx={{
borderColor: TEXT,
borderStyle: 'dashed',
borderWidth: '4px',
height: '100px',
width: '100px',
}}
/>
</MUIBox>
)} )}
</Panel> </Panel>
); );
}; };
const Init: FC = () => ( const Init: FC = () => (
<MUIBox> <MUIBox
sx={{
display: 'flex',
flexDirection: 'column',
}}
>
<NetworkInterfaceList /> <NetworkInterfaceList />
</MUIBox> </MUIBox>
); );

Loading…
Cancel
Save