import React from 'react'; import superagent from 'superagent'; import msgpack from 'msgpack-lite'; import {Button, Header, Label, Table, Image, Form} from 'semantic-ui-react'; import NetworkWrapper from './NetworkWrapper.jsx'; class Redis extends React.Component { constructor(props) { super(props); this.state = { pattern: null, loading: false, redisKeys: [], expandedRedisKeys: {} }; } onChange(e, { name, value }) { this.setState({ [name]: value }) } async onSubmit(e) { e.preventDefault(); this.setState({ loading: true }); try { const res = await superagent.post(`/cloud/admin/network/redis`).send({ pattern: this.state.pattern }).accept('json'); console.log(res.body); this.setState({ loading: false, redisKeys: res.body, expandedRedisKeys: {} }); } catch (e) { console.log(e); this.setState({ loading: false, redisKeys: [], expandedRedisKeys: {} }); } } async onExpand(redisKey) { } async onRedisKeyClick(redisKey, e) { e.preventDefault(); this.setState({ loading: true }); try { const res = await superagent.post(`/api/network/redis`).send({ key: redisKey }).accept('json'); const { expandedRedisKeys } = this.state; let redisValue = {}; if (res.body.data) { redisValue = msgpack.decode(Buffer.from(res.body.data, 'base64')); redisValue = JSON.stringify(redisValue, null, 4); } else { redisValue = JSON.stringify(res.body, null, 4); } expandedRedisKeys[redisKey] = redisValue; this.setState({ loading: false, expandedRedisKeys }); } catch (e) { console.log(e); this.setState({ loading: false }); } } renderRedisKey(redisKey) { let value = (this.state.expandedRedisKeys[redisKey]) &&
{this.state.expandedRedisKeys[redisKey]}
;
return (