add with permission control
This commit is contained in:
parent
33724448bb
commit
1e60fe299f
6 changed files with 35 additions and 16 deletions
|
|
@ -154,7 +154,7 @@ const RotationForm: FC<RotationFormProps> = observer((props) => {
|
|||
rolling_users: userGroups,
|
||||
interval: repeatEveryValue,
|
||||
frequency: repeatEveryPeriod,
|
||||
by_day: (repeatEveryPeriod === 0 && repeatEveryValue === 1) || repeatEveryPeriod === 1 ? selectedDays : null,
|
||||
by_day: repeatEveryPeriod === 0 || repeatEveryPeriod === 1 ? selectedDays : null,
|
||||
priority_level: shiftId === 'new' ? layerPriority : shift?.priority_level,
|
||||
}),
|
||||
[
|
||||
|
|
@ -343,7 +343,7 @@ const RotationForm: FC<RotationFormProps> = observer((props) => {
|
|||
/>
|
||||
</Field>
|
||||
</HorizontalGroup>
|
||||
{((repeatEveryPeriod === 0 && repeatEveryValue === 1) || repeatEveryPeriod === 1) && (
|
||||
{(repeatEveryPeriod === 0 || repeatEveryPeriod === 1) && (
|
||||
<Field label="Select days to repeat">
|
||||
<DaysSelector
|
||||
options={store.scheduleStore.byDayOptions}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,12 @@ import Text from 'components/Text/Text';
|
|||
import TimelineMarks from 'components/TimelineMarks/TimelineMarks';
|
||||
import Rotation from 'containers/Rotation/Rotation';
|
||||
import RotationForm from 'containers/RotationForm/RotationForm';
|
||||
import { WithPermissionControl } from 'containers/WithPermissionControl/WithPermissionControl';
|
||||
import { getColor, getFromString } from 'models/schedule/schedule.helpers';
|
||||
import { Layer, Schedule, Shift } from 'models/schedule/schedule.types';
|
||||
import { Timezone } from 'models/timezone/timezone.types';
|
||||
import { WithStoreProps } from 'state/types';
|
||||
import { UserAction } from 'state/userAction';
|
||||
import { withMobXProviderContext } from 'state/withStore';
|
||||
|
||||
import { DEFAULT_TRANSITION_TIMEOUT } from './Rotations.config';
|
||||
|
|
@ -96,9 +98,11 @@ class Rotations extends Component<RotationsProps, RotationsState> {
|
|||
</Text.Title>
|
||||
</div>
|
||||
{disabled ? (
|
||||
<Button variant="primary" icon="plus" disabled>
|
||||
Add rotation
|
||||
</Button>
|
||||
<WithPermissionControl userAction={UserAction.UpdateSchedules}>
|
||||
<Button variant="primary" icon="plus" disabled>
|
||||
Add rotation
|
||||
</Button>
|
||||
</WithPermissionControl>
|
||||
) : (
|
||||
<ValuePicker
|
||||
label="Add rotation"
|
||||
|
|
@ -187,10 +191,13 @@ class Rotations extends Component<RotationsProps, RotationsState> {
|
|||
<div
|
||||
className={cx('add-rotations-layer')}
|
||||
onClick={() => {
|
||||
if (disabled) {
|
||||
return;
|
||||
}
|
||||
this.handleAddLayer(nextPriority, startMoment);
|
||||
}}
|
||||
>
|
||||
<Text type="primary">+ Add rotations layer</Text>
|
||||
<Text type={disabled ? 'disabled' : 'primary'}>+ Add rotations layer</Text>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -10,10 +10,12 @@ import Text from 'components/Text/Text';
|
|||
import TimelineMarks from 'components/TimelineMarks/TimelineMarks';
|
||||
import Rotation from 'containers/Rotation/Rotation';
|
||||
import ScheduleOverrideForm from 'containers/RotationForm/ScheduleOverrideForm';
|
||||
import { WithPermissionControl } from 'containers/WithPermissionControl/WithPermissionControl';
|
||||
import { getOverrideColor, getOverridesFromStore } from 'models/schedule/schedule.helpers';
|
||||
import { Schedule, Shift, ShiftEvents } from 'models/schedule/schedule.types';
|
||||
import { Timezone } from 'models/timezone/timezone.types';
|
||||
import { WithStoreProps } from 'state/types';
|
||||
import { UserAction } from 'state/userAction';
|
||||
import { withMobXProviderContext } from 'state/withStore';
|
||||
|
||||
import { DEFAULT_TRANSITION_TIMEOUT } from './Rotations.config';
|
||||
|
|
@ -78,9 +80,11 @@ class ScheduleOverrides extends Component<ScheduleOverridesProps, ScheduleOverri
|
|||
Overrides
|
||||
</Text.Title>
|
||||
</div>
|
||||
<Button disabled={disabled} icon="plus" onClick={this.handleAddOverride} variant="secondary">
|
||||
Add override
|
||||
</Button>
|
||||
<WithPermissionControl userAction={UserAction.UpdateSchedules}>
|
||||
<Button disabled={disabled} icon="plus" onClick={this.handleAddOverride} variant="secondary">
|
||||
Add override
|
||||
</Button>
|
||||
</WithPermissionControl>
|
||||
</HorizontalGroup>
|
||||
</div>
|
||||
<div className={cx('header-plus-content')}>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { action } from 'mobx';
|
|||
|
||||
import { makeRequest } from 'network';
|
||||
import { RootStore } from 'state';
|
||||
import { openErrorNotification } from 'utils';
|
||||
import { openWarningNotification } from 'utils';
|
||||
|
||||
export default class BaseStore {
|
||||
protected rootStore: RootStore;
|
||||
|
|
@ -26,7 +26,7 @@ export default class BaseStore {
|
|||
: Object.keys(payload)
|
||||
.map((key) => `${sentenceCase(key)}: ${payload[key]}`)
|
||||
.join('\n');
|
||||
openErrorNotification(text);
|
||||
openWarningNotification(text);
|
||||
}
|
||||
|
||||
throw error;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import React from 'react';
|
|||
|
||||
import { AppRootProps } from '@grafana/data';
|
||||
import { getLocationSrv } from '@grafana/runtime';
|
||||
import { Button, HorizontalGroup, VerticalGroup, IconButton, ToolbarButton, Icon, Modal } from '@grafana/ui';
|
||||
import { Button, HorizontalGroup, Icon, IconButton, Modal, ToolbarButton, VerticalGroup } from '@grafana/ui';
|
||||
import cn from 'classnames/bind';
|
||||
import dayjs from 'dayjs';
|
||||
import { omit } from 'lodash-es';
|
||||
|
|
@ -22,11 +22,13 @@ import UsersTimezones from 'containers/UsersTimezones/UsersTimezones';
|
|||
import { Schedule, ScheduleType, Shift } from 'models/schedule/schedule.types';
|
||||
import { Timezone } from 'models/timezone/timezone.types';
|
||||
import { WithStoreProps } from 'state/types';
|
||||
import { UserAction } from 'state/userAction';
|
||||
import { withMobXProviderContext } from 'state/withStore';
|
||||
|
||||
import { getStartOfWeek } from './Schedule.helpers';
|
||||
|
||||
import styles from './Schedule.module.css';
|
||||
|
||||
const cx = cn.bind(styles);
|
||||
|
||||
interface SchedulePageProps extends AppRootProps, WithStoreProps {}
|
||||
|
|
@ -101,7 +103,11 @@ class SchedulePage extends React.Component<SchedulePageProps, SchedulePageState>
|
|||
const users = store.userStore.getSearchResult().results;
|
||||
const schedule = scheduleStore.items[scheduleId];
|
||||
|
||||
const disabled = schedule?.type !== ScheduleType.API || shiftIdToShowRotationForm || shiftIdToShowOverridesForm;
|
||||
const disabled =
|
||||
!store.isUserActionAllowed(UserAction.UpdateSchedules) ||
|
||||
schedule?.type !== ScheduleType.API ||
|
||||
shiftIdToShowRotationForm ||
|
||||
shiftIdToShowOverridesForm;
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
|
|||
|
|
@ -146,9 +146,11 @@ class SchedulesPage extends React.Component<SchedulesPageProps, SchedulesPageSta
|
|||
onChange={this.handleTimezoneChange}
|
||||
/>
|
||||
)}
|
||||
<Button variant="primary" onClick={this.handleCreateScheduleClick}>
|
||||
+ New schedule
|
||||
</Button>
|
||||
<WithPermissionControl userAction={UserAction.UpdateSchedules}>
|
||||
<Button variant="primary" onClick={this.handleCreateScheduleClick}>
|
||||
+ New schedule
|
||||
</Button>
|
||||
</WithPermissionControl>
|
||||
</HorizontalGroup>
|
||||
</HorizontalGroup>
|
||||
<Table
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue