Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console-shared: Introduce RecentEventsBodyContent #3039

Merged
merged 1 commit into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about just adding showTitle prop to original component ?

{showTitle && <div className="co-activity-card__recent-title">Recent events</div>}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my first thought as well. But do we want yet another boolean? In fact, the case here is about composition of components, so splitting these two make more sense to me.

<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