Skip to content

Commit

Permalink
improve ux
Browse files Browse the repository at this point in the history
  • Loading branch information
vapao committed Sep 28, 2021
1 parent 3d9ef76 commit 405f477
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 36 deletions.
1 change: 1 addition & 0 deletions spug_api/apps/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def extend_obj(self):

def to_dict(self, *args, **kwargs):
deploy = super().to_dict(*args, **kwargs)
deploy['app_key'] = self.app_key if hasattr(self, 'app_key') else None
deploy['app_name'] = self.app_name if hasattr(self, 'app_name') else None
deploy['host_ids'] = json.loads(self.host_ids)
deploy['rst_notify'] = json.loads(self.rst_notify)
Expand Down
4 changes: 3 additions & 1 deletion spug_api/apps/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def get(self, request):
perms = request.user.deploy_perms
form.app_id__in = perms['apps']
form.env_id__in = perms['envs']
deploys = Deploy.objects.filter(**form).annotate(app_name=F('app__name')).order_by('-app__sort_id')
deploys = Deploy.objects.filter(**form) \
.annotate(app_name=F('app__name'), app_key=F('app__key')) \
.order_by('-app__sort_id')
return json_response(deploys)

def post(self, request):
Expand Down
45 changes: 17 additions & 28 deletions spug_web/src/components/AppSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
import React, { useState, useEffect } from 'react';
import { Link } from 'react-router-dom';
import { observer } from 'mobx-react';
import { Modal, Button, Menu, Spin, Input, Tooltip } from 'antd';
import { OrderedListOutlined, BuildOutlined } from '@ant-design/icons';
import { Modal, Menu, Spin, Input } from 'antd';
import { OrderedListOutlined, BuildOutlined, SearchOutlined } from '@ant-design/icons';
import { includes, http } from 'libs';
import styles from './index.module.less';
import envStore from 'pages/config/environment/store';
import lds from 'lodash';

export default observer(function AppSelector(props) {
const [fetching, setFetching] = useState(false);
const [refs, setRefs] = useState({});
const [env_id, setEnvId] = useState();
const [search, setSearch] = useState();
const [deploys, setDeploys] = useState([]);
Expand All @@ -38,17 +37,8 @@ export default observer(function AppSelector(props) {
}
}

function handleRef(el, id) {
if (el && !refs.hasOwnProperty(id)) {
setTimeout(() => {
refs[id] = el.scrollWidth > el.clientWidth;
setRefs({...refs})
}, 200)
}
}

let records = deploys.filter(x => x.env_id === Number(env_id));
if (search) records = records.filter(x => includes(x['app_name'], search));
if (search) records = records.filter(x => includes(x['app_name'], search) || includes(x['app_key'], search));
if (props.filter) records = records.filter(x => props.filter(x));
return (
<Modal
Expand Down Expand Up @@ -76,25 +66,24 @@ export default observer(function AppSelector(props) {
<Spin spinning={fetching}>
<div className={styles.title}>
<div>{lds.get(envStore.idMap, `${env_id}.name`)}</div>
<Input.Search
<Input
allowClear
style={{width: 200}}
placeholder="请输入快速搜应用"
placeholder="请输入快速检索应用"
prefix={<SearchOutlined style={{color: 'rgba(0, 0, 0, 0.25)'}}/>}
onChange={e => setSearch(e.target.value)}/>
</div>
{records.map(item => (
<Tooltip key={item.id} title={refs[item.id] ? item['app_name'] : null}>
<Button type="primary" className={styles.appBlock} onClick={() => props.onSelect(item)}>
<div ref={el => handleRef(el, item.id)}
style={{width: 135, overflow: 'hidden', textOverflow: 'ellipsis'}}>
{item.extend === '1' ? <OrderedListOutlined/> : <BuildOutlined/>}
<span style={{marginLeft: 8}}>{item.app_name}</span>
</div>
</Button>
</Tooltip>
))}
{records.length === 0 &&
<div className={styles.tips}>该环境下还没有可发布或构建的应用哦,快去<Link to="/deploy/app">应用管理</Link>创建应用发布配置吧。</div>}
<div style={{height: 540, overflow: 'auto'}}>
{records.map(item => (
<div key={item.id} className={styles.appItem} onClick={() => props.onSelect(item)}>
{item.extend === '1' ? <OrderedListOutlined/> : <BuildOutlined/>}
<div className={styles.body}>{item.app_name}</div>
<div style={{color: '#999'}}>{item.app_key}</div>
</div>
))}
{records.length === 0 &&
<div className={styles.tips}>该环境下还没有可发布或构建的应用哦,快去<Link to="/deploy/app">应用管理</Link>创建应用发布配置吧。</div>}
</div>
</Spin>
</div>
</div>
Expand Down
33 changes: 26 additions & 7 deletions spug_web/src/components/index.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,38 @@
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
margin-bottom: 24px;
color: rgba(0, 0, 0, .85);
font-weight: 500;
font-size: 20px;
line-height: 28px;
}

.appBlock {
margin-top: 20px;
width: 165px;
height: 60px;
font-size: 18px;
margin-right: 20px;
.appItem {
width: 560px;
display: flex;
align-items: center;
padding: 12px 16px;
margin-bottom: 8px;
background: #fafafa;
border-radius: 2px;

:global(.anticon) {
color: #1890ff;
margin-right: 16px;
}

.body {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}

.appItem:hover {
cursor: pointer;
background: #e6f7ff;
}

.tips {
Expand Down

0 comments on commit 405f477

Please sign in to comment.