Skip to content

Commit

Permalink
feat(dashboard): dashboard card preview
Browse files Browse the repository at this point in the history
  • Loading branch information
tthvo committed Apr 6, 2023
1 parent d0f7ac9 commit b309e40
Show file tree
Hide file tree
Showing 14 changed files with 374 additions and 157 deletions.
32 changes: 24 additions & 8 deletions src/app/Dashboard/AddCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
*/
import { CardConfig } from '@app/Shared/Redux/Configurations/DashboardConfigSlice';
import { dashboardConfigAddCardIntent, StateDispatch } from '@app/Shared/Redux/ReduxStore';
import { ServiceContext } from '@app/Shared/Services/Services';
import { EmptyText } from '@app/Topology/Shared/EmptyText';
import QuickSearchIcon from '@app/Topology/Shared/QuickSearchIcon';
import { QuickSearchButton } from '@app/Topology/Toolbar/QuickSearchButton';
import { fakeServices } from '@app/utils/fakeData';
import { useFeatureLevel } from '@app/utils/useFeatureLevel';
import { useSubscriptions } from '@app/utils/useSubscriptions';
import { portalRoot } from '@app/utils/utils';
Expand Down Expand Up @@ -211,15 +212,15 @@ export const AddCard: React.FC<AddCardProps> = ({ variant, ..._props }) => {
default:
return null;
}
}, [handleStart, t]);
}, [handleStart, t, variant]);

return (
<>
{content}
<Modal
aria-label="Dashboard Card Catalog Modal"
isOpen={showWizard}
width={'80%'}
width={'90%'}
hasNoBodyWrapper
showClose={false}
>
Expand Down Expand Up @@ -254,7 +255,7 @@ export const AddCard: React.FC<AddCardProps> = ({ variant, ..._props }) => {
<StackItem>
<Text>{t('Dashboard.ADD_CARD_HELPER_TEXT')}</Text>
</StackItem>
<StackItem isFilled>
<StackItem isFilled style={{ overflow: 'auto' }}>
<CardGallery selection={selection} onSelect={handleSelect} />
</StackItem>
</Stack>
Expand Down Expand Up @@ -321,7 +322,13 @@ export const CardGallery: React.FC<CardGalleryProps> = ({ selection, onSelect })
key={title}
hasSelectableInput
isSelectableRaised
onClick={(event) => onSelect(event, t(title))}
onClick={(event) => {
if (selection === t(title)) {
setToViewCard(availableCards.find((card) => t(card.title) === selection));
} else {
onSelect(event, t(title));
}
}}
isFullHeight
isFlat
isSelected={selection === t(title)}
Expand Down Expand Up @@ -361,13 +368,13 @@ export const CardGallery: React.FC<CardGalleryProps> = ({ selection, onSelect })
}
const { title, icon, labels, preview } = toViewCard;
return (
<DrawerPanelContent isResizable defaultSize="300px">
<DrawerPanelContent isResizable defaultSize="50%">
<DrawerHead>
<DrawerActions>
<DrawerCloseButton onClick={() => setToViewCard(undefined)} />
</DrawerActions>
</DrawerHead>
<DrawerPanelBody>
<DrawerPanelBody className="card-catalog__detail-panel-body">
<Stack hasGutter>
<StackItem>
<Flex spacer={{ default: 'spacerSm' }}>
Expand All @@ -391,7 +398,16 @@ export const CardGallery: React.FC<CardGalleryProps> = ({ selection, onSelect })
<StackItem>{getFullDescription(t(toViewCard.title), t)}</StackItem>
<StackItem isFilled>
{preview ? (
preview
<div className="dashboard-card-preview">
<div
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
}}
className="non-interactive-overlay"
/>
<ServiceContext.Provider value={fakeServices}>{preview}</ServiceContext.Provider>
</div>
) : (
<Bullseye>
<EmptyText text={'No preview'} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,4 +969,5 @@ export const AutomatedAnalysisCardDescriptor: DashboardCardDescriptor = {
color: 'blue',
},
],
preview: <AutomatedAnalysisCard span={12} dashboardId={0} isDraggable={false} isResizable={false} />,
};
47 changes: 1 addition & 46 deletions src/app/Dashboard/Charts/jfr/JFRMetricsChartController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { SettingsService } from '@app/Shared/Services/Settings.service';
import { NO_TARGET, Target, TargetService } from '@app/Shared/Services/Target.service';
import {
BehaviorSubject,
catchError,
concatMap,
distinctUntilChanged,
finalize,
Expand Down Expand Up @@ -151,50 +150,6 @@ export class JFRMetricsChartController {
if (target === NO_TARGET) {
return of(false);
}

return this._api
.graphql<CountResponse>(
`
query ActiveRecordingsForAutomatedAnalysis($connectUrl: String) {
targetNodes(filter: { name: $connectUrl }) {
recordings {
active (filter: {
labels: ["origin=${RECORDING_NAME}"],
state: "RUNNING",
}) {
aggregate {
count
}
}
}
}
}`,
{ connectUrl: target.connectUrl }
)
.pipe(
map((resp) => {
const nodes = resp.data.targetNodes;
if (nodes.length === 0) {
return false;
}
const count = nodes[0].recordings.active.aggregate.count;
return count > 0;
}),
catchError((_) => of(false))
);
return this._api.targetHasRecording(target, RECORDING_NAME);
}
}

