Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nisum-scorecard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Venkaiah Naidu Singamchetty
nisum-scorecard
Commits
df0fb19f
Commit
df0fb19f
authored
Mar 21, 2024
by
Shiva Komirishetti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added sorting functionality to table
parent
2a5ebb50
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
93 additions
and
9 deletions
+93
-9
upVector.js
src/assets/icons/upVector.js
+24
-0
index.jsx
src/components/accordion/index.jsx
+1
-0
index.jsx
src/components/sortButton/index.jsx
+17
-0
index.jsx
src/components/table/index.jsx
+42
-3
index.jsx
src/pages/dashboard/index.jsx
+9
-6
No files found.
src/assets/icons/upVector.js
0 → 100644
View file @
df0fb19f
import
React
from
"react"
;
function
UpVector
({
isSelected
})
{
return
(
<
svg
fill
=
"#000000"
version
=
"1.1"
id
=
"Capa_1"
width
=
"10px"
height
=
"10px"
viewBox
=
"0 0 123.959 123.959"
>
<
g
>
<
path
style
=
{{
fill
:
isSelected
?
'#3E79F7'
:
'#BFBFBF'
}}
d
=
"M66.18,29.742c-2.301-2.3-6.101-2.3-8.401,0l-56,56c-3.8,3.801-1.1,10.2,4.2,10.2h112c5.3,0,8-6.399,4.2-10.2L66.18,29.742
z"
/>
<
/g
>
<
/svg
>
);
}
export
default
UpVector
;
src/components/accordion/index.jsx
View file @
df0fb19f
...
...
@@ -77,6 +77,7 @@ function Accordion({ title, data ,handleAddActivity,open,handleAccordian}) {
aria
-
labelledby=
"accordion-collapse-heading-2"
>
<
Table
headers=
{
headers
}
loading=
{
loading
}
data=
{
data
}
/>
</
div
>
</
div
>
);
...
...
src/components/sortButton/index.jsx
0 → 100644
View file @
df0fb19f
import
React
from
"react"
;
import
UpVector
from
"../../assets/icons/upVector"
;
function
SortButton
({
selected
,
handleClick
})
{
return
(
<
button
onClick=
{
handleClick
}
>
<
div
>
<
UpVector
isSelected=
{
selected
===
'asc'
?
true
:
false
}
/>
</
div
>
<
div
className=
{
`rotate-180 -mt-[2px] `
}
>
<
UpVector
isSelected=
{
selected
===
'desc'
?
true
:
false
}
/>
</
div
>
</
button
>
);
}
export
default
SortButton
;
src/components/table/index.jsx
View file @
df0fb19f
import
React
from
"react"
;
import
React
,
{
useState
,
useEffect
}
from
"react"
;
import
Loading
from
"../loading Component/Loading"
;
import
SortButton
from
"../sortButton"
;
function
Table
({
headers
,
data
,
loading
,
maxHeight
})
{
const
[
sortedData
,
setSortedData
]
=
useState
([]);
const
[
sortKey
,
setSortKey
]
=
useState
(
null
);
const
[
sortOrder
,
setSortOrder
]
=
useState
(
'asc'
);
useEffect
(()
=>
{
if
(
sortKey
)
{
setSortKey
(
null
);
}
setSortedData
(
data
);
},
[
data
]);
const
handleSort
=
(
key
)
=>
{
const
order
=
key
===
sortKey
?
(
sortOrder
===
'asc'
?
'desc'
:
'asc'
)
:
'asc'
;
if
(
sortOrder
===
'desc'
&&
key
===
sortKey
)
{
setSortedData
(
data
);
setSortKey
(
null
);
setSortOrder
(
'asc'
);
}
else
{
const
sorted
=
[...
data
].
sort
((
a
,
b
)
=>
{
if
(
typeof
a
[
key
]
===
'string'
)
{
return
order
===
'asc'
?
a
[
key
].
localeCompare
(
b
[
key
])
:
b
[
key
].
localeCompare
(
a
[
key
]);
}
return
order
===
'asc'
?
a
[
key
]
-
b
[
key
]
:
b
[
key
]
-
a
[
key
];
});
setSortedData
(
sorted
);
setSortKey
(
key
);
setSortOrder
(
order
);
}
};
if
(
loading
)
return
<
Loading
/>
else
return
(
...
...
@@ -11,7 +44,13 @@ function Table({headers, data,loading, maxHeight}) {
<
tr
className=
"mb-2"
>
{
headers
?.
map
((
item
,
index
)
=>
(
<
th
key=
{
index
}
scope=
"col"
className=
{
`px-6 py-4 w-[${item.width}]`
}
>
{
item
.
renderHeader
?
item
.
renderHeader
(
item
.
title
)
:
item
.
title
}
{
item
.
renderHeader
?
item
.
renderHeader
(
item
.
title
)
:
item
.
isSorting
?
<
span
className=
"flex items-center"
>
<
span
className=
"mr-4"
>
{
item
.
title
}
</
span
>
<
SortButton
selected=
{
item
.
id
===
sortKey
?
sortOrder
:
''
}
handleClick=
{
()
=>
handleSort
(
item
.
id
)
}
/>
</
span
>
:
<
span
>
{
item
.
title
}
</
span
>
}
</
th
>
))
}
</
tr
>
...
...
@@ -19,7 +58,7 @@ function Table({headers, data,loading, maxHeight}) {
{
(
data
?.
length
)?<
tbody
>
{
d
ata
?.
map
((
item
,
index
)
=>
(
sortedD
ata
?.
map
((
item
,
index
)
=>
(
<
tr
key=
{
item
.
id
}
className=
"bg-white hover:bg-gray-300 "
>
{
headers
?.
map
(({
render
,
id
})
=>
(
...
...
src/pages/dashboard/index.jsx
View file @
df0fb19f
...
...
@@ -76,23 +76,28 @@ function Dashboard() {
id
:
"empName"
,
render
:
(
value
)
=>
<
span
className=
"flex items-center"
>
{
/* <img className="pr-2" src="/man.png" width="30px" height="30px" /> */
}
{
value
}
</
span
>
{
value
}
</
span
>,
isSorting
:
true
},
{
title
:
"Emp.Id"
,
id
:
"empId"
id
:
"empId"
,
isSorting
:
true
},
{
title
:
"Designation"
,
id
:
'designation'
id
:
'designation'
,
isSorting
:
true
},
{
title
:
"Role"
,
id
:
'techStack'
id
:
'techStack'
,
isSorting
:
true
},
{
title
:
"score"
,
id
:
"score"
,
isSorting
:
true
,
render
:
(
value
)
=>
<
span
className=
{
`w-[30px] h-[30px] rounded-full flex items-center text-white justify-center ${scoreColor(value)}`
}
>
{
value
}
</
span
>
},
{
...
...
@@ -131,8 +136,6 @@ function Dashboard() {
)
}
</
div
>
</
div
>
</
div
>
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment