Skip to content

Commit

Permalink
Merge branch 'feat/custom-search-tree-adjustments' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Nov 25, 2024
2 parents d07af62 + 20cdcbd commit 4e54786
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 26 deletions.
45 changes: 26 additions & 19 deletions src/actionbar/TreeActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function TreeActionBar(props: Props) {
const { processAction } = contentRootContext || {};
const [exportModalVisible, setExportModalVisible] = useState(false);
const isFirstMount = useRef(true);
const isCustomSearchResults = currentModel === "custom.search.results";

useHotkeys(
"ctrl+l,command+l",
Expand Down Expand Up @@ -216,21 +217,23 @@ function TreeActionBar(props: Props) {
)}
{treeExpandable ? null : (
<>
<SearchBar
disabled={duplicatingItem || removingItem || treeIsLoading}
searchText={searchTreeNameSearch}
onSearch={(searchString?: string) => {
if (searchString && searchString.trim().length > 0) {
setSearchTreeNameSearch?.(searchString);
} else {
setSearchTreeNameSearch?.(undefined);
if (!isInfiniteTree) {
searchTreeRef?.current?.refreshResults();
{!isCustomSearchResults && (
<SearchBar
disabled={duplicatingItem || removingItem || treeIsLoading}
searchText={searchTreeNameSearch}
onSearch={(searchString?: string) => {
if (searchString && searchString.trim().length > 0) {
setSearchTreeNameSearch?.(searchString);
} else {
setSearchTreeNameSearch?.(undefined);
if (!isInfiniteTree) {
searchTreeRef?.current?.refreshResults();
}
}
}
}}
/>
{!treeExpandable && (
}}
/>
)}
{!treeExpandable && !isCustomSearchResults && (
<ButtonWithBadge
icon={
<FilterOutlined
Expand All @@ -247,7 +250,7 @@ function TreeActionBar(props: Props) {
/>
)}
{separator()}
<NewButton disabled={treeIsLoading} />
<NewButton disabled={treeIsLoading || isCustomSearchResults} />
<ActionButton
icon={<CopyOutlined />}
tooltip={t("duplicate")}
Expand Down Expand Up @@ -385,10 +388,14 @@ function TreeActionBar(props: Props) {
id: "print_screen",
name: t("printScreen"),
},
{
id: "export",
name: t("advancedExport"),
},
...(!isCustomSearchResults
? [
{
id: "export",
name: t("advancedExport"),
},
]
: []),
],
},
]}
Expand Down
8 changes: 3 additions & 5 deletions src/widgets/views/SearchTreeHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const { Text } = Typography;
export type SearchTreeHeaderProps = {
totalRows?: number | null;
selectedRowKeys: number[];
allRowSelectedMode: boolean;
hideSelectionSummary?: boolean;
};

export const SearchTreeHeader = ({
totalRows,
selectedRowKeys,
allRowSelectedMode,
hideSelectionSummary = false,
}: SearchTreeHeaderProps) => {
const { t } = useLocale();

Expand All @@ -22,9 +22,7 @@ export const SearchTreeHeader = ({
style={{ height: 40, maxHeight: 40, overflow: "hidden" }}
>
<Col span={12}>
{allRowSelectedMode ? (
<span>{`${selectedRowKeys.length} ${t("selectedRegisters")}`}</span>
) : (
{!hideSelectionSummary && (
<SearchTreeSelectionSummary selectedRowKeys={selectedRowKeys} />
)}
</Col>
Expand Down
21 changes: 19 additions & 2 deletions src/widgets/views/SearchTreeInfinite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { useSearchTreeState } from "@/hooks/useSearchTreeState";

export const HEIGHT_OFFSET = 10;
export const MAX_ROWS_TO_SELECT = 200;
const MAX_ROWS_ALLOWED_IN_CUSTOM_SEARCH = 500;

type OnRowClickedData = {
id: number;
Expand Down Expand Up @@ -96,6 +97,8 @@ function SearchTreeInfiniteComp(props: SearchTreeInfiniteProps, ref: any) {

const { t } = useLocale();

const isCustomSearchResults = model === "custom.search.results";

const containerRef = useRef<HTMLDivElement>(null);
const availableHeight = useAvailableHeight({
elementRef: containerRef,
Expand Down Expand Up @@ -204,6 +207,11 @@ function SearchTreeInfiniteComp(props: SearchTreeInfiniteProps, ref: any) {
}, [domain, mergedParams, nameSearch]);

const updateTotalRows = useCallback(async () => {
if (isCustomSearchResults) {
setTotalRowsLoading(false);
return;
}

setTotalRows(undefined);
setTotalItemsActionView(0);
setTotalRowsLoading(true);
Expand All @@ -223,6 +231,7 @@ function SearchTreeInfiniteComp(props: SearchTreeInfiniteProps, ref: any) {
}
}, [
domain,
isCustomSearchResults,
mergedParams,
model,
nameSearch,
Expand Down Expand Up @@ -281,6 +290,9 @@ function SearchTreeInfiniteComp(props: SearchTreeInfiniteProps, ref: any) {
order,
});

setTotalRows(results.length);
setTotalItemsActionView(results.length);

if (mustUpdateTotal() || prevSortOrder.current !== order) {
setActionViewResults?.(newResults);
} else {
Expand Down Expand Up @@ -496,7 +508,7 @@ function SearchTreeInfiniteComp(props: SearchTreeInfiniteProps, ref: any) {
height={availableHeight}
columns={columns}
onRequestData={onRequestData}
onRowDoubleClick={onRowClicked}
onRowDoubleClick={isCustomSearchResults ? undefined : onRowClicked}
onRowStyle={onRowStyle}
onRowSelectionChange={changeSelectedRowKeys}
onColumnChanged={updateColumnState}
Expand All @@ -511,6 +523,10 @@ function SearchTreeInfiniteComp(props: SearchTreeInfiniteProps, ref: any) {
statusComponent={statusComp}
onRowStatus={onRowStatus}
strings={strings}
cacheBlockSize={
isCustomSearchResults ? MAX_ROWS_ALLOWED_IN_CUSTOM_SEARCH : undefined
}
enableRowSelection={!isCustomSearchResults}
/>
);
}, [
Expand All @@ -520,6 +536,7 @@ function SearchTreeInfiniteComp(props: SearchTreeInfiniteProps, ref: any) {
firstVisibleRowIndex,
footerComp,
getColumnState,
isCustomSearchResults,
onRequestData,
onRowClicked,
onRowStatus,
Expand Down Expand Up @@ -692,8 +709,8 @@ function SearchTreeInfiniteComp(props: SearchTreeInfiniteProps, ref: any) {
/>
)}
<SearchTreeHeader
hideSelectionSummary={isCustomSearchResults}
selectedRowKeys={selectedRowKeys}
allRowSelectedMode={false}
totalRows={totalRows}
/>
<div ref={containerRef} style={containerStyle}>
Expand Down

0 comments on commit 4e54786

Please sign in to comment.