Skip to content

Commit

Permalink
Merge pull request #10 from agrifooddatacanada/fix/name_description_meta
Browse files Browse the repository at this point in the history
Fixed meta: name and description in language tabs
  • Loading branch information
mathew-at-guelph authored Jul 18, 2023
2 parents 710c2a7 + ec43064 commit 3e51dff
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 94 deletions.
8 changes: 4 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function App() {
English: { name: "", description: "" },
});
const [divisionGroup, setDivisionGroup] = useState({
division: 'Natural sciences',
group: 'Mathematics and statistics',
division: '',
group: '',
});
const [languages, setLanguages] = useState(["English"]);
const [attributeRowData, setAttributeRowData] = useState([]);
Expand Down Expand Up @@ -154,8 +154,8 @@ function App() {
});

setDivisionGroup({
division: 'Natural sciences',
group: 'Mathematics and statistics',
division: '',
group: '',
});

setLanguages(["English"]);
Expand Down
41 changes: 29 additions & 12 deletions src/AttributeDetails/AttributeDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export default function AttributeDetails({ pageBack, pageForward }) {
const [fieldArray, setFieldArray] = useState(["Type"]);
const navigationSafe = useRef();
const gridRef = useRef();
const refContainer = useRef();
const entryCodesRef = useRef();
const typeBlanksRef = useRef();

const typesObjectRef = useRef({});

useEffect(() => {
Expand All @@ -43,6 +43,21 @@ export default function AttributeDetails({ pageBack, pageForward }) {
typesObjectRef.current = newTypesObjetRef;
}, [attributeRowData]);

// Stops grid editing when clicking outside grid
useEffect(() => {
const handleClickOutsideGrid = (event) => {
if (gridRef.current.api && refContainer.current && !refContainer.current.contains(event.target)) {
gridRef.current.api.stopEditing();
}
};

document.addEventListener("click", handleClickOutsideGrid);

return () => {
document.removeEventListener("click", handleClickOutsideGrid);
};
}, [gridRef, refContainer]);

const handleSave = () => {
entryCodesRef.current = false;
navigationSafe.current = false;
Expand Down Expand Up @@ -105,7 +120,7 @@ export default function AttributeDetails({ pageBack, pageForward }) {
: item.Attribute,
Type:
typesObjectRef.current &&
item.Type !== typesObjectRef.current[item.Attribute]
item.Type !== typesObjectRef.current[item.Attribute]
? typesObjectRef.current[item.Attribute]
: item.Type,
}));
Expand Down Expand Up @@ -229,16 +244,18 @@ export default function AttributeDetails({ pageBack, pageForward }) {
{errorMessage}
</Alert>
)}
<Grid
gridRef={gridRef}
addButton1={addButton1}
addButton2={addButton2}
setErrorMessage={setErrorMessage}
canDelete={canDelete}
setCanDelete={setCanDelete}
setAddByTab={setAddByTab}
typesObjectRef={typesObjectRef}
/>
<div ref={refContainer}>
<Grid
gridRef={gridRef}
addButton1={addButton1}
addButton2={addButton2}
setErrorMessage={setErrorMessage}
canDelete={canDelete}
setCanDelete={setCanDelete}
setAddByTab={setAddByTab}
typesObjectRef={typesObjectRef}
/>
</div>
<AddAttribute
addButton1={addButton1}
addButton2={addButton2}
Expand Down
22 changes: 1 addition & 21 deletions src/AttributeDetails/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function Grid({
canDelete,
setCanDelete,
setAddByTab,
typesObjectRef,
typesObjectRef
}) {
const { attributesList, setAttributesList } = useContext(Context);
const [selectedCells, setSelectedCells] = useState([]);
Expand Down Expand Up @@ -692,26 +692,6 @@ export default function Grid({
[attributeRowData, attributesList]
);

//Stops grid editing when clicking outside grid
useEffect(() => {
const handleClickOutsideGrid = (event) => {
if (gridRef.current.api) {
if (
typeof event.target.className === "string" &&
!event.target.className.includes("ag-cell")
) {
gridRef.current.api.stopEditing();
}
}
};

document.addEventListener("click", handleClickOutsideGrid);

return () => {
document.removeEventListener("click", handleClickOutsideGrid);
};
}, [gridRef]);

//Saves elements in proper order after dragging
const onRowDragEnd = (event) => {
const oldIndex = attributeRowData.findIndex(
Expand Down
15 changes: 6 additions & 9 deletions src/CreateManually/CreateManually.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import "ag-grid-community/styles/ag-theme-alpine.css";
export default function CreateManually() {
const addRef = useRef();
const gridRef = useRef();
const refContainer = useRef();

const { setCurrentPage, setAttributesList, attributesList, setFileData } =
useContext(Context);
Expand Down Expand Up @@ -268,15 +269,11 @@ export default function CreateManually() {
setCanDelete(false);
};

// Stops grid editing when clicking outside grid
useEffect(() => {
const handleClickOutsideGrid = (event) => {
if (gridRef.current.api) {
if (
typeof event.target.className === "string" &&
!event.target.className.includes("ag-cell")
) {
gridRef.current.api.stopEditing();
}
if (gridRef.current.api && refContainer.current && !refContainer.current.contains(event.target)) {
gridRef.current.api.stopEditing();
}
};

Expand All @@ -285,7 +282,7 @@ export default function CreateManually() {
return () => {
document.removeEventListener("click", handleClickOutsideGrid);
};
}, [gridRef]);
}, [gridRef, refContainer]);

//Drops element when item is taken off grid
//Prevents error where when element comes back onto grid, the index isn't saved correctly onRowDragEnd
Expand Down Expand Up @@ -424,7 +421,7 @@ export default function CreateManually() {
</Box>
<Box>
<Box style={{ display: "flex" }}>
<Box className="ag-theme-alpine" style={{ width: 503 }}>
<Box className="ag-theme-alpine" style={{ width: 503 }} ref={refContainer}>
<style>{gridStyle}</style>
<AgGridReact
ref={gridRef}
Expand Down
44 changes: 23 additions & 21 deletions src/EntryCodes/CodeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ import { CustomPalette } from "../constants/customPalette";
import "ag-grid-community/styles/ag-grid.css";
import "ag-grid-community/styles/ag-theme-alpine.css";

export default function CodeGrid({ index, codeRefs }) {
export default function CodeGrid({ index, codeRefs, chosenTable, setChosenTable }) {
const { languages, setEntryCodeRowData } = useContext(Context);
const { entryCodeRowData } = useContext(Context);

const [buttonArray, setButtonArray] = useState([]);
const [gridWidth, setGridWidth] = useState(500);
const [hoveredRowIndex, setHoveredRowIndex] = useState(-1);

const refContainer = useRef(null);

//Overrides the default grid styles in a way that allows input fields to not look awkward when word wrapping happens

const gridStyle = `
Expand Down Expand Up @@ -300,22 +302,19 @@ export default function CodeGrid({ index, codeRefs }) {
useEffect(() => {
const handleClickOutsideGrid = (event) => {
const clickedGrid = event.target.closest(".ag-root-wrapper");
if (clickedGrid) {
const clickedGridPath = clickedGrid.getAttribute("data-ag-path");

if (!clickedGrid && refContainer.current && !refContainer.current.contains(event.target)) {
codeRefs.current.forEach((grid) => {
const gridElement =
grid.current?.gridOptions?.api?.gridPanel?.eGridDiv;
const gridPath = gridElement?.getAttribute("data-ag-path");
grid.current?.api?.stopEditing();
});
}

if (gridPath !== clickedGridPath && grid.current?.api) {
grid.current.api.stopEditing();
if (chosenTable) {
codeRefs.current.forEach((grid, idx) => {
if (idx !== chosenTable && grid.current?.api) {
grid.current?.api?.stopEditing();
}
});
} else {
codeRefs.current.forEach((grid) => {
grid.current?.api?.stopEditing();
});
}
};

Expand All @@ -324,21 +323,24 @@ export default function CodeGrid({ index, codeRefs }) {
return () => {
document.removeEventListener("click", handleClickOutsideGrid);
};
}, [codeRefs]);
}, [codeRefs, chosenTable]);

return (
<Box style={{ margin: "3rem", display: "flex", flexDirection: "column" }}>
<Box style={{ display: "flex" }}>
<Box className="ag-theme-alpine" style={{ width: gridWidth }}>
<style>{gridStyle}</style>
<AgGridReact
ref={codeRefs.current[index]}
rowData={entryCodeRowData[index]}
columnDefs={columnDefs}
defaultColDef={defaultColDef}
domLayout="autoHeight"
onCellKeyDown={onCellKeyDown}
/>
<div ref={refContainer}>
<AgGridReact
ref={codeRefs.current[index]}
rowData={entryCodeRowData[index]}
columnDefs={columnDefs}
defaultColDef={defaultColDef}
domLayout="autoHeight"
onCellKeyDown={onCellKeyDown}
onCellClicked={() => setChosenTable(index)}
/>
</div>
</Box>
<Box
style={{
Expand Down
3 changes: 3 additions & 0 deletions src/EntryCodes/EntryCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function EntryCodes() {
setCurrentPage,
languages,
} = useContext(Context);
const [chosenTable, setChosenTable] = useState(0);

const codeRefs = useRef();
const entryCodeData = useRef();
Expand Down Expand Up @@ -132,6 +133,8 @@ export default function EntryCodes() {
key={selectedAttributes[index].Attribute}
index={index}
codeRefs={codeRefs}
chosenTable={chosenTable}
setChosenTable={setChosenTable}
/>
);
});
Expand Down
4 changes: 2 additions & 2 deletions src/EntryCodes/SingleTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Box, Typography } from "@mui/material";
import { CustomPalette } from "../constants/customPalette";
import CodeGrid from "./CodeGrid";

export default function SingleTable({ attribute, index, codeRefs }) {
export default function SingleTable({ attribute, index, codeRefs, chosenTable, setChosenTable }) {
return (
<Box
sx={{
Expand All @@ -23,7 +23,7 @@ export default function SingleTable({ attribute, index, codeRefs }) {
>
{attribute.Attribute}
</Typography>
<CodeGrid index={index} codeRefs={codeRefs} />
<CodeGrid index={index} codeRefs={codeRefs} chosenTable={chosenTable} setChosenTable={setChosenTable} />
</Box>
);
}
19 changes: 0 additions & 19 deletions src/LanguageDetails/LanGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,6 @@ export default function LanGrid({ gridRef, currentLanguage }) {
]);
}, [attributesList]);

//Makes grid stop editing when clicking outside grid
useEffect(() => {
const handleClickOutsideGrid = (event) => {
if (gridRef.current.api) {
if (
typeof event.target.className === "string" &&
!event.target.className.includes("ag-cell")
) {
gridRef.current.api.stopEditing();
}
}
};

document.addEventListener("click", handleClickOutsideGrid);

return () => {
document.removeEventListener("click", handleClickOutsideGrid);
};
}, [gridRef]);

return (
<div className="ag-theme-balham" style={{ width: 800 }}>
Expand Down
22 changes: 20 additions & 2 deletions src/LanguageDetails/LanguageDetails.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, useContext, useState } from "react";
import React, { useRef, useContext, useState, useEffect } from "react";
import { Context } from "../App";
import { Box } from "@mui/system";
import { Button, Tooltip, Typography } from "@mui/material";
Expand All @@ -21,8 +21,24 @@ export default function LanguageDetails({ pageBack, pageForward }) {
const [currentLanguage, setCurrentLanguage] = useState(languages[0]);

const gridRef = useRef();
const refContainer = useRef();
const entryCodesRef = useRef();

// Stops grid editing when clicking outside grid
useEffect(() => {
const handleClickOutsideGrid = (event) => {
if (gridRef.current.api && refContainer.current && !refContainer.current.contains(event.target)) {
gridRef.current.api.stopEditing();
}
};

document.addEventListener("click", handleClickOutsideGrid);

return () => {
document.removeEventListener("click", handleClickOutsideGrid);
};
}, [gridRef, refContainer]);

const handleSave = () => {
entryCodesRef.current = false;
gridRef.current.api.stopEditing();
Expand Down Expand Up @@ -197,7 +213,9 @@ export default function LanguageDetails({ pageBack, pageForward }) {
<HelpOutlineIcon sx={{ fontSize: 15 }} />
</Tooltip>
</Box>
<LanGrid gridRef={gridRef} currentLanguage={currentLanguage} />
<div ref={refContainer}>
<LanGrid gridRef={gridRef} currentLanguage={currentLanguage} />
</div>
</Box>
</Box>
</Box>
Expand Down
4 changes: 2 additions & 2 deletions src/SchemaMetadata/Classification.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ const Classification = () => {
const divisionsDropdown = useMemo(() => {
return Object.keys(classification).map((division) => {
return (
<MenuItem key={division} value={division}>{division}</MenuItem>
<MenuItem sx={{ height: '38px' }} key={division} value={division}>{division}</MenuItem>
);
});
}, []);

const groupsDropdown = useMemo(() => {
return classification[divisionGroup.division].map((group) => {
return (
<MenuItem key={group} value={group}>{group}</MenuItem>
<MenuItem sx={{ height: '38px' }} key={group} value={group}>{group}</MenuItem>
);
});
}, [divisionGroup.division]);
Expand Down
Loading

0 comments on commit 3e51dff

Please sign in to comment.