1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-17 14:37:58 +00:00

change repo API token permission select (#7250)

This commit is contained in:
Michael An 2024-12-27 21:53:08 +08:00 committed by GitHub
parent b83e272f94
commit ca42f80d57
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 11 deletions

View File

@ -102,11 +102,10 @@ class RepoAPITokenDialog extends React.Component {
loading: true, loading: true,
isSubmitBtnActive: true, isSubmitBtnActive: true,
}; };
this.repo = this.props.repo;
} }
listAPITokens = () => { listAPITokens = () => {
seafileAPI.listRepoAPITokens(this.repo.repo_id).then((res) => { seafileAPI.listRepoAPITokens(this.props.repo.repo_id).then((res) => {
this.setState({ this.setState({
apiTokenList: res.data.repo_api_tokens, apiTokenList: res.data.repo_api_tokens,
loading: false, loading: false,
@ -150,7 +149,7 @@ class RepoAPITokenDialog extends React.Component {
}); });
const { appName, permission, apiTokenList } = this.state; const { appName, permission, apiTokenList } = this.state;
seafileAPI.addRepoAPIToken(this.repo.repo_id, appName, permission).then((res) => { seafileAPI.addRepoAPIToken(this.props.repo.repo_id, appName, permission).then((res) => {
apiTokenList.push(res.data); apiTokenList.push(res.data);
this.setState({ this.setState({
apiTokenList: apiTokenList, apiTokenList: apiTokenList,
@ -165,7 +164,7 @@ class RepoAPITokenDialog extends React.Component {
}; };
deleteAPIToken = (appName) => { deleteAPIToken = (appName) => {
seafileAPI.deleteRepoAPIToken(this.repo.repo_id, appName).then((res) => { seafileAPI.deleteRepoAPIToken(this.props.repo.repo_id, appName).then((res) => {
const apiTokenList = this.state.apiTokenList.filter(item => { const apiTokenList = this.state.apiTokenList.filter(item => {
return item.app_name !== appName; return item.app_name !== appName;
}); });
@ -178,7 +177,7 @@ class RepoAPITokenDialog extends React.Component {
}; };
updateAPIToken = (appName, permission) => { updateAPIToken = (appName, permission) => {
seafileAPI.updateRepoAPIToken(this.repo.repo_id, appName, permission).then((res) => { seafileAPI.updateRepoAPIToken(this.props.repo.repo_id, appName, permission).then((res) => {
let apiTokenList = this.state.apiTokenList.filter(item => { let apiTokenList = this.state.apiTokenList.filter(item => {
if (item.app_name === appName) { if (item.app_name === appName) {
item.permission = permission; item.permission = permission;
@ -280,9 +279,7 @@ class RepoAPITokenDialog extends React.Component {
}; };
render() { render() {
let repo = this.repo; const itemName = '<span class="op-target text-truncate mr-1">' + Utils.HTMLescape(this.props.repo.repo_name) + '</span>';
const itemName = '<span class="op-target text-truncate mr-1">' + Utils.HTMLescape(repo.repo_name) + '</span>';
const title = gettext('{placeholder} API Token').replace('{placeholder}', itemName); const title = gettext('{placeholder} API Token').replace('{placeholder}', itemName);
return ( return (
<Modal <Modal

View File

@ -1,4 +1,4 @@
import React, { Fragment } from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { gettext } from '../../utils/constants'; import { gettext } from '../../utils/constants';
import OpIcon from '../op-icon'; import OpIcon from '../op-icon';
@ -58,14 +58,16 @@ class RepoAPITokenPermissionEditor extends React.Component {
return ( return (
<div onClick={this.onSelectHandler}> <div onClick={this.onSelectHandler}>
{(isTextMode && !this.state.isEditing) ? {(isTextMode && !this.state.isEditing) ?
<Fragment> <>
<span>{optionTranslation}</span> <span>{optionTranslation}</span>
{this.props.isEditIconShow && {this.props.isEditIconShow &&
<OpIcon title={gettext('Edit')} className="sf3-font sf3-font-rename attr-action-icon" op={this.onEditPermission} /> <OpIcon title={gettext('Edit')} className="sf3-font sf3-font-rename attr-action-icon" op={this.onEditPermission} />
} }
</Fragment> </>
: :
<SeahubSelect <SeahubSelect
isSearchable={false}
isClearable={false}
options={this.options} options={this.options}
placeholder={optionTranslation} placeholder={optionTranslation}
onChange={this.onPermissionChanged} onChange={this.onPermissionChanged}