Fixed UserGroup selectors not showing the set value (#4394)

# What this PR does

Fix for https://github.com/grafana/oncall/issues/4371

- Fixed UserGroups' selectors not showing up the stored value - this
behavior was found in Schedule Form and Escalation Chains

## Which issue(s) this PR closes

Closes https://github.com/grafana/oncall/issues/4371
This commit is contained in:
Rares Mardare 2024-05-27 10:51:01 +03:00 committed by GitHub
parent 357857faca
commit 997cb64a57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 6 deletions

View file

@ -383,13 +383,12 @@ class _EscalationPolicy extends React.Component<EscalationPolicyProps, any> {
return (
<WithPermissionControlTooltip key="notify_to_group" userAction={UserActions.EscalationChainsWrite}>
<GSelect<UserGroup[]>
<GSelect<UserGroup>
allowClear
disabled={isDisabled}
items={userGroupStore.items}
fetchItemsFn={userGroupStore.updateItems}
fetchItemFn={() => undefined}
// TODO: fetchItemFn
fetchItemFn={userGroupStore.fetchItemById}
getSearchResult={userGroupStore.getSearchResult}
displayField="name"
valueField="id"

View file

@ -289,11 +289,11 @@ const ScheduleNotificationSettingsFields = () => {
invalid={!!errors.user_group}
error={errors.user_group?.message}
>
<GSelect<UserGroup[]>
<GSelect<UserGroup>
allowClear
items={userGroupStore.items}
fetchItemsFn={userGroupStore.updateItems}
fetchItemFn={() => undefined}
fetchItemFn={userGroupStore.fetchItemById}
getSearchResult={userGroupStore.getSearchResult}
displayField="handle"
placeholder="Select User Group"

View file

@ -11,7 +11,7 @@ export class UserGroupStore extends BaseStore {
searchResult: { [key: string]: Array<UserGroup['id']> } = {};
@observable.shallow
items?: { [id: string]: UserGroup[] } = {};
items?: { [id: string]: UserGroup } = {};
constructor(rootStore: RootStore) {
super(rootStore);
@ -46,6 +46,18 @@ export class UserGroupStore extends BaseStore {
});
}
@action.bound
async fetchItemById(id: string) {
const item: UserGroup = await this.getById(id);
runInAction(() => {
this.items = {
...this.items,
[id]: item,
};
});
}
getSearchResult = (query = '') => {
if (!this.searchResult[query]) {
return undefined;