|
| 1 | +import React from 'react'; |
| 2 | +import { Dispatch } from 'redux'; |
| 3 | +import { GridContent } from '@ant-design/pro-layout'; |
| 4 | +import { PageHeaderWrapper } from '@ant-design/pro-layout'; |
| 5 | +import { Spin, Menu, List } from 'antd'; |
| 6 | +import { connect } from 'dva'; |
| 7 | +import { SvcData, ResData } from './data.d'; |
| 8 | +import { ModelState } from './model'; |
| 9 | + |
| 10 | +import styles from './style.less'; |
| 11 | + |
| 12 | +const { Item } = Menu; |
| 13 | + |
| 14 | +interface SvcProps { |
| 15 | + dispatch: Dispatch<any>; |
| 16 | + ids: string[]; |
| 17 | + info: SvcData; |
| 18 | + loading: boolean; |
| 19 | +} |
| 20 | + |
| 21 | +const SvcView: React.FC<SvcProps> = props => { |
| 22 | + |
| 23 | + const [id, setId] = React.useState<string>(""); |
| 24 | + const [info, setInfo] = React.useState<Partial<SvcData>>({}); |
| 25 | + |
| 26 | + React.useEffect(() => { |
| 27 | + props.dispatch({ type: 'svc/fetchIds' }); |
| 28 | + }, []); |
| 29 | + |
| 30 | + const selectKey = (key: string) => { |
| 31 | + setId(key); |
| 32 | + props.dispatch({ |
| 33 | + type: 'svc/fetchInfo', |
| 34 | + payload: key, |
| 35 | + callback: (info: SvcData) => setInfo(info), |
| 36 | + }); |
| 37 | + } |
| 38 | + |
| 39 | + const { ids, loading } = props; |
| 40 | + |
| 41 | + return ( |
| 42 | + <PageHeaderWrapper> |
| 43 | + <Spin spinning={loading}> |
| 44 | + <GridContent> |
| 45 | + <div className={styles.main} > |
| 46 | + <div className={styles.leftMenu}> |
| 47 | + <Menu |
| 48 | + mode="inline" |
| 49 | + selectedKeys={[id]} |
| 50 | + onClick={({ key }) => selectKey(key)} |
| 51 | + > |
| 52 | + {ids.map(id => <Item key={id}>{id}</Item>)} |
| 53 | + </Menu> |
| 54 | + </div> |
| 55 | + <div className={styles.right}> |
| 56 | + <div className={styles.title}>{id}</div> |
| 57 | + <List |
| 58 | + loading={loading} |
| 59 | + itemLayout="horizontal" |
| 60 | + dataSource={info.resources} |
| 61 | + renderItem={(item: ResData) => ( |
| 62 | + <List.Item> |
| 63 | + <List.Item.Meta title={item.uri} description={item.ops.join(' | ')} /> |
| 64 | + </List.Item> |
| 65 | + )} |
| 66 | + /> |
| 67 | + </div> |
| 68 | + </div> |
| 69 | + </GridContent> |
| 70 | + </Spin> |
| 71 | + </PageHeaderWrapper> |
| 72 | + ) |
| 73 | +} |
| 74 | + |
| 75 | +export default connect( |
| 76 | + ({ svc, |
| 77 | + loading, |
| 78 | + }: { |
| 79 | + svc: ModelState, |
| 80 | + loading: { models: { [key: string]: boolean } }; |
| 81 | + }) => ({ |
| 82 | + ids: svc.ids, |
| 83 | + loading: loading.models.svc, |
| 84 | + }), |
| 85 | +)(SvcView); |
0 commit comments