refactor: remove coupling with form context
Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
This commit is contained in:
@@ -488,8 +488,6 @@ repoUrl:
|
||||
host: github.com
|
||||
```
|
||||
|
||||
This value will be overridden if a different host is specified in a `RepoUrlPicker` field extension.
|
||||
|
||||
### `excludedOwners`
|
||||
|
||||
List of owners that should be excluded from autocompletion.
|
||||
|
||||
@@ -570,12 +570,13 @@ Similar to the repository picker, there is a picker for owners to support autoco
|
||||
ui:field: RepoOwnerPicker
|
||||
ui:options:
|
||||
host: github.com
|
||||
excludedOwners:
|
||||
- backstage
|
||||
requestUserCredentials:
|
||||
secretsKey: USER_OAUTH_TOKEN
|
||||
```
|
||||
|
||||
Passing the `requestUserCredentials` and `host` properties is required for autocompletion to work. Only if the template contains a `RepoUrlPicker` field extension, `host` can be omitted as it will use the host specified in the field extension.
|
||||
For more information regarding the `requestUserCredentials` object, please refer to the [Using the Users `oauth` token](#using-the-users-oauth-token) section under [The Repository Picker](#the-repository-picker).
|
||||
Passing the `requestUserCredentials` and `host` properties is required for autocompletion to work. For more information regarding the `requestUserCredentials` object, please refer to the [Using the Users `oauth` token](#using-the-users-oauth-token) section under [The Repository Picker](#the-repository-picker).
|
||||
|
||||
For a list of all possible `ui:options` input props for `RepoOwnerPicker`, please visit [here](./ui-options-examples.md#repoownerpicker).
|
||||
|
||||
|
||||
@@ -35,19 +35,7 @@ import { GitHubRepoOwnerPicker } from './GitHubRepoOwnerPicker';
|
||||
* @public
|
||||
*/
|
||||
export const RepoOwnerPicker = (props: RepoOwnerPickerProps) => {
|
||||
const {
|
||||
uiSchema,
|
||||
onChange,
|
||||
rawErrors,
|
||||
formData,
|
||||
schema,
|
||||
formContext,
|
||||
required,
|
||||
} = props;
|
||||
const {
|
||||
formData: { repoUrl },
|
||||
} = formContext;
|
||||
|
||||
const { uiSchema, onChange, rawErrors, formData, schema, required } = props;
|
||||
const [state, setState] = useState<RepoOwnerPickerState>({
|
||||
owner: formData || '',
|
||||
});
|
||||
@@ -95,18 +83,11 @@ export const RepoOwnerPicker = (props: RepoOwnerPickerProps) => {
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (repoUrl) {
|
||||
const url = new URL(`https://${repoUrl}`);
|
||||
|
||||
setState(prevState => ({
|
||||
...prevState,
|
||||
host: url.host,
|
||||
}));
|
||||
} else if (uiSchema?.['ui:options']?.host) {
|
||||
const hardcodedHost = uiSchema['ui:options'].host;
|
||||
setState(prevState => ({ ...prevState, host: hardcodedHost }));
|
||||
if (uiSchema?.['ui:options']?.host) {
|
||||
const hostUiOption = uiSchema['ui:options'].host;
|
||||
setState(prevState => ({ ...prevState, host: hostUiOption }));
|
||||
}
|
||||
}, [repoUrl, uiSchema]);
|
||||
}, [uiSchema]);
|
||||
|
||||
useEffect(() => {
|
||||
onChange(owner);
|
||||
|
||||
Reference in New Issue
Block a user