Skip to content

Commit

Permalink
ISPN-15762 cleanup cache manager use
Browse files Browse the repository at this point in the history
  • Loading branch information
karesti committed Feb 28, 2024
1 parent b75315e commit 7cc0034
Show file tree
Hide file tree
Showing 26 changed files with 83 additions and 182 deletions.
6 changes: 3 additions & 3 deletions cypress/e2e/1_cluster-welcome.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Welcome page', () => {
it('successfully logs in and logs out', () => {
cy.login(Cypress.env('username'), Cypress.env('password'));

cy.contains('Default'); // cluster name
cy.contains('Data container');
cy.contains('Running'); // cluster status
cy.contains('Cluster rebalancing on'); // rebalancing status
cy.contains('15 Caches');
Expand All @@ -35,7 +35,7 @@ describe('Welcome page', () => {
it('successfully opens and navigates side menu', () => {
cy.login(Cypress.env('username'), Cypress.env('password'));

cy.contains('Default'); // cluster name
cy.contains('Data container');
cy.contains('Running'); // cluster status

//Checks if navigation menu is hidden
Expand Down Expand Up @@ -63,7 +63,7 @@ describe('Welcome page', () => {

//Clicks the Data Container link and should go to Data Container page
cy.contains('Data Container').click();
cy.contains('Default').should('be.visible');
cy.contains('Data container').should('be.visible');
cy.contains('Running'); // cluster status
cy.contains('Cluster rebalancing on'); // rebalancing status
});
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/1_data-container.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Data Container Overview', () => {

//Data Container Overview
it('successfully loads Data Container Overview', () => {
cy.contains('Default'); // cluster name
cy.contains('Data container');
cy.contains('Running'); // cluster status
cy.contains('Cluster rebalancing on'); // rebalancing status
cy.get('#cluster-manager-header').should('exist');
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/1_global-stats.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('Global stats', () => {
//click View all caches should navigate to console page
cy.get('[data-cy="viewCachesLink"]').click();
//Verify that page is properly loaded after click;
cy.contains('Default'); // cluster name
cy.contains('Data container');
cy.contains('Running'); // cluster status
cy.contains('Cluster rebalancing on'); // rebalancing status
cy.contains('default'); // cache default
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/1_rbac_func.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('RBAC Functionality Tests', () => {

function checkDataContainerView(isMonitor, isDeployer, isAdmin, isSuperAdmin) {
//Checking Data Container view
cy.contains('Default'); // cluster name
cy.contains('Data container'); // cluster name
cy.contains('Running'); // cluster status
if (isSuperAdmin) {
cy.get('[data-cy=rebalancingSwitch]').should('exist'); // rebalancing status
Expand Down
36 changes: 6 additions & 30 deletions src/__tests__/views/caches/IgnoreCache.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,7 @@ mockedCacheHook.useUndoIgnoreCache.mockImplementation(() => {
describe('Ignore/Hide cache', () => {
test('not render the dialog if the modal is closed', () => {
renderWithRouter(
<IgnoreCache
cmName={'cm-1'}
cacheName={'cache-1'}
isModalOpen={false}
closeModal={() => closeModalCalls++}
action="ignore"
/>
<IgnoreCache cacheName={'cache-1'} isModalOpen={false} closeModal={() => closeModalCalls++} action="ignore" />
);
expect(screen.queryByRole('modal')).toBeNull();
expect(closeModalCalls).toBe(0);
Expand All @@ -48,16 +42,10 @@ describe('Ignore/Hide cache', () => {

test('render the dialog and buttons work', () => {
renderWithRouter(
<IgnoreCache
cmName={'cm-1'}
cacheName={'cache-1'}
isModalOpen={true}
closeModal={() => closeModalCalls++}
action="ignore"
/>
<IgnoreCache cacheName={'cache-1'} isModalOpen={true} closeModal={() => closeModalCalls++} action="ignore" />
);

expect(mockedCacheHook.useIgnoreCache).toHaveBeenCalledWith('cm-1', 'cache-1');
expect(mockedCacheHook.useIgnoreCache).toHaveBeenCalledWith('cache-1');

expect(screen.queryByRole('modal')).toBeDefined();
expect(screen.queryAllByRole('button')).toHaveLength(3);
Expand All @@ -77,13 +65,7 @@ describe('Ignore/Hide cache', () => {
describe('Undo hide cache', () => {
test('not render the dialog if the modal is closed', () => {
renderWithRouter(
<IgnoreCache
cmName={'cm-1'}
cacheName={'cache-1'}
isModalOpen={false}
closeModal={() => closeModalCalls++}
action="undo"
/>
<IgnoreCache cacheName={'cache-1'} isModalOpen={false} closeModal={() => closeModalCalls++} action="undo" />
);
expect(screen.queryByRole('modal')).toBeNull();
expect(closeModalCalls).toBe(0);
Expand All @@ -93,16 +75,10 @@ describe('Undo hide cache', () => {

test('render the dialog and buttons work', () => {
renderWithRouter(
<IgnoreCache
cmName={'cm-1'}
cacheName={'cache-1'}
isModalOpen={true}
closeModal={() => closeModalCalls++}
action="undo"
/>
<IgnoreCache cacheName={'cache-1'} isModalOpen={true} closeModal={() => closeModalCalls++} action="undo" />
);

expect(mockedCacheHook.useIgnoreCache).toHaveBeenCalledWith('cm-1', 'cache-1');
expect(mockedCacheHook.useIgnoreCache).toHaveBeenCalledWith('cache-1');

expect(screen.queryByRole('modal')).toBeDefined();
expect(screen.queryAllByRole('button')).toHaveLength(3);
Expand Down
16 changes: 13 additions & 3 deletions src/app/About/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
TextList,
TextListItem,
TextListItemVariants,
TextListVariants
TextListVariants,
Spinner
} from '@patternfly/react-core';
import icon from '!!url-loader!@app/assets/favicons/ms-icon-310x310.png';
import backgroundImage from '!!url-loader!@app/assets/images/infinispanbg_1200.png';
Expand All @@ -29,12 +30,13 @@ import { global_spacer_lg } from '@patternfly/react-tokens';
import { useFetchVersion } from '@app/services/serverHook';
import { useTranslation } from 'react-i18next';
import './About.css';
import { useEffect } from 'react';

const About = (props: { isModalOpen: boolean; closeModal: () => void }) => {
const { t } = useTranslation();
const brandname = t('brandname.brandname');

const { version } = useFetchVersion();
const { version, loading, setLoading } = useFetchVersion();

const infinispanGithubLink = 'https://github.com/infinispan/';
const infinispanZulipLink = 'https://infinispan.zulipchat.com/';
Expand All @@ -46,6 +48,12 @@ const About = (props: { isModalOpen: boolean; closeModal: () => void }) => {
const license = t('welcome-page.license', { brandname: brandname });
const apacheLicense = t('welcome-page.apache-license');

useEffect(() => {
if (props.isModalOpen) {
setLoading(true);
}
}, [props.isModalOpen]);

return (
<AboutModal
isOpen={props.isModalOpen}
Expand Down Expand Up @@ -74,7 +82,9 @@ const About = (props: { isModalOpen: boolean; closeModal: () => void }) => {
<TextContent>
<TextList component={TextListVariants.dl}>
<TextListItem component={TextListItemVariants.dt}>Version</TextListItem>
<TextListItem component={TextListItemVariants.dd}>{version}</TextListItem>
<TextListItem component={TextListItemVariants.dd}>
{loading ? <Spinner size={'sm'} /> : version}
</TextListItem>
</TextList>
</TextContent>
</StackItem>
Expand Down
7 changes: 2 additions & 5 deletions src/app/CacheManagers/CacheManagers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const CacheManagers = () => {
const [showTasks, setShowTasks] = useState(false);
const [showSerializationContext, setShowSerializationContext] = useState(false);
const { t } = useTranslation();
const brandname = t('brandname.brandname');

const handleTabClick = (nav) => {
const tabIndex = nav.itemId;
Expand Down Expand Up @@ -131,7 +130,7 @@ const CacheManagers = () => {

return (
<React.Fragment>
{cm && <CacheTableDisplay cmName={cm.name} setCachesCount={setCachesCount} isVisible={showCaches} />}
{cm && <CacheTableDisplay setCachesCount={setCachesCount} isVisible={showCaches} />}
{cm && <CounterTableDisplay setCountersCount={setCountersCount} isVisible={showCounters} />}
{cm && ConsoleServices.security().hasConsoleACL(ConsoleACL.ADMIN, connectedUser) && (
<TasksTableDisplay setTasksCount={setTasksCount} isVisible={showTasks} />
Expand All @@ -157,7 +156,7 @@ const CacheManagers = () => {
};

const buildHeader = () => {
let title = t('cache-managers.title');
const title = t('cache-managers.title');
if (!cm) {
return (
<PageSection variant={PageSectionVariants.light}>
Expand All @@ -172,8 +171,6 @@ const CacheManagers = () => {
);
}

title = displayUtils.capitalize(cm.name);

return (
<PageSection variant={PageSectionVariants.light} style={{ paddingBottom: 0 }}>
<Toolbar id="cluster-manager-header">
Expand Down
5 changes: 2 additions & 3 deletions src/app/CacheManagers/CacheTableDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ interface CacheAction {
action: '' | 'ignore' | 'undo' | 'delete' | 'available';
}

const CacheTableDisplay = (props: { cmName: string; setCachesCount: (count: number) => void; isVisible: boolean }) => {
const CacheTableDisplay = (props: { setCachesCount: (count: number) => void; isVisible: boolean }) => {
const { t } = useTranslation();
const { connectedUser } = useConnectedUser();
const { setBanner } = useBanner();
Expand Down Expand Up @@ -466,7 +466,7 @@ const CacheTableDisplay = (props: { cmName: string; setCachesCount: (count: numb
const cacheTemplateButton = (
<Link
to={{
pathname: '/container/' + props.cmName + '/configurations/',
pathname: '/container/configurations/',
search: location.search
}}
>
Expand Down Expand Up @@ -810,7 +810,6 @@ const CacheTableDisplay = (props: { cmName: string; setCachesCount: (count: numb
closeModal={closeDeleteModal}
/>
<IgnoreCache
cmName={props.cmName}
cacheName={cacheAction.cacheName}
isModalOpen={cacheAction.action == 'ignore' || cacheAction.action == 'undo'}
action={cacheAction.action}
Expand Down
3 changes: 1 addition & 2 deletions src/app/Caches/Configuration/DetailConfigurations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ import { useParams } from 'react-router-dom';

const DetailConfigurations = () => {
const { t } = useTranslation();
const cmName = useParams()['cmName'] as string;
const { cacheTemplates, loading, error } = useFetchCacheTemplates(cmName);
const { cacheTemplates, loading, error } = useFetchCacheTemplates();
const [filteredTemplates, setFilteredTemplates] = useState<CacheConfig[]>([]);
const [rows, setRows] = useState<CacheConfig[]>([]);
const [expandedTemplateNames, setExpandedRepoNames] = useState<string[]>([]);
Expand Down
4 changes: 1 addition & 3 deletions src/app/Caches/Create/CacheConfigEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { selectOptionPropsFromArray } from '@utils/selectOptionPropsCreator';
import { TableEmptyState } from '@app/Common/TableEmptyState';

const CacheConfigEditor = (props: {
cmName: string;
cacheEditor: CacheEditorStep;
cacheEditorModifier: (CacheEditorStep) => void;
setReviewConfig: (string) => void;
Expand All @@ -46,7 +45,6 @@ const CacheConfigEditor = (props: {

const { addAlert } = useApiAlert();
const { t } = useTranslation();
const cmName = props.cmName;
const configurationDocs = t('brandname.configuration-docs-link');
const [selectedConfigDisabled, setSelectedConfigDisabled] = useState(false);

Expand All @@ -62,7 +60,7 @@ const CacheConfigEditor = (props: {
useEffect(() => {
if (loading) {
ConsoleServices.dataContainer()
.getCacheConfigurationTemplates(cmName)
.getCacheConfigurationTemplates()
.then((eitherTemplates) => {
if (eitherTemplates.isRight()) {
const options: TemplateOptionSelect[] = [];
Expand Down
2 changes: 0 additions & 2 deletions src/app/Caches/Create/CreateCacheWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const CreateCacheWizard = (props: { cacheManager: CacheManager; create: boolean
});

const [cacheEditor, setCacheEditor] = useState<CacheEditorStep>(CacheEditorInitialState);
const [stepIdReached, setStepIdReached] = useState(1);
const [reviewConfig, setReviewConfig] = useState<string>('');
const [isDownloadModalOpen, setIsDownloadModalOpen] = useState(false);
const canCreateCache = ConsoleServices.security().hasConsoleACL(ConsoleACL.CREATE, connectedUser);
Expand Down Expand Up @@ -211,7 +210,6 @@ const CreateCacheWizard = (props: { cacheManager: CacheManager; create: boolean
<CacheConfigEditor
cacheEditor={cacheEditor}
cacheEditorModifier={setCacheEditor}
cmName={props.cacheManager.name}
setReviewConfig={setReviewConfig}
/>
</WizardStep>
Expand Down
6 changes: 2 additions & 4 deletions src/app/Caches/CreateCache.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const CreateCache = () => {
const [loadingBackups, setLoadingBackups] = useState(true);
const [isBackupAvailable, setIsBackupAvailable] = useState(false);
const [localSite, setLocalSite] = useState('');
const [title, setTitle] = useState('Data container is empty.');
const { connectedUser } = useConnectedUser();
const canCreateCache = ConsoleServices.security().hasConsoleACL(ConsoleACL.CREATE, connectedUser);

Expand All @@ -47,7 +46,6 @@ const CreateCache = () => {
if (r.isRight()) {
const cm = r.value;
setCacheManager(cm);
setTitle(displayUtils.capitalize(displayUtils.capitalize(cm.name)));
setIsBackupAvailable(cm.backups_enabled);
if (cm.backups_enabled && cm.local_site) {
setLocalSite(cm.local_site);
Expand Down Expand Up @@ -92,8 +90,8 @@ const CreateCache = () => {
<TextContent>
<Text component={TextVariants.h1}>
{localSite == ''
? t(`caches.${id}.page-title`, { cmName: title })
: t(`caches.${id}.page-title-with-backups`, { cmName: title, localsite: localSite })}
? t(`caches.${id}.page-title`)
: t(`caches.${id}.page-title-with-backups`, { localsite: localSite })}
</Text>
</TextContent>
</ToolbarContent>
Expand Down
5 changes: 2 additions & 3 deletions src/app/Caches/IgnoreCache.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import { useIgnoreCache, useUndoIgnoreCache } from '@app/services/cachesHook';
* Ignore cache modal
*/
const IgnoreCache = (props: {
cmName: string;
cacheName: string;
isModalOpen: boolean;
closeModal: (boolean) => void;
action: string;
}) => {
const { reloadCaches } = useCaches();
const { onIgnore } = useIgnoreCache(props.cmName, props.cacheName);
const { onUndoIgnore } = useUndoIgnoreCache(props.cmName, props.cacheName);
const { onIgnore } = useIgnoreCache(props.cacheName);
const { onUndoIgnore } = useUndoIgnoreCache(props.cacheName);

const { t } = useTranslation();
const brandname = t('brandname.brandname');
Expand Down
2 changes: 1 addition & 1 deletion src/app/GlobalStats/GlobalStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ const GlobalStats = () => {
</PageSection>
<PageSection>{buildStats()}</PageSection>
<ClearMetrics
name={stats.name}
name={'cm'}
isModalOpen={isClearMetricsModalOpen}
closeModal={() => {
reload();
Expand Down
2 changes: 1 addition & 1 deletion src/app/Rebalancing/RebalancingCacheManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const RebalancingCacheManager = () => {
isModalOpen={confirmationModalOpened}
confirmAction={() =>
ConsoleServices.dataContainer()
.rebalancing(cm.name, !cm.rebalancing_enabled)
.rebalancing(!cm.rebalancing_enabled)
.then((r) => {
addAlert(r);
reload();
Expand Down
12 changes: 6 additions & 6 deletions src/app/Welcome/Welcome.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useState } from 'react';
import { useEffect, useState } from 'react';
import {
Alert,
Badge,
Expand Down Expand Up @@ -39,23 +39,23 @@ const Welcome = () => {
const navigate = useNavigate();
const [supportOpen, setSupportOpen] = useState(false);
const { notSecuredModeOn, logUser } = useConnectedUser();
const { version } = useFetchVersion();
const { version, setLoading } = useFetchVersion();

const brandname = t('brandname.brandname');

const description1 = t('welcome-page.description1', { brandname: brandname });
const description2 = t('welcome-page.description2', { brandname: brandname });
const license = t('welcome-page.license');

useEffect(() => {
setLoading(true);
}, []);

const login = () => {
navigate('/');
location.reload();
};

const notSecured = () => {
navigate('/');
};

const goToTheConsole = t('welcome-page.go-to-console');

const buildConsoleButton = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/app/assets/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@
},
"caches": {
"setup": {
"page-title": "Configure a cache in {{cmName}}",
"page-title-with-backups": "Configure a cache in {{cmName}} on site {{localsite}}",
"page-title": "Configure a cache",
"page-title-with-backups": "Configure a cache on site {{localsite}}",
"page-title-description": "You can generate a cache config. Note that the new cache will not be stored by {{brandname}}",
"getting-started": {
"cache-setup-title": "Select a way to configure your cache"
Expand Down
Loading

0 comments on commit 7cc0034

Please sign in to comment.