Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: infinite tree #595

Merged
merged 40 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f9681b5
feat: implement user view prefs (remote columns for one2manytree)
mguellsegarra Jul 29, 2024
20753b2
fix: adjustment in useNetworkRequest and development mode
mguellsegarra Jul 29, 2024
eaa0c7a
fix: remove console.log
mguellsegarra Jul 29, 2024
51ae0e6
fix: try to debug weird bug
mguellsegarra Jul 31, 2024
ea974c5
Merge branch 'v2' into feat/user_view_prefs
mguellsegarra Jul 31, 2024
19747d6
Merge branch 'v2' into feat/user_view_prefs
mguellsegarra Aug 14, 2024
1235374
fix: debug weird bug
mguellsegarra Aug 14, 2024
62b3f6c
Revert "fix: debug weird bug"
mguellsegarra Aug 14, 2024
5be48ea
Revert "fix: try to debug weird bug"
mguellsegarra Aug 14, 2024
5a99682
feat: allow sort columns in one2many infinite trees
mguellsegarra Aug 15, 2024
a3a9ff9
feat(inifite-tree): initial wip
mguellsegarra Aug 27, 2024
643fce8
fix: work
mguellsegarra Aug 28, 2024
0b404ab
Merge branch 'v2' into feat/infinite-tree
mguellsegarra Sep 17, 2024
924090a
feat: adjust method not exported
mguellsegarra Sep 19, 2024
f2642c6
feat: refactor for reusing localstorage and remotestorage column stat…
mguellsegarra Sep 19, 2024
02f5857
feat: search tree infinite does mostly work
mguellsegarra Sep 19, 2024
76a3ad7
feat: more work
mguellsegarra Sep 19, 2024
537cc3b
feat: adjust context props
mguellsegarra Sep 20, 2024
e46ebbf
feat: improve state restoring in infinite table
mguellsegarra Sep 20, 2024
fc42fb8
feat: adapt one2many to use new select all rows approach
mguellsegarra Sep 20, 2024
b64a981
feat: more adjustments in tree
mguellsegarra Sep 21, 2024
75dd0eb
fix: adjust namesearch prop
mguellsegarra Sep 21, 2024
08fd37e
fix: adjust treeactionview switcher
mguellsegarra Sep 21, 2024
6f64983
feat: work on side filter
mguellsegarra Sep 21, 2024
21129fa
feat: more work on side filtering
mguellsegarra Sep 21, 2024
c5ad943
feat: wip in side search drawer
mguellsegarra Sep 22, 2024
4a74622
fix: improve side drawer
mguellsegarra Sep 22, 2024
1f9514f
feat: more adjsutmetns
mguellsegarra Sep 22, 2024
6b8a165
feat: more work on side drawer
mguellsegarra Sep 22, 2024
a0ec55a
feat: improvements in filter
mguellsegarra Sep 22, 2024
64fc326
fix: adjust tree infinite from attr and implement name_Search
mguellsegarra Sep 22, 2024
57e815c
fix: avoid two calls and adjust selection when filtering
mguellsegarra Sep 23, 2024
ac2a06f
fix: select all ids with domain and mergedParams
mguellsegarra Sep 23, 2024
8855a34
fix: adjust name search selection
mguellsegarra Sep 23, 2024
e9f7eed
fix: improvements in search tree infinite
mguellsegarra Sep 24, 2024
bb7598a
fix: glitch
mguellsegarra Sep 24, 2024
53b0529
fix: adjust tree aggregates
mguellsegarra Sep 24, 2024
fc223ac
update gisce/react-formiga-table to v1.7.0 (#603)
giscegit Sep 26, 2024
18eeb1f
update gisce/ooui to v2.11.0 (#604)
giscegit Sep 26, 2024
39ba31b
Merge branch 'v2' into feat/infinite-tree
mguellsegarra Sep 26, 2024
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
47 changes: 39 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@
"dependencies": {
"@ant-design/plots": "^1.0.9",
"@gisce/fiber-diagram": "2.1.1",
"@gisce/ooui": "2.10.2",
"@gisce/ooui": "2.11.0",
"@gisce/react-formiga-components": "1.8.0",
"@gisce/react-formiga-table": "1.6.0",
"@gisce/react-formiga-table": "1.7.0",
"@monaco-editor/react": "^4.4.5",
"@tabler/icons-react": "^2.11.0",
"@types/deep-equal": "^1.0.4",
"antd": "5.13.1",
"buffer": "^6.0.3",
"file-type-buffer-browser": "git+ssh://[email protected]/mguellsegarra/file-type-buffer-browser.git",
"framer-motion": "^11.5.5",
"interweave": "^13.0.0",
"md5": "^2.3.0",
"nanoid": "^5.0.4",
Expand Down
82 changes: 54 additions & 28 deletions src/context/ActionViewContext.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
import { DEFAULT_SEARCH_LIMIT } from "@/models/constants";
import { View } from "@/types";
import { createContext, useEffect, useState } from "react";
import { createContext, useContext, useEffect, useState } from "react";

export type ActionViewContextType = {
type ActionViewProviderProps = {
title: string;
availableViews: View[];
currentView: View;
setCurrentView: (view: View) => void;
availableViews: View[];
formRef: any;
searchTreeRef: any;
onNewClicked: () => void;
currentId?: number;
setCurrentId: (id?: number) => void;
setCurrentItemIndex: (value?: number) => void;
currentItemIndex?: number;
results?: any[];
setResults: (value: any[]) => void;
currentModel: string;
sorter: any;
setSorter: (sorter: any) => void;
totalItems: number;
setTotalItems: (totalItems: number) => void;
selectedRowItems?: any[];
setSelectedRowItems: (value: any[]) => void;
setSearchTreeNameSearch: (searchString?: string) => void;
searchTreeNameSearch?: string;
goToResourceId: (ids: number[], openInSameTab?: boolean) => Promise<void>;
limit?: number;
isActive: boolean;
children: React.ReactNode;
};

export type ActionViewContextType = Omit<
ActionViewProviderProps,
"children"
> & {
formIsSaving?: boolean;
setFormIsSaving?: (value: boolean) => void;
formHasChanges?: boolean;
setFormHasChanges?: (value: boolean) => void;
onFormSave?: () => Promise<{ succeed: boolean; id: number }>;
formRef?: any;
searchTreeRef?: any;
onNewClicked: () => void;
currentId?: number;
setCurrentId?: (id?: number) => void;
currentItemIndex?: number;
setCurrentItemIndex?: (value?: number) => void;
results?: any[];
setResults?: (value: any[]) => void;
currentModel?: string;
removingItem?: boolean;
setRemovingItem?: (value: boolean) => void;
formIsLoading?: boolean;
Expand All @@ -32,39 +50,26 @@ export type ActionViewContextType = {
setGraphIsLoading?: (value: boolean) => void;
attachments?: any;
setAttachments?: (value: any) => void;
selectedRowItems?: any[];
setSelectedRowItems?: (value: any[]) => void;
duplicatingItem?: boolean;
setDuplicatingItem?: (value: boolean) => void;
searchParams?: any[];
setSearchParams?: (value: any[]) => void;
searchVisible?: boolean;
setSearchVisible?: (value: boolean) => void;
sorter: any;
setSorter: (sorter: any) => void;
totalItems: number;
setTotalItems: (totalItems: number) => void;
searchTreeNameSearch?: string;
setSearchTreeNameSearch?: (searchString?: string) => void;
previousView?: View;
setPreviousView?: (view: View) => void;
goToResourceId?: (ids: number[], openInSameTab?: boolean) => Promise<void>;
searchValues?: any;
setSearchValues?: (value: any) => void;
limit?: number;
setLimit?: (value: number) => void;
setTitle?: (value: string) => void;
isActive: boolean;
treeFirstVisibleRow: number;
setTreeFirstVisibleRow: (totalItems: number) => void;
};

export const ActionViewContext = createContext<ActionViewContextType | null>(
null,
);

type ActionViewProviderProps = ActionViewContextType & {
children: React.ReactNode;
};

const ActionViewProvider = (props: ActionViewProviderProps): any => {
const {
children,
Expand Down Expand Up @@ -107,6 +112,8 @@ const ActionViewProvider = (props: ActionViewProviderProps): any => {
const [graphIsLoading, setGraphIsLoading] = useState<boolean>(true);
const [previousView, setPreviousView] = useState<View>();
const [searchValues, setSearchValues] = useState<any>({});
const [treeFirstVisibleRow, setTreeFirstVisibleRow] = useState<number>(0);

const [limit, setLimit] = useState<number>(
limitProps !== undefined ? limitProps : DEFAULT_SEARCH_LIMIT,
);
Expand Down Expand Up @@ -207,11 +214,30 @@ const ActionViewProvider = (props: ActionViewProviderProps): any => {
setLimit,
setTitle,
isActive,
setTreeFirstVisibleRow,
treeFirstVisibleRow,
}}
>
{children}
</ActionViewContext.Provider>
);
};

export const useActionViewContext = (
isRoot: boolean,
): ActionViewContextType => {
const actionViewContext = useContext(
ActionViewContext,
) as ActionViewContextType;
if (!isRoot) {
return {} as ActionViewContextType;
}
if (!actionViewContext) {
throw new Error(
"useActionViewContext must be used within a ActionViewProvider",
);
}
return actionViewContext;
};

export default ActionViewProvider;
13 changes: 13 additions & 0 deletions src/helpers/o2m-columnStorageHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export type One2manyTreeDataForHash = {
parentViewId?: number;
treeViewId?: number;
one2ManyFieldName: string;
};

export type O2mDataForHashWithModel = One2manyTreeDataForHash & {
model: string;
};

export const getKey = (dataForHash: O2mDataForHashWithModel) => {
return `columnState-${dataForHash.parentViewId}-${dataForHash.treeViewId}-${dataForHash.one2ManyFieldName}-${dataForHash.model}`;
};
11 changes: 11 additions & 0 deletions src/helpers/tree-columnStorageHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type TreeDataForHash = {
treeViewId?: number;
model: string;
};

export const getKey = (dataForHash: TreeDataForHash) => {
if (!dataForHash.treeViewId || !dataForHash.model) {
return undefined;
}
return `columnState-${dataForHash.treeViewId}-${dataForHash.model}`;
};
29 changes: 29 additions & 0 deletions src/helpers/treeHelper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Reference,
} from "@gisce/ooui";
import { TreeView, Column } from "@/types";
import { SortDirection } from "@gisce/react-formiga-table";

const getTree = (treeView: TreeView): TreeOoui => {
const xml = treeView.arch;
Expand Down Expand Up @@ -218,6 +219,32 @@ function hasActualValues(obj: Record<string, any>): boolean {
return false;
}

const getOrderFromSortFields = (sortFields?: Record<string, SortDirection>) => {
if (!sortFields) {
return undefined;
}
return Object.keys(sortFields)
.map((field) => {
const direction = sortFields[field];
return `${field} ${direction}`;
})
.join(", ");
};

function extractTreeXmlAttribute(
archString: string,
attributeName: string,
): string | null {
const regex = new RegExp(`<tree[^>]*\\s+${attributeName}="([^"]+)"`, "i");
const match = archString.match(regex);

if (match && match[1]) {
return match[1];
}

return null;
}

export {
getTableColumns,
getTableItems,
Expand All @@ -228,4 +255,6 @@ export {
getStatusMap,
sortResults,
hasActualValues,
getOrderFromSortFields,
extractTreeXmlAttribute,
};
34 changes: 34 additions & 0 deletions src/hooks/useAvailableHeight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { useState, useEffect, RefObject, useMemo } from "react";

export const useAvailableHeight = <T extends HTMLElement>({
elementRef,
offset = 0,
dependencies = [],
}: {
elementRef: RefObject<T>;
offset?: number;
dependencies?: React.DependencyList;
}): number => {
const [availableHeight, setAvailableHeight] = useState<number>(0);

useEffect(() => {
const updateHeight = () => {
if (elementRef.current) {
const windowHeight = window.innerHeight;
const boundingRect = elementRef.current.getBoundingClientRect();
const availableHeight = windowHeight - boundingRect.top;
setAvailableHeight(availableHeight);
}
};

updateHeight();
window.addEventListener("resize", updateHeight);

return () => window.removeEventListener("resize", updateHeight);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [elementRef, ...dependencies]);

const memoizedHeight = useMemo(() => availableHeight, [availableHeight]);

return memoizedHeight - offset;
};
12 changes: 3 additions & 9 deletions src/hooks/useEffectDebugger.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { useRef, useEffect } from "react";

const usePrevious = (value: any, initialValue: any) => {
const ref = useRef(initialValue);
useEffect(() => {
ref.current = value;
});
return ref.current;
};
import { useEffect } from "react";
import { usePrevious } from "./usePrevious";

const useEffectDebugger = (
effectHook: any,
Expand Down Expand Up @@ -37,6 +30,7 @@ const useEffectDebugger = (
console.log("[use-effect-debugger] ", changedDeps);
}

// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(effectHook, dependencies);
};

Expand Down
Loading
Loading