Skip to content

Commit

Permalink
Update branch, removed differenceInDays
Browse files Browse the repository at this point in the history
  • Loading branch information
doracretu3pillar committed Oct 1, 2024
1 parent ba80109 commit e171ae7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { useSelector } from 'app/types';

import { Messages } from './PerconaUpdateVersion.constants';
import { getStyles } from './PerconaUpdateVersion.styles';
import { PMM_UPDATES_LINK } from 'app/percona/shared/components/PerconaBootstrapper/PerconaNavigation';

const PerconaUpdateVersion: FC = () => {
const { updateAvailable, installed, latest, changeLogs, lastChecked, snoozeCurrentVersion } =
Expand All @@ -24,25 +25,14 @@ const PerconaUpdateVersion: FC = () => {
const styles = useStyles2(getStyles);

useEffect(() => {
const differenceInDays = () => {
if (lastChecked) {
const lastCheckDate = new Date(lastChecked);
const currentDate = new Date();
const differenceInMilliseconds = currentDate.getTime() - lastCheckDate.getTime();
return Math.trunc(differenceInMilliseconds / (1000 * 60 * 60 * 24));
} else {
return 7;
}
};

const prepareModal = async () => {
if (!snoozeCurrentVersion) {
await dispatch(getSnoozeCurrentVersion());
}
const days = differenceInDays();

if (
(installed?.version !== latest?.version &&
days > 6 &&
snoozeCurrentVersion?.snoozedPmmVersion !== latest?.version) ||
!lastChecked
) {
Expand Down Expand Up @@ -72,6 +62,12 @@ const PerconaUpdateVersion: FC = () => {
setShowUpdate(false);
};

const onUpdateClick = () => {
setShowUpdate(false);
const baseUrl = `${window.location.protocol}//${window.location.hostname}${window.location.port ? `:${window.location.port}` : ''}`;
window.location.href = baseUrl + PMM_UPDATES_LINK.url;
}

return (
<>
<Modal
Expand All @@ -92,7 +88,7 @@ const PerconaUpdateVersion: FC = () => {
{Messages.snooze}
</Button>
<Button type="button" variant="primary">
<a href="/pmm-ui/updates">{Messages.goToUpdatesPage}</a>
<a onClick={onUpdateClick}>{Messages.goToUpdatesPage}</a>
</Button>
</div>
</div>
Expand Down Expand Up @@ -121,7 +117,7 @@ const PerconaUpdateVersion: FC = () => {
{Messages.snooze}
</Button>
<Button type="button" variant="primary">
<a href="/pmm-ui/updates">{Messages.goToUpdatesPage}</a>
<a onClick={onUpdateClick}>{Messages.goToUpdatesPage}</a>
</Button>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions public/app/percona/shared/core/reducers/updates/updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const updatesSlice = createSlice({
builder.addCase(checkUpdatesAction.fulfilled, (state, { payload }) => ({
...state,
...payload,
isLoading: false,
}));
builder.addCase(checkUpdatesAction.rejected, (state) => ({
...state,
Expand Down
6 changes: 3 additions & 3 deletions public/app/percona/shared/services/updates/Updates.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {

import { api } from '../../helpers/api';

import { CheckUpdatesBody, CheckUpdatesResponse } from './Updates.types';
import { CheckUpdatesParams, CheckUpdatesResponse } from './Updates.types';

export const UpdatesService = {
getCurrentVersion: (body: CheckUpdatesBody = { force: false }) =>
api.get<CheckUpdatesResponse, CheckUpdatesBody>('/v1/server/updates', true, { params: body }),
getCurrentVersion: (body: CheckUpdatesParams = { force: false }) =>
api.get<CheckUpdatesResponse, CheckUpdatesParams>('/v1/server/updates', true, { params: body }),

getUpdatesChangelogs: () => api.get<CheckUpdatesChangeLogsResponse, void>('/v1/server/updates/changelogs', false),

Expand Down

0 comments on commit e171ae7

Please sign in to comment.