Skip to content

Commit

Permalink
Project list view: Fetch notebooks for projects only on row render
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-phillips-18 committed Sep 27, 2024
1 parent a0d40fd commit d121dd0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
initialProjectsFilterData,
ProjectsFilterDataType,
} from '~/pages/projects/screens/projects/const';
import { useWatchProjectNotebooks } from '~/utilities/useWatchProjectNotebooks';
import { columns } from './tableData';
import DeleteProjectModal from './DeleteProjectModal';
import ManageProjectModal from './ManageProjectModal';
Expand All @@ -30,12 +29,6 @@ const ProjectListView: React.FC<ProjectListViewProps> = ({ allowCreate }) => {
() => setFilterData(initialProjectsFilterData),
[setFilterData],
);
const namespaces = React.useMemo(
() => projects.map((project) => project.metadata.name),
[projects],
);
const [projectNotebooks, loaded] = useWatchProjectNotebooks(namespaces);

const filteredProjects = React.useMemo(
() =>
projects.filter((project) => {
Expand Down Expand Up @@ -72,7 +65,7 @@ const ProjectListView: React.FC<ProjectListViewProps> = ({ allowCreate }) => {
<>
<Table
enablePagination
loading={!loaded}
loading={false}
variant="compact"
defaultSortColumn={0}
data={filteredProjects}
Expand All @@ -84,7 +77,6 @@ const ProjectListView: React.FC<ProjectListViewProps> = ({ allowCreate }) => {
<ProjectTableRow
key={project.metadata.uid}
obj={project}
notebooks={projectNotebooks[project.metadata.name] || []}
isRefreshing={refreshIds.includes(project.metadata.uid || '')}
setEditData={(data) => setEditData(data)}
setDeleteData={(data) => setDeleteData(data)}
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/pages/projects/screens/projects/ProjectTableRow.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import * as React from 'react';
import { Text, TextVariants, Timestamp } from '@patternfly/react-core';
import { Spinner, Text, TextVariants, Timestamp } from '@patternfly/react-core';
import { ActionsColumn, Tbody, Td, Tr } from '@patternfly/react-table';
import { NotebookKind, ProjectKind } from '~/k8sTypes';
import { ProjectKind } from '~/k8sTypes';
import NotebookIcon from '~/images/icons/NotebookIcon';
import useProjectTableRowItems from '~/pages/projects/screens/projects/useProjectTableRowItems';
import { getProjectOwner } from '~/concepts/projects/utils';
import ProjectTableRowNotebookTable from '~/pages/projects/screens/projects/ProjectTableRowNotebookTable';
import { TableRowTitleDescription } from '~/components/table';
import ResourceNameTooltip from '~/components/ResourceNameTooltip';
import { getDescriptionFromK8sResource } from '~/concepts/k8s/utils';
import { useWatchNotebooks } from '~/utilities/useWatchNotebooks';
import ProjectLink from './ProjectLink';

// Plans to add other expandable columns in the future
Expand All @@ -18,14 +19,12 @@ export enum ExpandableColumns {

type ProjectTableRowProps = {
obj: ProjectKind;
notebooks: NotebookKind[];
isRefreshing: boolean;
setEditData: (data: ProjectKind) => void;
setDeleteData: (data: ProjectKind) => void;
};
const ProjectTableRow: React.FC<ProjectTableRowProps> = ({
obj: project,
notebooks,
isRefreshing,
setEditData,
setDeleteData,
Expand All @@ -38,6 +37,7 @@ const ProjectTableRow: React.FC<ProjectTableRowProps> = ({
setEditData,
setDeleteData,
);
const [notebooks, loaded] = useWatchNotebooks(project.metadata.name);

const toggleExpandColumn = (colIndex: ExpandableColumns) => {
setExpandColumn(expandColumn === colIndex ? undefined : colIndex);
Expand Down Expand Up @@ -93,7 +93,7 @@ const ProjectTableRow: React.FC<ProjectTableRowProps> = ({
>
<span>
<NotebookIcon className="pf-v5-u-mr-xs" />
{notebooks.length}
{loaded ? notebooks.length : <Spinner size="sm" />}
</span>
</Td>
<Td
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/utilities/useWatchNotebooks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from 'react';
import useFetchState, { FetchState } from '~/utilities/useFetchState';
import { NotebookKind } from '~/k8sTypes';
import { getNotebooks } from '~/api';
import { POLL_INTERVAL } from '~/utilities/const';

export const useWatchNotebooks = (
namespace: string,
refreshRate = POLL_INTERVAL,
): FetchState<NotebookKind[]> =>
useFetchState<NotebookKind[]>(
React.useCallback(() => getNotebooks(namespace), [namespace]),
[],
{ refreshRate },
);
27 changes: 0 additions & 27 deletions frontend/src/utilities/useWatchProjectNotebooks.tsx

This file was deleted.

0 comments on commit d121dd0

Please sign in to comment.