Skip to content

Commit

Permalink
Add the disable functionality to dropdowns in the rundown
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Boberg <[email protected]>
  • Loading branch information
axelboberg committed Feb 29, 2024
1 parent 503d4ab commit ec4faa8
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 72 deletions.
78 changes: 6 additions & 72 deletions plugins/rundown/app/components/RundownList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { RundownGroupItem, RundownGroupItemContext } from '../RundownGroupItem'
import { RundownListItem } from '../RundownListItem'
import { RundownItem } from '../RundownItem'

import * as clipboard from '../../utils/clipboard'
import * as selectionUtils from '../../utils/selection'
import * as keyboard from '../../utils/keyboard'

/**
Expand Down Expand Up @@ -60,72 +60,6 @@ function scrollIntoView (el, animate = true, centered = true) {
})
}

/**
* Delete the current selection
*
* Fetch the selection from the main thread before doing the deletion as
* we want to make sure we don't delete the wrong items from an unsynced state
*
* @returns { Promise.<void> }
*/
async function deleteSelection () {
const selection = await bridge.client.getSelection()
bridge.items.deleteItems(selection)
}

/**
* Copy a string representation of the
* currently selected items to the clipboard
*
* @returns { Promise.<void> }
*/
async function copySelection () {
const selection = await bridge.client.getSelection()
const str = await bridge.commands.executeCommand('rundown.copyItems', selection)
await clipboard.copyText(str)
}

/**
* Play the currently selected items
* @returns { Promise.<void> }
*/
async function playSelection () {
const selection = await bridge.client.getSelection()
selection.forEach(itemId => bridge.items.playItem(itemId))
}

/**
* Stop the currently selected items
* @returns { Promise.<void> }
*/
async function stopSelection () {
const selection = await bridge.client.getSelection()
selection.forEach(itemId => bridge.items.stopItem(itemId))
}

/**
* Toggle the disabled property
* of the currently selected items
* @returns { Promise.<void> }
*/
async function toggleDisableSelection () {
const selection = await bridge.client.getSelection()

const set = {
items: {}
}

for (const itemId of selection) {
set.items[itemId] = {
data: {
disabled: { $invert: true }
}
}
}

bridge.state.apply(set)
}

export function RundownList ({
rundownId = '',
className = '',
Expand Down Expand Up @@ -231,19 +165,19 @@ export function RundownList ({
select(-1)
break
case 'toggleDisable':
toggleDisableSelection()
selectionUtils.toggleDisableSelection()
break
case 'delete':
deleteSelection()
selectionUtils.deleteSelection()
break
case 'play':
playSelection()
selectionUtils.playSelection()
break
case 'stop':
stopSelection()
selectionUtils.stopSelection()
break
case 'copy':
copySelection()
selectionUtils.copySelection()
break
}
}
Expand Down
2 changes: 2 additions & 0 deletions plugins/rundown/app/components/RundownListItem/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ContextMenuDivider } from '../../../../../app/components/ContextMenuDiv
import { ContextAddMenu } from '../ContextAddMenu'

import * as clipboard from '../../utils/clipboard'
import * as selection from '../../utils/selection'

const INDICATE_PLAYING_TIMEOUT_MS = 100

Expand Down Expand Up @@ -158,6 +159,7 @@ export function RundownListItem ({
<ContextAddMenu onAdd={newItemId => handleAdd(newItemId)} />
</ContextMenuItem>
<ContextMenuItem text='Create reference' onClick={() => handleCreateReference()} />
<ContextMenuItem text={item?.data?.disabled ? 'Enable' : 'Disable'} onClick={() => selection.disableSelection(!item?.data?.disabled)} />
<ContextMenuDivider />
<ContextMenuItem text='Remove' onClick={() => handleDelete()} />
{
Expand Down
92 changes: 92 additions & 0 deletions plugins/rundown/app/utils/selection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import bridge from 'bridge'

import * as clipboard from './clipboard'

/**
* Toggle the disabled property
* of the currently selected items
* @returns { Promise.<void> }
*/
export async function toggleDisableSelection () {
const selection = await bridge.client.getSelection()

const set = {
items: {}
}

for (const itemId of selection) {
set.items[itemId] = {
data: {
disabled: { $invert: true }
}
}
}

bridge.state.apply(set)
}

/**
* Set the disabled property
* of the currently selected items
* @returns { Promise.<void> }
*/
export async function disableSelection (disabled) {
const selection = await bridge.client.getSelection()

const set = {
items: {}
}

for (const itemId of selection) {
set.items[itemId] = {
data: {
disabled: !!disabled
}
}
}

bridge.state.apply(set)
}

/**
* Delete the current selection
*

Check failure on line 53 in plugins/rundown/app/utils/selection.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Trailing spaces not allowed

Check failure on line 53 in plugins/rundown/app/utils/selection.js

View workflow job for this annotation

GitHub Actions / test (16.x)

Trailing spaces not allowed
* Fetch the selection from the main thread before doing the deletion as
* we want to make sure we don't delete the wrong items from an unsynced state
*

Check failure on line 56 in plugins/rundown/app/utils/selection.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Trailing spaces not allowed

Check failure on line 56 in plugins/rundown/app/utils/selection.js

View workflow job for this annotation

GitHub Actions / test (16.x)

Trailing spaces not allowed
* @returns { Promise.<void> }
*/
export async function deleteSelection () {
const selection = await bridge.client.getSelection()
bridge.items.deleteItems(selection)
}

/**
* Copy a string representation of the
* currently selected items to the clipboard
*

Check failure on line 67 in plugins/rundown/app/utils/selection.js

View workflow job for this annotation

GitHub Actions / test (14.x)

Trailing spaces not allowed

Check failure on line 67 in plugins/rundown/app/utils/selection.js

View workflow job for this annotation

GitHub Actions / test (16.x)

Trailing spaces not allowed
* @returns { Promise.<void> }
*/
export async function copySelection () {
const selection = await bridge.client.getSelection()
const str = await bridge.commands.executeCommand('rundown.copyItems', selection)
await clipboard.copyText(str)
}

/**
* Play the currently selected items
* @returns { Promise.<void> }
*/
export async function playSelection () {
const selection = await bridge.client.getSelection()
selection.forEach(itemId => bridge.items.playItem(itemId))
}

/**
* Stop the currently selected items
* @returns { Promise.<void> }
*/
export async function stopSelection () {
const selection = await bridge.client.getSelection()
selection.forEach(itemId => bridge.items.stopItem(itemId))
}

0 comments on commit ec4faa8

Please sign in to comment.