Changeset View
Changeset View
Standalone View
Standalone View
js_modules/dagit/packages/core/src/schedules/ScheduleSwitch.tsx
import {useMutation} from '@apollo/client'; | import {gql, useMutation} from '@apollo/client'; | ||||
import {Tooltip2 as Tooltip} from '@blueprintjs/popover2'; | import {Tooltip2 as Tooltip} from '@blueprintjs/popover2'; | ||||
import * as React from 'react'; | import * as React from 'react'; | ||||
import {DISABLED_MESSAGE, usePermissions} from '../app/Permissions'; | import {DISABLED_MESSAGE, usePermissions} from '../app/Permissions'; | ||||
import {InstigationStatus} from '../types/globalTypes'; | import {InstigationStatus} from '../types/globalTypes'; | ||||
import {SwitchWithoutLabel} from '../ui/SwitchWithoutLabel'; | import {SwitchWithoutLabel} from '../ui/SwitchWithoutLabel'; | ||||
import {repoAddressToSelector} from '../workspace/repoAddressToSelector'; | import {repoAddressToSelector} from '../workspace/repoAddressToSelector'; | ||||
import {RepoAddress} from '../workspace/types'; | import {RepoAddress} from '../workspace/types'; | ||||
import { | import { | ||||
displayScheduleMutationErrors, | displayScheduleMutationErrors, | ||||
START_SCHEDULE_MUTATION, | START_SCHEDULE_MUTATION, | ||||
STOP_SCHEDULE_MUTATION, | STOP_SCHEDULE_MUTATION, | ||||
} from './ScheduleMutations'; | } from './ScheduleMutations'; | ||||
import {ScheduleFragment} from './types/ScheduleFragment'; | import {ScheduleSwitchFragment} from './types/ScheduleSwitchFragment'; | ||||
import {StartSchedule} from './types/StartSchedule'; | import {StartSchedule} from './types/StartSchedule'; | ||||
import {StopSchedule} from './types/StopSchedule'; | import {StopSchedule} from './types/StopSchedule'; | ||||
interface Props { | interface Props { | ||||
large?: boolean; | large?: boolean; | ||||
repoAddress: RepoAddress; | repoAddress: RepoAddress; | ||||
schedule: ScheduleFragment; | schedule: ScheduleSwitchFragment; | ||||
} | } | ||||
export const ScheduleSwitch: React.FC<Props> = (props) => { | export const ScheduleSwitch: React.FC<Props> = (props) => { | ||||
const {large = true, repoAddress, schedule} = props; | const {large = true, repoAddress, schedule} = props; | ||||
const {name, scheduleState} = schedule; | const {name, scheduleState} = schedule; | ||||
const {status, id} = scheduleState; | const {status, id} = scheduleState; | ||||
const {canStartSchedule, canStopRunningSchedule} = usePermissions(); | const {canStartSchedule, canStopRunningSchedule} = usePermissions(); | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | <Tooltip content={lacksPermission ? DISABLED_MESSAGE : undefined}> | ||||
disabled={disabled} | disabled={disabled} | ||||
innerLabelChecked="on" | innerLabelChecked="on" | ||||
innerLabel="off" | innerLabel="off" | ||||
onChange={onStatusChange} | onChange={onStatusChange} | ||||
/> | /> | ||||
</Tooltip> | </Tooltip> | ||||
); | ); | ||||
}; | }; | ||||
export const SCHEDULE_SWITCH_FRAGMENT = gql` | |||||
fragment ScheduleSwitchFragment on Schedule { | |||||
id | |||||
name | |||||
scheduleState { | |||||
id | |||||
status | |||||
} | |||||
} | |||||
`; |