Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMM-12910: Popup new version available #776

Merged
merged 25 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
70bc6bf
PerconaUpdateVersion added to the PerconaBootstrapper
doracretu3pillar Sep 19, 2024
72994e7
Added services for getting the changelogs and snooze updates
doracretu3pillar Sep 23, 2024
6af32cd
Updated updates service , reducer and dispatching logic
doracretu3pillar Sep 24, 2024
a862d3e
Added mocks for checkUpdatesChangelogs, dateTimeFormat and styled but…
doracretu3pillar Sep 24, 2024
426669f
Adding styles to the jsx , renamed CheckUpdatesChangelogsPayload, moc…
doracretu3pillar Sep 25, 2024
48505fe
Removed async from differenceInDays since it's redundant
doracretu3pillar Sep 25, 2024
4ee8491
Added tests for PerconaUpdateVersion
doracretu3pillar Sep 28, 2024
99df116
Fixed eslint
doracretu3pillar Sep 30, 2024
f4025a1
Fixed test PerconaUpdateVersion.test.tsx
doracretu3pillar Sep 30, 2024
0deb249
Added type to mocked store
doracretu3pillar Sep 30, 2024
ba80109
Added types to store
doracretu3pillar Sep 30, 2024
e171ae7
Update branch, removed differenceInDays
doracretu3pillar Oct 1, 2024
01782b3
Fixes after PR reviews
doracretu3pillar Oct 1, 2024
2e27eaa
Added spy for fetchUserDetailsAction
doracretu3pillar Oct 2, 2024
b7aa94a
Fixed prettier and lint
doracretu3pillar Oct 2, 2024
4a970bf
Adding mapper to the API response
doracretu3pillar Oct 2, 2024
7b2adc0
Removed unused parameters
doracretu3pillar Oct 2, 2024
f280f83
Changed the unique key for lists
doracretu3pillar Oct 2, 2024
d4f81fb
Added test that checks the functionality of the snooze button
doracretu3pillar Oct 2, 2024
3ac0b5d
Show tour after showUpdate becames false
doracretu3pillar Oct 3, 2024
5442bb5
Merge branch 'v3' into PMM-12910-popup-new-version-available
doracretu3pillar Oct 4, 2024
110314e
Check showUpdateModal that is set in the state, updated css and test
doracretu3pillar Oct 7, 2024
bd2eb5c
Check timestamp
doracretu3pillar Oct 9, 2024
e5e527f
Fixed comma after version
doracretu3pillar Oct 9, 2024
4f8871a
Merge branch 'v3' into PMM-12910-popup-new-version-available
doracretu3pillar Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {
fetchUserStatusAction,
setAuthorized,
} from 'app/percona/shared/core/reducers/user/user';
import { getUpdatesInfo } from 'app/percona/shared/core/selectors';
import { useAppDispatch } from 'app/store/store';
import { useSelector } from 'app/types';

import { Telemetry } from '../../../ui-events/components/Telemetry';
import usePerconaTour from '../../core/hooks/tour';
Expand All @@ -27,11 +29,14 @@ import { getStyles } from './PerconaBootstrapper.styles';
import { PerconaBootstrapperProps } from './PerconaBootstrapper.types';
import PerconaNavigation from './PerconaNavigation/PerconaNavigation';
import PerconaTourBootstrapper from './PerconaTour';
import PerconaUpdateVersion from './PerconaUpdateVersion/PerconaUpdateVersion';

