Skip to content

Commit 9e2ef80

Browse files
committed
separate persona change from apiKey creation
1 parent b6ec72c commit 9e2ef80

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

example-apps/internal-knowledge-search/app-ui/src/components/SearchApplicationSettings.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,31 +182,39 @@ const SearchApplicationSettings: React.FC = () => {
182182
const [searchPersonaOptions, setSearchPersonaOptions] = useState(["admin"]);
183183

184184
// Populate personas dropdown options
185-
useEffect(()=>{
185+
useEffect(() => {
186186
(async()=>{
187187
const fetchedPersonas = await fetchPersonaOptions()
188188
setSearchPersonaOptions(fetchedPersonas)
189189
})()
190190
},[])
191191

192192
// Ensure we have an API key and override the "missing" default
193-
useEffect(()=>{
194-
(async()=>{
193+
useEffect(() => {
194+
(async() => {
195195
if (searchPersonaAPIKey == "missing") {
196196
const createdAPIKey = await createPersonaAPIKey(searchPersona)
197197
updateSearchPersonaAPIKey(createdAPIKey)
198198
}
199199
})()
200200
}, [])
201201

202+
// Ensure that the API key is updated when searchPersona changes
203+
useEffect( () => {
204+
(async() => {
205+
const apiKey = await createPersonaAPIKey(searchPersona);
206+
updateSearchPersonaAPIKey(apiKey);
207+
})()
208+
}, [searchPersona]);
209+
202210
const [isOpen, setIsOpen] = useState(false);
203211

204212
const toggleDropdown = () => {
205213
setIsOpen(!isOpen);
206214
};
207215

208216
const handlePersonaChange = async (value: string) => {
209-
updateSearchPersona(value, await createPersonaAPIKey(value));
217+
updateSearchPersona(value);
210218
};
211219

212220
const handleSave = () => {
@@ -222,7 +230,7 @@ const SearchApplicationSettings: React.FC = () => {
222230

223231
const updateSearchEndpoint = (e) => dispatch(updateSettings({appName, appUser, appPassword, searchEndpoint: e.target.value, searchPersona, searchPersonaAPIKey}))
224232

225-
const updateSearchPersona = (persona, apiKey) => dispatch(updateSettings({appName, appUser, appPassword, searchEndpoint, searchPersona: persona, searchPersonaAPIKey: apiKey}))
233+
const updateSearchPersona = (persona) => dispatch(updateSettings({appName, appUser, appPassword, searchEndpoint, searchPersona: persona, searchPersonaAPIKey}))
226234

227235
const updateSearchPersonaAPIKey = (apiKey) => dispatch(updateSettings({appName, appUser, appPassword, searchEndpoint, searchPersona, searchPersonaAPIKey: apiKey}))
228236

0 commit comments

Comments
 (0)