Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

soup-context: update entity properties (#712)

Caleb Taylor69c631db68fe
diff --git a/js/app/packages/app/component/EntityActionsMenuItems.tsx b/js/app/packages/app/component/EntityActionsMenuItems.tsx
index 9e9a49acd4..69404386f1 100644
--- a/js/app/packages/app/component/EntityActionsMenuItems.tsx
+++ b/js/app/packages/app/component/EntityActionsMenuItems.tsx
@@ -17,10 +17,10 @@ export const EntityActionsMenuItems = (props: EntityActionsMenuItemsProps) => {
const { actionRegistry, viewsDataStore, selectedView } = unifiedListContext;
const entities = () => {
- const { selectedEntities } = viewsDataStore[selectedView()];
- if (selectedEntities.length > 0) {
- if (selectedEntities.some((e) => e.id === props.entity.id)) {
- return selectedEntities;
+ const { multiSelectEntities } = viewsDataStore[selectedView()];
+ if (multiSelectEntities.length > 0) {
+ if (multiSelectEntities.some((e) => e.id === props.entity.id)) {
+ return multiSelectEntities;
}
}
return [props.entity];
@@ -40,7 +40,7 @@ export const EntityActionsMenuItems = (props: EntityActionsMenuItemsProps) => {
const setSelection: Setter<EntityData[]> = (entities) => {
return unifiedListContext.setViewDataStore(
selectedView(),
- 'selectedEntities',
+ 'multiSelectEntities',
entities
);
};
diff --git a/js/app/packages/app/component/EntitySelectionToolbarModal.tsx b/js/app/packages/app/component/EntitySelectionToolbarModal.tsx
index cfaf96efd6..ab6cfd0567 100644
--- a/js/app/packages/app/component/EntitySelectionToolbarModal.tsx
+++ b/js/app/packages/app/component/EntitySelectionToolbarModal.tsx
@@ -4,7 +4,7 @@ import type { EntityData } from '@macro-entity';
import CloseIcon from '@phosphor-icons/core/regular/x.svg?component-solid';
interface EntitySelectionToolbarModalProps {
- selectedEntities: EntityData[];
+ multiSelectEntities: EntityData[];
onClose: VoidFunction;
onAction: VoidFunction;
}
@@ -26,7 +26,7 @@ export const EntitySelectionToolbarModal = (
<CloseIcon class="shrink-0 size-full" />
</button>
<span class="text-ink font-regular w-full whitespace-nowrap">
- {props.selectedEntities.length} selected
+ {props.multiSelectEntities.length} selected
</span>
</div>
<button
diff --git a/js/app/packages/app/component/SoupContext.tsx b/js/app/packages/app/component/SoupContext.tsx
index 4f1087df16..3d75c552d6 100644
--- a/js/app/packages/app/component/SoupContext.tsx
+++ b/js/app/packages/app/component/SoupContext.tsx
@@ -188,11 +188,10 @@ function createViewData(
limit: viewProps?.display?.limit,
},
sort: viewProps?.sort ?? VIEWCONFIG_BASE.sort,
- highlightedId: undefined,
selectedEntity: undefined,
scrollOffset: undefined,
initialConfig: undefined,
- selectedEntities: [],
+ multiSelectEntities: [],
hasUserInteractedEntity: false,
searchText: viewProps?.searchText,
};
@@ -201,7 +200,6 @@ function createViewData(
export type NavigationInput = {
axis: 'start' | 'end'; // movement direction
mode: 'step' | 'jump'; // how far: one step or to the end
- highlight?: boolean;
};
export type NavigationResult = {
@@ -283,11 +281,10 @@ export function createNavigationEntityListShortcut({
clearSelection?: boolean
) => {
if (clearSelection) {
- setViewDataStore(selectedView(), 'selectedEntities', []);
+ setViewDataStore(selectedView(), 'multiSelectEntities', []);
}
if (entity) {
setSelectedEntity(entity);
- setViewDataStore(selectedView(), 'highlightedId', entity.id);
const nextIndex = entities()?.findIndex(({ id }) => id === entity.id);
if (nextIndex !== undefined && nextIndex > -1) {
virtualizerHandle()?.scrollToIndex(nextIndex, {
@@ -366,7 +363,7 @@ export function createNavigationEntityListShortcut({
}
}
- setViewDataStore(selectedView(), 'selectedEntities', []);
+ setViewDataStore(selectedView(), 'multiSelectEntities', []);
}
return { success: true };
@@ -462,7 +459,9 @@ export function createNavigationEntityListShortcut({
hotkeyToken: TOKENS.entity.action.delete,
scopeId: splitHotkeyScope,
description: () =>
- viewData().selectedEntities.length > 1 ? 'Delete items' : 'Delete item',
+ viewData().multiSelectEntities.length > 1
+ ? 'Delete items'
+ : 'Delete item',
keyDownHandler: () => {
const entitiesForAction = getEntitiesForAction();
if (entitiesForAction.entities.length === 0) {
@@ -561,7 +560,9 @@ export function createNavigationEntityListShortcut({
scopeId: splitHotkeyScope,
hotkeyToken: TOKENS.entity.action.rename,
description: () =>
- viewData().selectedEntities.length > 1 ? 'Rename items' : 'Rename item',
+ viewData().multiSelectEntities.length > 1
+ ? 'Rename items'
+ : 'Rename item',
condition: () =>
isViewingList() &&
actionRegistry.isActionEnabled('rename', plainSelectedEntities()),
@@ -608,7 +609,7 @@ export function createNavigationEntityListShortcut({
hotkeyToken: TOKENS.entity.action.copy,
description: () =>
- viewData().selectedEntities.length > 1 ? 'Copy items' : 'Copy item',
+ viewData().multiSelectEntities.length > 1 ? 'Copy items' : 'Copy item',
condition: () =>
isViewingList() &&
actionRegistry.isActionEnabled('copy', plainSelectedEntities()),
@@ -663,7 +664,7 @@ export function createNavigationEntityListShortcut({
scopeId: splitHotkeyScope,
hotkeyToken: TOKENS.entity.action.moveToFolder,
description: () =>
- viewData().selectedEntities.length > 1
+ viewData().multiSelectEntities.length > 1
? 'Move items to folder'
: 'Move item to folder',
condition: () =>
@@ -700,10 +701,6 @@ export function createNavigationEntityListShortcut({
}
};
- const activeHighlightedId = () => {
- return viewData()?.highlightedId;
- };
-
const getEntityElAtIndex = (index: number) => {
const entity = entities()?.at(index);
if (!entity) return;
@@ -711,9 +708,11 @@ export function createNavigationEntityListShortcut({
return entityListRef()?.querySelector(`[data-entity-id="${entity.id}"]`);
};
- const getHighlightedEntity = createLazyMemo(() => {
+ const getSelectedEntity = createLazyMemo(() => {
const index =
- entities()?.findIndex(({ id }) => id === activeHighlightedId()) ?? -1;
+ entities()?.findIndex(
+ ({ id }) => id === viewData()?.selectedEntity?.id
+ ) ?? -1;
if (index < 0) return;
const entity = entities()?.at(index);
@@ -738,9 +737,9 @@ export function createNavigationEntityListShortcut({
let selectedEntityIndices: Array<{ entity: EntityData; index: number }> =
[];
- if (viewData().selectedEntities.length > 0) {
+ if (viewData().multiSelectEntities.length > 0) {
selectedEntityIndices = filterMap(
- viewData().selectedEntities,
+ viewData().multiSelectEntities,
(entity) => {
const index = idToIndexMap.get(entity.id);
if (index === undefined) {
@@ -753,7 +752,7 @@ export function createNavigationEntityListShortcut({
}
);
} else {
- const entity = getHighlightedEntity();
+ const entity = getSelectedEntity();
if (entity) selectedEntityIndices = [entity];
}
@@ -802,10 +801,10 @@ export function createNavigationEntityListShortcut({
const entityList = entities();
if (!entityList) return false;
- const highlightedEntity = getHighlightedEntity();
- if (!highlightedEntity) return false;
+ const selectedEntity = getSelectedEntity();
+ if (!selectedEntity) return false;
- return highlightedEntity.index >= entityList.length - 1;
+ return selectedEntity.index >= entityList.length - 1;
});
const calculateEntityIndex = (
@@ -840,7 +839,7 @@ export function createNavigationEntityListShortcut({
axis,
mode,
}: NavigationInput): Promise<NavigationResult> => {
- let index = calculateEntityIndex(getHighlightedEntity()?.index ?? -1, {
+ let index = calculateEntityIndex(getSelectedEntity()?.index ?? -1, {
axis,
mode,
});
@@ -892,7 +891,6 @@ export function createNavigationEntityListShortcut({
}
}
batch(() => {
- setViewDataStore(selectedView(), 'highlightedId', selectedEntity.id);
setSelectedEntity(selectedEntity);
});
}
@@ -938,12 +936,13 @@ export function createNavigationEntityListShortcut({
const isEntitySelected = (entityID: string) => {
return (
- viewData()?.selectedEntities.find((e) => e.id === entityID) !== undefined
+ viewData()?.multiSelectEntities.find((e) => e.id === entityID) !==
+ undefined
);
};
const toggleEntity = (entity: EntityData) => {
- setViewDataStore(selectedView(), 'selectedEntities', (s) => {
+ setViewDataStore(selectedView(), 'multiSelectEntities', (s) => {
if (isEntitySelected(entity.id)) {
return s.filter((e) => e.id !== entity.id);
}
@@ -960,37 +959,37 @@ export function createNavigationEntityListShortcut({
};
const handleNavigationSelection = (input: NavigationInput) => {
- const highlightedEntity = getHighlightedEntity();
- const currentIndex = highlightedEntity?.index ?? -1;
+ const selectedEntity = getSelectedEntity();
+ const currentIndex = selectedEntity?.index ?? -1;
const nextIndex = calculateEntityIndex(currentIndex, input);
const nextEntity = entities()?.at(nextIndex);
if (!nextEntity) return true;
- if (!highlightedEntity) {
+ if (!selectedEntity) {
navigateAndSelectEntity(input);
return true;
}
- // If selectedEntities is empty, select current item first without moving
- const selectedEntities = viewData()?.selectedEntities || [];
- if (selectedEntities.length === 0) {
- toggleEntity(highlightedEntity.entity);
+ // If multiSelectEntities is empty, select current item first without moving
+ const multiSelectEntities = viewData()?.multiSelectEntities || [];
+ if (multiSelectEntities.length === 0) {
+ toggleEntity(selectedEntity.entity);
return true;
}
if (
- !isEntitySelected(highlightedEntity.entity.id) &&
+ !isEntitySelected(selectedEntity.entity.id) &&
!isEntitySelected(nextEntity.id)
) {
- toggleEntity(highlightedEntity.entity);
+ toggleEntity(selectedEntity.entity);
navigateAndSelectEntity(input);
return true;
}
if (isEntitySelected(nextEntity.id)) {
- toggleEntity(highlightedEntity.entity);
+ toggleEntity(selectedEntity.entity);
navigateThroughList(input);
return true;
}
@@ -1007,9 +1006,9 @@ export function createNavigationEntityListShortcut({
condition: () => !konsoleOpen() && isViewingList(),
keyDownHandler: (e) => {
e?.preventDefault();
- const selectedEntities = viewData().selectedEntities;
+ const multiSelectEntities = viewData().multiSelectEntities;
- const hasSelection = selectedEntities.length > 0;
+ const hasSelection = multiSelectEntities.length > 0;
if (hasSelection) {
setKonsoleMode('SELECTION_MODIFICATION');
@@ -1022,7 +1021,7 @@ export function createNavigationEntityListShortcut({
searchCategories.showCategory('Selection');
setKonsoleContextInformation({
- selectedEntities: selectedEntities.slice(),
+ multiSelectEntities: multiSelectEntities.slice(),
});
toggleKonsoleVisibility();
@@ -1194,7 +1193,7 @@ export function createNavigationEntityListShortcut({
scopeId: splitHotkeyScope,
description: 'Open',
keyDownHandler: () => {
- const entity = getHighlightedEntity()?.entity;
+ const entity = getSelectedEntity()?.entity;
if (!entity) return false;
openEntity(entity);
@@ -1221,7 +1220,7 @@ export function createNavigationEntityListShortcut({
keyDownHandler: () => {
const [preview] = previewState;
- const entity = getHighlightedEntity()?.entity;
+ const entity = getSelectedEntity()?.entity;
if (!entity) return false;
if (preview()) {
@@ -1270,7 +1269,7 @@ export function createNavigationEntityListShortcut({
scopeId: splitHotkeyScope,
description: 'Toggle select item',
keyDownHandler: () => {
- const entity = getHighlightedEntity();
+ const entity = getSelectedEntity();
if (!entity) return false;
toggleEntity(entity.entity);
return true;
@@ -1283,12 +1282,12 @@ export function createNavigationEntityListShortcut({
scopeId: splitHotkeyScope,
description: 'Clear multi selection',
keyDownHandler: () => {
- const length = viewData().selectedEntities.length;
- setViewDataStore(selectedView(), 'selectedEntities', []);
+ const length = viewData().multiSelectEntities.length;
+ setViewDataStore(selectedView(), 'multiSelectEntities', []);
return length > 1;
},
canExecuteKeyDownHandler: () =>
- isViewingList() && viewData().selectedEntities.length > 0,
+ isViewingList() && viewData().multiSelectEntities.length > 0,
});
}
diff --git a/js/app/packages/app/component/UnifiedListView.tsx b/js/app/packages/app/component/UnifiedListView.tsx
index d892246f41..2c9c53fc90 100644
--- a/js/app/packages/app/component/UnifiedListView.tsx
+++ b/js/app/packages/app/component/UnifiedListView.tsx
@@ -267,7 +267,6 @@ export function UnifiedListView(props: UnifiedListViewProps) {
if (!firstEntity) return;
- setViewDataStore(selectedView(), 'highlightedId', firstEntity.id);
setSelectedEntity(firstEntity);
tryFocusEntity(firstEntity.id);
@@ -556,10 +555,6 @@ export function UnifiedListView(props: UnifiedListViewProps) {
return stringify(currentViewConfigBase());
});
- const setHighlightedId = (id: string) => {
- setViewDataStore(selectedView(), 'highlightedId', id);
- };
-
const { setFilters: setOptionalFilters, filterFn: optionalFilter } =
createFilterComposer();
const { setFilters: setRequiredFilters, filterFn: requiredFilter } =
@@ -1153,11 +1148,9 @@ export function UnifiedListView(props: UnifiedListViewProps) {
return <span class="text-[0.625rem]">{props.children}</span>;
};
- const highlightedSelector = createSelector(() => view()?.highlightedId);
-
const focusedSelector = createSelector(() => selectedEntity()?.id);
- const selectedSelector = createSelector(
- () => view()?.selectedEntities,
+ const multiSelectSelector = createSelector(
+ () => view()?.multiSelectEntities,
(a: string, b: EntityData[]) => b.find((e) => e.id === a) !== undefined
);
@@ -1247,7 +1240,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {
// reset last clicked on reset multi-selection.
createEffect(() => {
if (
- unifiedListContext.viewsDataStore[selectedView()].selectedEntities
+ unifiedListContext.viewsDataStore[selectedView()].multiSelectEntities
.length === 0
) {
lastClickedEntityId = -1;
@@ -1535,8 +1528,6 @@ export function UnifiedListView(props: UnifiedListViewProps) {
return (
<EntityWithEverything
onContextMenu={() => {
- setHighlightedId(innerProps.entity.id);
-
if (isPanelActive() && !preview()) {
setSelectedEntity(innerProps.entity);
}
@@ -1580,19 +1571,11 @@ export function UnifiedListView(props: UnifiedListViewProps) {
true
);
- setHighlightedId(innerProps.entity.id);
-
- if (isPanelActive() && !preview()) {
- setSelectedEntity(innerProps.entity);
- }
+ setSelectedEntity(innerProps.entity);
}}
onMouseLeave={() => {}}
onFocusIn={() => {
- setHighlightedId(innerProps.entity.id);
-
- if (isPanelActive() && !preview()) {
- setSelectedEntity(innerProps.entity);
- }
+ setSelectedEntity(innerProps.entity);
}}
showLeftColumnIndicator={
showUnreadIndicator() || importantFilter()
@@ -1604,16 +1587,16 @@ export function UnifiedListView(props: UnifiedListViewProps) {
)}
unreadIndicatorActive={unreadFilterFn(innerProps.entity)}
showDoneButton={displayDoneButton()}
- highlighted={highlightedSelector?.(innerProps.entity.id)}
- selected={
+ highlighted={
isPanelActive() && focusedSelector(innerProps.entity.id)
}
- checked={selectedSelector(innerProps.entity.id)}
+ selected={focusedSelector(innerProps.entity.id)}
+ checked={multiSelectSelector(innerProps.entity.id)}
onChecked={(next, shiftKey) => {
const toggleSingle = () =>
unifiedListContext.setViewDataStore(
selectedView(),
- 'selectedEntities',
+ 'multiSelectEntities',
(p) => {
if (!next) {
return p.filter(
@@ -1631,7 +1614,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {
const selectedEntitySet = new Set(
unifiedListContext.viewsDataStore[
unifiedListContext.selectedView()
- ].selectedEntities
+ ].multiSelectEntities
);
const newEnititiesForSeleciton: EntityData[] = [];
@@ -1670,7 +1653,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {
}
unifiedListContext.setViewDataStore(
selectedView(),
- 'selectedEntities',
+ 'multiSelectEntities',
(p) => {
return p.concat(newEnititiesForSeleciton);
}
@@ -1727,20 +1710,20 @@ export function UnifiedListView(props: UnifiedListViewProps) {
</Show>
</ContextMenu.Portal>
</ContextMenu.Trigger>
- <Show when={view()?.selectedEntities.length}>
+ <Show when={view()?.multiSelectEntities.length}>
<EntitySelectionToolbarModal
- selectedEntities={view()?.selectedEntities ?? []}
+ multiSelectEntities={view()?.multiSelectEntities ?? []}
onClose={() =>
unifiedListContext.setViewDataStore(
selectedView(),
- 'selectedEntities',
+ 'multiSelectEntities',
[]
)
}
onAction={() => {
- const selectedEntities =
- viewsData[selectedView()].selectedEntities;
- const hasSelection = selectedEntities.length > 0;
+ const multiSelectEntities =
+ viewsData[selectedView()].multiSelectEntities;
+ const hasSelection = multiSelectEntities.length > 0;
if (hasSelection) {
setKonsoleMode('SELECTION_MODIFICATION');
const selectionIndex =
@@ -1753,11 +1736,11 @@ export function UnifiedListView(props: UnifiedListViewProps) {
searchCategories.showCategory('Selection');
setKonsoleContextInformation({
- selectedEntities: selectedEntities.slice(),
+ selectedEntities: multiSelectEntities.slice(),
clearSelection: () => {
unifiedListContext.setViewDataStore(
selectedView(),
- 'selectedEntities',
+ 'multiSelectEntities',
[]
);
},
@@ -1833,7 +1816,7 @@ function SearchBar(props: {
};
const selectionClick = () => {
- const id = viewsDataStore[selectedView()].highlightedId;
+ const id = viewsDataStore[selectedView()].selectedEntity?.id;
if (!id) return;
const el = entityListRef()?.querySelector(`[data-entity-id="${id}"]`);
if (!(el instanceof HTMLElement)) return;
@@ -1854,7 +1837,6 @@ function SearchBar(props: {
const text = searchText().trim();
if (text !== prevText) {
setViewDataStore(selectedView(), 'selectedEntity', undefined);
- setViewDataStore(selectedView(), 'highlightedId', undefined);
setViewDataStore(selectedView(), 'hasUserInteractedEntity', false);
virtualizerHandle()?.scrollToIndex(0);
setWaitForLoadingEnd(true);
diff --git a/js/app/packages/app/component/ViewConfig.tsx b/js/app/packages/app/component/ViewConfig.tsx
index 72345440d0..736b1d2035 100644
--- a/js/app/packages/app/component/ViewConfig.tsx
+++ b/js/app/packages/app/component/ViewConfig.tsx
@@ -30,13 +30,12 @@ export type ViewData = {
id: ViewId;
view: ViewLabel;
viewType?: ViewType;
- highlightedId: string | undefined;
selectedEntity: EntityData | undefined;
scrollOffset: number | undefined;
initialConfig: string | undefined;
hasUserInteractedEntity: boolean;
searchText: string | undefined;
- selectedEntities: EntityData[];
+ multiSelectEntities: EntityData[];
} & ViewConfigBase;
/** maps view id to view data */
diff --git a/js/app/packages/block-project/component/Block.tsx b/js/app/packages/block-project/component/Block.tsx
index 4c8c758a6f..9b9ffde71a 100644
--- a/js/app/packages/block-project/component/Block.tsx
+++ b/js/app/packages/block-project/component/Block.tsx
@@ -96,7 +96,7 @@ const Block: Component = () => {
...PROJECT_VIEWCONFIG_BASE,
id: projectId,
view: name() ?? 'folder',
- selectedEntities: [],
+ multiSelectEntities: [],
filters: {
...PROJECT_VIEWCONFIG_BASE.filters,
projectFilter: projectId,
diff --git a/js/app/packages/macro-entity/src/components/EntityWithEverything.tsx b/js/app/packages/macro-entity/src/components/EntityWithEverything.tsx
index 14a391ee07..cae861c594 100644
--- a/js/app/packages/macro-entity/src/components/EntityWithEverything.tsx
+++ b/js/app/packages/macro-entity/src/components/EntityWithEverything.tsx
@@ -807,10 +807,10 @@ export function EntityWithEverything(
data-checked={props.checked}
class="everything-entity relative group/entity"
classList={{
- 'bg-hover/30': props.highlighted && !props.checked,
+ 'bg-hover/30': props.selected && !props.checked,
'bg-accent/5': props.checked,
'bracket outline outline-accent/20 outline-offset-[-1px]':
- props.selected,
+ props.highlighted,
}}
onMouseOver={(e) => {
if (!didCursorMove(e)) {
@@ -866,8 +866,8 @@ export function EntityWithEverything(
<div
class="size-4 p-0.5 flex items-center justify-center rounded-xs group-hover/button:border-accent group-hover/button:border pointer-events-none"
classList={{
- 'ring ring-edge-muted': props.selected,
- 'bg-panel': !props.checked && props.selected,
+ 'ring ring-edge-muted': props.highlighted,
+ 'bg-panel': !props.checked && props.highlighted,
'bg-accent border border-accent': props.checked,
}}
>
@@ -979,7 +979,7 @@ export function EntityWithEverything(
);
}}
</Show>
- <Show when={props.highlighted && props.onClickRowAction}>
+ <Show when={props.selected && props.onClickRowAction}>
<div class="absolute top-1 right-1 items-center flex @max-sm/split:hidden">
<Tooltip
tooltip={