// This component is only responsible for populating the store with Percona's settings initially
export const PerconaBootstrapper = ({ onReady }: PerconaBootstrapperProps) => {
const dispatch = useAppDispatch();
const { setSteps, startTour: startPerconaTour, endTour } = usePerconaTour();
const [showUpdate, setShowUpdate] = useState(true);
const { updateAvailable } = useSelector(getUpdatesInfo);
const [modalIsOpen, setModalIsOpen] = useState(true);
const [showTour, setShowTour] = useState(false);
const styles = useStyles2(getStyles);
Expand Down Expand Up @@ -104,49 +109,54 @@ export const PerconaBootstrapper = ({ onReady }: PerconaBootstrapperProps) => {
{isSignedIn && <Telemetry />}
<PerconaNavigation />
<PerconaTourBootstrapper />
{isSignedIn && showTour && (
<Modal onDismiss={dismissModal} isOpen={modalIsOpen} title={Messages.title}>
<div className={styles.iconContainer}>
<Icon type="mono" name={theme.isLight ? 'pmm-logo-light' : 'pmm-logo'} className={styles.svg} />
</div>
<p>
<strong>{Messages.pmm}</strong>
{Messages.pmmIs}
</p>
<p>
{Messages.pmmEnables}
<ul className={styles.list}>
<li>{Messages.spotCriticalPerformance}</li>
<li>{Messages.ensureDbPerformance}</li>
<li>{Messages.backup}</li>
</ul>
</p>
<p>
{Messages.moreInfo}
<a
href="https://per.co.na/pmm_documentation"
target="_blank"
rel="noreferrer noopener"
className={styles.docsLink}
>
{Messages.pmmOnlineHelp}
</a>
.
</p>
<HorizontalGroup justify="center" spacing="md">
<Button onClick={startTour} size="lg" className={styles.callToAction}>
{Messages.startTour}
</Button>
</HorizontalGroup>
<HorizontalGroup justify="flex-end" spacing="md">
<Button variant="secondary" onClick={finishTour}>
{Messages.skip}
</Button>
<Button variant="secondary" onClick={() => setModalIsOpen(false)}>
{Messages.checkLater}
</Button>
</HorizontalGroup>
</Modal>
{updateAvailable && showUpdate ? (
matejkubinec marked this conversation as resolved.
Show resolved Hide resolved
<PerconaUpdateVersion showUpdate={showUpdate} setShowUpdate={setShowUpdate} />
) : (
isSignedIn &&
showTour && (
<Modal onDismiss={dismissModal} isOpen={modalIsOpen} title={Messages.title}>
<div className={styles.iconContainer}>
<Icon type="mono" name={theme.isLight ? 'pmm-logo-light' : 'pmm-logo'} className={styles.svg} />
</div>
<p>
<strong>{Messages.pmm}</strong>
{Messages.pmmIs}
</p>
<p>
{Messages.pmmEnables}
<ul className={styles.list}>
<li>{Messages.spotCriticalPerformance}</li>
<li>{Messages.ensureDbPerformance}</li>
<li>{Messages.backup}</li>
</ul>
</p>
<p>
{Messages.moreInfo}
<a
href="https://per.co.na/pmm_documentation"
target="_blank"
rel="noreferrer noopener"
className={styles.docsLink}
>
{Messages.pmmOnlineHelp}
</a>
.
</p>
<HorizontalGroup justify="center" spacing="md">
<Button onClick={startTour} size="lg" className={styles.callToAction}>
{Messages.startTour}
</Button>
</HorizontalGroup>
<HorizontalGroup justify="flex-end" spacing="md">
<Button variant="secondary" onClick={finishTour}>
{Messages.skip}
</Button>
<Button variant="secondary" onClick={() => setModalIsOpen(false)}>
{Messages.checkLater}
</Button>
</HorizontalGroup>
</Modal>
)
)}
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const Messages = {
titleOneUpdate: 'New update available',
titleMultipleUpdates: 'New updates available',
howToUpdate: 'How to update',
howToUpdateDescription:
"We are inaugurating a new process for updating PMM. It's a new interface with an improved user experience and is ready for the future of PMM. Click on Go to Updates Page to find out more.",
newVersions: 'New Versions',
readMore: 'Read more',
fullReleaseNotes: 'Full release notes here',
goToUpdatesPage: 'Go to updates page',
snooze: 'Dismiss',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { css } from '@emotion/css';

import { GrafanaTheme2 } from '@grafana/data';

export const getStyles = ({ v1: { spacing, colors, typography } }: GrafanaTheme2) => ({
updateVersionModal: css`
display: flex;
flex-direction: column;
width: 480px;
height: 343px;
`,
version: css`
margin-bottom: ${spacing.md};
`,
releaseNotesText: css`
a {
color: ${colors.textBlue};
}
`,
newVersionsTitle: css`
font-weight: ${typography.weight.semibold};
font-size: ${typography.heading.h5};
margin-bottom: 8px;
`,
notesTitle: css`
font-weight: ${typography.weight.semibold};
font-size: ${typography.heading.h5};
margin-top: 27px;
`,
updateButtons: css`
margin-top: 35px;
display: flex;
justify-content: flex-end;
`,
snoozeButton: css`
margin-right: 20px;
`,
listOfReleaseNotes: css`
margin-left: 20px;
li a, li {
color: ${colors.textBlue};
},
`,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import { EnhancedStore } from '@reduxjs/toolkit';
import { fireEvent, render, screen } from '@testing-library/react';
import React, { useState } from 'react';
import { Provider } from 'react-redux';
import { waitFor } from 'test/test-utils';

import { Messages } from 'app/percona/shared/components/PerconaBootstrapper/PerconaUpdateVersion/PerconaUpdateVersion.constants';
import * as GrafanaUpdates from 'app/percona/shared/core/reducers/updates/updates';
import * as User from 'app/percona/shared/core/reducers/user/user';
import { UpdatesService } from 'app/percona/shared/services/updates';
import { configureStore } from 'app/store/configureStore';
import { StoreState } from 'app/types';

import PerconaUpdateVersion from './PerconaUpdateVersion';

const checkUpdatesChangeLogsSpy = jest.spyOn(GrafanaUpdates, 'checkUpdatesChangeLogs');
const setSnoozedVersionSpy = jest.spyOn(User, 'setSnoozedVersion');

const PerconaUpdateVersionWithProps = () => {
const [showUpdate, setShowUpdate] = useState(true);
return <PerconaUpdateVersion showUpdate={showUpdate} setShowUpdate={setShowUpdate} />;
};

describe('PerconaUpdateVersion', () => {
matejkubinec marked this conversation as resolved.
Show resolved Hide resolved
doracretu3pillar marked this conversation as resolved.
Show resolved Hide resolved
const setup = (store: EnhancedStore) =>
render(
<Provider store={store}>
<PerconaUpdateVersionWithProps />
</Provider>
);

beforeEach(() => {
jest.clearAllMocks();
});

it('should render modal with one update', async () => {
const changeLogsAPIResponse = {
last_check: '',
updates: [
{
version: 'PMM 3.0.1',
tag: 'string',
timestamp: '2024-09-23T09:12:31.488Z',
release_notes_url: 'http://localhost:3000',
release_notes_text: 'text1',
},
],
};
const state = {
updates: {
isLoading: false,
updateAvailable: true,
latest: { version: '3.0.1' },
lastChecked: '',
},
};
jest.spyOn(UpdatesService, 'getUpdatesChangelogs').mockReturnValue(Promise.resolve({ ...changeLogsAPIResponse }));

const defaultState = configureStore().getState();
const store = configureStore({
...defaultState,
percona: {
...defaultState.percona,
...state,
},
} as StoreState);
setup(store);
await waitFor(() => {
expect(checkUpdatesChangeLogsSpy).toHaveBeenCalled();
});

expect(screen.queryByTestId('one-update-modal')).toBeInTheDocument();
expect(screen.queryByTestId('multiple-updates-modal')).not.toBeInTheDocument();
});

it('should render modal with multiple updates', async () => {
const changeLogsAPIResponse = {
last_check: '',
updates: [
{
version: 'PMM 3.0.1',
tag: 'string',
timestamp: '2024-09-27T09:12:31.488Z',
release_notes_url: 'http://localhost:3000',
release_notes_text: 'text1',
},
{
version: 'PMM 3.0.2',
tag: 'string',
timestamp: '2024-09-23T09:12:31.488Z',
release_notes_url: 'http://localhost:3000',
release_notes_text: 'text2',
},
],
};
const state = {
updates: {
isLoading: false,
updateAvailable: true,
latest: { version: '3.0.1' },
lastChecked: '',
},
};
jest.spyOn(UpdatesService, 'getUpdatesChangelogs').mockReturnValue(Promise.resolve({ ...changeLogsAPIResponse }));

const defaultState = configureStore().getState();
const store = configureStore({
...defaultState,
percona: {
...defaultState.percona,
...state,
},
} as StoreState);

setup(store);
await waitFor(() => {
expect(checkUpdatesChangeLogsSpy).toHaveBeenCalled();
});

expect(screen.queryByTestId('one-update-modal')).not.toBeInTheDocument();
expect(screen.queryByTestId('multiple-updates-modal')).toBeInTheDocument();
});

it('should dispatch setSnoozedVersion when pressing button', async () => {
const changeLogsAPIResponse = {
last_check: '',
updates: [
{
version: 'PMM 3.0.1',
tag: 'string',
timestamp: '2024-09-23T09:12:31.488Z',
release_notes_url: 'http://localhost:3000',
release_notes_text: 'text1',
},
],
};
const state = {
updates: {
isLoading: false,
updateAvailable: true,
latest: { version: '3.0.1' },
lastChecked: '',
},
};
jest.spyOn(UpdatesService, 'getUpdatesChangelogs').mockReturnValue(Promise.resolve({ ...changeLogsAPIResponse }));

const defaultState = configureStore().getState();
const store = configureStore({
...defaultState,
percona: {
...defaultState.percona,
...state,
},
} as StoreState);
setup(store);
await waitFor(() => {
expect(checkUpdatesChangeLogsSpy).toHaveBeenCalled();
});

fireEvent.click(screen.getByRole('button', { name: Messages.snooze }));

await waitFor(() => {
expect(setSnoozedVersionSpy).toHaveBeenCalled();
});
});
});
Loading
Loading