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

fix(frontend): Enhance Edition of Properties for a Node #362

Merged
merged 6 commits into from
Feb 7, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { Box, Grid, Paper, TextField, Typography } from "@mui/material";
import MaterialTable, { MTableToolbar } from "@material-table/core";
import { useEffect, useState } from "react";
import { useState } from "react";

const ListAllEntryProperties = ({ nodeObject, setNodeObject }) => {
const [data, setData] = useState([]);

// Changes the properties to be rendered
// Dependent on changes occuring in "nodeObject"
useEffect(() => {
const collectProperties = () => {
let renderedProperties = [];
Object.keys(nodeObject).forEach((key) => {
// Collecting uuids of properties
Expand All @@ -30,8 +26,10 @@ const ListAllEntryProperties = ({ nodeObject, setNodeObject }) => {
});
}
});
setData(renderedProperties);
}, [nodeObject]);
return renderedProperties;
};

const [data, setData] = useState(collectProperties());

// Helper function used for changing comments from node
const changeCommentData = (value) => {
Expand Down Expand Up @@ -76,7 +74,7 @@ const ListAllEntryProperties = ({ nodeObject, setNodeObject }) => {
/>

{/* Properties */}
<Box sx={{ width: "50%", ml: 4 }}>
<Box sx={{ width: "90%", ml: 4, maxWidth: "1000px", m: "auto", mb: 3 }}>
<MaterialTable
data={data}
columns={[
Expand All @@ -100,8 +98,9 @@ const ListAllEntryProperties = ({ nodeObject, setNodeObject }) => {
onRowDelete: (selectedRow) =>
new Promise((resolve, reject) => {
// Delete property from rendered rows
const index = selectedRow.tableData.id;
const updatedRows = data.filter((obj) => !(index === obj.id));
const updatedRows = [...data];
const index = selectedRow.id;
updatedRows.splice(index, 1);
setData(updatedRows);

// Delete key-value pair of a property from nodeObject
Expand All @@ -115,7 +114,6 @@ const ListAllEntryProperties = ({ nodeObject, setNodeObject }) => {
el.id === oldRow.id ? updatedRow : el
);
setData(updatedRows);

// Updation takes place by deletion + addition
// If property name has been changed, previous key should be removed from nodeObject
updatedRow.propertyName !== oldRow.propertyName &&
Expand All @@ -131,6 +129,8 @@ const ListAllEntryProperties = ({ nodeObject, setNodeObject }) => {
options={{
actionsColumnIndex: -1,
addRowPosition: "last",
tableLayout: "fixed",
paging: false,
}}
components={{
Toolbar: (props) => {
Expand Down
Loading