Skip to content

Commit

Permalink
ISPN-16529 Display entries with all encodings
Browse files Browse the repository at this point in the history
  • Loading branch information
karesti committed Sep 9, 2024
1 parent caab808 commit 768637a
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 79 deletions.
60 changes: 5 additions & 55 deletions src/app/Caches/DetailCache.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as React from 'react';
import { useContext, useEffect, useState } from 'react';
import {
Alert,
AlertActionLink,
AlertVariant,
Button,
ButtonVariant,
Expand Down Expand Up @@ -49,7 +47,6 @@ import { DataContainerBreadcrumb } from '@app/Common/DataContainerBreadcrumb';
import {
global_BackgroundColor_100,
global_danger_color_200,
global_info_color_100,
global_info_color_200,
global_warning_color_100
} from '@patternfly/react-tokens';
Expand All @@ -62,8 +59,6 @@ import { ConsoleACL } from '@services/securityService';
import { useConnectedUser } from '@app/services/userManagementHook';
import { useTranslation } from 'react-i18next';
import { RebalancingCache } from '@app/Rebalancing/RebalancingCache';
import { CacheConfigUtils } from '@services/cacheConfigUtils';
import { EncodingType } from '@services/infinispanRefData';
import { ThemeContext } from '@app/providers/ThemeProvider';
import { useNavigate } from 'react-router';
import { TracingEnabled } from '@app/Common/TracingEnabled';
Expand All @@ -74,8 +69,6 @@ const DetailCache = (props: { cacheName: string }) => {
const { t } = useTranslation();
const navigate = useNavigate();
const { theme } = useContext(ThemeContext);
const brandname = t('brandname.brandname');
const encodingDocs = t('brandname.encoding-docs-link');
const { connectedUser } = useConnectedUser();
const { loading, error, cache, cacheManager, loadCache } = useCacheDetail();
const [activeTabKey1, setActiveTabKey1] = useState<number | string>('');
Expand All @@ -100,55 +93,13 @@ const DetailCache = (props: { cacheName: string }) => {
}
}, [cache]);

