Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ store.registerStores();

if (typeof window !== 'undefined') {
const AppWithRouter = withRouter(App);
try {
store.loginUser = JSON.parse(getCookie('loginUser') || '{}');
} catch (err) {}

import('./routes').then(({ default: routes }) => {
let sc = null;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Admin/Apps/Add/RepoList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class RepoList extends PureComponent {

return (
<div className={classNames(styles.repoList, { [styles.publicBg]: type === 'private' })}>
<div className={styles.title}>{capitalize(type)}</div>
<div className={styles.title}>{t(capitalize(type))}</div>
<ul>
{repos.map(repo => (
<li
Expand Down
11 changes: 7 additions & 4 deletions src/pages/Admin/Apps/Add/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ import styles from './index.scss';
}))
@observer
export default class AppAdd extends Component {
static async onEnter({ repoStore }) {
await repoStore.fetchAll({ noLimit: true });
static async onEnter({ repoStore, loginUser }) {
await repoStore.fetchAll({
noLimit: true,
isQueryPublic: loginUser.isDev
});
}

constructor(props) {
Expand Down Expand Up @@ -99,8 +102,8 @@ export default class AppAdd extends Component {
return (
<StepContent name={name} explain={explain} className={styles.createVersion}>
<div>
<RepoList type={t('public')} repos={publicRepos} onChange={this.onChange} />
<RepoList type={t('private')} repos={privateRepos} onChange={this.onChange} />
<RepoList type="public" repos={publicRepos} onChange={this.onChange} />
<RepoList type="private" repos={privateRepos} onChange={this.onChange} />
</div>
<div
onClick={() => this.selectRepoNext(selectRepos.length)}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Admin/Apps/Detail/DetailBlock/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class DetailBlock extends React.Component {
<dl>
<dt>{t('Status')}</dt>
<dd>
<Status name={appDetail.status} type={mappingStatus(appDetail.status)} />
<Status name={mappingStatus(appDetail.status)} type={appDetail.status} />
</dd>
</dl>
<dl>
Expand Down
20 changes: 7 additions & 13 deletions src/pages/Admin/Apps/Review/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ export default class Review extends Component {
const { repos } = repoStore;

let columns = [
{
title: t('Status'),
key: 'status',
width: '110px',
render: item => <Status type={item.status} name={mappingStatus(item.status)} />
},
{
title: t('App Name'),
key: 'name',
Expand All @@ -85,12 +91,6 @@ export default class Review extends Component {
width: '120px',
render: item => get(item, 'latest_app_version.name', '')
},
{
title: t('Status'),
key: 'status',
width: '90px',
render: item => <Status type={item.status} name={mappingStatus(item.status)} />
},
{
title: t('Categories'),
key: 'category',
Expand All @@ -103,12 +103,6 @@ export default class Review extends Component {
.join(', ')
)
},
{
title: t('Visibility'),
key: 'visibility',
width: '65px',
render: item => t(getObjName(repos, 'repo_id', item.repo_id, 'visibility'))
},
{
title: t('Repo'),
key: 'repo_id',
Expand All @@ -132,7 +126,7 @@ export default class Review extends Component {
{
title: t('Updated At'),
key: 'status_time',
width: '112px',
width: '92px',
sorter: this.role === 'global_admin',
onChangeSort: this.onChangeSort,
render: item => <TimeShow time={item.status_time} />
Expand Down
20 changes: 11 additions & 9 deletions src/pages/Admin/Apps/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import styles from './index.scss';
}))
@observer
export default class Apps extends Component {
static async onEnter({ appStore, categoryStore, repoStore, sessInfo }) {
static async onEnter({ appStore, categoryStore, repoStore, loginUser }) {
await appStore.fetchAll();
await repoStore.fetchAll({
status: ['active', 'deleted'],
noLimit: true
noLimit: true,
isQueryPublic: loginUser.isDev
});
await categoryStore.fetchAll();
}
Expand Down Expand Up @@ -205,9 +206,15 @@ export default class Apps extends Component {
render() {
const { appStore, repoStore, t } = this.props;
const { apps, summaryInfo, isLoading, onChangeStatus, selectStatus, viewType } = appStore;

const { repos } = repoStore;

let navLinkShow = t('My Apps') + ' / ' + t('All');
let urlFront = '/dashboard/app/';
if (this.role === 'global_admin') {
navLinkShow = t('Store') + ' / ' + t('All Apps');
urlFront = '/store/';
}

let columns = [
{
title: t('App Name'),
Expand All @@ -218,7 +225,7 @@ export default class Apps extends Component {
name={item.name}
description={item.app_id}
image={item.icon || 'appcenter'}
linkUrl={`/dashboard/app/${item.app_id}`}
linkUrl={urlFront + item.app_id}
/>
)
},
Expand Down Expand Up @@ -326,11 +333,6 @@ export default class Apps extends Component {
noCancel: false
};

let navLinkShow = t('My Apps') + ' / ' + t('All');
if (this.role === 'global_admin') {
navLinkShow = t('Store') + ' / ' + t('All Apps');
}

return (
<Layout className={styles.apps}>
<NavLink>{navLinkShow}</NavLink>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Admin/Categories/Detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class CategoryDetail extends Component {
return (
<div className="operate-menu">
<span onClick={() => showModifyCategory(category)}>{t('Modify Category')}</span>
<span onClick={() => showDeleteCategory(category)}>{t('Delete Category')}</span>
<span onClick={() => showDeleteCategory(category)}>{t('Delete')}</span>
</div>
);
};
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Admin/Repos/Add/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ export default class RepoAdd extends Component {
className={styles.input}
placeholder="www.example.com/path/point/"
maxLength="100"
required
name="url"
title={url}
required={!Boolean(repoId)}
disabled={Boolean(repoId)}
/>

Expand All @@ -144,13 +144,13 @@ export default class RepoAdd extends Component {
</p>
<Input
className={styles.inputMiddle}
required
required={!Boolean(repoId)}
value={accessKey}
onChange={this.store.changeAccessKey}
/>
<Input
className={styles.inputMiddle}
required
required={!Boolean(repoId)}
value={secretKey}
onChange={this.store.changeSecretKey}
/>
Expand Down
11 changes: 8 additions & 3 deletions src/pages/Admin/Repos/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ import styles from './index.scss';

@translate()
@inject(({ rootStore, sessInfo }) => ({
rootStore,
repoStore: rootStore.repoStore,
appStore: rootStore.appStore,
sessInfo
}))
@observer
export default class Repos extends Component {
static async onEnter({ repoStore, appStore }) {
static async onEnter({ repoStore, appStore, loginUser }) {
repoStore.appStore = appStore;
await repoStore.fetchAll({ noLimit: true }, appStore);
await repoStore.fetchAll(
{
noLimit: true,
isQueryPublic: loginUser.isDev
},
appStore
);
}

constructor(props) {
Expand Down
4 changes: 3 additions & 1 deletion src/pages/AppDetail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ export default class AppDetail extends Component {
const appDetail = appStore.appDetail;
const role = getSessInfo('role', sessInfo);
const isNormal = role === 'user';
const { path } = this.props.match;
const isShowReview = role === 'global_admin' && path.indexOf('review') > -1;

return (
<Layout
Expand All @@ -259,7 +261,7 @@ export default class AppDetail extends Component {

{this.renderVersions()}
</Grid>
{role === 'global_admin' && this.renderAdminReview()}
{isShowReview && this.renderAdminReview()}
{this.renderReasonDialog()}
</Layout>
);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Profile/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class Profile extends Component {
<label className={styles.name}>{t('User Name')}</label>
<Input
className={styles.input}
name="name"
name="username"
maxLength={50}
value={userDetail.username}
onChange={e => {
Expand Down
1 change: 1 addition & 0 deletions src/stores/RootStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const defaultNotifyOption = { title: '', message: '', type: 'info' };
export default class RootStore extends Store {
@observable fixNav = false;
@observable notifications = [];
@observable loginUser = {};

constructor(initialState) {
super(initialState);
Expand Down
10 changes: 10 additions & 0 deletions src/stores/UserStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,19 @@ export default class UserStore extends Store {
this.isLoading = true;
const result = await this.request.get(`users`, { user_id: userId });
this.userDetail = get(result, 'user_set[0]', {});

if (isLogin) {
const userInfo = pick({ ...this.userDetail }, ['user_id', 'username', 'email', 'role']);
const loginUser = {
...userInfo,
isAdmin: userInfo.role === 'global_admin',
isDev: userInfo.role === 'developer',
isUser: userInfo.role === 'user'
};
setCookie('user', this.userDetail.username, this.cookieTime);
setCookie('loginUser', JSON.stringify(loginUser), this.cookieTime);
}

this.isLoading = false;
};

Expand Down
30 changes: 7 additions & 23 deletions src/stores/repo/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,8 @@ export default class RepoCreateStore extends Store {
return this.info('Labels missing key');
}
}
/* if (_.isEmpty(selectors)) {
this.isLoading = false;
return this.info('missing selectors');
}

if (_.isEmpty(labels)) {
this.isLoading = false;
return this.info('missing labels');
}*/

if (protocolType === 's3') {
if (data.url && protocolType === 's3') {
data.credential = JSON.stringify({
access_key_id: accessKey,
secret_access_key: secretKey
Expand All @@ -205,21 +196,11 @@ export default class RepoCreateStore extends Store {
data.credential = '{}';
}

// fixme: both labels and selectors pass as queryString
/* data.selectors = selectors.map(selector => ({
selector_key: selector.label_key,
selector_value: selector.label_value
}));

data.labels = labels.map(label => ({
label_key: label.label_key,
label_value: label.label_value
}));*/

// fixed: both labels and selectors pass as queryString
data.selectors = this.toQueryString(selectors);
data.labels = this.toQueryString(labels);

// fix: provider is mobx array
// fixed: provider is mobx array
let flatProviders = providers.toJSON();
if (typeof flatProviders[0] !== 'string' && flatProviders[0].toJSON) {
flatProviders = flatProviders[0].toJSON();
Expand All @@ -234,6 +215,9 @@ export default class RepoCreateStore extends Store {
this.isLoading = true;
if (this.repoId) {
delete data.url;
if (!accessKey) {
delete data.credential;
}
_.extend(data, { repo_id: this.repoId });
await this.modifyRepo(data);
} else {
Expand All @@ -246,7 +230,7 @@ export default class RepoCreateStore extends Store {
this.success('Create repo successfully');
}

// disable re-submit form in 2 sec
// disable re-submit form in 1 sec
setTimeout(() => {
this.isLoading = false;
}, 1000);
Expand Down
13 changes: 12 additions & 1 deletion src/stores/repo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,22 @@ export default class RepoStore extends Store {
const result = await this.request.get('repos', assign(defaultParams, params));
this.repos = get(result, 'repo_set', []);
this.totalCount = get(result, 'total_count', 0);

if (params.isQueryPublic) {
delete params.isQueryPublic;
params.visibility = ['public'];
const pubResult = await this.request.get('repos', assign(defaultParams, params));
const pubRepos = get(pubResult, 'repo_set', []);
this.repos = [...pubRepos, ...this.repos];
}

if (appStore) {
for (let i = 0; i < this.initLoadNumber && i < this.repos.length; i++) {
await appStore.fetchAll({ repo_id: this.repos[i].repo_id });
this.repos[i] = { total: appStore.totalCount, apps: appStore.apps, ...this.repos[i] };
}
}

this.isLoading = false;
};

Expand Down Expand Up @@ -202,10 +212,11 @@ export default class RepoStore extends Store {
}

const itemKey = type === 'selectors' ? 'selector_key' : 'label_key';
const itemValue = type === 'selectors' ? 'selector_value' : 'label_value';

return get(this.repoDetail, type, [])
.filter(item => Boolean(item[itemKey]))
.map(item => values(item).join('='))
.map(item => item[itemKey] + '=' + item[itemValue])
.join('&');
};
}
Expand Down
8 changes: 1 addition & 7 deletions src/stores/runtime/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ export default class RuntimeCreateStore extends Store {

@action
handleValidateCredential = () => {
if (this.runtimeUrl && this.accessKey && this.secretKey) {
this.getRuntimeZone();
} else {
this.error('Incomplete credential information!');
}
this.getRuntimeZone();
};

@action
Expand Down Expand Up @@ -239,8 +235,6 @@ export default class RuntimeCreateStore extends Store {
this.runtimeZones = _.get(result, 'zone', []);
if (this.runtimeZones.length > 0) {
this.success('Get zone data success!');
} else {
this.error('Get zone data fail!');
}
}

Expand Down