aboutsummaryrefslogtreecommitdiffstats
path: root/src/web/src/components/System/System.js
blob: a4c79e12ff0183c8d4272428074f2bc0a177c77f (plain) (blame)
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
import React from 'react';
import { useRouteMatch, useHistory, Redirect } from 'react-router-dom';

import { Segment, Tab } from 'semantic-ui-react';

import './System.css';

import Info from './Info';
import Logs from './Logs';
import Options from './Options';

const System = ({ state = {}, options = {} }) => {
  const { params: { tab }, ...route } = useRouteMatch();
  const history = useHistory();

  const panes = [
    { route: 'info', menuItem: 'Info', render: () => <Tab.Pane><Info state={state}/></Tab.Pane> },
    {
      route: 'options', menuItem: 'Options', render: () =>
        <Tab.Pane className='full-height'><Options options={options} /></Tab.Pane>,
    },
    { route: 'logs', menuItem: 'Logs', render: () => <Tab.Pane><Logs/></Tab.Pane> },
  ]

  const activeIndex = panes.findIndex(pane => pane.route === tab)

  const onTabChange = (e, { activeIndex }) => {
    history.push(panes[activeIndex].route)
  }

  if (tab === undefined) {
    return <Redirect to={`${route.url}/${panes[0].route}`}/>
  }

  return (
    <div className='system'>
      <Segment raised>
        <Tab
          activeIndex={activeIndex > -1 ? activeIndex : 0} 
          panes={panes}
          onTabChange={onTabChange}
        />
      </Segment>
    </div>
  );
};

export default System;