const encodingMessageDisplay = () => {
const buildEntriesTabContent = () => {
if (!ConsoleServices.security().hasCacheConsoleACL(ConsoleACL.READ, cacheName, connectedUser)) {
return '';
}
const encodingKey = CacheConfigUtils.toEncoding(cache.encoding.key);
const encodingValue = CacheConfigUtils.toEncoding(cache.encoding.value);
if (
encodingKey == EncodingType.Java ||
encodingKey == EncodingType.JBoss ||
encodingValue == EncodingType.Java ||
encodingValue == EncodingType.JBoss
) {
return (
<Card isCompact>
<CardBody>
<Alert
isPlain
isInline
title={t('caches.configuration.pojo-encoding', {
brandname: brandname,
encodingKey: encodingKey,
encodingValue: encodingValue
})}
variant={AlertVariant.info}
actionLinks={
<AlertActionLink onClick={() => window.open(encodingDocs, '_blank')}>
{t('caches.configuration.encoding-docs-message')}
</AlertActionLink>
}
/>
</CardBody>
</Card>
);
}
return '';
};

const buildEntriesTabContent = (queryable: boolean) => {
if (!ConsoleServices.security().hasCacheConsoleACL(ConsoleACL.READ, cacheName, connectedUser)) {
return '';
}

if (!queryable) {
return (
<React.Fragment>
{encodingMessageDisplay()}
<CacheEntries cacheName={cacheName} />
</React.Fragment>
);
if (!cache.queryable) {
return <CacheEntries />;
}

return (
Expand All @@ -166,8 +117,7 @@ const DetailCache = (props: { cacheName: string }) => {
title={<TabTitleText>{t('caches.tabs.entries-manage')}</TabTitleText>}
data-cy="manageEntriesTab"
>
{encodingMessageDisplay()}
<CacheEntries cacheName={cacheName} />
<CacheEntries />
</Tab>
<Tab eventKey={11} data-cy="queriesTab" title={<TabTitleText>{t('caches.tabs.query-values')}</TabTitleText>}>
<QueryEntries cacheName={cacheName} changeTab={() => setActiveTabKey1(2)} />
Expand Down Expand Up @@ -221,7 +171,7 @@ const DetailCache = (props: { cacheName: string }) => {
}

if (activeTabKey1 == 0) {
return buildEntriesTabContent(cache.queryable);
return buildEntriesTabContent();
}

if (activeTabKey1 == 1) {
Expand Down
85 changes: 69 additions & 16 deletions src/app/Caches/Entries/CacheEntries.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React, { useContext, useEffect, useState } from 'react';
import {
Alert,
AlertActionLink,
AlertVariant,
Bullseye,
Button,
ButtonVariant,
Expand All @@ -24,7 +27,7 @@ import {
ToolbarToggleGroup,
Tooltip
} from '@patternfly/react-core';
import { ActionsColumn, IAction, Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table';
import { ActionsColumn, Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table';
import { FilterIcon, HelpIcon, PlusCircleIcon, SearchIcon } from '@patternfly/react-icons';
import { global_spacer_md, global_spacer_sm } from '@patternfly/react-tokens';
import SyntaxHighlighter from 'react-syntax-highlighter';
Expand All @@ -35,15 +38,15 @@ import { ConsoleServices } from '@services/ConsoleServices';
import { useConnectedUser } from '@app/services/userManagementHook';
import { ConsoleACL } from '@services/securityService';
import { CacheConfigUtils } from '@services/cacheConfigUtils';
import { ContentType, EncodingType, StorageType } from '@services/infinispanRefData';
import { ContentType, EncodingType } from '@services/infinispanRefData';
import { CreateOrUpdateEntryForm } from '@app/Caches/Entries/CreateOrUpdateEntryForm';
import { ClearAllEntries } from '@app/Caches/Entries/ClearAllEntries';
import { DeleteEntry } from '@app/Caches/Entries/DeleteEntry';
import { ThemeContext } from '@app/providers/ThemeProvider';
import { SelectSingle } from '@app/Common/SelectSingle';
import { selectOptionProps, selectOptionPropsFromArray } from '@utils/selectOptionPropsCreator';

const CacheEntries = (props: { cacheName: string }) => {
const CacheEntries = () => {
const {
cacheEntries,
totalEntriesCount,
Expand All @@ -59,6 +62,7 @@ const CacheEntries = (props: { cacheName: string }) => {
const { connectedUser } = useConnectedUser();
const { t } = useTranslation();
const brandname = t('brandname.brandname');
const encodingDocs = t('brandname.encoding-docs-link');
const [isCreateOrUpdateEntryFormOpen, setCreateOrUpdateEntryFormOpen] = useState<boolean>(false);
const [isDeleteEntryModalOpen, setDeleteEntryModalOpen] = useState<boolean>(false);
const [keyToDelete, setKeyToDelete] = useState<string>('');
Expand Down Expand Up @@ -138,18 +142,29 @@ const CacheEntries = (props: { cacheName: string }) => {
return <Td></Td>;
}

const actions = [
{
const actions = [];
if (cache.updateEntry) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
actions.push({
'aria-label': 'editEntryAction',
title: t('caches.entries.action-edit'),
onClick: () => onClickEditEntryButton(row.key, row.keyContentType as ContentType)
},
{
});
}
if (cache.deleteEntry) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
actions.push({
'aria-label': 'deleteEntryAction',
title: t('caches.entries.action-delete'),
onClick: () => onClickDeleteEntryButton(row.key, row.keyContentType as ContentType)
}
];
});
}

if (actions.length == 0) {
return undefined;
}

return (
<Td isActionCell data-cy={`actions-${row.key}`}>
Expand Down Expand Up @@ -379,8 +394,50 @@ const CacheEntries = (props: { cacheName: string }) => {
return entry.expires ? entry.expires : t('caches.entries.never-expire');
};

const encodingMessageDisplay = () => {
if (!ConsoleServices.security().hasCacheConsoleACL(ConsoleACL.READ, cache.name, connectedUser)) {
return '';
}
const encodingKey = CacheConfigUtils.toEncoding(cache.encoding.key);
const encodingValue = CacheConfigUtils.toEncoding(cache.encoding.value);
if (
encodingKey == EncodingType.Java ||
encodingKey == EncodingType.JavaSerialized ||
encodingKey == EncodingType.JBoss ||
encodingKey == EncodingType.Octet ||
encodingValue == EncodingType.Java ||
encodingValue == EncodingType.JavaSerialized ||
encodingValue == EncodingType.JBoss ||
encodingValue == EncodingType.Octet
) {
return (
<Card isCompact>
<CardBody>
<Alert
isPlain
isInline
title={t('caches.configuration.pojo-encoding', {
brandname: brandname,
encodingKey: encodingKey,
encodingValue: encodingValue
})}
variant={AlertVariant.info}
actionLinks={
<AlertActionLink onClick={() => window.open(encodingDocs, '_blank')}>
{t('caches.configuration.encoding-docs-message')}
</AlertActionLink>
}
/>
</CardBody>
</Card>
);
}
return '';
};

return (
<React.Fragment>
{encodingMessageDisplay()}
{totalEntriesCount == 0 ? (
emptyPage
) : (
Expand Down Expand Up @@ -481,26 +538,22 @@ const CacheEntries = (props: { cacheName: string }) => {
</React.Fragment>
)}
<CreateOrUpdateEntryForm
cacheName={props.cacheName}
cacheName={cache.name}
cacheEncoding={cache.encoding}
keyToEdit={keyToEdit}
keyContentType={keyContentTypeToEdit}
isModalOpen={isCreateOrUpdateEntryFormOpen}
closeModal={closeCreateOrEditEntryFormModal}
/>
<DeleteEntry
cacheName={props.cacheName}
cacheName={cache.name}
cacheEncoding={cache.encoding}
entryKey={keyToDelete}
keyContentType={keyContentTypeToEdit}
isModalOpen={isDeleteEntryModalOpen}
closeModal={closeDeleteEntryModal}
/>
<ClearAllEntries
cacheName={props.cacheName}
isModalOpen={isClearAllModalOpen}
closeModal={closeClearAllEntryModal}
/>
<ClearAllEntries cacheName={cache.name} isModalOpen={isClearAllModalOpen} closeModal={closeClearAllEntryModal} />
</React.Fragment>
);
};
Expand Down
37 changes: 30 additions & 7 deletions src/services/cacheConfigUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,42 @@ export class CacheConfigUtils {
}

/**
* Retrieve if an encoding is editable or not
* Retrieve if an encoding can display entries
*
* @param encoding
*/
public static isEditable(encoding: EncodingType): boolean {
public static canUpdateEntries(encoding: EncodingType): boolean {
return (
encoding == EncodingType.Text ||
encoding == EncodingType.JSON ||
encoding == EncodingType.XML ||
encoding == EncodingType.Protobuf
);
}

/**
* Retrieve if an encoding can display entries
*
* @param encoding
*/
public static canDeleteEntries(encoding: EncodingType): boolean {
return (
encoding != EncodingType.Empty &&
encoding != EncodingType.Unknown &&
encoding != EncodingType.JavaSerialized &&
encoding != EncodingType.Octet
encoding == EncodingType.Text ||
encoding == EncodingType.JSON ||
encoding == EncodingType.XML ||
encoding == EncodingType.Protobuf
);
}

/**
* Retrieve if an encoding is editable or not
*
* @param encoding
*/
public static isEditable(encoding: EncodingType): boolean {
return encoding != EncodingType.Empty && encoding != EncodingType.Unknown;
}

/**
* Map accepted content types to encoding
*
Expand Down Expand Up @@ -186,7 +209,7 @@ export class CacheConfigUtils {
contentTypes.push(ContentType.XML);
} else if (encodingType == EncodingType.JSON) {
contentTypes.push(ContentType.JSON);
} else if (encodingType == EncodingType.Text) {
} else {
contentTypes.push(ContentType.StringContentType);
}

Expand Down
6 changes: 5 additions & 1 deletion src/services/cacheService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export class CacheService {
data.indexed ||
(CacheConfigUtils.isEditable(keyValueEncoding.key as EncodingType) &&
CacheConfigUtils.isEditable(keyValueEncoding.value as EncodingType)),
updateEntry: CacheConfigUtils.canUpdateEntries(keyValueEncoding.key as EncodingType),
deleteEntry: CacheConfigUtils.canDeleteEntries(keyValueEncoding.key as EncodingType),
queryable: data.queryable,
features: <Features>{
bounded: data.bounded,
Expand Down Expand Up @@ -311,7 +313,9 @@ export class CacheService {
customHeaders.append('Accept', 'application/xml');
} else if (
(encoding.value as EncodingType) == EncodingType.JSON ||
(encoding.value as EncodingType) == EncodingType.Protobuf
(encoding.value as EncodingType) == EncodingType.Protobuf ||
(encoding.value as EncodingType) == EncodingType.JavaSerialized ||
(encoding.value as EncodingType) == EncodingType.Java
) {
customHeaders.append('Accept', 'application/json');
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/types/InfinispanTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ interface DetailedInfinispanCache {
indexing_in_progress?: boolean;
rebalancing_enabled?: boolean;
editable: boolean;
updateEntry: boolean;
deleteEntry: boolean;
queryable: boolean;
features: Features;
backupSites?: [XSite];
Expand Down

0 comments on commit 768637a

Please sign in to comment.