Apply new eslint rules; default to prettier for styling
This commit is contained in:
parent
f22cce8881
commit
dc84af9937
218 changed files with 3876 additions and 3564 deletions
|
@ -21,20 +21,22 @@ import getServerAllocations from '@/api/swr/getServerAllocations';
|
|||
import { ip } from '@/lib/formatters';
|
||||
import Code from '@/components/elements/Code';
|
||||
|
||||
const Label = styled.label`${tw`uppercase text-xs mt-1 text-neutral-400 block px-1 select-none transition-colors duration-150`}`;
|
||||
const Label = styled.label`
|
||||
${tw`uppercase text-xs mt-1 text-neutral-400 block px-1 select-none transition-colors duration-150`}
|
||||
`;
|
||||
|
||||
interface Props {
|
||||
allocation: Allocation;
|
||||
}
|
||||
|
||||
const AllocationRow = ({ allocation }: Props) => {
|
||||
const [ loading, setLoading ] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { clearFlashes, clearAndAddHttpError } = useFlashKey('server:network');
|
||||
const uuid = ServerContext.useStoreState(state => state.server.data!.uuid);
|
||||
const uuid = ServerContext.useStoreState((state) => state.server.data!.uuid);
|
||||
const { mutate } = getServerAllocations();
|
||||
|
||||
const onNotesChanged = useCallback((id: number, notes: string) => {
|
||||
mutate(data => data?.map(a => a.id === id ? { ...a, notes } : a), false);
|
||||
mutate((data) => data?.map((a) => (a.id === id ? { ...a, notes } : a)), false);
|
||||
}, []);
|
||||
|
||||
const setAllocationNotes = debounce((notes: string) => {
|
||||
|
@ -43,31 +45,38 @@ const AllocationRow = ({ allocation }: Props) => {
|
|||
|
||||
setServerAllocationNotes(uuid, allocation.id, notes)
|
||||
.then(() => onNotesChanged(allocation.id, notes))
|
||||
.catch(error => clearAndAddHttpError(error))
|
||||
.catch((error) => clearAndAddHttpError(error))
|
||||
.then(() => setLoading(false));
|
||||
}, 750);
|
||||
|
||||
const setPrimaryAllocation = () => {
|
||||
clearFlashes();
|
||||
mutate(data => data?.map(a => ({ ...a, isDefault: a.id === allocation.id })), false);
|
||||
mutate((data) => data?.map((a) => ({ ...a, isDefault: a.id === allocation.id })), false);
|
||||
|
||||
setPrimaryServerAllocation(uuid, allocation.id)
|
||||
.catch(error => {
|
||||
clearAndAddHttpError(error);
|
||||
mutate();
|
||||
});
|
||||
setPrimaryServerAllocation(uuid, allocation.id).catch((error) => {
|
||||
clearAndAddHttpError(error);
|
||||
mutate();
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<GreyRowBox $hoverable={false} className={'flex-wrap md:flex-nowrap mt-2'}>
|
||||
<div className={'flex items-center w-full md:w-auto'}>
|
||||
<div className={'pl-4 pr-6 text-neutral-400'}>
|
||||
<FontAwesomeIcon icon={faNetworkWired}/>
|
||||
<FontAwesomeIcon icon={faNetworkWired} />
|
||||
</div>
|
||||
<div className={'mr-4 flex-1 md:w-40'}>
|
||||
{allocation.alias ?
|
||||
<CopyOnClick text={allocation.alias}><Code dark className={'w-40 truncate'}>{allocation.alias}</Code></CopyOnClick> :
|
||||
<CopyOnClick text={ip(allocation.ip)}><Code dark>{ip(allocation.ip)}</Code></CopyOnClick>}
|
||||
{allocation.alias ? (
|
||||
<CopyOnClick text={allocation.alias}>
|
||||
<Code dark className={'w-40 truncate'}>
|
||||
{allocation.alias}
|
||||
</Code>
|
||||
</CopyOnClick>
|
||||
) : (
|
||||
<CopyOnClick text={ip(allocation.ip)}>
|
||||
<Code dark>{ip(allocation.ip)}</Code>
|
||||
</CopyOnClick>
|
||||
)}
|
||||
<Label>{allocation.alias ? 'Hostname' : 'IP Address'}</Label>
|
||||
</div>
|
||||
<div className={'w-16 md:w-24 overflow-hidden'}>
|
||||
|
@ -81,17 +90,19 @@ const AllocationRow = ({ allocation }: Props) => {
|
|||
className={'bg-neutral-800 hover:border-neutral-600 border-transparent'}
|
||||
placeholder={'Notes'}
|
||||
defaultValue={allocation.notes || undefined}
|
||||
onChange={e => setAllocationNotes(e.currentTarget.value)}
|
||||
onChange={(e) => setAllocationNotes(e.currentTarget.value)}
|
||||
/>
|
||||
</InputSpinner>
|
||||
</div>
|
||||
<div className={'flex justify-end space-x-4 mt-4 w-full md:mt-0 md:w-48'}>
|
||||
{allocation.isDefault ?
|
||||
<Button size={Button.Sizes.Small} className={'!text-gray-50 !bg-blue-600'} disabled>Primary</Button>
|
||||
:
|
||||
{allocation.isDefault ? (
|
||||
<Button size={Button.Sizes.Small} className={'!text-gray-50 !bg-blue-600'} disabled>
|
||||
Primary
|
||||
</Button>
|
||||
) : (
|
||||
<>
|
||||
<Can action={'allocation.delete'}>
|
||||
<DeleteAllocationButton allocation={allocation.id}/>
|
||||
<DeleteAllocationButton allocation={allocation.id} />
|
||||
</Can>
|
||||
<Can action={'allocation.update'}>
|
||||
<Button.Text size={Button.Sizes.Small} onClick={setPrimaryAllocation}>
|
||||
|
@ -99,7 +110,7 @@ const AllocationRow = ({ allocation }: Props) => {
|
|||
</Button.Text>
|
||||
</Can>
|
||||
</>
|
||||
}
|
||||
)}
|
||||
</div>
|
||||
</GreyRowBox>
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue