From 642ebfc4c343246ce1b26d34e8bc8c029d6f683b Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Mon, 17 Oct 2022 18:24:52 -0400 Subject: [PATCH] feat(striker-ui): add ManageChangedSSHKeysForm --- .../ManageChangedSSHKeysForm.tsx | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 striker-ui/components/StrikerConfig/ManageChangedSSHKeysForm.tsx diff --git a/striker-ui/components/StrikerConfig/ManageChangedSSHKeysForm.tsx b/striker-ui/components/StrikerConfig/ManageChangedSSHKeysForm.tsx new file mode 100644 index 00000000..44019645 --- /dev/null +++ b/striker-ui/components/StrikerConfig/ManageChangedSSHKeysForm.tsx @@ -0,0 +1,128 @@ +import { FC, useMemo, useRef } from 'react'; + +import Divider from '../Divider'; +import FlexBox from '../FlexBox'; +import List, { ListForwardedRefContent } from '../List'; +import MessageBox from '../MessageBox'; +import { ExpandablePanel } from '../Panels'; +import { BodyText } from '../Text'; +import useProtect from '../../hooks/useProtect'; +import useProtectedState from '../../hooks/useProtectedState'; + +type ChangedSSHKeys = { + [hostUUID: string]: { + hostName: string; + hostUUID: string; + ipAddress: string; + isChecked?: boolean; + }; +}; + +const ManageChangedSSHKeysForm: FC = () => { + const { protect } = useProtect(); + + const listRef = useRef({}); + + const [changedSSHKeys, setChangedSSHKeys] = useProtectedState( + {}, + protect, + ); + + const isAllowCheckAll = useMemo( + () => Object.keys(changedSSHKeys).length > 1, + [changedSSHKeys], + ); + + return ( + Manage changed SSH keys}> + + + The identity of the following targets have unexpectedly changed. + + + If you haven't rebuilt the listed targets, then you could be + experiencing a "Man In The Middle" attack. Please verify the + targets have changed for a known reason before proceeding to remove + the broken keys. + + :not(:last-child)': { + display: { xs: 'none', sm: 'flex' }, + }, + + '& > :last-child': { + display: { xs: 'initial', sm: 'none' }, + marginLeft: 0, + }, + }} + > + + Host name + + + + IP address + + + + + } + allowCheckAll={isAllowCheckAll} + allowCheckItem + allowDelete + allowEdit={false} + edit + listEmpty={ + + No conflicting keys found. + + } + listItems={changedSSHKeys} + onAllCheckboxChange={(event, isChecked) => { + Object.keys(changedSSHKeys).forEach((key) => { + changedSSHKeys[key].isChecked = isChecked; + }); + + setChangedSSHKeys((previous) => ({ ...previous })); + }} + onItemCheckboxChange={(key, event, isChecked) => { + changedSSHKeys[key].isChecked = isChecked; + + listRef.current.setCheckAll?.call( + null, + Object.values(changedSSHKeys).every( + ({ isChecked: isItemChecked }) => isItemChecked, + ), + ); + + setChangedSSHKeys((previous) => ({ ...previous })); + }} + renderListItem={(hostUUID, { hostName, ipAddress }) => ( + *': { flexBasis: '50%' } }} + xs="column" + > + {hostName} + {ipAddress} + + )} + renderListItemCheckboxState={(key, { isChecked }) => + isChecked === true + } + ref={listRef} + /> + + + ); +}; + +export default ManageChangedSSHKeysForm;