Skip to content
Snippets Groups Projects
Commit 12d7f114 authored by Max Frederiksen's avatar Max Frederiksen Committed by Max Frederiksen
Browse files

Add typing /hooks + /icons + /style + /types

parent ce3e8fd9
No related branches found
No related tags found
2 merge requests!612Release 5.0.0,!590CE-3429: Convert to typescript
import { useEffect, useRef } from "react";
function useMountEffect(effect, deps = [], afterMount) {
const didMountRef = useRef(false);
useEffect(() => {
let cleanup;
if (didMountRef.current === afterMount) {
cleanup = effect();
}
didMountRef.current = true;
return cleanup;
// eslint-disable-next-line
}, deps);
}
export function useEffectOnMount(effect) {
useMountEffect(effect, [], false);
}
export function useEffectAfterMount(effect, deps) {
useMountEffect(effect, deps, true);
}
...@@ -6,7 +6,7 @@ export function useRedirect() { ...@@ -6,7 +6,7 @@ export function useRedirect() {
const navigate = useNavigate(); const navigate = useNavigate();
// const history = useHistory(); // const history = useHistory();
const redirect = useCallback( const redirect = useCallback(
(destination, state, replace = false) => { (destination: string, state: object, replace: boolean = false) => {
/* const method = replace ? history.replace : history.push; /* const method = replace ? history.replace : history.push;
method(destination, { ...state, from: history.location.pathname });*/ method(destination, { ...state, from: history.location.pathname });*/
navigate(destination, { replace: replace, state: state }); navigate(destination, { replace: replace, state: state });
......
import { useState } from "react"; import { useState, type KeyboardEvent } from "react";
export function useTypingTimer({ init = "", interval = 750 } = {}) { interface UseTypingTimerReturn {
const [typingTimer, setTypingTimer] = useState(); value: string;
onKeyUp: (event: KeyboardEvent<HTMLInputElement>) => void;
}
export function useTypingTimer({
init = "",
interval = 750
} = {}): UseTypingTimerReturn {
const [typingTimer, setTypingTimer] = useState<number | undefined>(undefined);
const [value, setValue] = useState(init); const [value, setValue] = useState(init);
const doneTypingInterval = interval; // ms const doneTypingInterval = interval; // ms
const onKeyUp = (event) => { const onKeyUp = (event: KeyboardEvent<HTMLInputElement>): void => {
const { target, key } = event; const target = event.target as HTMLInputElement;
const { key } = event;
clearTimeout(typingTimer); clearTimeout(typingTimer);
if (key === "Enter") { if (key === "Enter") {
setValue(target.value); setValue(target.value);
...@@ -20,5 +29,5 @@ export function useTypingTimer({ init = "", interval = 750 } = {}) { ...@@ -20,5 +29,5 @@ export function useTypingTimer({ init = "", interval = 750 } = {}) {
} }
}; };
return [value, onKeyUp]; return { value, onKeyUp };
} }
import BatchDeployIcon from "./resources/batch/batch_deploy_icon.svg?react"; import { ComponentProps } from "react";
import BatchDeployIconSvg from "./resources/batch/batch_deploy_icon.svg?react";
import { BatchDeployIcon } from "../components/Job/JobIcons";
export function BatchDeploySymbol(props) { export function BatchDeploySymbol(
return <BatchDeployIcon {...props} />; props: ComponentProps<typeof BatchDeployIcon>
) {
return <BatchDeployIconSvg {...props} />;
} }
import BatchUndeployIcon from "./resources/batch/batch_undeploy_icon.svg?react"; import { type ComponentProps } from "react";
import BatchUndeployIconSvg from "./resources/batch/batch_undeploy_icon.svg?react";
import { BatchUndeployIcon } from "../components/Job/JobIcons";
export function BatchUndeploySymbol(props) { export function BatchUndeploySymbol(
return <BatchUndeployIcon {...props} />; props: ComponentProps<typeof BatchUndeployIcon>
) {
return <BatchUndeployIconSvg {...props} />;
} }
import CcceControlSymbolGray from "./resources/control/ccce-control-symbol_757575.svg?react"; import CcceControlSymbolGray from "./resources/control/ccce-control-symbol_757575.svg?react";
export function CCCEControlSymbol(props) { export function CCCEControlSymbol(props: { width: string; height: string }) {
return <CcceControlSymbolGray {...props} />; return <CcceControlSymbolGray {...props} />;
} }
import { Tooltip } from "@mui/material";
import { ReactComponent as RocketLaunchBlack } from "./resources/rocket/rocket_launch_black_24dp.svg?react";
export function RocketLaunch(props) {
return (
<Tooltip title="Deployment">
<RocketLaunchBlack {...props} />
</Tooltip>
);
}
...@@ -17,6 +17,13 @@ declare module "@mui/material/styles" { ...@@ -17,6 +17,13 @@ declare module "@mui/material/styles" {
disabled: { disabled: {
main: string; main: string;
}; };
icons: string;
};
error: {
main: string;
};
warning: {
main: string;
}; };
primary: { primary: {
inconsistency: string; inconsistency: string;
......
...@@ -47,3 +47,25 @@ export interface ApiResult<T> { ...@@ -47,3 +47,25 @@ export interface ApiResult<T> {
export type FormElements<U extends string> = HTMLFormControlsCollection & export type FormElements<U extends string> = HTMLFormControlsCollection &
Record<U, HTMLInputElement>; Record<U, HTMLInputElement>;
export interface Pagination {
page: number;
rows: number;
query?: string;
orderAsc?: boolean;
totalCount?: number;
rowsPerPageOptions?: number[];
}
export interface DeployIocFormDefaults {
name: string;
description: string;
git: string;
gitProjectId?: number;
reference?: string;
short_reference?: string;
netBoxHost?: {
fqdn: string;
hostId: string;
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment