Skip to content

Commit

Permalink
feat: infinite tree (#595)
Browse files Browse the repository at this point in the history
* feat: implement user view prefs (remote columns for one2manytree)

* fix: adjustment in useNetworkRequest and development mode

* fix: remove console.log

* fix: try to debug weird bug

* fix: debug weird bug

* Revert "fix: debug weird bug"

This reverts commit 1235374.

* Revert "fix: try to debug weird bug"

This reverts commit 51ae0e6.

* feat: allow sort columns in one2many infinite trees

* feat(inifite-tree): initial wip

* fix: work

* feat: adjust method not exported

* feat: refactor for reusing localstorage and remotestorage column state hooks

* feat: search tree infinite does mostly work

* feat: more work

* feat: adjust context props

* feat: improve state restoring in infinite table

* feat: adapt one2many to use new select all rows approach

* feat: more adjustments in tree

* fix: adjust namesearch prop

* fix: adjust treeactionview switcher

* feat: work on side filter

* feat: more work on side filtering

* feat: wip in side search drawer

* fix: improve side drawer

* feat: more adjsutmetns

* feat: more work on side drawer

* feat: improvements in filter

* fix: adjust tree infinite from attr and implement name_Search

* fix: avoid two calls and adjust selection when filtering

* fix: select all ids with domain and mergedParams

* fix: adjust name search selection

* fix: improvements in search tree infinite

* fix: glitch

* fix: adjust tree aggregates

* update gisce/react-formiga-table to v1.7.0 (#603)

* chore(release): 2.21.0 [skip ci]

# [2.21.0](v2.20.0...v2.21.0) (2024-09-17)

### Features

* infinite one2many's improvements, sort and persist state ([#590](#590)) ([cbc4479](cbc4479)), closes [#591](#591) [#592](#592)

* fix: adjust fixed height in graph components in forms (#598)

gisce/webclient#1220

* chore(release): 2.21.1 [skip ci]

## [2.21.1](v2.21.0...v2.21.1) (2024-09-23)

### Bug Fixes

* adjust fixed height in graph components in forms ([#598](#598)) ([d8cb903](d8cb903))

* fix: allow clear in selection fields (#602)

* chore(release): 2.21.2 [skip ci]

## [2.21.2](v2.21.1...v2.21.2) (2024-09-25)

### Bug Fixes

* allow clear in selection fields ([#602](#602)) ([e73fd0b](e73fd0b))

* feat: update gisce/react-formiga-table to v1.7.0

https://github.com/gisce/react-formiga-table/releases/tag/v1.7.0

---------

Co-authored-by: semantic-release-bot <[email protected]>
Co-authored-by: Marc Güell Segarra <[email protected]>
Co-authored-by: mguellsegarra <[email protected]>

* update gisce/ooui to v2.11.0 (#604)

* chore(release): 2.21.0 [skip ci]

# [2.21.0](v2.20.0...v2.21.0) (2024-09-17)

### Features

* infinite one2many's improvements, sort and persist state ([#590](#590)) ([cbc4479](cbc4479)), closes [#591](#591) [#592](#592)

* fix: adjust fixed height in graph components in forms (#598)

gisce/webclient#1220

* chore(release): 2.21.1 [skip ci]

## [2.21.1](v2.21.0...v2.21.1) (2024-09-23)

### Bug Fixes

* adjust fixed height in graph components in forms ([#598](#598)) ([d8cb903](d8cb903))

* fix: allow clear in selection fields (#602)

* chore(release): 2.21.2 [skip ci]

## [2.21.2](v2.21.1...v2.21.2) (2024-09-25)

### Bug Fixes

* allow clear in selection fields ([#602](#602)) ([e73fd0b](e73fd0b))

* feat: update gisce/ooui to v2.11.0

https://github.com/gisce/ooui/releases/tag/v2.11.0

---------

Co-authored-by: semantic-release-bot <[email protected]>
Co-authored-by: Marc Güell Segarra <[email protected]>
Co-authored-by: mguellsegarra <[email protected]>

---------

Co-authored-by: Gisce <[email protected]>
Co-authored-by: semantic-release-bot <[email protected]>
Co-authored-by: mguellsegarra <[email protected]>
  • Loading branch information
4 people authored Sep 26, 2024
1 parent 8a73550 commit 41b390d
Show file tree
Hide file tree
Showing 35 changed files with 1,571 additions and 215 deletions.
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

0 comments on commit 41b390d

Please sign in to comment.