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
fd202cb9
Commit
fd202cb9
authored
1 year ago
by
Jacopo Gasparetto
Browse files
Options
Downloads
Patches
Plain Diff
New table logic
Use hashmap to match column and values. Add new checkbox button if selectable prop is passed
parent
a63a9300
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/components/Table.tsx
+35
-13
35 additions, 13 deletions
frontend/src/components/Table.tsx
frontend/src/routes/Home/index.tsx
+28
-18
28 additions, 18 deletions
frontend/src/routes/Home/index.tsx
with
63 additions
and
31 deletions
frontend/src/components/Table.tsx
+
35
−
13
View file @
fd202cb9
// import './Table.css'
export
type
Column
=
{
name
:
string
,
columnType
:
"
boolean
"
|
"
number
"
|
"
string
"
;
}
export
type
Value
=
{
columnName
:
string
,
value
:
any
}
type
TableParams
=
{
c
lassName
:
string
columns
:
string
[],
data
:
any
[][],
c
olumns
:
Column
[],
data
:
Value
[]
[],
selectable
?:
boolean
onClick
?:
(
element
:
React
.
MouseEvent
<
HTMLTableRowElement
>
,
index
:
number
)
=>
void
}
export
const
Table
=
({
className
,
columns
,
data
,
onClick
}:
TableParams
)
=>
{
export
const
Table
=
({
columns
,
data
,
selectable
=
false
,
onClick
}:
TableParams
)
=>
{
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
>
<
tr
>
{
selectable
?
<
th
></
th
>
:
null
}
{
columns
.
map
(
column
=>
<
th
className
=
"
border-b
font-medium
p-4
first
:
pl-8
last
:
pr-8
pt-0
pb-3
text-left
text-slate-800
"
key
=
{
column
}
>
{
column
}
className
=
{
thClassName
}
key
=
{
column
.
name
}
>
{
column
.
name
}
</
th
>)
}
</
tr
>
</
thead
>
...
...
@@ -25,21 +38,30 @@ export const Table = ({ className, columns, data, onClick }: TableParams) => {
};
const
Body
=
()
=>
{
const
columnNames
=
columns
.
map
(
col
=>
col
.
name
);
const
rows
=
data
.
map
(
row
=>
{
return
row
.
reduce
((
acc
:
any
,
item
)
=>
{
acc
[
item
.
columnName
]
=
item
.
value
;
return
acc
;
},
new
Map
());
})
return
(
<
tbody
className
=
"bg-white"
>
{
data
.
map
((
row
,
i
ndex
)
=>
{
rows
.
map
((
row
,
rowI
ndex
)
=>
{
return
<
tr
className
=
"
hover
:
bg-slate-200
text-slate-500
hover
:
text-slate-800
hover
:
cursor-pointer
"
onClick
=
{
(
el
)
=>
onClick
?.(
el
,
index
)
}
key
=
{
index
}
>
{
row
.
map
((
el
,
index
)
=>
{
onClick
=
{
(
el
)
=>
onClick
?.(
el
,
rowIndex
)
}
key
=
{
rowIndex
}
>
{
selectable
?
<
th
className
=
"pl-4"
><
input
type
=
"checkbox"
></
input
></
th
>
:
null
}
{
columnNames
.
map
((
colName
,
index
)
=>
{
return
<
td
className
=
"
border-b
border-slate-100
p-4
first
:
pl-8
last
:
pr-8
text-left
"
key
=
{
index
}
>
{
el
}
{
row
[
colName
]
}
</
td
>
})
}
</
tr
>;
...
...
This diff is collapsed.
Click to expand it.
frontend/src/routes/Home/index.tsx
+
28
−
18
View file @
fd202cb9
import
{
Page
}
from
'
../../components/Page
'
;
import
{
Table
}
from
'
../../components/Table
'
;
import
{
Table
,
Column
,
Value
}
from
'
../../components/Table
'
;
import
{
useContext
}
from
'
react
'
;
import
{
BucketInfo
}
from
'
../../models/bucket
'
;
import
{
getHumanSize
,
parseReadWriteAccess
}
from
'
../../commons/utils
'
;
import
{
BucketsListContext
}
from
'
../../services/BucketListContext
'
;
import
{
useNavigate
}
from
'
react-router-dom
'
;
import
'
./index.css
'
;
export
const
Home
=
()
=>
{
const
navigate
=
useNavigate
();
const
bucketList
=
useContext
(
BucketsListContext
);
const
onClick
=
(
element
:
React
.
MouseEvent
<
HTMLTableRowElement
>
,
index
:
number
)
=>
{
const
bucketName
=
element
.
currentTarget
.
firstChild
?.
textContent
;
console
.
log
(
bucketName
);
}
const
columns
=
[
"
Bucket
"
,
"
Objects
"
,
"
Size
"
,
"
Access
"
];
const
columns
:
Column
[]
=
[
{
name
:
"
Bucket
"
,
columnType
:
"
string
"
},
{
name
:
"
Objects
"
,
columnType
:
"
string
"
},
{
name
:
"
Size
"
,
columnType
:
"
string
"
},
{
name
:
"
Access
"
,
columnType
:
"
string
"
}
];
const
bucketList
=
useContext
(
B
ucket
s
List
Context
)
.
map
((
bucket
:
BucketInfo
)
=>
{
const
tableData
=
b
ucketList
.
map
((
bucket
:
BucketInfo
)
=>
{
return
[
bucket
.
name
,
bucket
.
objects
,
getHumanSize
(
bucket
.
size
),
parseReadWriteAccess
(
bucket
.
rw_access
)
{
columnName
:
"
Bucket
"
,
value
:
bucket
.
name
}
,
{
columnName
:
"
Objects
"
,
value
:
bucket
.
objects
}
,
{
columnName
:
"
Size
"
,
value
:
getHumanSize
(
bucket
.
size
)
}
,
{
columnName
:
"
Access
"
,
value
:
parseReadWriteAccess
(
bucket
.
rw_access
)
}
]
});
const
onClick
=
(
_
:
React
.
MouseEvent
<
HTMLTableRowElement
>
,
index
:
number
)
=>
{
const
bucketName
=
bucketList
[
index
].
name
;
navigate
(
"
/
"
+
bucketName
)
console
.
log
(
bucketName
);
}
return
(
<
Page
title
=
"Home"
>
<
div
className
=
"Home"
>
<
div
className
=
"flex place-content-center"
>
<
Table
className
=
"table-auto w-2/3"
columns
=
{
columns
}
data
=
{
bucketList
}
onClick
=
{
onClick
}
/>
<
div
className
=
"flex w-2/3"
>
<
Table
columns
=
{
columns
}
data
=
{
tableData
}
onClick
=
{
onClick
}
/>
</
div
>
</
div
>
</
div
>
</
Page
>
...
...
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