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 authored and subinasr committed Jun 13, 2024
1 parent 4643781 commit 8c26bfd
Show file tree
Hide file tree
Showing 7 changed files with 656 additions and 22 deletions.
44 changes: 33 additions & 11 deletions app/components/LeftPaneEntries/EntryItem/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import {
IoClose,
IoCheckmark,
Expand Down Expand Up @@ -28,6 +28,7 @@ import EntryCommentWrapper from '#components/entryReview/EntryCommentWrapper';

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

import styles from './styles.css';

Expand Down Expand Up @@ -99,6 +100,7 @@ interface EntryItemProps extends EntryInput {
projectId: string | undefined;
entryServerId: string | undefined;
draftEntry?: string;
attachmentData?: LeadPreviewAttachmentType;
}

function EntryItem(props: EntryItemProps) {
Expand Down Expand Up @@ -126,6 +128,7 @@ function EntryItem(props: EntryItemProps) {
deleted,
errored,
stale,
attachmentData,
} = props;

const editExcerptDropdownRef: QuickActionDropdownMenuProps['componentRef'] = React.useRef(null);
Expand All @@ -149,6 +152,13 @@ function EntryItem(props: EntryItemProps) {
[entryId, onExcerptChange],
);

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

return (
<Container
className={_cs(
Expand Down Expand Up @@ -310,16 +320,28 @@ 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
/>
{isDefined(entryTypeFromLead) ? (
<ExcerptInput
// className={styles.taggedExcerpt}
value={attachmentData?.type}
leadImageUrl={attachmentData?.filePreview?.url ?? undefined}
entryType={entryTypeFromLead}
image={undefined}
imageRaw={undefined}
readOnly
/>
) : (
<ExcerptInput
value={excerpt}
// droppedExcerpt={droppedExcerpt}
image={entryImage}
imageRaw={imageRaw}
// FIXME: pass this after image drag/drop is implemented
leadImageUrl={undefined}
entryType={entryType}
readOnly
/>
)}
</div>
<div className={styles.verticalBorder} />
</Container>
Expand Down
247 changes: 247 additions & 0 deletions app/components/LeftPaneEntries/TableAndVisualItem/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
import React, { useCallback, useMemo } from 'react';
import { BsDownload } from 'react-icons/bs';
import {
IoCheckmark,
IoClose,
} from 'react-icons/io5';

import {
_cs,
isDefined,
} from '@togglecorp/fujs';
import {
Container,
QuickActionButton,
useInputState,
Button,
QuickActionButtonProps,
QuickActionLink,
} 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'], type: 'IMAGE' | 'ATTACHMENT') => void;
onApproveButtonClick?: QuickActionButtonProps<string>['onClick'];
onDiscardButtonClick?: QuickActionButtonProps<string>['onClick'];
onEntryDelete?: (entryId: string) => void;
onEntryRestore?: (entryId: string) => void;
className?: string;
disableApproveButton?: boolean;
disableDiscardButton?: boolean;
disableClick?: boolean;
errored?: boolean;
data: LeadPreviewAttachmentType;
isActive?: boolean;
}

function TableAndVisualItem(props: TableAndVisualItemProps) {
const {
className,
attachmentId,
onClick,
onApproveButtonClick,
onDiscardButtonClick,
disableApproveButton,
disableDiscardButton,
disableClick,
onEntryDelete,
onEntryRestore,
deleted,
errored,
stale,
data,
isActive,
} = 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, data?.type === 'IMAGE' ? 'IMAGE' : 'ATTACHMENT');
}
}, [attachmentId, onClick, disableClick, data?.type]);

return (
<div
className={styles.clickableArea}
onClick={handleClick}
role="presentation"
>
<Container
className={_cs(
className,
isActive && styles.active && styles.taggedExcerpt,
)}
headerActions={data?.type === 'XLSX' ? (
<QuickActionLink
title="Open external"
to={data?.file?.url || ''}
>
<BsDownload />
</QuickActionLink>
) : undefined}
// heading={isDefined(entryServerId) ? (
// <NumberOutput
// className={styles.attachmentId}
// prefix="#"
// value={Number(entryServerId)}
// />
// ) : (
// <span className={styles.unsavedEntry}>(unsaved entry)</span>
// )}
heading={isActive && (
<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>
{/* {deleted ? (
<QuickActionButton
title="Restore entry"
name={attachmentId}
onClick={onEntryRestore}
>
<IoArrowUndoSharp />
</QuickActionButton>
) : (
<QuickActionButton
title="Delete entry"
name={attachmentId}
onClick={onEntryDelete}
>
<IoTrashBinOutline />
</QuickActionButton>
)} */}
</>
)}
contentClassName={styles.content}
>
{isDefined(entryTypeFromLead) && (
<ExcerptInput
// className={styles.taggedExcerpt}
value={data?.type}
leadImageUrl={data?.filePreview?.url ?? undefined}
entryType={entryTypeFromLead}
image={undefined}
imageRaw={undefined}
readOnly
/>
)}

<div className={styles.verticalBorder} />
</Container>
</div>
);
}

export default TableAndVisualItem;
Loading

0 comments on commit 8c26bfd

Please sign in to comment.