Skip to content

Commit 46799a2

Browse files
committed
[#629] Add cache delete in cache detail
1 parent abfd1a7 commit 46799a2

File tree

7 files changed

+81
-17
lines changed

7 files changed

+81
-17
lines changed

cypress/e2e/2_cache-detail.cy.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ describe('Cache Detail Overview', () => {
326326
cy.contains('Rebalancing is on');
327327
});
328328

329+
it('successfully displays delete cache modal', () => {
330+
cy.get('[data-cy=detailCacheActions]').click();
331+
cy.get("[data-cy=manageDeleteLink]").click();
332+
cy.get('#deleteCacheModal').should('exist');
333+
})
334+
329335
function verifyGet(keyType, key, value) {
330336
// Going back to cache entries page
331337
cy.get('[data-cy=cacheEntriesTab]').click();

cypress/e2e/3_cache-crud-wizard.cy.js

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ describe('Cache Creation Wizard', () => {
211211
deleteCache('aSimpleCache');
212212
});
213213

214-
it('successfully creates without a template a XML config', () => {
214+
it.only('successfully creates without a template a XML config', () => {
215215
//go to create cache page
216216
cy.get('[data-cy=createCacheButton]').click();
217217
cy.get('#cache-name').click();
@@ -242,26 +242,43 @@ describe('Cache Creation Wizard', () => {
242242
cy.get('[data-cy="statusInfo-clusterManager"]').should('exist');
243243
cy.get('[data-cy=rebalancingSwitch]').should('exist');
244244
cy.contains('aSimpleXmlCache');
245-
deleteCache('aSimpleXmlCache');
245+
deleteCache('aSimpleXmlCache', true);
246246
});
247247

248-
function deleteCache(cacheName) {
249-
cy.login(Cypress.env('username'), Cypress.env('password'));
250-
cy.get(`[data-cy=actions-${cacheName}]`).click();
251-
cy.get('[aria-label=deleteCacheAction]').click();
248+
function deleteCache(cacheName, isDetailPage) {
249+
if (isDetailPage) {
250+
cy.login(Cypress.env('username'), Cypress.env('password'), `/cache/${cacheName}`);
251+
cy.get('[data-cy=detailCacheActions]').click();
252+
cy.get("[data-cy=manageDeleteLink]").click();
253+
} else {
254+
cy.login(Cypress.env('username'), Cypress.env('password'));
255+
cy.get(`[data-cy=actions-${cacheName}]`).click();
256+
cy.get('[aria-label=deleteCacheAction]').click();
257+
}
258+
252259
cy.get('#deleteCacheModal').should('exist');
253260
cy.contains('Permanently delete cache?');
254261
cy.get('#deleteCacheModal [aria-label=Close]').click(); //Closing modal with close button
255262
cy.contains('Permanently delete cache?').should('not.exist');
256263

257-
cy.get(`[data-cy=actions-${cacheName}]`).click();
258-
cy.get('[aria-label=deleteCacheAction]').click();
264+
if (isDetailPage) {
265+
cy.get('[data-cy=detailCacheActions]').click();
266+
cy.get("[data-cy=manageDeleteLink]").click();
267+
} else {
268+
cy.get(`[data-cy=actions-${cacheName}]`).click();
269+
cy.get('[aria-label=deleteCacheAction]').click();
270+
}
259271
cy.contains('Permanently delete cache?');
260272
cy.get('[data-cy=cancelCacheDeleteButton]').click(); //Closing modal with Cancel button
261273
cy.contains('Permanently delete cache?').should('not.exist');
262274

263-
cy.get(`[data-cy=actions-${cacheName}]`).click();
264-
cy.get('[aria-label=deleteCacheAction]').click();
275+
if (isDetailPage) {
276+
cy.get('[data-cy=detailCacheActions]').click();
277+
cy.get("[data-cy=manageDeleteLink]").click();
278+
} else {
279+
cy.get(`[data-cy=actions-${cacheName}]`).click();
280+
cy.get('[aria-label=deleteCacheAction]').click();
281+
}
265282
cy.get('#cache-to-delete').click();
266283
cy.get('#cache-to-delete').type(cacheName);
267284
cy.get('[data-cy=deleteCacheButton]').click(); //Deleting cache aCache

src/app/Caches/DetailCache.tsx

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ import {
4444
ExclamationCircleIcon,
4545
InfoCircleIcon,
4646
PencilAltIcon,
47-
RedoIcon
47+
RedoIcon,
48+
TrashIcon
4849
} from '@patternfly/react-icons';
4950
import { QueryEntries } from '@app/Caches/Query/QueryEntries';
5051
import { Link } from 'react-router-dom';
@@ -60,6 +61,7 @@ import { TracingEnabled } from '@app/Common/TracingEnabled';
6061
import { InfinispanComponentStatus } from '@app/Common/InfinispanComponentStatus';
6162
import { PageHeader } from '@patternfly/react-component-groups';
6263
import { UpdateAliasCache } from '@app/Caches/UpdateAliasCache';
64+
import { DeleteCache } from '@app/Caches/DeleteCache';
6365

6466
const DetailCache = (props: { cacheName: string }) => {
6567
const cacheName = props.cacheName;
@@ -71,6 +73,7 @@ const DetailCache = (props: { cacheName: string }) => {
7173
const [activeTabKey1, setActiveTabKey1] = useState<number | string>('');
7274
const [activeTabKey2, setActiveTabKey2] = useState<number | string>(10);
7375
const [isOpen, setIsOpen] = useState(false);
76+
const [isOpenDelete, setIsOpenDelete] = useState(false);
7477
const [cacheAction, setCacheAction] = useState<string>('');
7578
const isAdmin = ConsoleServices.security().hasConsoleACL(ConsoleACL.ADMIN, connectedUser);
7679
const isCacheReader = ConsoleServices.security().hasCacheConsoleACL(ConsoleACL.READ, cacheName, connectedUser);
@@ -209,6 +212,10 @@ const DetailCache = (props: { cacheName: string }) => {
209212
return cache && cache?.features?.indexed;
210213
};
211214

215+
const displayDelete = () => {
216+
return isAdmin && cache;
217+
};
218+
212219
const displayEditConfigManage = () => {
213220
return isAdmin && cache;
214221
};
@@ -296,6 +303,25 @@ const DetailCache = (props: { cacheName: string }) => {
296303
);
297304
};
298305

306+
const buildDelete = () => {
307+
if (!displayDelete()) return;
308+
309+
return (
310+
<DropdownItem
311+
value={'deleteCache'}
312+
key="manageDeleteLink"
313+
data-cy="manageDeleteLink"
314+
icon={<TrashIcon />}
315+
onClick={(ev) => {
316+
setIsOpenDelete(true);
317+
setIsOpen(false);
318+
}}
319+
>
320+
{t('caches.actions.action-delete')}
321+
</DropdownItem>
322+
);
323+
};
324+
299325
const buildRefresh = () => {
300326
return (
301327
<React.Fragment>
@@ -460,6 +486,7 @@ const DetailCache = (props: { cacheName: string }) => {
460486
{buildIndexManage()}
461487
{buildBackupsManage()}
462488
{buildRefresh()}
489+
{buildDelete()}
463490
</DropdownList>
464491
</Dropdown>
465492
</ToolbarItem>
@@ -513,6 +540,20 @@ const DetailCache = (props: { cacheName: string }) => {
513540
)}
514541
{buildDetailContent()}
515542
</PageSection>
543+
<DeleteCache
544+
cacheName={cacheName}
545+
isModalOpen={isOpenDelete}
546+
closeModal={(deleteDone: boolean) => {
547+
if (deleteDone) {
548+
navigate({
549+
pathname: '/',
550+
search: location.search
551+
});
552+
} else {
553+
setIsOpenDelete(false);
554+
}
555+
}}
556+
/>
516557
<UpdateAliasCache
517558
cacheName={cacheName}
518559
isModalOpen={cacheAction == 'aliases'}

src/app/Common/SelectMultiWithChips.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ const SelectMultiWithChips = (props: {
213213
props.onClear();
214214
textInputRef?.current?.focus();
215215
}}
216-
aria-label="Clear input value" id="clearInput"
216+
aria-label="Clear input value"
217+
id="clearInput"
217218
>
218219
<TimesIcon aria-hidden />
219220
</Button>

src/app/assets/languages/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,7 @@
589589
"action-manage-tracing": "Manage tracing",
590590
"action-manage-backups": "Manage backups",
591591
"action-manage-config": "Edit configuration",
592+
"action-delete": "Delete",
592593
"refresh": "Refresh",
593594
"back": "Back"
594595
},

src/app/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ const App = () => {
2525
ConsoleServices.init();
2626
}
2727
// Base is coming from index.html, and can dynamically change in prod with a reverse proxy
28-
const base =
29-
document.querySelector('base')?.getAttribute('href')?.replace(/\/$/, '') || '/';
30-
28+
const base = document.querySelector('base')?.getAttribute('href')?.replace(/\/$/, '') || '/';
3129

3230
return (
3331
<Router basename={base == '{{INFINISPAN_BASE_PATH}}' ? '/console' : base}>

src/services/ConsoleServices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export class ConsoleServices {
5050
return process.env.INFINISPAN_SERVER_URL + '/rest/v2';
5151
}
5252
} else {
53-
const x = (window as any);
54-
return window.location.origin.toString() + (x.INFINISPAN_CONFIG?.restContextPath || '/rest') + '/v2';
53+
const x = window as any;
54+
return window.location.origin.toString() + (x.INFINISPAN_CONFIG?.restContextPath || '/rest') + '/v2';
5555
}
5656
}
5757

0 commit comments

Comments
 (0)