Skip to content

The open alternative to Salesforce, designed for AI.

Allow renaming names from uploaded files (#6358)

nitined0102ec58c1
diff --git a/packages/twenty-front/src/modules/activities/files/components/AttachmentDropdown.tsx b/packages/twenty-front/src/modules/activities/files/components/AttachmentDropdown.tsx
index 884c43c812e..7dc80b17172 100644
--- a/packages/twenty-front/src/modules/activities/files/components/AttachmentDropdown.tsx
+++ b/packages/twenty-front/src/modules/activities/files/components/AttachmentDropdown.tsx
@@ -1,4 +1,9 @@
-import { IconDotsVertical, IconDownload, IconTrash } from 'twenty-ui';
+import {
+ IconDotsVertical,
+ IconDownload,
+ IconPencil,
+ IconTrash,
+} from 'twenty-ui';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
@@ -10,12 +15,14 @@ import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem';
type AttachmentDropdownProps = {
onDownload: () => void;
onDelete: () => void;
+ onRename: () => void;
scopeKey: string;
};
export const AttachmentDropdown = ({
onDownload,
onDelete,
+ onRename,
scopeKey,
}: AttachmentDropdownProps) => {
const dropdownId = `${scopeKey}-settings-field-active-action-dropdown`;
@@ -32,6 +39,11 @@ export const AttachmentDropdown = ({
closeDropdown();
};
+ const handleRename = () => {
+ onRename();
+ closeDropdown();
+ };
+
return (
<Dropdown
dropdownId={dropdownId}
@@ -46,6 +58,11 @@ export const AttachmentDropdown = ({
LeftIcon={IconDownload}
onClick={handleDownload}
/>
+ <MenuItem
+ text="Rename"
+ LeftIcon={IconPencil}
+ onClick={handleRename}
+ />
<MenuItem
text="Delete"
accent="danger"
diff --git a/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx b/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx
index 691ebb74650..478cacc723e 100644
--- a/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx
+++ b/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx
@@ -1,18 +1,20 @@
-import { useMemo } from 'react';
-import { useTheme } from '@emotion/react';
-import styled from '@emotion/styled';
-import { IconCalendar } from 'twenty-ui';
-
import { AttachmentDropdown } from '@/activities/files/components/AttachmentDropdown';
import { AttachmentIcon } from '@/activities/files/components/AttachmentIcon';
import { Attachment } from '@/activities/files/types/Attachment';
import { downloadFile } from '@/activities/files/utils/downloadFile';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { useDeleteOneRecord } from '@/object-record/hooks/useDeleteOneRecord';
+import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import {
FieldContext,
GenericFieldContextType,
} from '@/object-record/record-field/contexts/FieldContext';
+import { TextInput } from '@/ui/input/components/TextInput';
+import { useTheme } from '@emotion/react';
+import styled from '@emotion/styled';
+import { useMemo, useState } from 'react';
+import { IconCalendar } from 'twenty-ui';
+
import { formatToHumanReadableDate } from '~/utils/date-utils';
import { getFileAbsoluteURI } from '~/utils/file/getFileAbsoluteURI';
@@ -23,8 +25,8 @@ const StyledRow = styled.div`
color: ${({ theme }) => theme.font.color.primary};
display: flex;
justify-content: space-between;
-
padding: ${({ theme }) => theme.spacing(2)};
+ height: 32px;
`;
const StyledLeftContent = styled.div`
@@ -57,6 +59,9 @@ const StyledLink = styled.a`
export const AttachmentRow = ({ attachment }: { attachment: Attachment }) => {
const theme = useTheme();
+ const [isEditing, setIsEditing] = useState(false);
+ const [attachmentName, setAttachmentName] = useState(attachment.name);
+
const fieldContext = useMemo(
() => ({ recoilScopeId: attachment?.id ?? '' }),
[attachment?.id],
@@ -70,17 +75,47 @@ export const AttachmentRow = ({ attachment }: { attachment: Attachment }) => {
deleteOneAttachment(attachment.id);
};
+ const { updateOneRecord: updateOneAttachment } = useUpdateOneRecord({
+ objectNameSingular: CoreObjectNameSingular.Attachment,
+ });
+
+ const handleRename = () => {
+ setIsEditing(true);
+ };
+
+ const handleOnBlur = () => {
+ setIsEditing(false);
+ updateOneAttachment({
+ idToUpdate: attachment.id,
+ updateOneRecordInput: { name: attachmentName },
+ });
+ };
+
+ const handleOnChange = (newName: string) => {
+ setAttachmentName(newName);
+ };
+
return (
<FieldContext.Provider value={fieldContext as GenericFieldContextType}>
<StyledRow>
<StyledLeftContent>
<AttachmentIcon attachmentType={attachment.type} />
- <StyledLink
- href={getFileAbsoluteURI(attachment.fullPath)}
- target="__blank"
- >
- {attachment.name}
- </StyledLink>
+ {isEditing ? (
+ <TextInput
+ value={attachmentName}
+ onChange={handleOnChange}
+ onBlur={handleOnBlur}
+ autoFocus
+ fullWidth
+ />
+ ) : (
+ <StyledLink
+ href={getFileAbsoluteURI(attachment.fullPath)}
+ target="__blank"
+ >
+ {attachment.name}
+ </StyledLink>
+ )}
</StyledLeftContent>
<StyledRightContent>
<StyledCalendarIconContainer>
@@ -93,6 +128,7 @@ export const AttachmentRow = ({ attachment }: { attachment: Attachment }) => {
onDownload={() => {
downloadFile(attachment.fullPath, attachment.name);
}}
+ onRename={handleRename}
/>
</StyledRightContent>
</StyledRow>