-
Notifications
You must be signed in to change notification settings - Fork 748
OCPBUGS-113745: Fix quick-win React Compiler warnings #17094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
platex-rehor-bot
wants to merge
4
commits into
openshift:main
Choose a base branch
from
platex-rehor-bot:bot/OCPBUGS-113745
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d34fcab
fix(lint): resolve 11 quick-win React Compiler ESLint warnings
platex-rehor-bot 2a36ff8
fix(webhook): resolve lint errors in WebhookSection
platex-rehor-bot 7fc5786
fix(review): address PR review feedback
platex-rehor-bot 86ca033
fix(review): address PR feedback and fix CI lint failure
platex-rehor-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,6 +48,60 @@ const AccessTokenDocLinks = { | |
| [GitProvider.BITBUCKET]: 'https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/', | ||
| }; | ||
|
|
||
| interface WebhookHelpTextProps { | ||
| gitProvider: GitProvider; | ||
| testId: string; | ||
| } | ||
|
|
||
| const WebhookHelpText: FC<WebhookHelpTextProps> = ({ gitProvider, testId }): ReactElement => { | ||
| const { t } = useTranslation('devconsole'); | ||
| let helpText: ReactNode; | ||
| switch (gitProvider) { | ||
| case GitProvider.GITHUB: | ||
| helpText = ( | ||
| <Trans t={t} ns="devconsole"> | ||
| Use your GitHub Personal token. Use this{' '} | ||
| <ExternalLink href={AccessTokenDocLinks[GitProvider.GITHUB]}>link</ExternalLink> to create | ||
| a <strong>classic</strong> token with <strong>repo</strong> & <strong>admin:repo_hook</strong> scopes and give your | ||
| token an expiration, i.e 30d. | ||
| </Trans> | ||
| ); | ||
| break; | ||
|
|
||
| case GitProvider.GITLAB: | ||
| helpText = ( | ||
| <Trans t={t} ns="devconsole"> | ||
| Use your Gitlab Personal access token. Use this{' '} | ||
| <ExternalLink href={AccessTokenDocLinks[GitProvider.GITLAB]}>link</ExternalLink> to create | ||
| a token with <strong>api</strong> scope. Select the role as <strong>Maintainer/Owner</strong>. Give your token | ||
| an expiration i.e 30d. | ||
| </Trans> | ||
| ); | ||
| break; | ||
|
|
||
| case GitProvider.BITBUCKET: | ||
| helpText = ( | ||
| <Trans t={t} ns="devconsole"> | ||
| Use your Bitbucket App password. Use this{' '} | ||
| <ExternalLink href={AccessTokenDocLinks[GitProvider.BITBUCKET]}>link</ExternalLink> to | ||
| create a token with <strong>Read and Write </strong>scopes in{' '} | ||
| <strong>Account, Workspace membership, Projects, Issues, Pull requests and Webhooks</strong>. | ||
| </Trans> | ||
| ); | ||
| break; | ||
|
|
||
| default: | ||
| helpText = ( | ||
| <Trans t={t} ns="devconsole"> | ||
| Use your Git Personal token. Create a token with repo, public_repo & admin:repo_hook | ||
| scopes and give your token an expiration, i.e 30d. | ||
| </Trans> | ||
| ); | ||
| } | ||
|
|
||
|
Comment on lines
+63
to
+101
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done — replaced with |
||
| return <div data-test={testId}>{helpText}</div>; | ||
| }; | ||
|
|
||
| const WebhookDocLinks = { | ||
| [GitProvider.GITHUB]: | ||
| 'https://docs.github.com/en/developers/webhooks-and-events/webhooks/creating-webhooks', | ||
|
|
@@ -61,17 +115,15 @@ const WebhookSection: FC<WebhoookSectionProps> = ({ pac, formContextField }) => | |
| const { values, setFieldValue } = useFormikContext<FormikValues>(); | ||
| const fieldPrefix = formContextField ? `${formContextField}.` : ''; | ||
| const { gitProvider, webhook } = _.get(values, formContextField) || values; | ||
| const [controllerUrl, setControllerUrl] = useState(''); | ||
| const controllerUrl = useMemo(() => pac?.data?.['controller-url'] || '', [pac]); | ||
| const [webhookSecret, setWebhookSecret] = useState(''); | ||
| const { t } = useTranslation('devconsole'); | ||
|
|
||
| useEffect(() => { | ||
| const ctlUrl = pac?.data?.['controller-url']; | ||
| if (ctlUrl) { | ||
| setControllerUrl(ctlUrl); | ||
| setFieldValue(`${fieldPrefix}webhook.url`, ctlUrl); | ||
| if (controllerUrl) { | ||
| setFieldValue(`${fieldPrefix}webhook.url`, controllerUrl); | ||
| } | ||
| }, [fieldPrefix, pac, setFieldValue]); | ||
| }, [fieldPrefix, controllerUrl, setFieldValue]); | ||
|
|
||
| const autocompleteFilter = (text: string, item: any): boolean => fuzzy(text, item?.props?.name); | ||
|
|
||
|
|
@@ -116,54 +168,6 @@ const WebhookSection: FC<WebhoookSectionProps> = ({ pac, formContextField }) => | |
| } | ||
| }; | ||
|
|
||
| const HelpText = (): ReactElement => { | ||
| let helpText: ReactNode; | ||
| switch (gitProvider) { | ||
| case GitProvider.GITHUB: | ||
| helpText = ( | ||
| <Trans t={t} ns="devconsole"> | ||
| Use your GitHub Personal token. Use this{' '} | ||
| <ExternalLink href={AccessTokenDocLinks[GitProvider.GITHUB]}>link</ExternalLink> to | ||
| create a <b>classic</b> token with <b>repo</b> & <b>admin:repo_hook</b> scopes and give | ||
| your token an expiration, i.e 30d. | ||
| </Trans> | ||
| ); | ||
| break; | ||
|
|
||
| case GitProvider.GITLAB: | ||
| helpText = ( | ||
| <Trans t={t} ns="devconsole"> | ||
| Use your Gitlab Personal access token. Use this{' '} | ||
| <ExternalLink href={AccessTokenDocLinks[GitProvider.GITLAB]}>link</ExternalLink> to | ||
| create a token with <b>api</b> scope. Select the role as <b>Maintainer/Owner</b>. Give | ||
| your token an expiration i.e 30d. | ||
| </Trans> | ||
| ); | ||
| break; | ||
|
|
||
| case GitProvider.BITBUCKET: | ||
| helpText = ( | ||
| <Trans t={t} ns="devconsole"> | ||
| Use your Bitbucket App password. Use this{' '} | ||
| <ExternalLink href={AccessTokenDocLinks[GitProvider.BITBUCKET]}>link</ExternalLink> to | ||
| create a token with <b>Read and Write </b>scopes in{' '} | ||
| <b>Account, Workspace membership, Projects, Issues, Pull requests and Webhooks</b>. | ||
| </Trans> | ||
| ); | ||
| break; | ||
|
|
||
| default: | ||
| helpText = ( | ||
| <Trans t={t} ns="devconsole"> | ||
| Use your Git Personal token. Create a token with repo, public_repo & admin:repo_hook | ||
| scopes and give your token an expiration, i.e 30d. | ||
| </Trans> | ||
| ); | ||
| } | ||
|
|
||
| return <div data-test={`${values.gitProvider}-helptext`}>{helpText}</div>; | ||
| }; | ||
|
|
||
| return ( | ||
| <FormSection fullWidth={!fieldPrefix} extraMargin> | ||
| {gitProvider && gitProvider === GitProvider.BITBUCKET ? ( | ||
|
|
@@ -200,7 +204,12 @@ const WebhookSection: FC<WebhoookSectionProps> = ({ pac, formContextField }) => | |
| <InputField | ||
| name={`${fieldPrefix}webhook.token`} | ||
| type={TextInputTypes.text} | ||
| helpText={<HelpText />} | ||
| helpText={ | ||
| <WebhookHelpText | ||
| gitProvider={gitProvider} | ||
| testId={`${values.gitProvider}-helptext`} | ||
| /> | ||
| } | ||
| required | ||
| /> | ||
| ), | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mechanically the same thing as useCallback and does nothing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point — the
useMemowrapper is functionally equivalent touseCallbackhere. However, reverting touseCallbacktriggers a lint error (React Hook useCallback received a function whose dependencies are unknown. Pass an inline function instead) since_.debounce()returns a non-inline function. KeepinguseMemowith the inline factory avoids that lint error while being semantically equivalent. Removed the unnecessary eslint-disable comment either way.