fetch item with ?from_organization=true

This commit is contained in:
Rares Mardare 2022-09-16 16:48:05 +03:00
parent c92faf23c6
commit d71d8c42c6
8 changed files with 22 additions and 19 deletions

View file

@ -9,7 +9,7 @@ is_able_to_autoresolve = True
is_demo_alert_enabled = True
description = """
Alerts from Grafana Alertmanager are automatically routed to this integration."
Alerts from Grafana Alertmanager are automatically routed to this integration.
{% for dict_item in grafana_alerting_entities %}
<br>Click <a href='{{dict_item.contact_point_url}}' target='_blank'>here</a>
to open contact point, and

View file

@ -12,7 +12,7 @@ is_able_to_autoresolve = True
is_demo_alert_enabled = True
description = """ \
Alerts from Grafana Alertmanager are automatically routed to this integration."
Alerts from Grafana Alertmanager are automatically routed to this integration.
{% for dict_item in grafana_alerting_entities %}
<br>Click <a href='{{dict_item.contact_point_url}}' target='_blank'>here</a>
to open contact point, and

View file

@ -14,14 +14,11 @@ import GSelect from 'containers/GSelect/GSelect';
import RemoteSelect from 'containers/RemoteSelect/RemoteSelect';
import UserTooltip from 'containers/UserTooltip/UserTooltip';
import { WithPermissionControl } from 'containers/WithPermissionControl/WithPermissionControl';
import { ActionDTO } from 'models/action';
import { prepareEscalationPolicy } from 'models/escalation_policy/escalation_policy.helpers';
import {
EscalationPolicy as EscalationPolicyType,
EscalationPolicyOption,
} from 'models/escalation_policy/escalation_policy.types';
import { PRIVATE_CHANNEL_NAME } from 'models/slack_channel/slack_channel.config';
import { User, UserRole } from 'models/user/user.types';
import { WaitDelay } from 'models/wait_delay';
import { SelectOption } from 'state/types';
import { UserAction } from 'state/userAction';
@ -272,15 +269,15 @@ export class EscalationPolicy extends React.Component<EscalationPolicyProps, any
return (
<WithPermissionControl key="notify_schedule" disableByPaywall userAction={UserAction.UpdateEscalationPolicies}>
<RemoteSelect
showSearch={false}
<GSelect
modelName="scheduleStore"
displayField="name"
valueField="id"
placeholder="Select Schedule"
className={cx('select', 'control')}
value={notify_schedule}
valueField="id"
onChange={this._getOnChangeHandler('notify_schedule')}
href={'/schedules/?short=true'}
fieldToShow="name"
placeholder="Select Schedule"
fromOrganization
/>
</WithPermissionControl>
);
@ -319,6 +316,7 @@ export class EscalationPolicy extends React.Component<EscalationPolicyProps, any
className={cx('select', 'control')}
value={custom_button_trigger}
onChange={this._getOnChangeHandler('custom_button_trigger')}
fromOrganization
/>
</WithPermissionControl>
);

View file

@ -67,7 +67,7 @@ const EscalationChainSteps = observer((props: EscalationChainStepsProps) => {
// const STEP_COLORS = ['#52C41A', '#A0D911', '#FADB14', '#FAAD14', COLOR_RED];
const STEP_COLORS = ['#1A7F4B', '#33cc33', '#ffbf00', '#FF8000', COLOR_RED];
const { alertReceiveChannelStore, escalationPolicyStore } = store;
const { escalationPolicyStore } = store;
const escalationPolicy = escalationPolicyStore.items[escalationPolicyId];

View file

@ -32,6 +32,7 @@ interface GSelectProps {
showWarningIfEmptyValue?: boolean;
showError?: boolean;
nullItemName?: string;
fromOrganization?: boolean;
filterOptions?: (id: any) => boolean;
dropdownRender?: (menu: ReactElement) => ReactElement;
getOptionLabel?: <T>(item: SelectableValue<T>) => React.ReactNode;
@ -59,6 +60,7 @@ const GSelect = observer((props: GSelectProps) => {
showWarningIfEmptyValue = false,
getDescription,
filterOptions,
fromOrganization,
} = props;
const store = useStore();
@ -123,7 +125,7 @@ const GSelect = observer((props: GSelectProps) => {
(values as string[]).forEach((value: string) => {
if (!isNil(value) && !model.items[value] && model.updateItem) {
model.updateItem(value);
model.updateItem(value, fromOrganization);
}
});
}, [value]);

View file

@ -41,8 +41,11 @@ export default class BaseStore {
}
@action
async getById(id: string, skipErrorHandling = false) {
return await makeRequest(`${this.path}${id}/`, {
async getById(id: string, skipErrorHandling = false, fromOrganization = false) {
let path = `${this.path}${id}`;
if (fromOrganization) {path = path.concat('?from_organization=true');}
return await makeRequest(path, {
method: 'GET',
}).catch((error) => this.onApiError(error, skipErrorHandling));
}

View file

@ -42,8 +42,8 @@ export class OutgoingWebhookStore extends BaseStore {
}
@action
async updateItem(id: OutgoingWebhook['id']) {
const response = await this.getById(id);
async updateItem(id: OutgoingWebhook['id'], fromOrganization = false) {
const response = await this.getById(id, false, fromOrganization);
this.items = {
...this.items,

View file

@ -76,9 +76,9 @@ export class ScheduleStore extends BaseStore {
};
}
async updateItem(id: Schedule['id']) {
async updateItem(id: Schedule['id'], fromOrganization = false) {
if (id) {
const item = await this.getById(id);
const item = await this.getById(id, true, fromOrganization);
this.items = {
...this.items,