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

fix: sync changes from v2 to v2-develop #862

Merged
merged 28 commits into from
Jan 28, 2025
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c520994
fix: improve action separator and treeactions bar
mguellsegarra Jan 22, 2025
1600b5c
feat: extract toolbar behaviour to hooks
mguellsegarra Jan 22, 2025
4e8627e
feat: improve actionbar components with react best practices
mguellsegarra Jan 22, 2025
0081027
feat: add new localization strings and improve One2many top bar
mguellsegarra Jan 22, 2025
4d82eac
feat: improve form handling and toolbar integration in One2many compo…
mguellsegarra Jan 22, 2025
0419afe
feat: allow use of hooks from one2many's
mguellsegarra Jan 23, 2025
36913b2
Merge branch 'v2' into feat/add-toolbar-buttons-to-x2many
mguellsegarra Jan 23, 2025
b91ffeb
Merge branch 'v2' into feat/add-toolbar-buttons-to-x2many
mguellsegarra Jan 23, 2025
6c09769
fix: bad conflict resolution
mguellsegarra Jan 23, 2025
b9f3d30
fix: adjust sharebutton for formactionbar
mguellsegarra Jan 23, 2025
c68ec43
fix: remove unused function
mguellsegarra Jan 24, 2025
2563045
Merge branch 'v2' into feat/add-toolbar-buttons-to-x2many
mguellsegarra Jan 24, 2025
9fd9d6a
fix: adjust value key filtering in URL sharing
mguellsegarra Jan 24, 2025
1b5d7dd
fix: improve value merging logic in useUrlFromCurrentTab
mguellsegarra Jan 24, 2025
c79c3e0
fix: improve and export parameter filtering
mguellsegarra Jan 25, 2025
28fff0a
fix: transform initialView to initialViewId
mguellsegarra Jan 25, 2025
bf072e5
fix: also clear url when closing all tabs
mguellsegarra Jan 26, 2025
68d42f0
fix: clear title when no tabs
mguellsegarra Jan 28, 2025
c0e6959
Merge pull request #857 from gisce/fix/clear-title-when-no-tabs
mguellsegarra Jan 28, 2025
b46cf2f
chore(release): 2.58.1 [skip ci]
semantic-release-bot Jan 28, 2025
6251874
feat: fetch toolbar if needed and if view of one2many is hardcoded
mguellsegarra Jan 28, 2025
85f1f6e
Merge branch 'v2' into feat/add-toolbar-buttons-to-x2many
mguellsegarra Jan 28, 2025
7470e76
fix: temporally disable toolbar in one2many's until we decide which d…
mguellsegarra Jan 28, 2025
8a4745d
Merge branch 'feat/add-toolbar-buttons-to-x2many' into v2
mguellsegarra Jan 28, 2025
5a59093
chore(release): 2.59.0 [skip ci]
semantic-release-bot Jan 28, 2025
fd9d10f
fix: restore bad conflict resolution
mguellsegarra Jan 28, 2025
f89c7b1
chore(release): 2.59.1 [skip ci]
semantic-release-bot Jan 28, 2025
202f05b
Merge remote-tracking branch 'origin/v2' into sync/v2-to-v2-develop-2…
github-actions[bot] Jan 28, 2025
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
Prev Previous commit
Next Next commit
feat: allow use of hooks from one2many's
mguellsegarra committed Jan 23, 2025

Verified

This commit was signed with the committer’s verified signature.
mguellsegarra Marc Güell Segarra
commit 0419afe1f03a80878b339fc65029e11d75f31d25
23 changes: 12 additions & 11 deletions src/actionbar/FormActionBar.tsx
Original file line number Diff line number Diff line change
@@ -78,13 +78,6 @@ function FormActionBarComponent({ toolbar }: { toolbar: any }) {
[formIsSaving, removingItem, formIsLoading, duplicatingItem],
);

const { actionButtonProps, printButtonProps, relateButtonProps } =
useFormToolbarButtons({
toolbar,
mustDisableButtons,
formRef,
});

