src/components/Cities/CityList.jsx   A
last analyzed

Complexity

Total Complexity 3
Complexity/F 0

Size

Lines of Code 70
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 61
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 3
mnd 3
bc 3
fnc 0
bpm 0
cpm 0
noi 0
1
import React, { useEffect, useState } from "react";
2
//import cities from "../../models/cities";
3
import { Link, NavLink } from "react-router-dom";
4
import { AiOutlineRight } from "react-icons/ai";
5
const CityList = ({ filterPhrase, cityData }) => {
6
  const citiesList = () => {
7
    return cityData.arrayOverview
8
      .filter((item) => {
9
        if (filterPhrase === "") {
10
          return item;
11
        } else if (
12
          item.name.toLowerCase().includes(filterPhrase.toLowerCase())
13
        ) {
14
          return item;
15
        }
16
        return;
17
      })
18
      .map((item, index) => {
19
        return (
20
          <tr key={index} className="border-b text-base border-gray-400">
21
            <td className="py-3 px-6">{index}</td>
22
            <td className="py-3 px-6">{item.name}</td>
23
            <td className="py-3 px-6">{item.totalScooters}</td>
24
            <td className="py-3 px-6">{item.totalInUse}</td>
25
            <td className="py-3 px-6">{item.totalAvailable}</td>
26
            <td className="py-3 px-6">{item.totalUnavailable}</td>
27
            <td className="py-3 px-6">{item.totalMaintenance}</td>
28
            <td className="py-3 px-6">{item.totalOff}</td>
29
            <td className="py-3 px-6">{item.totalZones}</td>
30
            <td className="py-3 px-6 text-right">
31
              <Link to={"/cities/select"} state={{ id: item._id }}>
32
                <span>
33
                  <AiOutlineRight />
34
                </span>
35
              </Link>
36
            </td>
37
          </tr>
38
        );
39
      });
40
  };
41
42
  if (!cityData.arrayOverview) {
43
    return <div>Loading</div>;
44
  }
45
46
  return (
47
    <>
48
      <table className="w-full text-lg content-between text-center">
49
        <thead className=" bg-sidebarBlue text-gray-200">
50
          <tr>
51
            <th className="font-normal px-6">ID</th>
52
            <th className="font-normal px-6">City</th>
53
            <th className="font-normal px-6">Scooters</th>
54
            <th className="font-normal px-6">Active</th>
55
            <th className="font-normal px-6">Available</th>
56
            <th className="font-normal px-6">Charging</th>
57
            <th className="font-normal px-6">Maintance</th>
58
            <th className="font-normal px-6">Off</th>
59
            <th className="font-normal px-6">Zones</th>
60
            <th className="font-normal px-6">View</th>
61
          </tr>
62
        </thead>
63
        <tbody>{citiesList()}</tbody>
64
      </table>
65
    </>
66
  );
67
};
68
69
export default CityList;
70