Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions js/app/packages/app/component/SoupContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export function createNavigationEntityListShortcut({
return { success: true };
},
{
testEnabled: (entity) => {
canExecute: (entity) => {
if (entity.type === 'email' || entity.type === 'channel') return true;
if (entityHasUnreadNotifications(notificationSource, entity))
return true;
Expand Down Expand Up @@ -381,15 +381,15 @@ export function createNavigationEntityListShortcut({
return { success: true };
},
{
testEnabled: (entity) => {
canExecute: (entity) => {
// can't delete these bad boys yet.
if (entity.type === 'channel' || entity.type === 'email') return false;
// only delete what you own.
return entity.ownerId === userId();
},
// TODO (seamus): fix the handler from the modal so that we can delete
// some of the items. Then switch this to some.
enabledMode: 'every',
mode: 'every',
}
);

Expand Down Expand Up @@ -449,7 +449,7 @@ export function createNavigationEntityListShortcut({
return { success: true };
},
{
testEnabled: (entity) => {
canExecute: (entity) => {
if (entity.type === 'channel') {
if (entity.channelType === 'direct_message') return false;

Expand Down Expand Up @@ -531,7 +531,7 @@ export function createNavigationEntityListShortcut({
return { success: true };
},
{
testEnabled: (entity) => {
canExecute: (entity) => {
if (entity.type === 'channel' || entity.type === 'email') return false;
return true;
},
Expand All @@ -540,6 +540,7 @@ export function createNavigationEntityListShortcut({

registerHotkey({
scopeId: splitHotkeyScope,

hotkeyToken: TOKENS.entity.action.copy,
description: () =>
viewData().selectedEntities.length > 1 ? 'Copy items' : 'Copy item',
Expand Down Expand Up @@ -586,7 +587,7 @@ export function createNavigationEntityListShortcut({
return { success: true };
},
{
testEnabled: (entity) => {
canExecute: (entity) => {
if (entity.type === 'channel' || entity.type === 'email') return false;
return true;
},
Expand Down
22 changes: 11 additions & 11 deletions js/app/packages/app/component/UnifiedEntityActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ export type EntityActionConfig = {
/** Optional icon component */
icon?: Component;
/**
* Optional test to run over an entity to see if the action can be performed
* Optional condition to run over an entity to see if the action can be performed
* on that entity.
*/
testEnabled?: (entity: EntityData) => boolean;
canExecute?: (entity: EntityData) => boolean;
/**
* Enabled mode for bulk version of action. If 'every' then all entities must pass
* Mode for bulk version of action. If 'every' then all entities must pass
* for the action to register as enabled. If 'some' then the action can be
* enabled if a single entity passes the test. Only meaningful if testEnabled
* enabled if a single entity passes the test. Only meaningful if canExecute
* is also provided. Default is 'every'
*/
enabledMode?: 'some' | 'every';
mode?: 'some' | 'every';
};

export type EntityActionRegistry = {
Expand Down Expand Up @@ -109,16 +109,16 @@ export function createEntityActionRegistry(): EntityActionRegistry {
type: EntityActionType,
entities: EntityData | EntityData[]
): boolean => {
const { testEnabled, enabledMode } = configs.get(type) ?? {};
if (!testEnabled) return true;
const { canExecute, mode } = configs.get(type) ?? {};
if (!canExecute) return true;
if (Array.isArray(entities)) {
if (enabledMode === 'some') {
return entities.some(testEnabled);
if (mode === 'some') {
return entities.some(canExecute);
} else {
return entities.every(testEnabled);
return entities.every(canExecute);
}
} else if (isEntityData(entities)) {
return testEnabled(entities);
return canExecute(entities);
}
return false;
};
Expand Down