DockerImageList.js
1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import React, { useEffect, useState } from 'react'
import {
Container,
Heading,
Button,
Text,
Box,
} from '@chakra-ui/react'
import {
Divider, Grid,
Header,
} from 'semantic-ui-react'
import http from '../utils/http'
import { useHistory } from 'react-router-dom'
const ImageBlock = ({ title, desc, ...rest }) => {
return (
<Box p={5} shadow="md" borderWidth="1px" {...rest}>
<Heading fontSize="xl">{title}</Heading>
<Text mt={4}>{desc}</Text>
</Box>
)
}
const DockerImageList = () => {
const [token, setToken] = useState('')
const [images, setImages] = useState([])
const history = useHistory()
const setTokenFromLocalStorage = () => {
const token = localStorage.getItem('token')
setToken(token)
}
const getImages = () => {
http.get('/image/list', {
headers: {
Authorization: `token ${token}`,
},
}).then(response => {
const { success, code, data, message } = response.data
if (success) {
const { count, data } = data
setImages(data)
}
})
}
useEffect(() => {
setTokenFromLocalStorage()
getImages()
}, [])
return (
<Container>
<Divider hidden />
<Heading>Image List</Heading>
<Divider hidden />
<Grid>
<Grid.Column
floated='right' width={3}
>
<Button
size='xs'
colorScheme='blue'
onClick={() => history.push('/docker/image/create')}
>
New Image
</Button>
</Grid.Column>
</Grid>
{images.map(image => (
<ImageBlock
title={image.name}
desc={image.name}
/>
))}
</Container>
)
}
export default DockerImageList