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

refactor(taxonomy-editor-frontend): Create a component for nodes table #290

Merged
merged 1 commit into from
Nov 23, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions taxonomy-editor-frontend/src/components/NodesTableBody.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
IconButton,
TableBody,
TableCell,
TableRow,
Typography,
} from "@mui/material";
import EditIcon from "@mui/icons-material/Edit";
import { Link } from "react-router-dom";

type Props = {
nodeIds: string[];
taxonomyName: string;
branchName: string;
};

const NodesTableBody = ({ nodeIds, taxonomyName, branchName }: Props) => {
return (
<>
<TableBody>
{nodeIds.map((nodeId) => (
<TableRow key={nodeId}>
<TableCell align="left" component="td" scope="row">
<Typography variant="subtitle1">{nodeId}</Typography>
</TableCell>
<TableCell align="left" component="td" scope="row">
<IconButton
component={Link}
to={`/${taxonomyName}/${branchName}/entry/${nodeId}`}
aria-label="edit"
>
<EditIcon color="primary" />
</IconButton>
</TableCell>
</TableRow>
))}
</TableBody>
</>
);
};

export default NodesTableBody;
33 changes: 12 additions & 21 deletions taxonomy-editor-frontend/src/pages/root-nodes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from "react";
import { Link, useParams } from "react-router-dom";
import { useParams } from "react-router-dom";

import {
Typography,
Expand All @@ -15,7 +15,6 @@ import TableCell from "@mui/material/TableCell";
import TableContainer from "@mui/material/TableContainer";
import TableHead from "@mui/material/TableHead";
import TableRow from "@mui/material/TableRow";
import EditIcon from "@mui/icons-material/Edit";
import AddBoxIcon from "@mui/icons-material/AddBox";
import Dialog from "@mui/material/Dialog";

Expand All @@ -24,6 +23,7 @@ import useFetch from "../../components/useFetch";
import { toTitleCase, createBaseURL } from "../../utils";
import { greyHexCode } from "../../constants";
import type { RootEntriesAPIResponse } from "../../backend-types/types";
import NodesTableBody from "../../components/NodesTableBody";

type RootNodesProps = {
addNavLinks: ({
Expand Down Expand Up @@ -55,6 +55,11 @@ const RootNodes = ({
errorMessage,
} = useFetch<RootEntriesAPIResponse>(`${baseUrl}rootentries`);

let nodeIds: string[] = [];
if (nodes && nodes.length > 0) {
nodeIds = nodes.map((node) => node[0].id);
}

useEffect(
function defineMainNavLinks() {
addNavLinks({ branchName, taxonomyName });
Expand Down Expand Up @@ -143,25 +148,11 @@ const RootNodes = ({
</TableCell>
</TableRow>
</TableHead>

<TableBody>
{nodes.map((node) => (
<TableRow key={node[0].id}>
<TableCell align="left" component="td" scope="row">
<Typography variant="subtitle1">{node[0].id}</Typography>
</TableCell>
<TableCell align="left" component="td" scope="row">
<IconButton
component={Link}
to={`/${taxonomyName}/${branchName}/entry/${node[0].id}`}
aria-label="edit"
>
<EditIcon color="primary" />
</IconButton>
</TableCell>
</TableRow>
))}
</TableBody>
<NodesTableBody
nodeIds={nodeIds}
taxonomyName={taxonomyName}
branchName={branchName}
/>
</Table>
</TableContainer>
</div>
Expand Down
27 changes: 6 additions & 21 deletions taxonomy-editor-frontend/src/pages/search/SearchResults.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useState } from "react";
import { Link } from "react-router-dom";

import {
Typography,
Expand All @@ -13,12 +12,10 @@ import {
} from "@mui/material";
import Container from "@mui/material/Container";
import Table from "@mui/material/Table";
import TableBody from "@mui/material/TableBody";
import TableCell from "@mui/material/TableCell";
import TableContainer from "@mui/material/TableContainer";
import TableHead from "@mui/material/TableHead";
import TableRow from "@mui/material/TableRow";
import EditIcon from "@mui/icons-material/Edit";
import AddBoxIcon from "@mui/icons-material/AddBox";
import Dialog from "@mui/material/Dialog";

Expand All @@ -27,6 +24,7 @@ import { createBaseURL } from "../../utils";
import { greyHexCode } from "../../constants";
import type { SearchAPIResponse } from "../../backend-types/types";
import CreateNodeDialogContent from "../../components/CreateNodeDialogContent";
import NodesTableBody from "../../components/NodesTableBody";

type Props = {
query: string;
Expand Down Expand Up @@ -125,24 +123,11 @@ const SearchResults = ({ query, taxonomyName, branchName }: Props) => {
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{(nodeIds ?? []).map((nodeId) => (
<TableRow key={nodeId}>
<TableCell align="left" component="td" scope="row">
<Typography variant="subtitle1">{nodeId}</Typography>
</TableCell>
<TableCell align="left" component="td" scope="row">
<IconButton
component={Link}
to={`/${taxonomyName}/${branchName}/entry/${nodeId}`}
aria-label="edit"
>
<EditIcon color="primary" />
</IconButton>
</TableCell>
</TableRow>
))}
</TableBody>
<NodesTableBody
nodeIds={nodeIds ?? []}
taxonomyName={taxonomyName}
branchName={branchName}
/>
</Table>
</TableContainer>

Expand Down