-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for remote selection (#323)
Co-authored-by: Matthias Lehner <[email protected]>
- Loading branch information
1 parent
4b4a1ef
commit bbd593c
Showing
16 changed files
with
266 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
export type UMLElementSelectorType = { | ||
elementId: string; | ||
name: string; | ||
color: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/services/uml-element/remote-selectable/remote-selectable-types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { UMLElementSelectorType } from '../../../packages/uml-element-selector-type'; | ||
import { Action } from '../../../utils/actions/actions'; | ||
import { UMLElementState } from '../uml-element-types'; | ||
|
||
export const enum RemoteSelectionActionTypes { | ||
SELECTION_CHANGE = '@@element/remote-selection/CHANGE', | ||
PRUNE_SELECTORS = '@@element/remote-selection/PRUNE_SELECTORS', | ||
} | ||
|
||
export const enum RemoteSelectionChangeTypes { | ||
SELECT = '@@element/remote-selection/SELECT', | ||
DESELECT = '@@element/remote-selection/DESELECT', | ||
} | ||
|
||
export interface RemoteSelectionChange { | ||
type: RemoteSelectionChangeTypes.SELECT | RemoteSelectionChangeTypes.DESELECT; | ||
id: string; | ||
} | ||
|
||
export type RemoteSelectionChangeAction = Action<RemoteSelectionActionTypes.SELECTION_CHANGE> & { | ||
payload: { | ||
changes: RemoteSelectionChange[]; | ||
selector: UMLElementSelectorType; | ||
}; | ||
}; | ||
|
||
export type RemoteSelectionPruneSelectorsAction = Action<RemoteSelectionActionTypes.PRUNE_SELECTORS> & { | ||
payload: { | ||
allowedSelectors: UMLElementSelectorType[]; | ||
}; | ||
}; | ||
|
||
export type RemoteSelectionState = { | ||
[id: string]: UMLElementSelectorType[]; | ||
}; | ||
|
||
export type RemoteSelectionActions = RemoteSelectionChangeAction | RemoteSelectionPruneSelectorsAction; |
50 changes: 50 additions & 0 deletions
50
src/main/services/uml-element/remote-selectable/remote-selection-reducer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Reducer } from 'redux'; | ||
import { | ||
RemoteSelectionActionTypes, | ||
RemoteSelectionChangeTypes, | ||
RemoteSelectionState, | ||
} from './remote-selectable-types'; | ||
import { Actions } from '../../actions'; | ||
import { UMLElementSelectorType } from '../../../packages/uml-element-selector-type'; | ||
|
||
const sameSelector = (a: UMLElementSelectorType, b: UMLElementSelectorType) => { | ||
return a.name === b.name && a.color === b.color; | ||
}; | ||
|
||
export const RemoteSelectionReducer: Reducer<RemoteSelectionState, Actions> = (state = {}, action) => { | ||
switch (action.type) { | ||
case RemoteSelectionActionTypes.SELECTION_CHANGE: | ||
const { payload } = action; | ||
const { selector, changes } = payload; | ||
|
||
return changes.reduce<RemoteSelectionState>((selection, change) => { | ||
const { id } = change; | ||
const selectors: UMLElementSelectorType[] = [...(selection[id] ?? [])]; | ||
|
||
if (change.type === RemoteSelectionChangeTypes.SELECT && !selectors.some((s) => sameSelector(s, selector))) { | ||
selectors.push(selector); | ||
} else if (change.type === RemoteSelectionChangeTypes.DESELECT) { | ||
const index = selectors.findIndex((s) => sameSelector(s, selector)); | ||
if (index >= 0) { | ||
selectors.splice(index, 1); | ||
} | ||
} | ||
|
||
return { | ||
...selection, | ||
[id]: selectors, | ||
}; | ||
}, state); | ||
|
||
case RemoteSelectionActionTypes.PRUNE_SELECTORS: | ||
const { allowedSelectors } = action.payload; | ||
|
||
return Object.fromEntries( | ||
Object.entries(state).map(([id, selectors]) => { | ||
return [id, selectors.filter((s) => allowedSelectors.some((selector) => sameSelector(s, selector)))]; | ||
}), | ||
); | ||
} | ||
|
||
return state; | ||
}; |
52 changes: 52 additions & 0 deletions
52
src/main/services/uml-element/remote-selectable/remote-selection-repository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { UMLElementSelectorType } from '../../../packages/uml-element-selector-type'; | ||
import { | ||
RemoteSelectionActionTypes, | ||
RemoteSelectionChangeTypes, | ||
RemoteSelectionChange, | ||
RemoteSelectionChangeAction, | ||
RemoteSelectionPruneSelectorsAction, | ||
} from './remote-selectable-types'; | ||
|
||
export const RemoteSelectable = { | ||
remoteSelectionChange: ( | ||
selector: UMLElementSelectorType, | ||
changes: RemoteSelectionChange[], | ||
): RemoteSelectionChangeAction => ({ | ||
type: RemoteSelectionActionTypes.SELECTION_CHANGE, | ||
payload: { | ||
selector, | ||
changes, | ||
}, | ||
undoable: false, | ||
}), | ||
|
||
remoteSelect: (selector: UMLElementSelectorType, ids: string[]): RemoteSelectionChangeAction => | ||
RemoteSelectable.remoteSelectionChange( | ||
selector, | ||
ids.map((id) => ({ type: RemoteSelectionChangeTypes.SELECT, id })), | ||
), | ||
|
||
remoteDeselect: (selector: UMLElementSelectorType, ids: string[]): RemoteSelectionChangeAction => | ||
RemoteSelectable.remoteSelectionChange( | ||
selector, | ||
ids.map((id) => ({ type: RemoteSelectionChangeTypes.DESELECT, id })), | ||
), | ||
|
||
remoteSelectDeselect: ( | ||
selector: UMLElementSelectorType, | ||
select: string[], | ||
deselect: string[], | ||
): RemoteSelectionChangeAction => | ||
RemoteSelectable.remoteSelectionChange(selector, [ | ||
...select.map((id) => ({ type: RemoteSelectionChangeTypes.SELECT, id })), | ||
...deselect.map((id) => ({ type: RemoteSelectionChangeTypes.DESELECT, id })), | ||
]), | ||
|
||
pruneRemoteSelectors: (allowedSelectors: UMLElementSelectorType[]): RemoteSelectionPruneSelectorsAction => ({ | ||
type: RemoteSelectionActionTypes.PRUNE_SELECTORS, | ||
payload: { | ||
allowedSelectors, | ||
}, | ||
undoable: false, | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.