interface CountResponse {
data: {
targetNodes: {
recordings: {
active: {
aggregate: {
count: number;
};
};
};
}[];
};
}
13 changes: 13 additions & 0 deletions src/app/Dashboard/Charts/mbean/MBeanMetricsChartCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -569,4 +569,17 @@ export const MBeanMetricsChartCardDescriptor: DashboardCardDescriptor = {
color: 'blue',
},
],
preview: (
<MBeanMetricsChartCard
themeColor={'blue'}
chartKind={chartKinds[0].displayName}
duration={60}
period={10}
span={12}
isFullHeight
isDraggable={false}
isResizable={false}
dashboardId={0}
/>
),
};
27 changes: 2 additions & 25 deletions src/app/Dashboard/Charts/mbean/MBeanMetricsChartController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,18 @@
* SOFTWARE.
*/

import { ApiService, MBeanMetrics, MBeanMetricsResponse } from '@app/Shared/Services/Api.service';
import { ApiService, MBeanMetrics } from '@app/Shared/Services/Api.service';
import { SettingsService } from '@app/Shared/Services/Settings.service';
import { Target, TargetService } from '@app/Shared/Services/Target.service';
import {
BehaviorSubject,
catchError,
concatMap,
distinctUntilChanged,
finalize,
first,
map,
merge,
Observable,
of,
pairwise,
ReplaySubject,
Subject,
Expand Down Expand Up @@ -164,27 +162,6 @@ export class MBeanMetricsChartController {
l += '}';
q.push(l);
});
return this._api
.graphql<MBeanMetricsResponse>(
`
query MBeanMXMetricsForTarget($connectUrl: String) {
targetNodes(filter: { name: $connectUrl }) {
mbeanMetrics {
${q.join('\n')}
}
}
}`,
{ connectUrl: target.connectUrl }
)
.pipe(
map((resp) => {
const nodes = resp.data.targetNodes;
if (!nodes || nodes.length === 0) {
return {};
}
return nodes[0]?.mbeanMetrics;
}),
catchError((_) => of({}))
);
return this._api.getTargetMBeanMetrics(target, q);
}
}
1 change: 0 additions & 1 deletion src/app/Dashboard/DashboardCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export const DashboardCard: React.FC<DashboardCardProps> = ({
isDraggable = true,
isResizable = true,
cardSizes,

...props
}: DashboardCardProps) => {
const cardRef = React.useRef<HTMLDivElement>(null);
Expand Down
2 changes: 1 addition & 1 deletion src/app/Dashboard/DashboardLayoutConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import {
ToolbarItem,
} from '@patternfly/react-core';
import { Dropdown } from '@patternfly/react-core/dist/js/next';
import { DownloadIcon, PencilAltIcon, PlusCircleIcon, TrashIcon, UploadIcon } from '@patternfly/react-icons';
import { DownloadIcon, PencilAltIcon, TrashIcon, UploadIcon } from '@patternfly/react-icons';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
Expand Down
7 changes: 3 additions & 4 deletions src/app/Dashboard/JvmDetails/JvmDetailsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,10 @@ export const JvmDetailsCard: React.FC<JvmDetailsCardProps> = (props) => {
<CardActions>{...props.actions || []}</CardActions>
</CardHeader>
}
style={{ height: '36em' }} // FIXME: Remove after implementing height resizing
{...props}
>
<CardBody
// FIXME: Remove after implementing height resizing
style={{ height: '36em' }}
>
<CardBody>
<EntityDetails entity={wrappedTarget} actionFilter={actionFilter} />
</CardBody>
</DashboardCard>
Expand Down Expand Up @@ -131,4 +129,5 @@ export const JvmDetailsCardDescriptor: DashboardCardDescriptor = {
color: 'blue',
},
],
preview: <JvmDetailsCard span={12} isDraggable={false} isFullHeight={false} isResizable={false} dashboardId={0} />,
};
Loading

0 comments on commit b309e40

Please sign in to comment.