fix(striker-ui): relocate add network button

main
Tsu-ba-me 2 years ago
parent 2dd05a33dd
commit c4a04ddbae
  1. 42
      striker-ui/components/NetworkInitForm.tsx

@ -24,6 +24,7 @@ import {
useCallback, useCallback,
useEffect, useEffect,
useImperativeHandle, useImperativeHandle,
useMemo,
useRef, useRef,
useState, useState,
} from 'react'; } from 'react';
@ -35,6 +36,7 @@ import { BLUE, GREY } from '../lib/consts/DEFAULT_THEME';
import BriefNetworkInterface from './BriefNetworkInterface'; import BriefNetworkInterface from './BriefNetworkInterface';
import Decorator from './Decorator'; import Decorator from './Decorator';
import DropArea from './DropArea'; import DropArea from './DropArea';
import FlexBox from './FlexBox';
import IconButton from './IconButton'; import IconButton from './IconButton';
import InputWithRef, { InputForwardedRefContent } from './InputWithRef'; import InputWithRef, { InputForwardedRefContent } from './InputWithRef';
import OutlinedInputWithLabel from './OutlinedInputWithLabel'; import OutlinedInputWithLabel from './OutlinedInputWithLabel';
@ -425,8 +427,6 @@ const NetworkInitForm = forwardRef<NetworkInitFormForwardRefContent>(
NetworkInterfaceOverviewMetadata | undefined NetworkInterfaceOverviewMetadata | undefined
>(); >();
const optionalNetworkInputsLength = networkInputs.length - 2;
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`, {
@ -448,10 +448,22 @@ const NetworkInitForm = forwardRef<NetworkInitFormForwardRefContent>(
}, },
}); });
const optionalNetworkInputsLength: number = useMemo(
() => networkInputs.length - 2,
[networkInputs],
);
const isDisableAddNetworkButton: boolean = useMemo(
() =>
networkInputs.length >= networkInterfaces.length ||
Object.values(networkInterfaceInputMap).every(
({ isApplied }) => isApplied,
),
[networkInputs, networkInterfaces, networkInterfaceInputMap],
);
const clearNetworkInterfaceHeld = useCallback(() => { const clearNetworkInterfaceHeld = useCallback(() => {
setNetworkInterfaceHeld(undefined); setNetworkInterfaceHeld(undefined);
}, []); }, []);
const createNetwork = useCallback(() => { const createNetwork = useCallback(() => {
networkInputs.unshift({ networkInputs.unshift({
inputUUID: uuidv4(), inputUUID: uuidv4(),
@ -464,7 +476,6 @@ const NetworkInitForm = forwardRef<NetworkInitFormForwardRefContent>(
setNetworkInputs([...networkInputs]); setNetworkInputs([...networkInputs]);
}, [networkInputs]); }, [networkInputs]);
const getNetworkTypeCount = useCallback( const getNetworkTypeCount = useCallback(
(targetType: string, lastIndex = 0) => { (targetType: string, lastIndex = 0) => {
let count = 0; let count = 0;
@ -647,25 +658,25 @@ const NetworkInitForm = forwardRef<NetworkInitFormForwardRefContent>(
}, },
}} }}
/> />
<MUIBox <FlexBox
row
sx={{ sx={{
display: 'flex', '& > :first-child': {
flexDirection: 'row', alignSelf: 'start',
justifyContent: 'center', marginTop: '1.1em',
},
'& > :last-child': {
flexGrow: 1,
},
}} }}
> >
<IconButton <IconButton
disabled={ disabled={isDisableAddNetworkButton}
networkInputs.length >= networkInterfaces.length ||
Object.values(networkInterfaceInputMap).every(
({ isApplied }) => isApplied,
)
}
onClick={createNetwork} onClick={createNetwork}
> >
<MUIAddIcon /> <MUIAddIcon />
</IconButton> </IconButton>
</MUIBox>
<MUIBox <MUIBox
sx={{ sx={{
alignItems: 'strech', alignItems: 'strech',
@ -707,6 +718,7 @@ const NetworkInitForm = forwardRef<NetworkInitFormForwardRefContent>(
); );
})} })}
</MUIBox> </MUIBox>
</FlexBox>
</MUIBox> </MUIBox>
</MUIBox> </MUIBox>
); );

Loading…
Cancel
Save