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

Show namespace in list view #40

Merged
merged 1 commit into from
Mar 2, 2020
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
63 changes: 49 additions & 14 deletions src/components/resources/ListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import {
IonButton,
IonButtons,
IonContent,
IonHeader, IonIcon,
IonHeader,
IonIcon,
IonLabel,
IonList,
IonListHeader,
IonMenuButton,
IonPage,
IonProgressBar,
Expand All @@ -13,7 +16,7 @@ import {
isPlatform,
} from '@ionic/react';
import { refresh } from 'ionicons/icons';
import React, {useContext, useEffect, useState} from 'react';
import React, { useContext, useEffect, useState } from 'react';
import { RouteComponentProps } from 'react-router';

import { IContext } from '../../declarations';
Expand All @@ -27,23 +30,36 @@ import NamespacePopover from './misc/NamespacePopover';
interface IMatchParams {
section: string;
type: string;
namespace: string;
name: string;
}

interface IListPageProps extends RouteComponentProps<IMatchParams> {}

// ListPage shows a list of the selected resource. The list can be filtered by namespace and each item contains a status
// indicator, to get an overview of problems in the cluster.
const ListPage: React.FunctionComponent<IListPageProps> = ({ match }) => {
const context = useContext<IContext>(AppContext);

// namespace and showNamespace is used to group all items by namespace and to only show the namespace once via the
// IonListHeader component.
let namespace = '';
let showNamespace = false;

// Determine one which page we are currently (which items for a resource do we want to show) by the section and type
// parameter. Get the component 'ResourceItem' we want to render.
const page = resources[match.params.section].pages[match.params.type];
const Component = page.listItemComponent;

// The error state is used to show error message to the user, when the Kubernetes API request fails. showLoading is
// the indicator the the items are currently loaded/reloaded.
// HACK: url is used to avoid unnecessary rendering. We should try to remove this and test if it is really required in
// the current version. Maybe it's already improved and not needed.
const [error, setError] = useState<string>('');
const [showLoading, setShowLoading] = useState<boolean>(false);
const [items, setItems] = useState<any>();
const [url, setUrl] = useState<string>('');

// When the component is rendered the first time and on every change route change or a modification to the context
// object we are loading all items for the corresponding resource.
useEffect(() => {
(async() => {
setItems(undefined);
Expand All @@ -54,11 +70,16 @@ const ListPage: React.FunctionComponent<IListPageProps> = ({ match }) => {
return () => {};
}, [match, context.clusters, context.cluster]); /* eslint-disable-line */

// The doRefresh method is used for a manual reload of the items for the corresponding resource. The
// event.detail.complete() call is required to finish the animation of the IonRefresher component.
const doRefresh = async (event) => {
event.detail.complete();
await load();
};

// load loads all the items for the corresponding resource. If the clusters or cluster property of the context is
// undefined we are returning an error. If everything is defined we are getting the selected namespace of the current
// cluster and trying to get all the items.
const load = async () => {
setShowLoading(true);

Expand Down Expand Up @@ -103,17 +124,31 @@ const ListPage: React.FunctionComponent<IListPageProps> = ({ match }) => {
{error === '' && context.clusters && context.cluster && context.clusters.hasOwnProperty(context.cluster) ? (
<IonList>
{match.url === url && items ? items.map((item, index) => {
if (isNamespaced(match.params.type) && item.metadata && item.metadata.namespace
&& item.metadata.namespace !== namespace) {
namespace = item.metadata.namespace;
showNamespace = true;
} else {
showNamespace = false;
}

return (
<ItemOptions
key={index}
item={item}
url={page.detailsURL(
item.metadata ? item.metadata.namespace : '',
item.metadata ? item.metadata.name : ''
)}
>
<Component key={index} item={item} section={match.params.section} type={match.params.type} />
</ItemOptions>
<React.Fragment key={index}>
{showNamespace ? (
<IonListHeader>
<IonLabel>{namespace}</IonLabel>
</IonListHeader>
) : null}
<ItemOptions
item={item}
url={page.detailsURL(
item.metadata ? item.metadata.namespace : '',
item.metadata ? item.metadata.name : ''
)}
>
<Component key={index} item={item} section={match.params.section} type={match.params.type} />
</ItemOptions>
</React.Fragment>
)
}) : null}
</IonList>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const CustomResourceItem: React.FunctionComponent<ICustomResourceItemProps> = ({
<IonItem button={true} onClick={() => setShowModal(true)}>
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>Namespace: {item.metadata ? item.metadata.namespace : '-'}</p>
</IonLabel>
</IonItem>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const ConfigMapItem: React.FunctionComponent<IConfigMapItemProps> = ({ item, sec
<IonItem routerLink={`/resources/${section}/${type}/${item.metadata ? item.metadata.namespace : ''}/${item.metadata ? item.metadata.name : ''}`} routerDirection="forward">
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>Namespace: {item.metadata ? item.metadata.namespace : '-'}</p>
</IonLabel>
</IonItem>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const PersistentVolumeClaimItem: React.FunctionComponent<IPersistentVolumeClaimI
<IonItem routerLink={`/resources/${section}/${type}/${item.metadata ? item.metadata.namespace : ''}/${item.metadata ? item.metadata.name : ''}`} routerDirection="forward">
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>Namespace: {item.metadata ? item.metadata.namespace : '-'}{item.status ? ` | Phase: ${item.status.phase}` : ''}{item.status && item.status.capacity ? ` | Capacity: ${item.status.capacity.storage}` : ''}</p>
<p>{item.status ? ` | Phase: ${item.status.phase}` : ''}{item.status && item.status.capacity ? ` | Capacity: ${item.status.capacity.storage}` : ''}</p>
</IonLabel>
</IonItem>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const SecretItem: React.FunctionComponent<ISecretItemProps> = ({ item, section,
<IonItem routerLink={`/resources/${section}/${type}/${item.metadata ? item.metadata.namespace : ''}/${item.metadata ? item.metadata.name : ''}`} routerDirection="forward">
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>Namespace: {item.metadata ? item.metadata.namespace : '-'}</p>
</IonLabel>
</IonItem>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const ServiceAccountItem: React.FunctionComponent<IServiceAccountItemProps> = ({
<IonItem routerLink={`/resources/${section}/${type}/${item.metadata ? item.metadata.namespace : ''}/${item.metadata ? item.metadata.name : ''}`} routerDirection="forward">
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>Namespace: {item.metadata ? item.metadata.namespace : '-'}</p>
</IonLabel>
</IonItem>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const IngressItem: React.FunctionComponent<IIngressItemProps> = ({ item, section
<IonItem routerLink={`/resources/${section}/${type}/${item.metadata ? item.metadata.namespace : ''}/${item.metadata ? item.metadata.name : ''}`} routerDirection="forward">
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>Namespace: {item.metadata ? item.metadata.namespace : '-'}</p>
</IonLabel>
</IonItem>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const ServiceItem: React.FunctionComponent<IServiceItemProps> = ({ item, section
<IonItem routerLink={`/resources/${section}/${type}/${item.metadata ? item.metadata.namespace : ''}/${item.metadata ? item.metadata.name : ''}`} routerDirection="forward">
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>Namespace: {item.metadata ? item.metadata.namespace : '-'}</p>
</IonLabel>
</IonItem>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const RoleBindingItem: React.FunctionComponent<IRoleBindingItemProps> = ({ item,
<IonItem routerLink={`/resources/${section}/${type}/${item.metadata ? item.metadata.namespace : ''}/${item.metadata ? item.metadata.name : ''}`} routerDirection="forward">
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>Namespace: {item.metadata ? item.metadata.namespace : '-'}</p>
</IonLabel>
</IonItem>
)
Expand Down
1 change: 0 additions & 1 deletion src/components/resources/rbac/roles/RoleItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const RoleItem: React.FunctionComponent<IRoleItemProps> = ({ item, section, type
<IonItem routerLink={`/resources/${section}/${type}/${item.metadata ? item.metadata.namespace : ''}/${item.metadata ? item.metadata.name : ''}`} routerDirection="forward">
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>Namespace: {item.metadata ? item.metadata.namespace : '-'}</p>
</IonLabel>
</IonItem>
)
Expand Down
3 changes: 1 addition & 2 deletions src/components/resources/workloads/cronJobs/CronJobItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ const CronJobItem: React.FunctionComponent<ICronJobItemProps> = ({ item, section
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>
Namespace: {item.metadata ? item.metadata.namespace : '-'}
| Last Time Schedule : {item.status && item.status.lastScheduleTime
Last Time Schedule : {item.status && item.status.lastScheduleTime
? timeDifference(new Date().getTime(), new Date(item.status.lastScheduleTime.toString()).getTime()) : '-'}
</p>
</IonLabel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ const DaemonSetItem: React.FunctionComponent<IDaemonSetItemProps> = ({ item, sec
<ItemStatus status={status} />
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>Namespace: {item.metadata ? item.metadata.namespace : '-'}</p>
</IonLabel>
</IonItem>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const DeploymentItem: React.FunctionComponent<IDeploymentItemProps> = ({ item, s
<ItemStatus status={status} />
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>Namespace: {item.metadata ? item.metadata.namespace : '-'}</p>
</IonLabel>
</IonItem>
)
Expand Down
1 change: 0 additions & 1 deletion src/components/resources/workloads/jobs/JobItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const JobItem: React.FunctionComponent<IJobItemProps> = ({ item, section, type }
<ItemStatus status={status} />
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>Namespace: {item.metadata ? item.metadata.namespace : '-'}</p>
</IonLabel>
</IonItem>
)
Expand Down
1 change: 0 additions & 1 deletion src/components/resources/workloads/pods/PodItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const PodItem: React.FunctionComponent<IPodItemProps> = ({ item, section, type }
<ItemStatus status={status} />
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>Namespace: {item.metadata ? item.metadata.namespace : '-'}</p>
</IonLabel>
</IonItem>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const ReplicaSetItem: React.FunctionComponent<IReplicaSetItemProps> = ({ item, s
<ItemStatus status={status} />
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>Namespace: {item.metadata ? item.metadata.namespace : '-'}</p>
</IonLabel>
</IonItem>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const ReplicationControllerItem: React.FunctionComponent<IReplicationControllerI
<ItemStatus status={status} />
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>Namespace: {item.metadata ? item.metadata.namespace : '-'}</p>
</IonLabel>
</IonItem>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const StatefulSetItem: React.FunctionComponent<IStatefulSetItemProps> = ({ item,
<ItemStatus status={status} />
<IonLabel>
<h2>{item.metadata ? item.metadata.name : ''}</h2>
<p>Namespace: {item.metadata ? item.metadata.namespace : '-'}</p>
</IonLabel>
</IonItem>
)
Expand Down