Skip to content

Commit

Permalink
ESlint with react-hooks/exhaustive-deps (#7482)
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszkp96 authored Jan 22, 2025
1 parent 942db11 commit d4ea5e8
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 47 deletions.
3 changes: 2 additions & 1 deletion designer/client/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@
]
}
],
"react/prop-types": "off"
"react/prop-types": "off",
"react-hooks/exhaustive-deps": "error"
},
"overrides": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExpressionObj } from "../types";
import React, { useEffect, useRef, useState } from "react";
import React, { useCallback, useEffect, useRef, useState } from "react";
import Cron from "react-cron-generator";
import "react-cron-generator/dist/cron-builder.css";
import Input from "../../field/Input";
Expand Down Expand Up @@ -33,9 +33,12 @@ export const CronEditor: ExtendedEditor<Props> = (props: Props) => {

const cronFormatter = formatter == null ? typeFormatters[FormatterType.Cron] : formatter;

function encode(value) {
return value == "" ? "" : cronFormatter.encode(value);
}
const encode = useCallback(
(value: string): string => {
return value === "" ? "" : cronFormatter.encode(value);
},
[cronFormatter],
);

function decode(expression: string): CronExpression {
const result = cronFormatter.decode(expression);
Expand Down Expand Up @@ -65,7 +68,7 @@ export const CronEditor: ExtendedEditor<Props> = (props: Props) => {

useEffect(() => {
onValueChange(encode(value));
}, [value]);
}, [encode, onValueChange, value]);

const onInputFocus = () => {
if (!readOnly) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,25 @@ function useAliasUsageHighlight(token = "alias") {
[session, token],
);

const toggleClassname = useCallback(
debounce(
(classname: string, enabled: boolean): void => {
const el = ref.current?.refEditor;

if (el) {
if (!enabled) {
el.className = el.className.replace(classname, "");
const toggleClassname = useMemo(
() =>
debounce(
(classname: string, enabled: boolean): void => {
const el = ref.current?.refEditor;

if (el) {
if (!enabled) {
el.className = el.className.replace(classname, "");
}

if (!el.className.includes(classname)) {
el.className = cx(el.className, { [classname]: enabled });
}
}

if (!el.className.includes(classname)) {
el.className = cx(el.className, { [classname]: enabled });
}
}
},
1000,
{ trailing: true, leading: true },
),
},
1000,
{ trailing: true, leading: true },
),
[],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function AdhocTestingDialog(props: WindowContentProps<WindowKind, AdhocTestingDa
disabled: !isValid,
},
];
}, [close, confirm, isValid, view.cancelText, view.confirmText, t]);
}, [close, confirm, isValid, t]);

return (
<WindowContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function useActivityHistory(processName: string, processingMode: string):
return res;
})
.then(setActivities);
}, [t, processName]);
}, [t, processName, processingMode]);

return activities;
}
6 changes: 2 additions & 4 deletions designer/client/src/components/modals/DeployProcessDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { css, cx } from "@emotion/css";
import { WindowButtonProps, WindowContentProps } from "@touk/window-manager";
import React, { useCallback, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { useDispatch, useSelector } from "react-redux";
import { useSelector } from "react-redux";
import { getProcessName } from "../../reducers/selectors/graph";
import { getFeatureSettings } from "../../reducers/selectors/settings";
import { ProcessName } from "../Process/types";
Expand All @@ -28,16 +28,14 @@ export function DeployProcessDialog(props: WindowContentProps<WindowKind, Toggle
const featureSettings = useSelector(getFeatureSettings);
const deploymentCommentSettings = featureSettings.deploymentCommentSettings;

const dispatch = useDispatch();

const confirmAction = useCallback(async () => {
try {
await action(processName, comment);
props.close();
} catch (error) {
setValidationError(error?.response?.data);
}
}, [action, comment, dispatch, processName, props]);
}, [action, comment, processName, props]);

const { t } = useTranslation();
const buttons: WindowButtonProps[] = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function useStateToggleWithReset(resetCondition: boolean, initialState = false):

useEffect(() => {
if (resetCondition) setFlag(initialState);
}, [resetCondition]);
}, [initialState, resetCondition]);

const toggle = useCallback(() => setFlag((state) => !state), []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function MigrateButton(props: Props) {
confirmText: t("panels.actions.process-migrate.yes", "Yes"),
denyText: t("panels.actions.process-migrate.no", "No"),
}),
[confirm, processName, t, targetEnvironmentId, versionId],
[confirm, dispatch, processName, t, targetEnvironmentId, versionId],
);

if (isEmpty(featuresSettings?.remoteEnvironment)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function AdvancedSearchFilters({
return new Set(
componentsGroups.flatMap((componentGroup) => componentGroup.components).map((component) => component.label.toLowerCase()),
);
}, []);
}, [componentsGroups]);

const nodeTypes = useMemo(() => {
const availableTypes = allNodes
Expand All @@ -60,12 +60,12 @@ export function AdvancedSearchFilters({
.filter((type) => componentLabels.has(type.toLowerCase()));

return uniq(availableTypes);
}, [allNodes]);
}, [allNodes, componentLabels]);

useEffect(() => {
const searchQuery = resolveSearchQuery(filter);
setFilterFields(searchQuery);
}, [filter]);
}, [filter, setFilterFields]);

const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
Expand Down
2 changes: 1 addition & 1 deletion designer/client/src/components/toolbars/search/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function useFilteredNodes(searchQuery: SearchQuery): {
}
})
.filter(({ groups }) => groups.length),
[displayNames, allEdges, searchQuery, allNodes],
[allNodes, allEdges, displayNames, isSimpleSearch, searchQuery],
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ export const useErrorRegister = () => {
});

apm.setCustomContext({ nuApiVersion: buildInfo.version, nuUiVersion: __BUILD_VERSION__ });
}, [buildInfo?.version]);
}, [areErrorReportsEnabled, buildInfo?.version, environment]);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { debounce } from "lodash";
import httpService from "../../http/HttpService";
import { useCallback } from "react";
import { useCallback, useMemo } from "react";
import { getEventStatisticName } from "./helpers";
import { useSelector } from "react-redux";
import { getFeatureSettings } from "../../reducers/selectors/settings";
Expand All @@ -12,17 +12,17 @@ export const useEventTracking = () => {
const featuresSettings = useSelector(getFeatureSettings);
const areStatisticsEnabled = featuresSettings.usageStatisticsReports.enabled;

const trackEvent = async (trackEventParams: TrackEventParams) => {
if (!areStatisticsEnabled) {
return;
}
await httpService.sendStatistics([{ name: getEventStatisticName(trackEventParams) }]);
};

const trackEventWithDebounce = useCallback(
debounce((event: TrackEventParams) => trackEvent(event), 1500),
[],
const trackEvent = useCallback(
async (trackEventParams: TrackEventParams) => {
if (!areStatisticsEnabled) {
return;
}
await httpService.sendStatistics([{ name: getEventStatisticName(trackEventParams) }]);
},
[areStatisticsEnabled],
);

const trackEventWithDebounce = useMemo(() => debounce((event: TrackEventParams) => trackEvent(event), 1500), [trackEvent]);

return { trackEvent, trackEventWithDebounce };
};

0 comments on commit d4ea5e8

Please sign in to comment.