Skip to content

Commit 44a7a3f

Browse files
committed
chore: code refactoring
1 parent d487694 commit 44a7a3f

File tree

6 files changed

+14
-35
lines changed

6 files changed

+14
-35
lines changed

src/Pages/GlobalConfigurations/Authorization/APITokens/ApiTokens.component.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
import emptyGeneratToken from '@Images/ic-empty-generate-token.png'
2929
import { EMPTY_STATE_STATUS } from '@Config/constantMessaging'
3030

31-
import { TokenListType, TokenResponseType } from './apiToken.type'
31+
import { TokenListType } from './apiToken.type'
3232
import APITokenList from './APITokenList'
3333
import CreateAPIToken from './CreateAPIToken'
3434
import EditAPIToken from './EditAPIToken'
@@ -80,10 +80,7 @@ const ApiTokens = () => {
8080

8181
const handleFilterChanges = (_searchText: string): void => {
8282
const _searchTextTrimmed = _searchText.trim()
83-
const _filteredData = tokenList.filter(
84-
(_tokenData) =>
85-
_tokenData.name.indexOf(_searchTextTrimmed) >= 0 || _tokenData?.token?.indexOf(_searchTextTrimmed) >= 0,
86-
)
83+
const _filteredData = tokenList.filter((_tokenData) => _tokenData.name.indexOf(_searchTextTrimmed) >= 0)
8784
setFilteredTokenList(_filteredData)
8885
setNoResults(_filteredData.length === 0)
8986
}
@@ -93,14 +90,6 @@ const ApiTokens = () => {
9390
handleFilterChanges(_searchText)
9491
}
9592

96-
const [tokenResponse, setTokenResponse] = useState<TokenResponseType>({
97-
success: false,
98-
token: '',
99-
userId: 0,
100-
userIdentifier: 'API-TOKEN:test',
101-
hideApiToken: false,
102-
})
103-
10493
const renderSearchToken = () => (
10594
<SearchBar
10695
initialSearchText={searchText}
@@ -135,8 +124,6 @@ const ApiTokens = () => {
135124
handleGenerateTokenActionButton={handleActionButton}
136125
setSelectedExpirationDate={setSelectedExpirationDate}
137126
selectedExpirationDate={selectedExpirationDate}
138-
tokenResponse={tokenResponse}
139-
setTokenResponse={setTokenResponse}
140127
reload={getData}
141128
/>
142129
</Route>

src/Pages/GlobalConfigurations/Authorization/APITokens/CreateAPIToken.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343
usePermissionConfiguration,
4444
} from '../Shared/components/PermissionConfigurationForm'
4545
import { createUserPermissionPayload, validateDirectPermissionForm } from '../utils'
46-
import { FormType, GenerateTokenType } from './apiToken.type'
46+
import { FormType, GenerateTokenType, TokenResponseType } from './apiToken.type'
4747
import { getDateInMilliseconds } from './apiToken.utils'
4848
import ExpirationDate from './ExpirationDate'
4949
import GenerateActionButton from './GenerateActionButton'
@@ -69,8 +69,6 @@ const CreateAPIToken = ({
6969
handleGenerateTokenActionButton,
7070
setSelectedExpirationDate,
7171
selectedExpirationDate,
72-
tokenResponse,
73-
setTokenResponse,
7472
reload,
7573
}: GenerateTokenType) => {
7674
const history = useHistory()
@@ -106,6 +104,13 @@ const CreateAPIToken = ({
106104
allowManageAllAccess,
107105
} = usePermissionConfiguration()
108106
const [customDate, setCustomDate] = useState<Moment>(null)
107+
const [tokenResponse, setTokenResponse] = useState<TokenResponseType>({
108+
success: false,
109+
token: '',
110+
userId: 0,
111+
userIdentifier: 'API-TOKEN:test',
112+
hideApiToken: false,
113+
})
109114
const validationRules = new ValidationRules()
110115

111116
// Reset selected expiration date to 30 days on unmount

src/Pages/GlobalConfigurations/Authorization/APITokens/EditAPIToken.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ const EditAPIToken = ({
125125
const userPermissionPayload = createUserPermissionPayload({
126126
id: editData.userId,
127127
userIdentifier: editData.userIdentifier,
128-
hideApiToken: result.hideApiToken,
129128
userRoleGroups,
130129
serverMode,
131130
directPermission,

src/Pages/GlobalConfigurations/Authorization/APITokens/apiToken.type.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ export interface GenerateTokenType {
3838
handleGenerateTokenActionButton: () => void
3939
setSelectedExpirationDate
4040
selectedExpirationDate
41-
tokenResponse: TokenResponseType
42-
setTokenResponse: React.Dispatch<React.SetStateAction<TokenResponseType>>
4341
reload: () => void
4442
}
4543

src/components/ciPipeline/Webhook/WebhookDetailsModal.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ import { createGeneratedAPIToken } from '@Pages/GlobalConfigurations/Authorizati
5454
import {
5555
CURL_PREFIX,
5656
GENERATE_TOKEN_WITH_REQUIRED_PERMISSIONS,
57-
getWebhookTokenListOptions,
5857
PLAYGROUND_TAB_LIST,
5958
REQUEST_BODY_TAB_LIST,
6059
RESPONSE_TAB_LIST,
@@ -72,7 +71,6 @@ import {
7271
getDefaultUserStatusAndTimeout,
7372
} from '@Pages/GlobalConfigurations/Authorization/libUtils'
7473
import { getApiTokenHeader } from '@Pages/GlobalConfigurations/Authorization/APITokens/apiToken.utils'
75-
import { TokenListType } from '@Pages/GlobalConfigurations/Authorization/APITokens/apiToken.type'
7674

7775
export const WebhookDetailsModal = ({ close, isTemplateView }: WebhookDetailType) => {
7876
const { appId, webhookId } = useParams<{
@@ -102,7 +100,7 @@ export const WebhookDetailsModal = ({ close, isTemplateView }: WebhookDetailType
102100
const [showTryoutAPITokenError, setTryoutAPITokenError] = useState(false)
103101
const [webhookDetails, setWebhookDetails] = useState<WebhookDetailsType>(null)
104102
const [selectedToken, setSelectedToken] = useState<TokenListOptionsType>(null)
105-
const [tokenList, setTokenList] = useState<TokenListType[]>(null)
103+
const [tokenList, setTokenList] = useState<TokenListOptionsType[]>(null)
106104
const [selectedSchema, setSelectedSchema] = useState<string>('')
107105
const [errorInGetData, setErrorInGetData] = useState(false)
108106
const [copyToClipboardPromise, setCopyToClipboardPromise] = useState<ReturnType<typeof copyToClipboard>>(null)
@@ -205,7 +203,8 @@ export const WebhookDetailsModal = ({ close, isTemplateView }: WebhookDetailType
205203
.map((tokenData) => ({
206204
...tokenData,
207205
label: tokenData.name,
208-
value: tokenData.id,
206+
value: tokenData.id.toString(),
207+
description: 'Has access',
209208
})) || []
210209
setTokenList(sortedResult)
211210
}
@@ -466,7 +465,7 @@ export const WebhookDetailsModal = ({ close, isTemplateView }: WebhookDetailType
466465
classNamePrefix="select-token"
467466
placeholder="Select API token"
468467
isClearable={false}
469-
options={getWebhookTokenListOptions(tokenList)}
468+
options={tokenList}
470469
value={selectedToken}
471470
onChange={handleSelectedTokenChange}
472471
isSearchable={false}

src/components/ciPipeline/Webhook/webhook.utils.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,3 @@ export const GENERATE_TOKEN_WITH_REQUIRED_PERMISSIONS = 'Generate token with req
4646
export const SELECT_AUTO_GENERATE_TOKEN_WITH_REQUIRED_PERMISSIONS =
4747
'Select or auto-generate token with required permissions'
4848

49-
export const getWebhookTokenListOptions = (tokenList: TokenListType[]): TokenListOptionsType[] =>
50-
tokenList.map((token) => {
51-
return {
52-
...token,
53-
label: token.name,
54-
value: token.id.toString(),
55-
description: 'Has access',
56-
}
57-
})

0 commit comments

Comments
 (0)