Skip to content

Commit

Permalink
Add table tab and add image
Browse files Browse the repository at this point in the history
  • Loading branch information
barshathakuri committed Jun 17, 2024
1 parent 4643781 commit 83c05d8
Show file tree
Hide file tree
Showing 17 changed files with 669 additions and 44 deletions.
46 changes: 31 additions & 15 deletions app/components/LeftPaneEntries/EntryItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
IoArrowUndoSharp,
IoTrashBinOutline,
} from 'react-icons/io5';
import { BsFileDiff } from 'react-icons/bs';
import { BsDownload, BsFileDiff } from 'react-icons/bs';
import { requiredStringCondition } from '@togglecorp/toggle-form';
import { _cs, isDefined } from '@togglecorp/fujs';
import {
Expand All @@ -20,6 +20,7 @@ import {
Heading,
useInputState,
Button,
QuickActionLink,
} from '@the-deep/deep-ui';

import ExcerptInput from '#components/entry/ExcerptInput';
Expand All @@ -28,9 +29,12 @@ import EntryCommentWrapper from '#components/entryReview/EntryCommentWrapper';

import { PartialEntryType as EntryInput } from '#components/entry/schema';
import { Entry } from '#components/entry/types';
import { LeadPreviewAttachmentType } from '#generated/types';

import styles from './styles.css';

export type EntryAttachmentsMap = { [key: string]: Entry['entryAttachment'] | undefined };

interface ExcerptModalProps {
title: string;
excerpt?: string;
Expand Down Expand Up @@ -99,6 +103,8 @@ interface EntryItemProps extends EntryInput {
projectId: string | undefined;
entryServerId: string | undefined;
draftEntry?: string;
leadAttachmentImage?: LeadPreviewAttachmentType;
entryAttachment?: Entry['entryAttachment'] | undefined | null;
}

function EntryItem(props: EntryItemProps) {
Expand All @@ -120,12 +126,13 @@ function EntryItem(props: EntryItemProps) {
disableClick,
onEntryDelete,
onEntryRestore,
imageRaw,
entryImage,
entryType,
deleted,
errored,
stale,
leadAttachmentImage,
entryAttachment,
} = props;

const editExcerptDropdownRef: QuickActionDropdownMenuProps['componentRef'] = React.useRef(null);
Expand Down Expand Up @@ -177,9 +184,8 @@ function EntryItem(props: EntryItemProps) {
<ExcerptInput
value={excerpt}
image={entryImage}
imageRaw={imageRaw}
// FIXME: pass this after image drag/drop is implemented
leadImageUrl={undefined}
imageRaw={leadAttachmentImage?.filePreview?.url ?? ''}
entryAttachment={entryAttachment}
entryType={entryType}
readOnly
/>
Expand Down Expand Up @@ -310,16 +316,26 @@ function EntryItem(props: EntryItemProps) {
onClick={handleClick}
role="presentation"
>
<ExcerptInput
value={excerpt}
// droppedExcerpt={droppedExcerpt}
image={entryImage}
imageRaw={imageRaw}
// FIXME: pass this after image drag/drop is implemented
leadImageUrl={undefined}
entryType={entryType}
readOnly
/>
<Container
headerActions={leadAttachmentImage?.file?.url && (
<QuickActionLink
title="Open external"
to={leadAttachmentImage.file.url}
>
<BsDownload />
</QuickActionLink>
)}
>
<ExcerptInput
value={excerpt}
// droppedExcerpt={droppedExcerpt}
image={entryImage}
imageRaw={leadAttachmentImage?.filePreview?.url ?? undefined}
entryType={entryType}
entryAttachment={entryAttachment}
readOnly
/>
</Container>
</div>
<div className={styles.verticalBorder} />
</Container>
Expand Down
1 change: 1 addition & 0 deletions app/components/LeftPaneEntries/EntryItem/styles.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.tagged-excerpt {
/* NOTE: when user select tagged excerpt, the add button will be visible */
position: relative;
flex-shrink: 0;
border: var(--dui-width-separator-thin) solid var(--dui-color-accent);
background-color: var(--dui-color-foreground);
max-height: 360px;
Expand Down
257 changes: 257 additions & 0 deletions app/components/LeftPaneEntries/TableAndVisualItem/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
import React, { useMemo } from 'react';
import { BsDownload } from 'react-icons/bs';
import {
IoCheckmark,
IoClose,
} from 'react-icons/io5';

import {
_cs,
isDefined,
isNotDefined,
} from '@togglecorp/fujs';
import {
Container,
QuickActionButton,
useInputState,
Button,
QuickActionButtonProps,
QuickActionLink,
NumberOutput,
Tag,
} from '@the-deep/deep-ui';
import { requiredStringCondition } from '@togglecorp/toggle-form';

import ExcerptTextArea from '#components/entry/ExcerptTextArea';
import ExcerptInput from '#components/entry/ExcerptInput';
import {
EntryTagTypeEnum,
LeadPreviewAttachmentType,
} from '#generated/types';

import styles from './styles.css';

interface ExcerptModalProps {
title: string;
excerpt?: string;
onComplete?: (modifiedExcerpt: string | undefined) => void;
}

export function ExcerptModal(props: ExcerptModalProps) {
const {
title,
excerpt: excerptFromProps,
onComplete,
} = props;

const [excerpt, setExcerpt] = useInputState(excerptFromProps);

const handleSubmit = React.useCallback(
() => {
if (onComplete) {
onComplete(excerpt);
}
},
[onComplete, excerpt],
);

return (
<Container
className={styles.excerptModalContainer}
heading={title}
spacing="compact"
footerActions={(
<Button
name={excerpt}
onClick={handleSubmit}
disabled={requiredStringCondition(excerpt) !== undefined}
>
Done
</Button>
)}
>
<ExcerptTextArea
className={styles.excerptTextArea}
name="modified-excerpt"
value={excerpt}
onChange={setExcerpt}
rows={10}
/>
</Container>
);
}

interface TableAndVisualItemProps {
attachmentId: string;
onClick?: (dataId: LeadPreviewAttachmentType['id']) => void;
onApproveButtonClick?: QuickActionButtonProps<string>['onClick'];
onDiscardButtonClick?: QuickActionButtonProps<string>['onClick'];
className?: string;
disableApproveButton?: boolean;
disableDiscardButton?: boolean;
disableClick?: boolean;
errored?: boolean;
deleted?: boolean;
stale?: boolean;
data: LeadPreviewAttachmentType;
isActive?: boolean;
entryId: string | undefined;
}

function TableAndVisualItem(props: TableAndVisualItemProps) {
const {
className,
attachmentId,
onClick,
onApproveButtonClick,
onDiscardButtonClick,
disableApproveButton,
disableDiscardButton,
disableClick,
deleted,
errored,
stale,
data,
isActive,
entryId,
} = props;

const entryTypeFromLead = useMemo((): EntryTagTypeEnum | undefined => {
if (data?.type === 'IMAGE' || data?.type === 'XLSX') {
return 'IMAGE';
}
return undefined;
}, [data]);

const handleClick = React.useCallback(() => {
if (onClick && !disableClick) {
onClick(attachmentId);
}
}, [attachmentId, onClick, disableClick]);

if (isNotDefined(entryId)) {
return (
<div
className={styles.clickableArea}
onClick={handleClick}
role="presentation"
>
<Container
headerActions={data?.type === 'XLSX' ? (
<QuickActionLink
title="Open external"
to={data?.file?.url || ''}
>
<BsDownload />
</QuickActionLink>
) : undefined}
>
{isDefined(entryTypeFromLead) && (
<ExcerptInput
value={data?.type}
entryType={entryTypeFromLead}
image={undefined}
entryAttachment={undefined}
imageRaw={data?.filePreview?.url ?? ''}
readOnly
/>
)}
</Container>
</div>
);
}

return (
<div>
<Container
className={_cs(
styles.taggedExcerpt,
className,
entryId && isActive && styles.active,
)}
headerActions={data?.type === 'XLSX' ? (
<QuickActionLink
title="Open external"
to={data?.file?.url || ''}
>
<BsDownload />
</QuickActionLink>
) : undefined}
heading={isNotDefined(attachmentId) ? (
<NumberOutput
className={styles.entryId}
prefix="#"
value={Number(attachmentId)}
/>
) : (
<span className={styles.unsavedEntry}>(unsaved entry)</span>
)}
headingClassName={styles.heading}
headingSize="extraSmall"
headingSectionClassName={styles.headingSection}
footerIcons={(
<>
{stale && !deleted && !errored && (
<Tag
spacing="compact"
>
Changed
</Tag>
)}
{deleted && (
<Tag
variant="complement2"
spacing="compact"
>
Deleted
</Tag>
)}
{errored && (
<Tag
spacing="compact"
>
Error
</Tag>
)}
</>
)}
footerQuickActions={isActive && (
<>
<QuickActionButton
title="Discard changes"
name={attachmentId}
onClick={onDiscardButtonClick}
disabled={disableDiscardButton}
>
<IoClose />
</QuickActionButton>
<QuickActionButton
title="Approve changes"
name={attachmentId}
onClick={onApproveButtonClick}
variant="primary"
disabled={disableApproveButton}
>
<IoCheckmark />
</QuickActionButton>
</>
)}
contentClassName={styles.content}
>
{isDefined(entryTypeFromLead) && (
<ExcerptInput
value={data?.type}
entryType={entryTypeFromLead}
imageRaw={data?.filePreview?.url ?? ''}
image={undefined}
entryAttachment={undefined}
readOnly
/>
)}
<div className={styles.verticalBorder} />
</Container>
</div>
);
}

export default TableAndVisualItem;
Loading

0 comments on commit 83c05d8

Please sign in to comment.