Skip to content

Commit

Permalink
Merge pull request #3039 from mareklibra/vmActivityCardTitle
Browse files Browse the repository at this point in the history
console-shared: Introduce RecentEventsBodyContent
  • Loading branch information
openshift-merge-robot committed Oct 23, 2019
2 parents f3875ca + 9a873da commit b4aea52
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Activity: React.FC<ActivityProps> = ({ timestamp, children }) => (
</div>
);

export const RecentEventsBody: React.FC<RecentEventsBodyProps> = ({ events, filter }) => {
export const RecentEventsBodyContent: React.FC<RecentEventsBodyProps> = ({ events, filter }) => {
const [expanded, setExpanded] = React.useState([]);
const onToggle = React.useCallback(
(uid: string) => {
Expand All @@ -46,42 +46,45 @@ export const RecentEventsBody: React.FC<RecentEventsBodyProps> = ({ events, filt
[isExpanded, onToggle],
);

let eventsBody: React.ReactNode;
if (events && events.loadError) {
eventsBody = <ErrorLoadingEvents />;
} else if (!(events && events.loaded)) {
eventsBody = <div className="skeleton-activity" />;
} else {
const filteredEvents = filter ? events.data.filter(filter) : events.data;
const sortedEvents = _.orderBy(filteredEvents, ['lastTimestamp', 'name'], ['desc', 'asc']);
eventsBody =
filteredEvents.length === 0 ? (
<Activity>
<div className="text-secondary">There are no recent events.</div>
</Activity>
) : (
<Accordion
asDefinitionList={false}
headingLevel="h5"
className="co-activity-card__recent-accordion"
>
<EventStreamList
className="co-activity-card__recent-list"
events={sortedEvents}
EventComponent={eventItem}
scrollableElementId="activity-body"
/>
</Accordion>
);
return <ErrorLoadingEvents />;
}
if (!(events && events.loaded)) {
return <div className="skeleton-activity" />;
}

const filteredEvents = filter ? events.data.filter(filter) : events.data;
const sortedEvents = _.orderBy(filteredEvents, ['lastTimestamp', 'name'], ['desc', 'asc']);
if (filteredEvents.length === 0) {
return (
<Activity>
<div className="text-secondary">There are no recent events.</div>
</Activity>
);
}
return (
<>
<div className="co-activity-card__recent-title">Recent events</div>
{eventsBody}
</>
<Accordion
asDefinitionList={false}
headingLevel="h5"
className="co-activity-card__recent-accordion"
>
<EventStreamList
className="co-activity-card__recent-list"
events={sortedEvents}
EventComponent={eventItem}
scrollableElementId="activity-body"
/>
</Accordion>
);
};

export const RecentEventsBody: React.FC<RecentEventsBodyProps> = (props) => (
<>
<div className="co-activity-card__recent-title">Recent events</div>
<RecentEventsBodyContent {...props} />
</>
);

export const OngoingActivityBody: React.FC<OngoingActivityBodyProps> = ({
loaded,
resourceActivities = [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DashboardCardHeader from '@console/shared/src/components/dashboard/dashbo
import DashboardCardLink from '@console/shared/src/components/dashboard/dashboard-card/DashboardCardLink';
import DashboardCardTitle from '@console/shared/src/components/dashboard/dashboard-card/DashboardCardTitle';
import ActivityBody, {
RecentEventsBody,
RecentEventsBodyContent,
} from '@console/shared/src/components/dashboard/activity-card/ActivityBody';
import { getName, getNamespace } from '@console/shared';
import { resourcePath, FirehoseResource, FirehoseResult } from '@console/internal/components/utils';
Expand Down Expand Up @@ -43,7 +43,7 @@ const RecentEvent = withDashboardResources(
return null;
}, [watchK8sResource, stopWatchK8sResource, vm]);
return (
<RecentEventsBody
<RecentEventsBodyContent
events={resources.events as FirehoseResult<EventKind[]>}
filter={combinedVmFilter(vm)}
/>
Expand Down

0 comments on commit b4aea52

Please sign in to comment.