Passed
Push — development ( 8e8ffd...1af938 )
by Peter
18:46 queued 06:25
created

BikeList.tsx ➔ BikeList   B

Complexity

Conditions 1

Size

Total Lines 53
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.125

Importance

Changes 0
Metric Value
cc 1
eloc 50
dl 0
loc 53
ccs 1
cts 2
cp 0.5
crap 1.125
rs 8.6363
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
import { Scooter } from '../helpers/map/leaflet-types'
2
import { Badge } from 'flowbite-react'
3
4
type Props = {
5
    scooterData: Scooter[];
6
    isCityList: boolean
7
8
}
9
10
export default function BikeList( {scooterData, isCityList} : Props) {
11 1
  return (
12
        <ul className="w-full sm:max-w-4xl mx-auto" data-testid="bikelist">
13
            {scooterData.map((scooter) => (
14
                <li key={scooter.id} className="flex flex-col w-full flex-nowrap justify-between gap-4 p-4 mb-6 bg-gray-100 rounded-lg
15
                    shadow-md sm:flex-row sm:items-center">
16
                    <div>
17
                        <div className="flex items-center p-1 rounded-lg">
18
                            <span className="font-semibold">id:</span>
19
                            <Badge>{scooter.id}</Badge>
20
                        </div>
21
                        { isCityList &&
22
                            <div className="flex items-center p-1 rounded-lg">
23
                                <span className="font-semibold">city:</span>
24
                                <Badge>{scooter.city}</Badge>
25
                            </div>
26
                        }
27
                        <div className="flex items-center p-1 rounded-lg">
28
                            <span className="font-semibold">createdAt:</span>
29
                            <Badge>{scooter.createdAt}</Badge>
30
                        </div>
31
32
                        <div className="flex items-center p-1 rounded-lg">
33
                            <span className="font-semibold">updatedAt:</span>
34
                            <Badge>{scooter.updatedAt}</Badge>
35
                        </div>
36
                    </div>
37
38
                    <div>
39
                        <div className="flex items-center p-1 rounded-lg">
40
                            <span className="font-semibold">batteryLevel:</span>
41
                            <Badge>{scooter.batteryLevel}</Badge>
42
                        </div>
43
44
                        <div className="flex items-center p-1 rounded-lg">
45
                            <span className="font-semibold">status:</span>
46
                            <Badge>{scooter.status}</Badge>
47
                        </div>
48
49
                        <div className="flex items-center p-1 rounded-lg">
50
                            <span className="font-semibold">longitude:</span>
51
                            <Badge>{scooter.longitude}</Badge>
52
                        </div>
53
54
                        <div className="flex items-center p-1 rounded-lg">
55
                            <span className="font-semibold">latitude:</span>
56
                            <Badge>{scooter.latitude}</Badge>
57
                        </div>
58
                    </div>
59
                </li>
60
            ))}
61
        </ul>
62
  )
63
}
64