Skip to content

Commit 265795f

Browse files
authored
feat(setup-wizard): Prefill project and team (#85920)
Pre-fill project and team input if there is only one available option. - closes #85529
1 parent abe185b commit 265795f

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

static/app/views/setupWizard/wizardProjectSelection.tsx

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Fragment, useCallback, useMemo, useState} from 'react';
1+
import {Fragment, useCallback, useEffect, useMemo, useState} from 'react';
22
import styled from '@emotion/styled';
33

44
import {addErrorMessage} from 'sentry/actionCreators/indicator';
@@ -130,6 +130,22 @@ export function WizardProjectSelection({
130130
const {options: cachedProjectOptions, clear: clearProjectOptions} =
131131
useCompactSelectOptionsCache(projectOptions);
132132

133+
// Set the selected project to the first option if there is only one
134+
useEffect(() => {
135+
// We need to check the cached options as they hold all options that were fetched for the org
136+
// and not just the options that match the search query
137+
if (cachedProjectOptions.length === 1) {
138+
setSelectedProjectId(cachedProjectOptions[0]!.value);
139+
}
140+
}, [cachedProjectOptions]);
141+
142+
// Set the selected team to the first team if there is only one
143+
useEffect(() => {
144+
if (teamsRequest.data && teamsRequest.data.length === 1) {
145+
setNewProjectTeam(teamsRequest.data[0]!.slug);
146+
}
147+
}, [teamsRequest.data]);
148+
133149
// As the cache hook sorts the options by value, we need to sort them afterwards
134150
const sortedProjectOptions = useMemo(
135151
() =>

0 commit comments

Comments
 (0)