Skip to content

Commit 9241cc3

Browse files
committed
Using useMemo instead of useCallback. Using enum instead of string for getRedeploymentTrigger.
1 parent 184530a commit 9241cc3

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

app/client/src/ce/selectors/applicationSelectors.tsx

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -215,28 +215,32 @@ export const getIsFetchingAppSlugSuggestion = (state: DefaultRootState) =>
215215
export const getAppSlugSuggestion = (state: DefaultRootState) =>
216216
state.ui.applications.appSlugSuggestion;
217217

218-
export const getRedeployApplicationTrigger = (
219-
state: DefaultRootState,
220-
): string | null => {
221-
const currentApplication = getCurrentApplication(state);
218+
export enum RedeployTrigger {
219+
PendingDeployment = "PENDING_DEPLOYMENT",
220+
PendingDeploymentWithPackage = "PENDING_DEPLOYMENT_WITH_PACKAGE",
221+
}
222222

223-
if (!currentApplication?.modifiedAt) {
224-
return null;
225-
}
223+
export const getRedeployApplicationTrigger = createSelector(
224+
getCurrentApplication,
225+
(currentApplication): RedeployTrigger | null => {
226+
if (!currentApplication?.modifiedAt) {
227+
return null;
228+
}
226229

227-
if (!currentApplication?.lastDeployedAt) {
228-
return "PENDING_DEPLOYMENT";
229-
}
230+
if (!currentApplication?.lastDeployedAt) {
231+
return RedeployTrigger.PendingDeployment;
232+
}
230233

231-
const lastDeployedAtMs = new Date(
232-
currentApplication.lastDeployedAt,
233-
).getTime();
234-
const modifiedAtMs = new Date(currentApplication.modifiedAt).getTime();
234+
const lastDeployedAtMs = new Date(
235+
currentApplication.lastDeployedAt,
236+
).getTime();
237+
const modifiedAtMs = new Date(currentApplication.modifiedAt).getTime();
235238

236-
// If modifiedAt is greater than lastDeployedAt by more than 1 second, deployment is needed
237-
if (modifiedAtMs - lastDeployedAtMs > 1000) {
238-
return "PENDING_DEPLOYMENT";
239-
}
239+
// If modifiedAt is greater than lastDeployedAt by more than 1 second, deployment is needed
240+
if (modifiedAtMs - lastDeployedAtMs > 1000) {
241+
return RedeployTrigger.PendingDeployment;
242+
}
240243

241-
return null;
242-
};
244+
return null;
245+
},
246+
);

app/client/src/pages/AppIDE/layouts/components/Header/DeployButton.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
useGitConnected,
2424
useGitModEnabled,
2525
} from "pages/Editor/gitSync/hooks/modHooks";
26-
import React, { useCallback } from "react";
26+
import React, { useCallback, useMemo } from "react";
2727
import { useDispatch, useSelector } from "react-redux";
2828
import {
2929
getCurrentApplicationId,
@@ -50,7 +50,7 @@ function DeployButton() {
5050
const gitStatusState = useArtifactSelector(selectStatusState);
5151
const redeployTrigger = useSelector(getRedeployApplicationTrigger);
5252

53-
const getTooltipText = useCallback(() => {
53+
const tooltipText = useMemo(() => {
5454
if (isPackageUpgrading) {
5555
return createMessage(PACKAGE_UPGRADING_ACTION_STATUS, "deploy this app");
5656
}
@@ -100,7 +100,7 @@ function DeployButton() {
100100
toggleOpsModal,
101101
]);
102102

103-
const getStartIcon = useCallback(() => {
103+
const startIcon = useMemo(() => {
104104
if (isGitConnected && !gitStatusState?.loading) {
105105
const hasPendingCommits =
106106
gitStatusState?.value && !gitStatusState.value.isClean;
@@ -118,7 +118,7 @@ function DeployButton() {
118118
}, [isGitConnected, gitStatusState, redeployTrigger]);
119119

120120
return (
121-
<Tooltip content={getTooltipText()} placement="bottomRight">
121+
<Tooltip content={tooltipText} placement="bottomRight">
122122
<StyledTooltipTarget>
123123
<Button
124124
className="t--application-publish-btn"
@@ -129,7 +129,7 @@ function DeployButton() {
129129
kind="tertiary"
130130
onClick={handleClickDeploy}
131131
size="md"
132-
startIcon={getStartIcon()}
132+
startIcon={startIcon}
133133
>
134134
{createMessage(DEPLOY_MENU_OPTION)}
135135
</Button>

0 commit comments

Comments
 (0)