diff --git a/CHANGELOG.md b/CHANGELOG.md index 57f84435..d9311a63 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## v1.3.49 (2023-10-31) + +### Changed + +- Removed the hardcoding of page size on frontend ([#3205](https://github.com/grafana/oncall/pull/3205)) +- Prevent additional polling on Incidents if the previous request didn't complete + ([#3205](https://github.com/grafana/oncall/pull/3205)) +- Order results from `GET /teams` internal API endpoint by ascending name by @joeyorlando ([#3220](https://github.com/grafana/oncall/pull/3220)) + +### Fixed + +- Improve slow `GET /users` + `GET /teams` internal API endpoints by @joeyorlando ([#3220](https://github.com/grafana/oncall/pull/3220)) +- Fix search issue when searching for teams in the add responders popup window by @joeyorlando ([#3220](https://github.com/grafana/oncall/pull/3220)) +- CSS changes to add responders dropdown to fix long search results list by @joeyorlando ([#3220](https://github.com/grafana/oncall/pull/3220)) +- Do not allow to update terraform-based shifts in web UI schedule API ([#3224](https://github.com/grafana/oncall/pull/3224)) + ## v1.3.48 (2023-10-30) ### Added diff --git a/engine/apps/api/serializers/on_call_shifts.py b/engine/apps/api/serializers/on_call_shifts.py index def64076..f2178e28 100644 --- a/engine/apps/api/serializers/on_call_shifts.py +++ b/engine/apps/api/serializers/on_call_shifts.py @@ -228,6 +228,9 @@ class OnCallShiftUpdateSerializer(OnCallShiftSerializer): read_only_fields = ["schedule", "type"] def update(self, instance, validated_data): + if not instance.schedule: + # only web-based schedule events can be updated using UI + raise serializers.ValidationError(["This event cannot be updated"]) validated_data = self._correct_validated_data(instance.type, validated_data) change_only_name = True create_or_update_last_shift = False diff --git a/engine/apps/api/serializers/team.py b/engine/apps/api/serializers/team.py index dd7e172d..b7263bcd 100644 --- a/engine/apps/api/serializers/team.py +++ b/engine/apps/api/serializers/team.py @@ -19,21 +19,17 @@ class FastTeamSerializer(serializers.ModelSerializer): class TeamSerializer(serializers.ModelSerializer): - context: TeamSerializerContext - id = serializers.CharField(read_only=True, source="public_primary_key") - number_of_users_currently_oncall = serializers.SerializerMethodField() class Meta: model = Team - fields = ( + fields = [ "id", "name", "email", "avatar_url", "is_sharing_resources_to_all", - "number_of_users_currently_oncall", - ) + ] read_only_fields = [ "id", @@ -42,6 +38,17 @@ class TeamSerializer(serializers.ModelSerializer): "avatar_url", ] + +class TeamLongSerializer(TeamSerializer): + context: TeamSerializerContext + + number_of_users_currently_oncall = serializers.SerializerMethodField() + + class Meta(TeamSerializer.Meta): + fields = TeamSerializer.Meta.fields + [ + "number_of_users_currently_oncall", + ] + def get_number_of_users_currently_oncall(self, obj: Team) -> int: num_of_users_oncall_for_team = 0 diff --git a/engine/apps/api/tests/test_oncall_shift.py b/engine/apps/api/tests/test_oncall_shift.py index af8191fe..3e471009 100644 --- a/engine/apps/api/tests/test_oncall_shift.py +++ b/engine/apps/api/tests/test_oncall_shift.py @@ -400,6 +400,42 @@ def test_list_on_call_shift_filter_schedule_id( assert response.json() == expected_payload +@pytest.mark.django_db +def test_update_calendar_shift_is_disabled( + on_call_shift_internal_api_setup, + make_schedule, + make_on_call_shift, + make_user_auth_headers, +): + token, user1, user2, organization, _ = on_call_shift_internal_api_setup + schedule = make_schedule(organization, schedule_class=OnCallScheduleCalendar) + + client = APIClient() + start_date = timezone.now().replace(microsecond=0) + + name = "Test Shift Rotation" + on_call_shift = make_on_call_shift( + schedule.organization, + shift_type=CustomOnCallShift.TYPE_ROLLING_USERS_EVENT, + name=name, + start=start_date, + duration=timezone.timedelta(hours=1), + rotation_start=start_date, + rolling_users=[{user1.pk: user1.public_primary_key}, {user2.pk: user2.public_primary_key}], + ) + on_call_shift.schedules.add(schedule) + + client = APIClient() + + data_to_update = { + "name": name, + } + url = reverse("api-internal:oncall_shifts-detail", kwargs={"pk": on_call_shift.public_primary_key}) + + response = client.put(url, data=data_to_update, format="json", **make_user_auth_headers(user1, token)) + assert response.status_code == status.HTTP_400_BAD_REQUEST + + @pytest.mark.django_db def test_update_future_on_call_shift( on_call_shift_internal_api_setup, diff --git a/engine/apps/api/tests/test_team.py b/engine/apps/api/tests/test_team.py index a5a93a9a..69a8afbe 100644 --- a/engine/apps/api/tests/test_team.py +++ b/engine/apps/api/tests/test_team.py @@ -14,16 +14,19 @@ from apps.user_management.models import Team GENERAL_TEAM = Team(public_primary_key="null", name="No team", email=None, avatar_url=None) -def get_payload_from_team(team): - return { +def get_payload_from_team(team, long=False): + payload = { "id": team.public_primary_key, "name": team.name, "email": team.email, "avatar_url": team.avatar_url, "is_sharing_resources_to_all": team.is_sharing_resources_to_all, - "number_of_users_currently_oncall": 0, } + if long: + payload.update({"number_of_users_currently_oncall": 0}) + return payload + @pytest.mark.django_db def test_list_teams( @@ -40,22 +43,36 @@ def test_list_teams( team = make_team(organization) team.users.add(user) + auth_headers = make_user_auth_headers(user, token) + general_team_payload = get_payload_from_team(GENERAL_TEAM) + general_team_long_payload = get_payload_from_team(GENERAL_TEAM, long=True) team_payload = get_payload_from_team(team) + team_long_payload = get_payload_from_team(team, long=True) client = APIClient() url = reverse("api-internal:team-list") - response = client.get(url, format="json", **make_user_auth_headers(user, token)) + response = client.get(url, format="json", **auth_headers) assert response.status_code == status.HTTP_200_OK assert response.json() == [general_team_payload, team_payload] + response = client.get(f"{url}?short=false", format="json", **auth_headers) + + assert response.status_code == status.HTTP_200_OK + assert response.json() == [general_team_long_payload, team_long_payload] + url = reverse("api-internal:team-list") - response = client.get(f"{url}?include_no_team=false", format="json", **make_user_auth_headers(user, token)) + response = client.get(f"{url}?include_no_team=false", format="json", **auth_headers) assert response.status_code == status.HTTP_200_OK assert response.json() == [team_payload] + response = client.get(f"{url}?include_no_team=false&short=false", format="json", **auth_headers) + + assert response.status_code == status.HTTP_200_OK + assert response.json() == [team_long_payload] + @pytest.mark.django_db def test_list_teams_only_include_notifiable_teams( @@ -146,7 +163,7 @@ def test_teams_number_of_users_currently_oncall_attribute_works_properly( _make_schedule(team=team3, oncall_users=[]) client = APIClient() - url = reverse("api-internal:team-list") + url = f"{reverse('api-internal:team-list')}?short=false" response = client.get(url, format="json", **make_user_auth_headers(user1, token)) diff --git a/engine/apps/api/views/team.py b/engine/apps/api/views/team.py index 4e6dd481..47c10e11 100644 --- a/engine/apps/api/views/team.py +++ b/engine/apps/api/views/team.py @@ -6,7 +6,7 @@ from rest_framework.response import Response from apps.alerts.paging import integration_is_notifiable from apps.api.permissions import RBACPermission -from apps.api.serializers.team import TeamSerializer +from apps.api.serializers.team import TeamLongSerializer, TeamSerializer from apps.auth_token.auth import PluginAuthentication from apps.mobile_app.auth import MobileAppAuthTokenAuthentication from apps.schedules.ical_utils import get_oncall_users_for_multiple_schedules @@ -33,6 +33,9 @@ class TeamViewSet(PublicPrimaryKeyMixin, mixins.ListModelMixin, mixins.UpdateMod def get_queryset(self): return self.request.user.available_teams + def _is_long_request(self) -> bool: + return self.request.query_params.get("short", "true").lower() == "false" + @cached_property def schedules_with_oncall_users(self): """ @@ -45,9 +48,14 @@ class TeamViewSet(PublicPrimaryKeyMixin, mixins.ListModelMixin, mixins.UpdateMod def get_serializer_context(self): context = super().get_serializer_context() - context.update({"schedules_with_oncall_users": self.schedules_with_oncall_users}) + context.update( + {"schedules_with_oncall_users": self.schedules_with_oncall_users if self._is_long_request() else {}} + ) return context + def get_serializer_class(self): + return TeamLongSerializer if self._is_long_request() else TeamSerializer + def list(self, request, *args, **kwargs): general_team = [Team(public_primary_key="null", name="No team", email=None, avatar_url=None)] queryset = self.filter_queryset(self.get_queryset()) @@ -62,6 +70,8 @@ class TeamViewSet(PublicPrimaryKeyMixin, mixins.ListModelMixin, mixins.UpdateMod queryset = queryset.filter(pk__in=team_ids) + queryset = queryset.order_by("name") + teams = list(queryset) if self.request.query_params.get("include_no_team", "true") != "false": # Adds general team to the queryset in a way that it always shows up first (even when not searched for). diff --git a/engine/apps/api/views/user.py b/engine/apps/api/views/user.py index b6df3df3..c6a51fc7 100644 --- a/engine/apps/api/views/user.py +++ b/engine/apps/api/views/user.py @@ -234,9 +234,27 @@ class UserView( """ return get_oncall_users_for_multiple_schedules(self.request.user.organization.oncall_schedules.all()) + def _get_is_currently_oncall_query_param(self) -> str: + return self.request.query_params.get("is_currently_oncall", "").lower() + + def _is_currently_oncall_request(self) -> bool: + return self._get_is_currently_oncall_query_param() in ["true", "false"] + + def _is_long_request(self) -> bool: + return self.request.query_params.get("short", "true").lower() == "false" + + def _is_currently_oncall_or_long_request(self) -> bool: + return self._is_currently_oncall_request() or self._is_long_request() + def get_serializer_context(self): context = super().get_serializer_context() - context.update({"schedules_with_oncall_users": self.schedules_with_oncall_users}) + context.update( + { + "schedules_with_oncall_users": self.schedules_with_oncall_users + if self._is_currently_oncall_or_long_request() + else {} + } + ) return context def get_serializer_class(self): @@ -247,12 +265,10 @@ class UserView( is_list_request = self.action in ["list"] is_filters_request = query_params.get("filters", "false") == "true" - is_short_request = query_params.get("short", "true") == "false" - is_currently_oncall_request = query_params.get("is_currently_oncall", "").lower() in ["true", "false"] if is_list_request and is_filters_request: return self.get_filter_serializer_class() - elif is_list_request and (is_short_request or is_currently_oncall_request): + elif is_list_request and self._is_currently_oncall_or_long_request(): return UserLongSerializer is_users_own_data = kwargs.get("pk") is not None and kwargs.get("pk") == user.public_primary_key @@ -277,11 +293,10 @@ class UserView( def list(self, request, *args, **kwargs) -> Response: queryset = self.filter_queryset(self.get_queryset()) - is_currently_oncall_query_param = request.query_params.get("is_currently_oncall", "").lower() - def _get_oncall_user_ids(): return {user.pk for _, users in self.schedules_with_oncall_users.items() for user in users} + is_currently_oncall_query_param = self._get_is_currently_oncall_query_param() if is_currently_oncall_query_param == "true": # client explicitly wants to filter out users that are on-call queryset = queryset.filter(pk__in=_get_oncall_user_ids()) diff --git a/grafana-plugin/src/containers/AddResponders/parts/AddRespondersPopup/AddRespondersPopup.module.scss b/grafana-plugin/src/containers/AddResponders/parts/AddRespondersPopup/AddRespondersPopup.module.scss index 2c2f92f5..fbbd2163 100644 --- a/grafana-plugin/src/containers/AddResponders/parts/AddRespondersPopup/AddRespondersPopup.module.scss +++ b/grafana-plugin/src/containers/AddResponders/parts/AddRespondersPopup/AddRespondersPopup.module.scss @@ -31,6 +31,7 @@ } .table { + max-height: 150px; overflow: auto; padding: 4px 0px; diff --git a/grafana-plugin/src/containers/AddResponders/parts/AddRespondersPopup/AddRespondersPopup.tsx b/grafana-plugin/src/containers/AddResponders/parts/AddRespondersPopup/AddRespondersPopup.tsx index d36c3532..3aa328dd 100644 --- a/grafana-plugin/src/containers/AddResponders/parts/AddRespondersPopup/AddRespondersPopup.tsx +++ b/grafana-plugin/src/containers/AddResponders/parts/AddRespondersPopup/AddRespondersPopup.tsx @@ -115,7 +115,7 @@ const AddRespondersPopup = observer( const handleSearchTermChange = useDebouncedCallback(() => { if (isCreateMode && activeOption === TabOptions.Teams) { - grafanaTeamStore.updateItems(searchTerm, false, true); + grafanaTeamStore.updateItems(searchTerm, false, true, false); } else { userStore.updateItems({ searchTerm, short: 'false' }); } diff --git a/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx b/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx index bd86eebc..bfcdc2eb 100644 --- a/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx +++ b/grafana-plugin/src/containers/RemoteFilters/RemoteFilters.tsx @@ -1,6 +1,6 @@ import React, { Component } from 'react'; -import { SelectableValue, TimeRange } from '@grafana/data'; +import { KeyValue, SelectableValue, TimeRange } from '@grafana/data'; import { InlineSwitch, MultiSelect, @@ -31,16 +31,15 @@ import LocationHelper from 'utils/LocationHelper'; import { PAGE } from 'utils/consts'; import { parseFilters } from './RemoteFilters.helpers'; -import { FilterOption, RemoteFiltersType } from './RemoteFilters.types'; +import { FilterOption } from './RemoteFilters.types'; import styles from './RemoteFilters.module.css'; const cx = cn.bind(styles); interface RemoteFiltersProps extends WithStoreProps { - value: RemoteFiltersType; onChange: (filters: { [key: string]: any }, isOnMount: boolean, invalidateFn: () => boolean) => void; - query: { [key: string]: any }; + query: KeyValue; page: PAGE; defaultFilters?: FiltersValues; extraFilters?: (state, setState, onFiltersValueChange) => React.ReactNode; @@ -82,11 +81,18 @@ class RemoteFilters extends Component { } async componentDidMount() { - const { query, page, store, defaultFilters } = this.props; - - const { filtersStore } = store; + const { + query, + page, + store: { filtersStore }, + defaultFilters, + } = this.props; const filterOptions = await filtersStore.updateOptionsForPage(page); + const currentTablePageNum = parseInt(filtersStore.currentTablePageNum[page] || query.p || 1, 10); + + // set the current page from filters/query or default it to 1 + filtersStore.setCurrentTablePageNum(page, currentTablePageNum); let { filters, values } = parseFilters({ ...query, ...filtersStore.globalValues }, filterOptions, query); @@ -422,10 +428,7 @@ class RemoteFilters extends Component { } const currentRequestId = this.getNewRequestId(); - - this.setState({ - lastRequestId: currentRequestId, - }); + this.setState({ lastRequestId: currentRequestId }); LocationHelper.update({ ...values }, 'partial'); onChange(values, isOnMount, this.invalidateFn.bind(this, currentRequestId)); @@ -443,4 +446,6 @@ class RemoteFilters extends Component { debouncedOnChange = debounce(this.onChange, 500); } -export default withMobXProviderContext(RemoteFilters); +export default withMobXProviderContext(RemoteFilters) as unknown as React.ComponentClass< + Omit +>; diff --git a/grafana-plugin/src/models/alert_receive_channel/alert_receive_channel.ts b/grafana-plugin/src/models/alert_receive_channel/alert_receive_channel.ts index 2978c5b0..67afa9e6 100644 --- a/grafana-plugin/src/models/alert_receive_channel/alert_receive_channel.ts +++ b/grafana-plugin/src/models/alert_receive_channel/alert_receive_channel.ts @@ -28,7 +28,7 @@ export class AlertReceiveChannelStore extends BaseStore { searchResult: Array; @observable.shallow - paginatedSearchResult: { count?: number; results?: Array } = {}; + paginatedSearchResult: { count?: number; results?: Array; page_size?: number } = {}; @observable.shallow items: { [id: string]: AlertReceiveChannel } = {}; @@ -81,6 +81,7 @@ export class AlertReceiveChannelStore extends BaseStore { } return { + page_size: this.paginatedSearchResult.page_size, count: this.paginatedSearchResult.count, results: this.paginatedSearchResult.results && @@ -133,7 +134,7 @@ export class AlertReceiveChannelStore extends BaseStore { async updatePaginatedItems(query: any = '', page = 1, updateCounters = false, invalidateFn = undefined) { const filters = typeof query === 'string' ? { search: query } : query; - const { count, results } = await makeRequest(this.path, { params: { ...filters, page } }); + const { count, results, page_size } = await makeRequest(this.path, { params: { ...filters, page } }); if (invalidateFn?.()) { return undefined; @@ -155,6 +156,7 @@ export class AlertReceiveChannelStore extends BaseStore { this.paginatedSearchResult = { count, results: results.map((item: AlertReceiveChannel) => item.id), + page_size, }; if (updateCounters) { diff --git a/grafana-plugin/src/models/alertgroup/alertgroup.ts b/grafana-plugin/src/models/alertgroup/alertgroup.ts index f0068af1..72a645d3 100644 --- a/grafana-plugin/src/models/alertgroup/alertgroup.ts +++ b/grafana-plugin/src/models/alertgroup/alertgroup.ts @@ -41,10 +41,14 @@ export class AlertGroupStore extends BaseStore { incidentsCursor?: string; @observable - incidentsItemsPerPage?: number; - - @observable - alertsSearchResult: any = {}; + alertsSearchResult: { + [key: string]: { + prev?: string; + next?: string; + results?: string[]; + page_size?: number; + }; + } = {}; @observable alerts = new Map(); @@ -89,29 +93,6 @@ export class AlertGroupStore extends BaseStore { }).catch(showApiError); } - @action // FIXME for `attach to` feature ONLY - async updateItems(query = '') { - const { results } = await makeRequest(`${this.path}`, { - params: { search: query, resolved: false, is_root: true }, - }); - - this.items = { - ...this.items, - ...results.reduce( - (acc: { [key: string]: Alert }, item: Alert) => ({ - ...acc, - [item.pk]: item, - }), - {} - ), - }; - - this.searchResult = { - ...this.searchResult, - [query]: results.map((item: Alert) => item.pk), - }; - } - async updateItem(id: Alert['pk']) { const item = await this.getById(id); @@ -220,12 +201,13 @@ export class AlertGroupStore extends BaseStore { // TODO check if methods are dublicating existing ones @action async updateIncidents() { - this.getNewIncidentsStats(); - this.getAcknowledgedIncidentsStats(); - this.getResolvedIncidentsStats(); - this.getSilencedIncidentsStats(); - - this.updateAlertGroups(); + await Promise.all([ + this.getNewIncidentsStats(), + this.getAcknowledgedIncidentsStats(), + this.getResolvedIncidentsStats(), + this.getSilencedIncidentsStats(), + this.updateAlertGroups(), + ]); this.liveUpdatesPaused = false; } @@ -238,7 +220,7 @@ export class AlertGroupStore extends BaseStore { this.incidentFilters = params; - this.updateIncidents(); + await this.updateIncidents(); } @action @@ -256,9 +238,8 @@ export class AlertGroupStore extends BaseStore { } @action - async setIncidentsItemsPerPage(value: number) { + async setIncidentsItemsPerPage() { this.setIncidentsCursor(undefined); - this.incidentsItemsPerPage = value; this.updateAlertGroups(); } @@ -271,11 +252,12 @@ export class AlertGroupStore extends BaseStore { results, next: nextRaw, previous: previousRaw, + page_size, } = await makeRequest(`${this.path}`, { params: { ...this.incidentFilters, + perpage: this.alertsSearchResult?.['default']?.page_size, cursor: this.incidentsCursor, - perpage: this.incidentsItemsPerPage, is_root: true, }, }).catch(refreshPageError); @@ -298,17 +280,24 @@ export class AlertGroupStore extends BaseStore { prev: prevCursor, next: nextCursor, results: results.map((alert: Alert) => alert.pk), + page_size, }; this.alertGroupsLoading = false; } getAlertSearchResult(query: string) { - if (!this.alertsSearchResult[query]) { - return undefined; + const result = this.alertsSearchResult[query]; + if (!result) { + return {}; } - return this.alertsSearchResult[query].results.map((pk: Alert['pk']) => this.alerts.get(pk)); + return { + prev: result.prev, + next: result.next, + page_size: result.page_size, + results: result.results.map((pk: Alert['pk']) => this.alerts.get(pk)), + }; } @action diff --git a/grafana-plugin/src/models/alertgroup/alertgroup.types.ts b/grafana-plugin/src/models/alertgroup/alertgroup.types.ts index 48369f4e..5514042e 100644 --- a/grafana-plugin/src/models/alertgroup/alertgroup.types.ts +++ b/grafana-plugin/src/models/alertgroup/alertgroup.types.ts @@ -55,7 +55,6 @@ export interface Alert { acknowledged_at: string; acknowledged_by_user: User; acknowledged_on_source: boolean; - is_restricted: boolean; channel: Channel; slack_permalink?: string; permalinks: { diff --git a/grafana-plugin/src/models/filters/filters.ts b/grafana-plugin/src/models/filters/filters.ts index d3acff00..472dd727 100644 --- a/grafana-plugin/src/models/filters/filters.ts +++ b/grafana-plugin/src/models/filters/filters.ts @@ -3,6 +3,7 @@ import { action, observable } from 'mobx'; import BaseStore from 'models/base_store'; import { makeRequest } from 'network'; import { RootStore } from 'state'; +import { PAGE } from 'utils/consts'; import { getItem, setItem } from 'utils/localStorage'; import { getApiPathByPage } from './filters.helpers'; @@ -17,6 +18,9 @@ export class FiltersStore extends BaseStore { @observable.shallow public values: { [page: string]: FiltersValues } = {}; + @observable.shallow + public currentTablePageNum: { [page: string]: number } = {}; + private _globalValues: FiltersValues = {}; @observable @@ -65,4 +69,9 @@ export class FiltersStore extends BaseStore { [page]: value, }; } + + @action + setCurrentTablePageNum(page: PAGE, currentTablePageNum: number) { + this.currentTablePageNum[page] = currentTablePageNum; + } } diff --git a/grafana-plugin/src/models/grafana_team/grafana_team.ts b/grafana-plugin/src/models/grafana_team/grafana_team.ts index bb0b3cee..023150be 100644 --- a/grafana-plugin/src/models/grafana_team/grafana_team.ts +++ b/grafana-plugin/src/models/grafana_team/grafana_team.ts @@ -5,12 +5,14 @@ import { GrafanaTeam } from 'models/grafana_team/grafana_team.types'; import { makeRequest } from 'network'; import { RootStore } from 'state'; +type TeamItems = { [id: string]: GrafanaTeam }; + export class GrafanaTeamStore extends BaseStore { @observable - searchResult: { [key: string]: Array } = {}; + searchResult: Array = []; @observable.shallow - items: { [id: string]: GrafanaTeam } = {}; + items: TeamItems = {}; constructor(rootStore: RootStore) { super(rootStore); @@ -29,10 +31,11 @@ export class GrafanaTeamStore extends BaseStore { } @action - async updateItems(query = '', includeNoTeam = true, onlyIncludeNotifiableTeams = false) { - const result = await makeRequest(`${this.path}`, { + async updateItems(query = '', includeNoTeam = true, onlyIncludeNotifiableTeams = false, short = true) { + const result = await makeRequest(`${this.path}`, { params: { search: query, + short: short ? 'true' : 'false', include_no_team: includeNoTeam ? 'true' : 'false', only_include_notifiable_teams: onlyIncludeNotifiableTeams ? 'true' : 'false', }, @@ -40,8 +43,8 @@ export class GrafanaTeamStore extends BaseStore { this.items = { ...this.items, - ...result.reduce( - (acc: { [key: number]: GrafanaTeam }, item: GrafanaTeam) => ({ + ...result.reduce( + (acc, item) => ({ ...acc, [item.id]: item, }), @@ -49,17 +52,10 @@ export class GrafanaTeamStore extends BaseStore { ), }; - this.searchResult = { - ...this.searchResult, - [query]: result.map((item: GrafanaTeam) => item.id), - }; + this.searchResult = result.map((item: GrafanaTeam) => item.id); } - getSearchResult(query = '') { - if (!this.searchResult[query]) { - return []; - } - - return this.searchResult[query].map((teamId: GrafanaTeam['id']) => this.items[teamId]); + getSearchResult() { + return this.searchResult.map((teamId: GrafanaTeam['id']) => this.items[teamId]); } } diff --git a/grafana-plugin/src/models/grafana_team/grafana_team.types.ts b/grafana-plugin/src/models/grafana_team/grafana_team.types.ts index 8b0af307..97210b8b 100644 --- a/grafana-plugin/src/models/grafana_team/grafana_team.types.ts +++ b/grafana-plugin/src/models/grafana_team/grafana_team.types.ts @@ -4,5 +4,5 @@ export interface GrafanaTeam { email: string; avatar_url: string; is_sharing_resources_to_all: boolean; - number_of_users_currently_oncall: number; + number_of_users_currently_oncall?: number; } diff --git a/grafana-plugin/src/models/user/user.ts b/grafana-plugin/src/models/user/user.ts index dd92f538..1fd01a03 100644 --- a/grafana-plugin/src/models/user/user.ts +++ b/grafana-plugin/src/models/user/user.ts @@ -17,7 +17,7 @@ import { User } from './user.types'; export class UserStore extends BaseStore { @observable.shallow - searchResult: { count?: number; results?: Array } = {}; + searchResult: { count?: number; results?: Array; page_size?: number } = {}; @observable.shallow items: { [pk: string]: User } = {}; @@ -122,7 +122,7 @@ export class UserStore extends BaseStore { return; } - const { count, results } = response; + const { count, results, page_size } = response; this.items = { ...this.items, @@ -140,6 +140,7 @@ export class UserStore extends BaseStore { this.searchResult = { count, + page_size, results: results.map((item: User) => item.pk), }; @@ -148,6 +149,7 @@ export class UserStore extends BaseStore { getSearchResult() { return { + page_size: this.searchResult.page_size, count: this.searchResult.count, results: this.searchResult.results && this.searchResult.results.map((userPk: User['pk']) => this.items?.[userPk]), }; diff --git a/grafana-plugin/src/models/user/user.types.ts b/grafana-plugin/src/models/user/user.types.ts index a1bad61b..11d6247b 100644 --- a/grafana-plugin/src/models/user/user.types.ts +++ b/grafana-plugin/src/models/user/user.types.ts @@ -43,6 +43,6 @@ export interface User { hidden_fields?: boolean; timezone: Timezone; working_hours: { [key: string]: [] }; - is_currently_oncall: boolean; - teams: GrafanaTeam[]; + is_currently_oncall?: boolean; + teams?: GrafanaTeam[]; } diff --git a/grafana-plugin/src/pages/incident/Incident.helpers.tsx b/grafana-plugin/src/pages/incident/Incident.helpers.tsx index 39b5c162..938b4841 100644 --- a/grafana-plugin/src/pages/incident/Incident.helpers.tsx +++ b/grafana-plugin/src/pages/incident/Incident.helpers.tsx @@ -153,7 +153,7 @@ export function getActionButtons(incident: AlertType, cx: any, callbacks: { [key const resolveButton = ( - @@ -161,7 +161,7 @@ export function getActionButtons(incident: AlertType, cx: any, callbacks: { [key const unacknowledgeButton = ( - @@ -169,7 +169,7 @@ export function getActionButtons(incident: AlertType, cx: any, callbacks: { [key const unresolveButton = ( - @@ -177,7 +177,7 @@ export function getActionButtons(incident: AlertType, cx: any, callbacks: { [key const acknowledgeButton = ( - @@ -188,7 +188,7 @@ export function getActionButtons(incident: AlertType, cx: any, callbacks: { [key if (incident.status === IncidentStatus.Silenced) { buttons.push( - @@ -198,7 +198,7 @@ export function getActionButtons(incident: AlertType, cx: any, callbacks: { [key ); diff --git a/grafana-plugin/src/pages/incident/Incident.tsx b/grafana-plugin/src/pages/incident/Incident.tsx index 98aca39f..42d2fc6d 100644 --- a/grafana-plugin/src/pages/incident/Incident.tsx +++ b/grafana-plugin/src/pages/incident/Incident.tsx @@ -171,7 +171,6 @@ class IncidentPage extends React.Component @@ -289,12 +288,7 @@ class IncidentPage extends React.Component {incident.root_alert_group.render_for_web.title} {' '} - @@ -310,16 +304,10 @@ class IncidentPage extends React.Component onClick={this.showAttachIncidentForm} tooltip="Attach to another Alert Group" className={cx('title-icon')} - disabled={incident.is_restricted} /> )} - + openNotification('Link copied'); }} > - + @@ -358,7 +341,7 @@ class IncidentPage extends React.Component query={{ page: 'integrations', id: incident.alert_receive_channel.id }} > @@ -427,7 +410,7 @@ class IncidentPage extends React.Component