const tryAction = useCallback(
(action: () => void) => {
if (formHasChanges) {
@@ -96,6 +89,18 @@ function FormActionBarComponent({ toolbar }: { toolbar: any }) {
[formHasChanges, t],
);

const handleRefresh = useCallback(() => {
tryAction(() => (formRef.current as any).fetchValues());
}, [tryAction, formRef]);

const { actionButtonProps, printButtonProps, relateButtonProps } =
useFormToolbarButtons({
toolbar,
mustDisableButtons,
formRef,
onRefreshParentValues: handleRefresh,
});

const handleRemove = useCallback(async () => {
try {
setRemovingItem?.(true);
@@ -162,10 +167,6 @@ function FormActionBarComponent({ toolbar }: { toolbar: any }) {
[currentView, setPreviousView, setFormHasChanges, setCurrentView],
);

const handleRefresh = useCallback(() => {
tryAction(() => (formRef.current as any).fetchValues());
}, [tryAction, formRef]);

const handleAddNewAttachment = useCallback(async () => {
const result = await saveDocument({ onFormSave });
if (result.succeed) {
15 changes: 10 additions & 5 deletions src/actionbar/TreeActionBar.tsx
Original file line number Diff line number Diff line change
@@ -88,13 +88,22 @@ function TreeActionBarComponent({
const [exportModalVisible, setExportModalVisible] = useState(false);
const isFirstMount = useRef(true);

const handleRefresh = useCallback(() => {
searchTreeRef?.current?.refreshResults();
}, [searchTreeRef]);

const { actionButtonProps, printButtonProps } = useTreeToolbarButtons({
toolbar,
disabled: treeIsLoading,
parentContext,
selectedRowItems,
onRefreshParentValues: handleRefresh,
});

const runAction = useRunTreeAction();
const runAction = useRunTreeAction({
selectedRowItems,
onRefreshParentValues: handleRefresh,
});

const hasNameSearch = useMemo(
() =>
@@ -167,10 +176,6 @@ function TreeActionBarComponent({
[currentView, setPreviousView, setCurrentView],
);

const handleRefresh = useCallback(() => {
searchTreeRef?.current?.refreshResults();
}, [searchTreeRef]);

const handleSearch = useCallback(
(searchString?: string) => {
if (searchString && searchString.trim().length > 0) {
4 changes: 3 additions & 1 deletion src/context/ContentRootContext.tsx
Original file line number Diff line number Diff line change
@@ -172,7 +172,9 @@ const ContentRootProvider = (
onRefreshParentValues?: any;
}) {
const { type } = actionData;
onRefreshParentValues.current.push(onRefreshParentValuesFn);
if (onRefreshParentValuesFn) {
onRefreshParentValues.current.push(onRefreshParentValuesFn);
}

if (type === "ir.actions.report.xml") {
return await generateReport({
6 changes: 4 additions & 2 deletions src/hooks/useFormToolbarButtons.ts
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ interface UseFormToolbarButtonsProps {
toolbar: any;
mustDisableButtons?: boolean;
formRef: RefObject<any>;
onRefreshParentValues?: () => void;
}

interface SaveDocumentResult {
@@ -24,6 +25,7 @@ export const useFormToolbarButtons = ({
toolbar,
mustDisableButtons = false,
formRef,
onRefreshParentValues,
}: UseFormToolbarButtonsProps) => {
const { t } = useLocale();
const contentRootContext = useContext(
@@ -47,10 +49,10 @@ export const useFormToolbarButtons = ({
values: formRef.current?.getValues(),
fields: formRef.current?.getFields(),
context: formRef.current?.getContext(),
onRefreshParentValues: () => formRef.current?.fetchValues(),
onRefreshParentValues,
});
},
[formRef, processAction],
[formRef, processAction, onRefreshParentValues],
);

const actionButtonProps = {
26 changes: 17 additions & 9 deletions src/hooks/useTreeToolbarButtons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useCallback, useContext } from "react";
import { useLocale } from "@gisce/react-formiga-components";
import { useActionViewContext } from "@/context/ActionViewContext";
import {
ContentRootContext,
ContentRootContextType,
@@ -10,14 +9,21 @@ interface UseTreeToolbarButtonsProps {
toolbar: any;
disabled?: boolean;
parentContext?: any;
selectedRowItems?: any[];
onRefreshParentValues?: () => void;
}

export const useRunTreeAction = () => {
export const useRunTreeAction = ({
selectedRowItems,
onRefreshParentValues,
}: {
selectedRowItems?: any[];
onRefreshParentValues?: () => void;
}) => {
const contentRootContext = useContext(
ContentRootContext,
) as ContentRootContextType;
const { processAction } = contentRootContext || {};
const { selectedRowItems, searchTreeRef } = useActionViewContext();

return useCallback(
(actionData: any, context: any = {}) => {
@@ -33,23 +39,25 @@ export const useRunTreeAction = () => {
active_id: selectedRowItems?.map((item) => item.id)[0],
active_ids: selectedRowItems?.map((item) => item.id),
},
onRefreshParentValues: () => {
searchTreeRef?.current?.refreshResults();
},
onRefreshParentValues,
});
},
[processAction, selectedRowItems, searchTreeRef],
[processAction, selectedRowItems, onRefreshParentValues],
);
};

export const useTreeToolbarButtons = ({
toolbar,
disabled = false,
parentContext = {},
selectedRowItems = [],
onRefreshParentValues,
}: UseTreeToolbarButtonsProps) => {
const { t } = useLocale();
const { selectedRowItems } = useActionViewContext();
const runAction = useRunTreeAction();
const runAction = useRunTreeAction({
selectedRowItems,
onRefreshParentValues,
});

const actionButtonProps = {
placement: "bottomRight" as const,
3 changes: 3 additions & 0 deletions src/widgets/base/one2many/One2manyInput.tsx
Original file line number Diff line number Diff line change
@@ -698,6 +698,9 @@ const One2manyInput: React.FC<One2manyInputProps> = (
toolbar={views.get(currentView)?.toolbar}
context={{ ...getContext?.(), ...context }}
formRef={formRef}
onRefreshParentValues={() => {
fetchParentFormValues?.({ forceRefresh: true });
}}
/>
{content()}
<FormModal
3 changes: 3 additions & 0 deletions src/widgets/base/one2many/One2manyInputInfinite.tsx
Original file line number Diff line number Diff line change
@@ -268,6 +268,9 @@ export const One2manyInput: React.FC<One2manyInputInfiniteProps> = (
toolbar={views.get(currentView)?.toolbar}
context={{ ...getContext?.(), ...context }}
formRef={formRef}
onRefreshParentValues={() => {
fetchParentFormValues?.({ forceRefresh: true });
}}
/>
{currentView === "tree" && (
<One2manyTree
5 changes: 5 additions & 0 deletions src/widgets/base/one2many/One2manyTopBar.tsx
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ type One2manyTopBarProps = {
toolbar?: any;
context?: any;
formRef: RefObject<any>;
onRefreshParentValues?: () => void;
};

function One2manyTopBarComponent(props: One2manyTopBarProps) {
@@ -61,6 +62,7 @@ function One2manyTopBarComponent(props: One2manyTopBarProps) {
toolbar,
context,
formRef,
onRefreshParentValues,
} = props;

const { token } = useToken();
@@ -71,6 +73,7 @@ function One2manyTopBarComponent(props: One2manyTopBarProps) {
toolbar,
mustDisableButtons: readOnly,
formRef,
onRefreshParentValues,
});

const {
@@ -80,6 +83,8 @@ function One2manyTopBarComponent(props: One2manyTopBarProps) {
toolbar,
disabled: readOnly,
parentContext: context,
selectedRowItems: selectedRowKeys.map((key) => ({ id: key })),
onRefreshParentValues,
});

return (