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: update filters/sort scroll to top and select first entity (#703)

Caleb Taylorf285dc0f88a9
diff --git a/js/app/packages/app/component/UnifiedListView.tsx b/js/app/packages/app/component/UnifiedListView.tsx
index 2c9c53fc90..6cdce341fa 100644
--- a/js/app/packages/app/component/UnifiedListView.tsx
+++ b/js/app/packages/app/component/UnifiedListView.tsx
@@ -223,7 +223,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {
viewsDataStore: viewsData,
setViewDataStore,
selectedView,
- virtualizerHandleSignal: [, setVirtualizerHandle],
+ virtualizerHandleSignal: [virtualizerHandle, setVirtualizerHandle],
entityListRefSignal: [, setEntityListRef],
entitiesSignal: [entities_, setEntities],
} = unifiedListContext;
@@ -240,6 +240,11 @@ export function UnifiedListView(props: UnifiedListViewProps) {
);
};
+ const entityListResetScroll = () => {
+ setSelectedEntity(entities_()?.at(0));
+ virtualizerHandle()?.scrollTo(0);
+ };
+
const rawSearchText = createMemo<string>(() => view()?.searchText ?? '');
const searchText = createMemo(() => rawSearchText()?.trim() ?? '');
@@ -360,6 +365,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {
> = (...args: any[]) => {
// @ts-ignore narrowing set store function is annoying due to function overloading
setViewDataStore(selectedView(), 'filters', 'typeFilter', ...args);
+ entityListResetScroll();
};
const fileTypeFilter = createMemo(
@@ -560,7 +566,7 @@ export function UnifiedListView(props: UnifiedListViewProps) {
const { setFilters: setRequiredFilters, filterFn: requiredFilter } =
createFilterComposer();
- const toggleFileTypeFilter = (fileType: DocumentTypeFilter) =>
+ const toggleFileTypeFilter = (fileType: DocumentTypeFilter) => {
batch(() => {
if (!entityTypeFilter().includes('document'))
setEntityTypeFilter((prev) => [...prev, 'document']);
@@ -571,6 +577,8 @@ export function UnifiedListView(props: UnifiedListViewProps) {
: [...prev, fileType]
);
});
+ entityListResetScroll();
+ };
const nameFuzzySearchFilter = createMemo(() =>
rawSearchText()
@@ -1463,7 +1471,12 @@ export function UnifiedListView(props: UnifiedListViewProps) {
/>
</section>
<section class="p-2">
- <SortComponent size="SM" />
+ <SortComponent
+ size="SM"
+ onSelectSystemSort={() => {
+ entityListResetScroll();
+ }}
+ />
</section>
<Show when={ENABLE_PROPERTY_DISPLAY_CONTROL}>
<section class="p-2">
diff --git a/js/app/packages/macro-entity/src/components/Sort.tsx b/js/app/packages/macro-entity/src/components/Sort.tsx
index 4a6c278388..2ac19aa901 100644
--- a/js/app/packages/macro-entity/src/components/Sort.tsx
+++ b/js/app/packages/macro-entity/src/components/Sort.tsx
@@ -233,7 +233,10 @@ type InferSortFn<Options extends SortOption<any, string>[]> =
? EntityComparator<U>
: never;
-type SortComponent = (props: { size?: 'SM' | 'Base' }) => JSX.Element;
+type SortComponent = (props: {
+ size?: 'SM' | 'Base';
+ onSelectSystemSort?: () => void;
+}) => JSX.Element;
export function createSort(): {
sortFn: Accessor<EntityComparator<WithNotification<EntityData>>>;
@@ -449,12 +452,15 @@ export function createSort<
);
};
- const SortComponent: SortComponent = (_props) => (
+ const SortComponent: SortComponent = (props) => (
<div class="flex flex-col gap-2">
<span class="text-xs font-medium">Sort</span>
<SystemSortPills
sortType={sortType}
- onSelect={handleSelectSystemSort}
+ onSelect={(value) => {
+ handleSelectSystemSort(value);
+ props.onSelectSystemSort?.();
+ }}
disabled={disabled}
isSortedByProperty={isSortedByProperty}
/>