Skip to content

Commit 6a6226d

Browse files
committed
Sean 5/9 Fixed render issues with more MUI Components; added JSDoc comment blocks throughout the codebase for better inline documentation that adheres to industry best practices; added a window resizer to iframe
> > Co-authored-by: Heather Pfeiffer <[email protected]> Co-authored-by: Jesse Wowczuk <[email protected]> Co-authored-by: Zack Vandiver <[email protected]> Co-authored-by: Austin Alvarez <[email protected]>
1 parent 5767d4e commit 6a6226d

File tree

139 files changed

+5225
-2176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+5225
-2176
lines changed

app/src/Dashboard/NavbarDash.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,25 @@ const StyledMenuItem = withStyles((theme) => ({
7474
}
7575
}
7676
}))(MenuItem);
77-
// TO DO: set types of props validation
78-
export default function NavBar(props) {
77+
78+
/**
79+
* NavBar is a component that provides navigation and theming controls for an application.
80+
* It includes a logo, navigation links, and buttons for sorting projects and toggling the theme.
81+
* The NavBar uses a mix of MUI components styled with custom themes and styles.
82+
*
83+
* @param {Object} props - The properties passed to the component.
84+
* @param {Function} props.optionClicked - Callback function called when a sort option is selected.
85+
* @param {boolean} props.isThemeLight - Indicates if the light theme is currently active.
86+
* @param {Function} props.setTheme - Function to toggle the theme between light and dark.
87+
* @returns {JSX.Element} The NavBar component which includes a logo, navigation links, and control buttons.
88+
*
89+
* The NavBar is styled using `makeStyles` to handle theming and spacing. It features a responsive AppBar
90+
* containing an Avatar with the application's logo, a Typography component for the application name,
91+
* and various buttons for navigating the application, sorting data, and toggling the theme.
92+
* The sorting options are presented in a custom-styled Menu component, `StyledMenu`, with specific
93+
* icons indicating the sort method. The theme toggle button changes icon based on the current theme.
94+
*/
95+
export default function NavBar(props): JSX.Element {
7996
// TO DO: import setStyle
8097
const classes = useStyles();
8198
const style = useSelector((store) => store.styleSlice);

app/src/Dashboard/Project.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ type props = {
3232
const currUserSSID = window.localStorage.getItem('ssid') || 'unavailable';
3333
const currUsername = window.localStorage.getItem('username') || 'unavailable';
3434

35+
/**
36+
* `Project` is a React component that displays information about a specific project, such as its name,
37+
* author, and the number of likes it has received. It provides functionality for liking, copying, publishing,
38+
* commenting on, and deleting projects. The component integrates several mutations using Apollo Client to interact
39+
* with a GraphQL backend.
40+
* @param {Object} props - The properties passed to the component.
41+
* @param {string} props.name - The name of the project.
42+
* @param {string} props.id - The unique identifier for the project.
43+
* @param {string} props.userId - The user ID of the project owner.
44+
* @param {string} props.username - The username of the project owner.
45+
* @param {number} props.likes - The number of likes the project has received.
46+
* @param {boolean} props.published - Indicates if the project is currently published.
47+
* @param {Array} props.comments - An array of comment objects associated with the project.
48+
* @returns {JSX.Element} The rendered component which allows interaction with project data and includes
49+
* buttons for different actions depending on the user and project status.
50+
*
51+
* Each button in the component is associated with a specific action (like, copy, publish, comment, delete) and
52+
* uses GraphQL mutations to perform these actions. The component also manages local state for handling comments,
53+
* modals, and toggling UI elements based on the user's interaction.
54+
*/
3555
const Project = ({
3656
name,
3757
likes,

app/src/Dashboard/ProjectContainer.tsx

Lines changed: 59 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import React, { useState} from 'react';
2-
import { ThemeProvider, Theme, StyledEngineProvider, useTheme } from '@mui/material/styles';
1+
import React, { useState } from 'react';
2+
import {
3+
ThemeProvider,
4+
Theme,
5+
StyledEngineProvider,
6+
useTheme
7+
} from '@mui/material/styles';
38
import makeStyles from '@mui/styles/makeStyles';
49
import { useQuery } from '@apollo/client';
510
import Tabs from '@mui/material/Tabs';
@@ -11,22 +16,27 @@ import NavBarDash from './NavbarDash';
1116
import { useSelector } from 'react-redux';
1217
import { theme1, theme2 } from '../public/styles/theme';
1318

14-
1519
declare module '@mui/styles/defaultTheme' {
1620
interface DefaultTheme extends Theme {}
1721
}
1822

19-
2023
// Implement Apollo Client useQuery hook to retrieve data from the server through graphQL. This includes 2 steps:
2124
// 1) Impliment Apollo Provider in the top component in ./src/index.js, this allows children components access to the queried data
2225
// 2) useQuery hook will update the data stored in Apollo Client's cache and automatically trigger child components rendering
2326

24-
2527
// setting light and dark themes (navbar and background); linked to theme.ts
2628
const lightTheme = theme1;
2729
const darkTheme = theme2; // dark mode color in theme.ts not reached
2830

29-
const arrToComponent = arr =>
31+
/**
32+
* Transforms an array of project data into an array of <Project> React components.
33+
* Each project in the array is passed as props to the <Project> component, creating a list
34+
* of these components based on the provided array. Each component is given a unique `key` prop
35+
* based on its index in the array to optimize React's rendering process.
36+
* @param {Array} arr - An array of project objects, where each object contains project data.
37+
* @returns {Array<JSX.Element>} An array of <Project> components populated with data from the input array.
38+
*/
39+
const arrToComponent = (arr): Array<JSX.Element> =>
3040
arr.map((proj, index) => (
3141
<Project
3242
key={index}
@@ -41,8 +51,14 @@ const arrToComponent = arr =>
4151
/>
4252
));
4353

44-
// Start Pulled from materialUI to create a tab panel
45-
const a11yProps = (index: any) => ({
54+
/**
55+
* Generates accessibility props for a tab component within a tab panel. These properties help in
56+
* linking the tab to its corresponding tab panel, improving accessibility and usability for users
57+
* with assistive technologies.
58+
* @param {any} index - The index of the tab and its corresponding panel.
59+
* @returns {Object} An object containing the `id` and `aria-controls` attributes for accessibility purposes.
60+
*/
61+
const a11yProps = (index: any): Object => ({
4662
id: `vertical-tab-${index}`,
4763
'aria-controls': `vertical-tabpanel-${index}`
4864
});
@@ -75,7 +91,7 @@ const TabPanelItem = (props: TabPanelProps): JSX.Element => {
7591
);
7692
};
7793

78-
const useStyles = makeStyles(theme => ({
94+
const useStyles = makeStyles((theme) => ({
7995
root: {
8096
flexGrow: 1,
8197
// backgroundColor: theme.palette.background.paper,
@@ -85,7 +101,31 @@ const useStyles = makeStyles(theme => ({
85101
// borderRight: `1px solid ${theme.palette.divider}`
86102
}
87103
}));
88-
// End of prefab code to generate a tab panel
104+
105+
/**
106+
* `ProjectContainer` is a React component that manages the display and sorting of project data retrieved
107+
* from a GraphQL server using the Apollo Client. It provides a user interface with two dashboards:
108+
* a shared dashboard that displays all published projects and a private dashboard that shows projects
109+
* created by the currently logged-in user. The component includes sorting functionality based on project
110+
* rating, creation date, or user.
111+
*
112+
* @returns {JSX.Element} The ProjectContainer component which provides a tabbed interface for navigating
113+
* between shared and private dashboards, each displaying a list of projects.
114+
*
115+
* This component utilizes MUI's Tabs for navigation between the dashboards. It leverages the Apollo Client's
116+
* `useQuery` hook to fetch projects data and automatically update the UI upon data changes. Sorting preferences
117+
* are managed through local state and applied to the project data based on user interaction. The component
118+
* supports theming and uses `ThemeProvider` to switch between light and dark themes based on user settings.
119+
*
120+
* Dependencies:
121+
* - Apollo Client: For data fetching and state management with GraphQL.
122+
* - Material-UI: For UI components and theming.
123+
* - Redux: For managing application-wide state like theme settings.
124+
*
125+
* The component is designed to be responsive and accessible, with appropriate ARIA attributes for navigation
126+
* and content sections. It includes error handling for data fetching issues and a loading state during data
127+
* retrieval.
128+
*/
89129
const ProjectContainer = (): JSX.Element => {
90130
const classes = useStyles();
91131
const [value, setValue] = useState(0);
@@ -98,26 +138,26 @@ const ProjectContainer = (): JSX.Element => {
98138
const userSSID = window.localStorage.getItem('ssid') || 'unavailable';
99139
const username = window.localStorage.getItem('username') || 'unavailable';
100140
const [isThemeLight, setTheme] = useState(true);
101-
const style = useSelector(store => store.styleSlice)
141+
const style = useSelector((store) => store.styleSlice);
102142
// hook for sorting menu
103143
const [selectedOption, setSelectedOption] = useState('RATING');
104-
const sortByRating = projects => {
144+
const sortByRating = (projects) => {
105145
// generate a sorted array of public projects based on likes
106146
const sortedRatings = projects.sort((a, b) => b.likes - a.likes);
107147
return sortedRatings;
108148
};
109-
const sortByDate = projects => {
149+
const sortByDate = (projects) => {
110150
// generate a sorted array of public projects based on date
111151
const sortedRatings = projects.sort((a, b) => b.createdAt - a.createdAt);
112152
return sortedRatings;
113153
};
114-
const sortByUser = projects => {
154+
const sortByUser = (projects) => {
115155
// generate a sorted array of public projects based on username
116156
const sortedRatings = projects.sort((a, b) => b.username - a.username);
117157
return sortedRatings;
118158
};
119159
// function for selecting drop down sorting menu
120-
const optionClicked = value => {
160+
const optionClicked = (value) => {
121161
setSelectedOption(value);
122162
};
123163
// useQuery hook abstracts fetch request
@@ -129,12 +169,12 @@ const ProjectContainer = (): JSX.Element => {
129169
if (error) return <p>Error :{error}</p>;
130170
// based on resolver(getAllProject) for this query, the data is stored in the data object with the key 'getAllProjects'
131171
const projects = data.getAllProjects;
132-
172+
133173
//create array to hold the data recieved in the public dashboard the will be conditionally rendered
134-
let sortedProjects = projects.filter(proj => {
174+
let sortedProjects = projects.filter((proj) => {
135175
return proj.published;
136176
});
137-
const userProjects = projects.filter(proj => {
177+
const userProjects = projects.filter((proj) => {
138178
return proj.username === username;
139179
});
140180
// checking which sorting method was selected from drop down menu and invoking correct sorting function
@@ -156,7 +196,7 @@ const ProjectContainer = (): JSX.Element => {
156196
<div className={'dashboardContainer'}>
157197
<NavBarDash
158198
setTheme={setTheme}
159-
// styles={[style]}
199+
// styles={[style]}
160200
isThemeLight={isThemeLight}
161201
optionClicked={optionClicked}
162202
/>

app/src/components/App.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ import { useDispatch } from 'react-redux';
66

77
import AppContainer from '../containers/AppContainer';
88

9+
/**
10+
* The `App` component is the root component of the React application. It performs an initial check
11+
* to determine if a user is logged in (not a 'guest') by inspecting local storage, and updates the
12+
* application's state accordingly using Redux. It then renders the `AppContainer`, which serves as
13+
* the main container for the application's user interface.
14+
*
15+
* The `useEffect` hook is used to perform the login check once on component mount, ensuring that
16+
* the login state is correctly set based on the presence of a specific item in local storage.
17+
*
18+
* @returns {JSX.Element} Renders the `AppContainer` wrapped within a div with a class of 'app',
19+
* serving as the root of the user interface.
20+
*
21+
* This component interacts with Redux by dispatching actions to modify the global state, particularly
22+
* the logged-in status of the user. This is central for managing conditional rendering and access
23+
* throughout the application based on user authentication status.
24+
*/
925
export const App: React.FC = (): JSX.Element => {
1026
const dispatch = useDispatch();
1127
useEffect(() => {

app/src/components/ContextAPIManager/AssignTab/AssignContainer.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,24 @@ import { deleteElement } from '../../../redux/reducers/slice/appStateSlice';
1313
import { RootState } from '../../../redux/store';
1414
import { emitEvent } from '../../../../src/helperFunctions/socket';
1515

16-
const AssignContainer = () => {
16+
/**
17+
* Provides an interface for assigning components to contexts within an application.
18+
* The component allows the selection of contexts and components through dropdown menus,
19+
* displays related data in tables, and permits the assignment of components to selected contexts.
20+
* It leverages Redux for state management and may trigger socket events for real-time updates across sessions.
21+
*
22+
* This component integrates several subcomponents:
23+
* - `ContextDropDown` for selecting contexts which triggers updates to the data table.
24+
* - `DataTable` for displaying key-value pairs related to the selected context.
25+
* - `ComponentDropDown` for selecting components which triggers updates to the component table.
26+
* - `ComponentTable` for displaying a list of contexts associated with a selected component.
27+
* - A button for assigning the selected component to the selected context, potentially emitting socket events if a room code is present.
28+
*
29+
* The state management involves interaction with the Redux store to fetch state information and dispatch actions related to context and component management.
30+
*
31+
* @returns {JSX.Element} A React component structured with a Grid layout, integrating forms and tables for managing and viewing context and component assignments.
32+
*/
33+
const AssignContainer = (): JSX.Element => {
1734
const dispatch = useDispatch();
1835
const defaultTableData = [{ key: 'Key', value: 'Value' }];
1936
const [tableState, setTableState] = React.useState(defaultTableData);

app/src/components/ContextAPIManager/AssignTab/components/ComponentDropDrown.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,26 @@ import { RootState } from '../../../../redux/store';
77

88
const filter = createFilterOptions();
99

10+
/**
11+
* Renders an autocomplete dropdown list that allows the user to select or enter a component.
12+
* When a component is selected or entered, this triggers a specified callback to render the component table.
13+
* The dropdown uses a custom filter for suggestions, allowing users to add components not already listed in the options.
14+
*
15+
* @param {Object} props - The props passed to the ComponentDropDown component.
16+
* @param {Function} props.renderComponentTable - Callback function that is triggered to render the component table based on the selected component.
17+
* @param {Object|null} props.componentInput - The currently selected component object or null if nothing is selected.
18+
* @param {Function} props.setComponentInput - Sets the state of the componentInput in the parent component.
19+
*
20+
* Redux State Dependencies:
21+
* - `appState`: Expects `appState.components` from the Redux store to provide the list of available components.
22+
*
23+
* @returns {JSX.Element} A React Fragment that includes a Box containing the Autocomplete component which provides a dropdown for selecting components.
24+
*/
1025
const ComponentDropDown = ({
1126
renderComponentTable,
1227
componentInput,
1328
setComponentInput
14-
}) => {
29+
}): JSX.Element => {
1530
const { state } = useSelector((store: RootState) => ({
1631
state: store.appState
1732
}));
@@ -70,7 +85,7 @@ const ComponentDropDown = ({
7085

7186
return (
7287
<Fragment>
73-
<Box sx={{ display: 'flex', gap: 2, mb: 4}}>
88+
<Box sx={{ display: 'flex', gap: 2, mb: 4 }}>
7489
<Autocomplete
7590
id="autoCompleteContextField"
7691
value={componentInput}

app/src/components/ContextAPIManager/AssignTab/components/ComponentTable.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import Paper from '@mui/material/Paper';
88
import { styled } from '@mui/material/styles';
99
import TableCell, { tableCellClasses } from '@mui/material/TableCell';
1010

11+
/**
12+
* Styles the TableCell component using Material-UI's styling system. Custom styles are applied to table head and body cells:
13+
* - Head cells are styled with a black background and white text.
14+
* - Body cells have a font size of 14.
15+
*
16+
* @param {object} theme - The theme object provided by Material-UI's ThemeProvider.
17+
* @returns {object} A styled TableCell component with customized appearance.
18+
*/
1119
const StyledTableCell = styled(TableCell)(({ theme }) => ({
1220
[`&.${tableCellClasses.head}`]: {
1321
backgroundColor: theme.palette.common.black,
@@ -18,6 +26,14 @@ const StyledTableCell = styled(TableCell)(({ theme }) => ({
1826
}
1927
}));
2028

29+
/**
30+
* Styles the TableRow component to enhance table row appearance. Custom styles include:
31+
* - Every odd row is styled with a background color for hover state.
32+
* - Removes the border from the last child table cells and headers to enhance appearance.
33+
*
34+
* @param {object} theme - The theme object provided by Material-UI's ThemeProvider.
35+
* @returns {JSX.Element} A styled TableRow component with alternate row coloring and modified border visibility.
36+
*/
2137
const StyledTableRow = styled(TableRow)(({ theme }) => ({
2238
'&:nth-of-type(odd)': {
2339
backgroundColor: theme.palette.action.hover
@@ -28,6 +44,16 @@ const StyledTableRow = styled(TableRow)(({ theme }) => ({
2844
}
2945
}));
3046

47+
/**
48+
* A styled data table component that displays a list of items in a single column format.
49+
* This component uses Material-UI to create a visually distinct table with styled cells and rows.
50+
* It is specifically designed to display 'contexts consumed' but can be generalized for other single-column data.
51+
*
52+
* @param {Object} props - Component props.
53+
* @param {Array<string>} props.target - The data array containing strings to be displayed in the table.
54+
*
55+
* @returns {JSX.Element} A TableContainer component housing a Table, where each row displays an element from the `target` prop.
56+
*/
3157
export default function DataTable({ target }) {
3258
return (
3359
<TableContainer component={Paper}>

app/src/components/ContextAPIManager/AssignTab/components/ContextDropDown.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,27 @@ import TextField from '@mui/material/TextField';
33
import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
44
import Box from '@mui/material/Box';
55

6-
76
const filter = createFilterOptions();
87

8+
/**
9+
* A React component that provides an autocomplete dropdown for selecting or adding new contexts.
10+
* It integrates with the contextStore to list available contexts and allows the user to create a new context by entering a unique name.
11+
* When a context is selected or a new one is entered, the specified `renderTable` function is triggered to reflect changes elsewhere in the UI.
12+
*
13+
* @param {Object} props - Component props.
14+
* @param {Object} props.contextStore - The store holding all context data.
15+
* @param {Function} props.renderTable - Function to call when a context is selected or created to update associated data display.
16+
* @param {Object|null} props.contextInput - The currently selected or entered context.
17+
* @param {Function} props.setContextInput - Function to update the contextInput state.
18+
*
19+
* @returns {JSX.Element} A React fragment containing an Autocomplete component wrapped in a Box for layout adjustments.
20+
*/
921
const ContextDropDown = ({
1022
contextStore,
1123
renderTable,
1224
contextInput,
1325
setContextInput
14-
}) => {
26+
}): JSX.Element => {
1527
const { allContext } = contextStore;
1628

1729
const onChange = (event, newValue) => {

0 commit comments

Comments
 (0)