mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 01:20:24 +03:00
Fix coding standards for typescript-eslint 8
This commit is contained in:
parent
81ea262999
commit
a8258ff2cc
16 changed files with 48 additions and 24 deletions
|
@ -9,7 +9,7 @@ import './AppUpdateBanner.scss';
|
||||||
interface AppUpdateBannerProps {
|
interface AppUpdateBannerProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
toggle: MouseEventHandler<any>;
|
toggle: MouseEventHandler<any>;
|
||||||
forceUpdate: Function;
|
forceUpdate: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AppUpdateBanner = forwardRef<HTMLElement, AppUpdateBannerProps>(({ isOpen, toggle, forceUpdate }, ref) => {
|
export const AppUpdateBanner = forwardRef<HTMLElement, AppUpdateBannerProps>(({ isOpen, toggle, forceUpdate }, ref) => {
|
||||||
|
|
|
@ -21,7 +21,9 @@ export const Home = ({ servers }: HomeProps) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Try to redirect to the first server marked as auto-connect
|
// Try to redirect to the first server marked as auto-connect
|
||||||
const autoConnectServer = serversList.find(({ autoConnect }) => autoConnect);
|
const autoConnectServer = serversList.find(({ autoConnect }) => autoConnect);
|
||||||
autoConnectServer && navigate(`/server/${autoConnectServer.id}`);
|
if (autoConnectServer) {
|
||||||
|
navigate(`/server/${autoConnectServer.id}`);
|
||||||
|
}
|
||||||
}, [serversList, navigate]);
|
}, [serversList, navigate]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -15,7 +15,7 @@ type MainHeaderDeps = {
|
||||||
ServersDropdown: FC;
|
ServersDropdown: FC;
|
||||||
};
|
};
|
||||||
|
|
||||||
const MainHeader: FCWithDeps<{}, MainHeaderDeps> = () => {
|
const MainHeader: FCWithDeps<unknown, MainHeaderDeps> = () => {
|
||||||
const { ServersDropdown } = useDependencies(MainHeader);
|
const { ServersDropdown } = useDependencies(MainHeader);
|
||||||
const [isNotCollapsed, toggleCollapse, , collapse] = useToggle();
|
const [isNotCollapsed, toggleCollapse, , collapse] = useToggle();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
|
@ -9,13 +9,13 @@ import { provideServices as provideSettingsServices } from '../settings/services
|
||||||
import { provideServices as provideUtilsServices } from '../utils/services/provideServices';
|
import { provideServices as provideUtilsServices } from '../utils/services/provideServices';
|
||||||
import type { ConnectDecorator } from './types';
|
import type { ConnectDecorator } from './types';
|
||||||
|
|
||||||
type LazyActionMap = Record<string, Function>;
|
type LazyActionMap = Record<string, (...args: unknown[]) => unknown>;
|
||||||
|
|
||||||
const bottle = new Bottle();
|
const bottle = new Bottle();
|
||||||
|
|
||||||
export const { container } = bottle;
|
export const { container } = bottle;
|
||||||
|
|
||||||
const lazyService = <T extends Function, K>(cont: IContainer, serviceName: string) =>
|
const lazyService = <T extends (...args: unknown[]) => unknown, K>(cont: IContainer, serviceName: string) =>
|
||||||
(...args: any[]) => (cont[serviceName] as T)(...args) as K;
|
(...args: any[]) => (cont[serviceName] as T)(...args) as K;
|
||||||
|
|
||||||
const mapActionService = (map: LazyActionMap, actionName: string): LazyActionMap => ({
|
const mapActionService = (map: LazyActionMap, actionName: string): LazyActionMap => ({
|
||||||
|
|
|
@ -60,7 +60,11 @@ const CreateServer: FCWithDeps<CreateServerProps, CreateServerDeps> = ({ servers
|
||||||
({ url, apiKey }) => serverData?.url === url && serverData?.apiKey === apiKey,
|
({ url, apiKey }) => serverData?.url === url && serverData?.apiKey === apiKey,
|
||||||
);
|
);
|
||||||
|
|
||||||
serverExists ? toggleConfirmModal() : saveNewServer(serverData);
|
if (serverExists) {
|
||||||
|
toggleConfirmModal();
|
||||||
|
} else {
|
||||||
|
saveNewServer(serverData);
|
||||||
|
}
|
||||||
}, [saveNewServer, serverData, servers, toggleConfirmModal]);
|
}, [saveNewServer, serverData, servers, toggleConfirmModal]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -30,7 +30,9 @@ export const DeleteServerModal: FC<DeleteServerModalConnectProps> = (
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteServer(server);
|
deleteServer(server);
|
||||||
redirectHome && navigate('/');
|
if (redirectHome) {
|
||||||
|
navigate('/');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -31,7 +31,9 @@ const EditServer: FCWithDeps<EditServerProps, EditServerDeps> = withSelectedServ
|
||||||
|
|
||||||
const handleSubmit = (serverData: ServerData) => {
|
const handleSubmit = (serverData: ServerData) => {
|
||||||
editServer(selectedServer.id, serverData);
|
editServer(selectedServer.id, serverData);
|
||||||
reconnect === 'true' && selectServer(selectedServer.id);
|
if (reconnect === 'true') {
|
||||||
|
selectServer(selectedServer.id);
|
||||||
|
}
|
||||||
goBack();
|
goBack();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -58,8 +58,12 @@ const ImportServersBtn: FCWithDeps<ImportServersBtnConnectProps, ImportServersBt
|
||||||
const dupServers = newServers.filter((server) => serversInclude(existingServers, server));
|
const dupServers = newServers.filter((server) => serversInclude(existingServers, server));
|
||||||
const hasDuplicatedServers = !!dupServers.length;
|
const hasDuplicatedServers = !!dupServers.length;
|
||||||
|
|
||||||
!hasDuplicatedServers ? create(newServers) : setDuplicatedServers(dupServers);
|
if (!hasDuplicatedServers) {
|
||||||
hasDuplicatedServers && showModal();
|
create(newServers);
|
||||||
|
} else {
|
||||||
|
setDuplicatedServers(dupServers);
|
||||||
|
showModal();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// Reset input after processing file
|
// Reset input after processing file
|
||||||
|
|
|
@ -17,9 +17,11 @@ export const ServerForm: FC<ServerFormProps> = ({ onSubmit, initialValues, child
|
||||||
const handleSubmit = handleEventPreventingDefault(() => onSubmit({ name, url, apiKey }));
|
const handleSubmit = handleEventPreventingDefault(() => onSubmit({ name, url, apiKey }));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
initialValues && setName(initialValues.name);
|
if (initialValues) {
|
||||||
initialValues && setUrl(initialValues.url);
|
setName(initialValues.name);
|
||||||
initialValues && setApiKey(initialValues.apiKey);
|
setUrl(initialValues.url);
|
||||||
|
setApiKey(initialValues.apiKey);
|
||||||
|
}
|
||||||
}, [initialValues]);
|
}, [initialValues]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -17,7 +17,7 @@ type WithSelectedServerPropsDeps = {
|
||||||
ServerError: FC;
|
ServerError: FC;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function withSelectedServer<T = {}>(
|
export function withSelectedServer<T extends object>(
|
||||||
WrappedComponent: FCWithDeps<WithSelectedServerProps & T, WithSelectedServerPropsDeps>,
|
WrappedComponent: FCWithDeps<WithSelectedServerProps & T, WithSelectedServerPropsDeps>,
|
||||||
) {
|
) {
|
||||||
const ComponentWrapper: FCWithDeps<WithSelectedServerProps & T, WithSelectedServerPropsDeps> = (props) => {
|
const ComponentWrapper: FCWithDeps<WithSelectedServerProps & T, WithSelectedServerPropsDeps> = (props) => {
|
||||||
|
@ -26,7 +26,9 @@ export function withSelectedServer<T = {}>(
|
||||||
const { selectServer, selectedServer } = props;
|
const { selectServer, selectedServer } = props;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
params.serverId && selectServer(params.serverId);
|
if (params.serverId) {
|
||||||
|
selectServer(params.serverId);
|
||||||
|
}
|
||||||
}, [params.serverId, selectServer]);
|
}, [params.serverId, selectServer]);
|
||||||
|
|
||||||
if (!selectedServer) {
|
if (!selectedServer) {
|
||||||
|
|
|
@ -2,10 +2,10 @@ import type { FC } from 'react';
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
interface WithoutSelectedServerProps {
|
interface WithoutSelectedServerProps {
|
||||||
resetSelectedServer: Function;
|
resetSelectedServer: () => unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function withoutSelectedServer<T = {}>(WrappedComponent: FC<WithoutSelectedServerProps & T>) {
|
export function withoutSelectedServer<T extends object>(WrappedComponent: FC<WithoutSelectedServerProps & T>) {
|
||||||
return (props: WithoutSelectedServerProps & T) => {
|
return (props: WithoutSelectedServerProps & T) => {
|
||||||
const { resetSelectedServer } = props;
|
const { resetSelectedServer } = props;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -50,7 +50,7 @@ export const selectServer = (buildShlinkApiClient: ShlinkApiClientBuilder) => cr
|
||||||
version,
|
version,
|
||||||
printableVersion,
|
printableVersion,
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch {
|
||||||
return { ...selectedServer, serverNotReachable: true };
|
return { ...selectedServer, serverNotReachable: true };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,8 +7,8 @@ export const migrateDeprecatedSettings = (state: Partial<ShlinkState>): Partial<
|
||||||
}
|
}
|
||||||
|
|
||||||
// The "last180Days" interval had a typo, with a lowercase d
|
// The "last180Days" interval had a typo, with a lowercase d
|
||||||
if ((state.settings.visits?.defaultInterval as any) === 'last180days') {
|
if (state.settings.visits && (state.settings.visits.defaultInterval as any) === 'last180days') {
|
||||||
state.settings.visits && (state.settings.visits.defaultInterval = 'last180Days');
|
state.settings.visits.defaultInterval = 'last180Days';
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
|
|
@ -38,7 +38,7 @@ export const versionMatch = (versionToMatch: SemVer | Empty, { maxVersion, minVe
|
||||||
const versionIsValidSemVer = memoizeWith((v) => v, (version: string): version is SemVer => {
|
const versionIsValidSemVer = memoizeWith((v) => v, (version: string): version is SemVer => {
|
||||||
try {
|
try {
|
||||||
return compare(version, version, '=');
|
return compare(version, version, '=');
|
||||||
} catch (e) {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -32,7 +32,9 @@ describe('<DeleteServerButton />', () => {
|
||||||
|
|
||||||
expect(screen.getByText(/DeleteServerModal/)).toHaveTextContent(/Closed/);
|
expect(screen.getByText(/DeleteServerModal/)).toHaveTextContent(/Closed/);
|
||||||
expect(screen.getByText(/DeleteServerModal/)).not.toHaveTextContent(/Open/);
|
expect(screen.getByText(/DeleteServerModal/)).not.toHaveTextContent(/Open/);
|
||||||
container.firstElementChild && await user.click(container.firstElementChild);
|
if (container.firstElementChild) {
|
||||||
|
await user.click(container.firstElementChild);
|
||||||
|
}
|
||||||
|
|
||||||
await waitFor(() => expect(screen.getByText(/DeleteServerModal/)).toHaveTextContent(/Open/));
|
await waitFor(() => expect(screen.getByText(/DeleteServerModal/)).toHaveTextContent(/Open/));
|
||||||
});
|
});
|
||||||
|
|
|
@ -57,7 +57,9 @@ describe('<ImportServersBtn />', () => {
|
||||||
const { container } = setUp();
|
const { container } = setUp();
|
||||||
const input = container.querySelector('[type=file]');
|
const input = container.querySelector('[type=file]');
|
||||||
|
|
||||||
input && fireEvent.change(input, { target: { files: [''] } });
|
if (input) {
|
||||||
|
fireEvent.change(input, { target: { files: [''] } });
|
||||||
|
}
|
||||||
expect(importServersFromFile).toHaveBeenCalledTimes(1);
|
expect(importServersFromFile).toHaveBeenCalledTimes(1);
|
||||||
await waitFor(() => expect(createServersMock).toHaveBeenCalledTimes(1));
|
await waitFor(() => expect(createServersMock).toHaveBeenCalledTimes(1));
|
||||||
});
|
});
|
||||||
|
@ -73,7 +75,9 @@ describe('<ImportServersBtn />', () => {
|
||||||
importServersFromFile.mockResolvedValue([existingServer, newServer]);
|
importServersFromFile.mockResolvedValue([existingServer, newServer]);
|
||||||
|
|
||||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
||||||
input && fireEvent.change(input, { target: { files: [''] } });
|
if (input) {
|
||||||
|
fireEvent.change(input, { target: { files: [''] } });
|
||||||
|
}
|
||||||
await waitFor(() => expect(screen.getByRole('dialog')).toBeInTheDocument());
|
await waitFor(() => expect(screen.getByRole('dialog')).toBeInTheDocument());
|
||||||
await user.click(screen.getByRole('button', { name: btnName }));
|
await user.click(screen.getByRole('button', { name: btnName }));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue