Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Ceph Webapp Poc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Jacopo Gasparetto
Ceph Webapp Poc
Commits
ce46dbfa
Commit
ce46dbfa
authored
1 year ago
by
Jacopo Gasparetto
Browse files
Options
Downloads
Patches
Plain Diff
Add onSelect function to Table component
parent
5ac94f09
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/components/Table.tsx
+29
-6
29 additions, 6 deletions
frontend/src/components/Table.tsx
with
29 additions
and
6 deletions
frontend/src/components/Table.tsx
+
29
−
6
View file @
ce46dbfa
// import './Table.css'
import
{
ChangeEvent
,
MouseEvent
}
from
"
react
"
;
export
interface
Column
{
id
:
string
...
...
@@ -12,15 +13,27 @@ export interface Value {
}
interface
TableParams
{
columns
:
Column
[],
data
:
Value
[][],
selectable
?:
boolean
onClick
?:
(
element
:
React
.
MouseEvent
<
HTMLTableRowElement
>
,
index
:
number
)
=>
void
columns
:
Column
[];
data
:
Value
[][];
selectable
?:
boolean
;
selectedRows
?:
Set
<
number
>
;
onClick
?:
(
element
:
MouseEvent
<
HTMLTableRowElement
>
,
index
:
number
)
=>
void
onSelect
?:
(
element
:
ChangeEvent
<
HTMLInputElement
>
,
index
:
number
)
=>
void
}
export
const
Table
=
({
columns
,
data
,
selectable
=
false
,
onClick
}:
TableParams
)
=>
{
export
const
Table
=
(
props
:
TableParams
)
=>
{
const
{
columns
,
data
,
selectable
=
false
,
selectedRows
,
onClick
,
onSelect
}
=
props
;
const
thClassName
=
"
border-b font-medium p-4 first:pl-8 last:pr-8 pt-0 pb-3
\
text-left text-slate-800
"
;
const
Header
=
()
=>
{
return
(
<
thead
>
...
...
@@ -56,7 +69,17 @@ export const Table = ({ columns, data, selectable = false, onClick }: TableParam
hover
:
text-slate-800
hover
:
cursor-pointer
"
onClick
=
{
(
el
)
=>
onClick
?.(
el
,
rowIndex
)
}
key
=
{
rowIndex
}
>
{
selectable
?
<
th
className
=
"pl-4"
><
input
type
=
"checkbox"
></
input
></
th
>
:
null
}
{
selectable
?
<
th
className
=
"pl-4"
>
<
input
type
=
"checkbox"
onChange
=
{
(
el
)
=>
(
onSelect
&&
onSelect
(
el
,
rowIndex
))
}
checked
=
{
selectedRows
&&
selectedRows
.
has
(
rowIndex
)
}
>
</
input
>
</
th
>
:
null
}
{
columnIds
.
map
((
colId
,
index
)
=>
{
return
<
td
className
=
"
border-b
border-slate-100
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment