refactor: remove coupling with form context

Signed-off-by: Benjamin Janssens <benji.janssens@gmail.com>
This commit is contained in:
Benjamin Janssens
2025-12-16 09:49:35 +01:00
parent 5ce3294f8d
commit 49579170e9
3 changed files with 8 additions and 28 deletions
@@ -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);