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
[RAM] Add the feature for slack api to have allowed list on channels #159534
Conversation
x-pack/plugins/stack_connectors/public/connector_types/slack_api/translations.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/stack_connectors/public/connector_types/slack_api/slack_connectors.tsx
Outdated
Show resolved
Hide resolved
…pi/translations.ts Co-authored-by: Lisa Cawley <lcawley@elastic.co>
…pi/slack_connectors.tsx Co-authored-by: Lisa Cawley <lcawley@elastic.co>
Pinging @elastic/response-ops (Team:ResponseOps) |
x-pack/plugins/triggers_actions_ui/public/application/components/simple_connector_form.tsx
Show resolved
Hide resolved
x-pack/plugins/stack_connectors/server/routes/get_slack_api_channels.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/stack_connectors/public/connector_types/slack_api/slack_connectors.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/stack_connectors/server/connector_types/slack_api/service.ts
Show resolved
Hide resolved
const debounceSetToken = debounce(setAuthToken, INPUT_TIMEOUT); | ||
useEffect(() => { | ||
if (formData.secrets && formData.secrets.token !== authToken) { | ||
debounceSetToken(formData.secrets.token); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [formData.secrets]); |
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.
I don't think you need the useEffect
here. You can do:
const authToken = formData.secrets && formData.secrets.token ? formData.secrets.token : ''
const debounceSetToken = debounce(setAuthToken, INPUT_TIMEOUT);
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.
I do believe that you need the useEffect, if the user decide to empty the token or not and also the way the form lib is getting initialized
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.
Maybe I miss something but if the user decides to empty the token it will still run the code, right? I don't see any difference between having the useEffect
and not having it in this code. Probably I miss something.
x-pack/plugins/stack_connectors/public/connector_types/slack_api/slack_connectors.tsx
Outdated
Show resolved
Hide resolved
|
||
return ( | ||
<SimpleConnectorForm | ||
isEdit={isEdit} | ||
readOnly={readOnly} | ||
configFormSchema={[]} | ||
secretsFormSchema={getSecretsFormSchema(docLinks)} | ||
configFormSchemaAfterSecrets={configFormSchemaAfterSecrets} |
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.
I get the reasoning behind it (given also time constraints) but I think the slack connector should have its own customized component and not use the SimpleConnectorForm
. The reason is not the position of the configs after the secrets but mostly that the secrets are connected with these configs. We should disable the channels combo box until the user has filled out the secrets and provided a helpful message why they are disabled and what the user should do to be able to config the allowed channels. In Swimlane (more complex), we use steps where in step 1 you put the URL and the password and in step 2 you configure the rest of the options (I am not proposing this complex UI for the slack connector).
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.
Ok, I just see what you did with configFormSchemaAfterSecrets
. You connected them with getConfigFormSchemaAfterSecrets
. Makes sense.
id: 'allowedChannels', | ||
isRequired: false, | ||
label: i18n.ALLOWED_CHANNELS, | ||
helpText: ( |
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.
Maybe we can add a message explaining why the combo box is disabled if the user has not filled out the secrets.
x-pack/plugins/stack_connectors/public/connector_types/slack_api/slack_connectors.tsx
Outdated
Show resolved
Hide resolved
} | ||
|
||
const configFormSchemaAfterSecrets = useMemo( | ||
() => getConfigFormSchemaAfterSecrets(channels, isLoading, channels.length === 0), |
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.
I think we should disable it formData.secrets.token
is undefined
.
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.
that will be taking care when the channels is empty
@@ -32,35 +39,45 @@ interface SimpleConnectorFormProps { | |||
readOnly: boolean; | |||
configFormSchema: ConfigFieldSchema[]; | |||
secretsFormSchema: SecretsFieldSchema[]; | |||
configFormSchemaAfterSecrets?: ConfigFieldSchema[]; |
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.
Another solution would be to extend ConfigFieldSchema
with a afterSecrets?: boolean
attribute and do the partition in the SimpleConnectorFormComponent
. This way consumers will not have to create two configurations.
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.
You might need both, I do not know!
x-pack/plugins/triggers_actions_ui/public/application/components/simple_connector_form.tsx
Outdated
Show resolved
Hide resolved
…a into slack_api_allowed_channels
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.
LGTM! Great to see react query being used.
Just have 1 small nitpick regarding naming
import { INTERNAL_BASE_STACK_CONNECTORS_API_PATH } from '../../../common'; | ||
import * as i18n from './translations'; | ||
|
||
interface UseLoadTagsQueryProps { |
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.
nitpick: this should be UseFetchChannelsProps
💚 Build Succeeded
Metrics [docs]Module Count
Public APIs missing comments
Async chunks
Page load bundle
Unknown metric groupsAPI count
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
Summary
This will enable our user to create a slack api connector with the ability to only allow some channels as an allowed list. Our user will only be able to edit this input if the secrets is enter like the
test
button work.Checklist
Delete any items that are not applicable to this PR.