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

Adding drives view #652

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

Cezary-Janicki
Copy link

This is my first PR, the view was done at @juliaanholcer request, and according the original view written in Vue

Drives view is a basic component that heavily utilizes material-UI v4 for easier development and maintenance. Components used are: Accordion ( for collapsible drive descriptions) and Pagination ( for pagination button on the bottom of the page). Style-wise I was trying it keep it close to the original Drives view written in Vue.

The full change-log is listed below.

Changes done

  • Added Drives view
  • Changed routes in routes.js in order to accommodate for the new page being made
  • Added a new route in sidebar

Not working properly

  • User doesn't logout when logout button is clicked
  • "Drives" doesn't currently have a translation

Features to implement

  • Drives view need to fetch drives data from the back-end. Right now the view takes mock data that was downloaded from pah admin page.
  • Due to implemented drives pagination, a small popup menu for number of results per page might be added

Copy link
Member

@arturtamborski arturtamborski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you went hardcore with the mockup data! ;D
thank you for the PR.

@Cezary-Janicki
Copy link
Author

I just exported all of the data from the backend. Thanks for approving my work 😀

Copy link
Contributor

@juliaanholcer juliaanholcer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested the solution yet, but there are some things that should be changed.

@@ -115,6 +115,7 @@ const Sidebar = ({
className={classes.link}
onClick={onClose}
>
{console.log('traslations', r)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove console.log

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, removed

@@ -0,0 +1,45 @@
// values to generate MenuItems in select fields. Will be converted to redux slice.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is redundant, cars, passengers and projects are fetched from backend and real data are used in the form

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't recall creating this file, removed nonetheless

@@ -0,0 +1,168 @@
import React, { useState } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React import is redundant as from version 17 you no longer need to explicitly import the React module in files containing React components

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, removed

},
}));

const totalMilage = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totalMileage should be calculated inside the component (using useMemo hook)
Even if we use mock data, the component should be written in such a way that in the next iteration of development, only the source of mock data will be replaced with one that will be returned by the selector from the store. So the data should be defined and operations on it should happen in the component.

const totalMilage = () => {
let milage = 0;

mockDrives.map((drive) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array.prototype.map() is a method that creates a new array populated with the results of calling a provided callback function on every element in the calling array. To achieve the effect you expect, you should use Array.prototype.reduce() method.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewritten to utilized reduce and use Memo

@@ -0,0 +1,2804 @@
export const mockDrives = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data format is not consistent with Drives format returned from the backend. Properties names should be in camelCase and data for nested objects (e.g. projects) should not be flattened. Mocking data in the final format allows you to avoid further changes in components when real data will be used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This data was taken from Django Admin. Where can I check the returned back-end data so that my mock data is consistent with it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the best source will be to check in the browser how the data is returned by this endpoint for the vue application

@@ -0,0 +1,6 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

react import is redundant

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@Cezary-Janicki
Copy link
Author

Thanks for the insights. I'll make the changes when I find the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants