Skip to content

Commit 2a0993e

Browse files
mma-axelorpbe-axelor
authored andcommitted
Hide attachment icon for custom form editor popup and not saved record
On not saved records in form editor popup, it shouldn't show the attachment icon. Same for some custom form editor popups like user preferences. Fixes #1393
1 parent 34b5219 commit 2a0993e

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

axelor-front/src/hooks/use-relation/use-editor.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import isEqual from "lodash/isEqual";
44
import uniqueId from "lodash/uniqueId";
55
import { useCallback, useEffect, useRef } from "react";
66

7-
import { Box, Button, CommandBar, CommandItemProps } from "@axelor/ui";
7+
import { Box, Button, CommandBar } from "@axelor/ui";
88

99
import { dialogs } from "@/components/dialogs";
1010
import { openTab_internal as openTab } from "@/hooks/use-tabs";
@@ -30,6 +30,7 @@ export type EditorOptions = {
3030
view?: FormView;
3131
viewName?: string;
3232
context?: DataContext;
33+
canAttach?: boolean;
3334
canSave?: boolean;
3435
params?: ActionView["params"];
3536
header?: PopupProps["header"];
@@ -101,6 +102,7 @@ export function useEditor() {
101102
context,
102103
readonly,
103104
maximize,
105+
canAttach = true,
104106
canSave = true,
105107
params,
106108
header,
@@ -141,6 +143,7 @@ export function useEditor() {
141143
footer: ({ close }) => (
142144
<Footer
143145
footer={footer}
146+
canAttach={canAttach && (record?.id ?? 0) > 0}
144147
hasOk={canSave}
145148
params={tabParams}
146149
onClose={close}
@@ -154,13 +157,15 @@ export function useEditor() {
154157
}
155158

156159
function Footer({
160+
canAttach = true,
157161
hasOk = true,
158162
footer: FooterComp,
159163
params,
160164
onClose,
161165
onSave,
162166
onSelect,
163167
}: {
168+
canAttach?: boolean;
164169
hasOk?: boolean;
165170
footer?: EditorOptions["footer"];
166171
onClose: (result: boolean) => void;
@@ -251,11 +256,11 @@ function Footer({
251256

252257
const { attachmentItem } = handler;
253258

254-
const commandItems = [attachmentItem].filter(Boolean) as CommandItemProps[];
255-
256259
return (
257260
<>
258-
{commandItems && <CommandBar items={commandItems} iconOnly />}
261+
{canAttach && attachmentItem && (
262+
<CommandBar items={[attachmentItem]} iconOnly />
263+
)}
259264
<Box d="flex" flex={1} justifyContent="flex-end" g={2}>
260265
{FooterComp && <FooterComp close={onClose} />}
261266
<Box d="flex" g={2}>

axelor-front/src/layout/nav-header/nav-header.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ function FarItems() {
343343
model: "com.axelor.auth.db.User",
344344
title: i18n.get("Preferences"),
345345
viewName: "user-preferences-form",
346+
canAttach: false,
346347
record: {
347348
id: session.info?.user?.id,
348349
},

axelor-front/src/views/dms/dms.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ export function Dms(props: ViewProps<GridView>) {
410410
model: view.model!,
411411
viewName: "dms-file-permission-form",
412412
record: doc,
413+
canAttach: false,
413414
readonly: false,
414415
onSelect: () => {},
415416
});

axelor-front/src/views/form/widgets/mail-messages/message/message.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export function MessageUser({
8484
record: { id },
8585
readonly: true,
8686
canSave: false,
87+
canAttach: false,
8788
});
8889
} else if (isDevelopment() && !view) {
8990
console.log(`${name} view doesn't exist`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
title: Hide attachment icon for custom form editor popup and not saved record
3+
type: fix
4+
description: |
5+
On not saved records in form editor popup, it shouldn't show the attachment icon.
6+
Same for some custom form editor popups like user preferences.

0 commit comments

Comments
 (0)