Skip to content

Commit

Permalink
Hide non textual entries from analysis module
Browse files Browse the repository at this point in the history
  • Loading branch information
subinasr committed Jul 1, 2024
1 parent 41f01fb commit 35b17c4
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 84 deletions.
2 changes: 0 additions & 2 deletions app/components/LeftPaneEntries/AssistItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,6 @@ function AssistItem(props: Props) {
}
predictionsErrored={!!fetchErrors || !!createErrors || isErrored}
messageText={messageText}
// NOTE: Setting this as undefined as this
// component is only used for textual entries
footerActions={(
<>
<QuickActionButton
Expand Down
7 changes: 4 additions & 3 deletions app/components/LeftPaneEntries/EntryItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function ExcerptModal(props: ExcerptModalProps) {

export interface EntryItemProps extends Pick<
EntryInput,
'droppedExcerpt' | 'excerpt' | 'entryType' | 'deleted' | 'stale'
'droppedExcerpt' | 'excerpt' | 'entryType' | 'deleted' | 'stale' | 'imageRaw'
> {
entryId: string;
isActive?: boolean;
Expand Down Expand Up @@ -135,6 +135,7 @@ function EntryItem(props: EntryItemProps) {
stale,
leadAttachment,
entryAttachment,
imageRaw,
} = props;

const editExcerptDropdownRef: QuickActionDropdownMenuProps['componentRef'] = React.useRef(null);
Expand Down Expand Up @@ -186,7 +187,7 @@ function EntryItem(props: EntryItemProps) {
<ExcerptInput
value={excerpt}
image={entryImage}
imageRaw={leadAttachment?.filePreview?.url ?? ''}
imageRaw={imageRaw ?? leadAttachment?.filePreview?.url ?? undefined}
entryAttachment={entryAttachment}
entryType={entryType}
readOnly
Expand Down Expand Up @@ -322,7 +323,7 @@ function EntryItem(props: EntryItemProps) {
value={excerpt}
// droppedExcerpt={droppedExcerpt}
image={entryImage}
imageRaw={leadAttachment?.filePreview?.url ?? undefined}
imageRaw={imageRaw ?? leadAttachment?.filePreview?.url ?? undefined}
entryType={entryType}
entryAttachment={entryAttachment}
leadAttachment={leadAttachment}
Expand Down
34 changes: 22 additions & 12 deletions app/components/LeftPaneEntries/TableAndVisualItem/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React from 'react';
import React, { useCallback } from 'react';
import { BsDownload } from 'react-icons/bs';
import {
IoAdd,
} from 'react-icons/io5';

import {
isDefined,
} from '@togglecorp/fujs';
import {
Container,
QuickActionButton,
Expand Down Expand Up @@ -31,6 +33,20 @@ interface VisualProps {
export type Props = EntryProps | VisualProps;

function TableAndVisualItem(props: Props) {
const handleEntryAddFromAttachment = useCallback(() => {
// eslint-disable-next-line react/destructuring-assignment
if (props.type === 'entry-item') {
return;
}
// eslint-disable-next-line react/destructuring-assignment
if (props.onClick) {
// eslint-disable-next-line react/destructuring-assignment
props.onClick(props.attachment);
}
}, [
props,
]);

// eslint-disable-next-line react/destructuring-assignment
if (props.type === 'entry-item') {
return (
Expand All @@ -42,7 +58,6 @@ function TableAndVisualItem(props: Props) {

const {
attachment,
onClick,
disableClick,
} = props;

Expand All @@ -51,22 +66,17 @@ function TableAndVisualItem(props: Props) {
headerActions={(
<>
<QuickActionButton
// FIXME:
name={undefined}
title="Add Entry"
onClick={() => {
if (onClick) {
onClick(attachment);
}
}}
onClick={handleEntryAddFromAttachment}
disabled={disableClick}
>
<IoAdd />
</QuickActionButton>
{attachment.type === 'XLSX' && (
{attachment.type === 'XLSX' && isDefined(attachment.file.url) && (
<QuickActionLink
title="Open external"
to={attachment.file?.url || ''}
to={attachment.file.url}
>
<BsDownload />
</QuickActionLink>
Expand All @@ -77,7 +87,7 @@ function TableAndVisualItem(props: Props) {
>
<ImagePreview
alt="Preview Image"
src={attachment.filePreview?.url ?? ''}
src={attachment.filePreview?.url ?? undefined}
/>
</Container>
);
Expand Down
87 changes: 43 additions & 44 deletions app/components/LeftPaneEntries/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ interface Props {
} | null>;
}

const defaultMaxItemsPerPage = 10;
const MAX_ITEMS_PER_PAGE = 10;

function LeftPane(props: Props) {
const {
Expand Down Expand Up @@ -206,21 +206,22 @@ function LeftPane(props: Props) {
const alert = useAlert();
const { user } = useContext(UserContext);

// FIXME: memoize this
const entriesMappingByAttachment = listToMap(
entries?.map((entry) => {
if (isDefined(entry.leadAttachment)) {
// FIXME: this is a hack to assert leadAttachment value
return {
...entry,
leadAttachment: entry.leadAttachment,
};
}
return undefined;
}).filter(isDefined) ?? [],
(item) => item.leadAttachment,
(item) => item,
);
const entriesMappingByAttachment = useMemo(() => (
listToMap(
entries?.map((entry) => {
if (isDefined(entry.leadAttachment)) {
// FIXME: this is a hack to assert leadAttachment value
return {
...entry,
leadAttachment: entry.leadAttachment,
};
}
return undefined;
}).filter(isDefined) ?? [],
(item) => item.leadAttachment,
(item) => item,
)
), [entries]);

const isAssistedTaggingAccessible = !!user
?.accessibleFeatures?.some((feature) => feature.key === 'ASSISTED');
Expand Down Expand Up @@ -265,10 +266,7 @@ function LeftPane(props: Props) {

const editExcerptDropdownRef: QuickActionDropdownMenuProps['componentRef'] = useRef(null);

// FIXME: rename the following variables to indicate that these are for
// lead attachments
const [activePage, setActivePage] = useState<number>(1);
const [maxItemsPerPage, setMaxItemsPerPage] = useState(defaultMaxItemsPerPage);
const [activeLeadAttachmentPage, setActiveLeadAttachmentPage] = useState<number>(1);

const [
attachmentsWithEntriesHidden,
Expand All @@ -287,17 +285,16 @@ function LeftPane(props: Props) {
() => ((leadId && projectId) ? ({
leadId,
projectId,
page: activePage,
pageSize: maxItemsPerPage,
page: activeLeadAttachmentPage,
pageSize: MAX_ITEMS_PER_PAGE,
excludeAttachmentIds: attachmentsWithEntriesHidden
? leadAttachmentIdsWithEntries
: [],
}) : undefined),
[
leadId,
projectId,
activePage,
maxItemsPerPage,
activeLeadAttachmentPage,
attachmentsWithEntriesHidden,
leadAttachmentIdsWithEntries,
],
Expand Down Expand Up @@ -438,8 +435,7 @@ function LeftPane(props: Props) {
entry: EntryInput,
): EntryItemProps => ({
...entry,
// FIXME: We can directly use entryId
entryId: entry.clientId,
entryId,
entryServerId: entry.id,
isActive: activeEntry === entry.clientId,
projectId,
Expand All @@ -450,7 +446,7 @@ function LeftPane(props: Props) {
entryImage: entry?.image
? entryImagesMap?.[entry.image]
: undefined,
entryAttachment: entryAttachmentsMap?.[entry.clientId],
entryAttachment: entryAttachmentsMap?.[entryId],
leadAttachment: entry.leadAttachment
? leadAttachmentsMap?.[entry.leadAttachment]
: undefined,
Expand Down Expand Up @@ -483,8 +479,8 @@ function LeftPane(props: Props) {
if (entry) {
const entryId = entry.clientId;
return {
type: 'entry-item' as const,
...entry,
type: 'entry-item' as const,
entryId: entry.clientId,
entryServerId: entry.id,
isActive: activeEntry === entry.clientId,
Expand Down Expand Up @@ -918,12 +914,14 @@ function LeftPane(props: Props) {
activeClassName={styles.visualsTab}
retainMount="lazy"
>
<Switch
name="hide attachments"
label="Hide Created entries"
value={attachmentsWithEntriesHidden}
onChange={setAttachmentsWithEntriesHidden}
/>
{isDefined(leadPreviewCount) && (leadPreviewCount > 0) && (
<Switch
name="hide attachments"
label="Hide Created entries"
value={attachmentsWithEntriesHidden}
onChange={setAttachmentsWithEntriesHidden}
/>
)}
<ListView
spacing="comfortable"
direction="vertical"
Expand All @@ -940,19 +938,20 @@ function LeftPane(props: Props) {
variant="search"
/>
)}
emptyMessage="No entries found"
emptyMessage="No tables or visuals found"
messageShown
messageIconShown
/>
<Pager
className={styles.pager}
activePage={activePage}
itemsCount={leadPreviewCount ?? 0}
maxItemsPerPage={maxItemsPerPage}
onActivePageChange={setActivePage}
onItemsPerPageChange={setMaxItemsPerPage}
itemsPerPageControlHidden
/>
{isDefined(leadPreviewCount) && (leadPreviewCount > 0) && (
<Pager
className={styles.pager}
activePage={activeLeadAttachmentPage}
itemsCount={leadPreviewCount}
maxItemsPerPage={MAX_ITEMS_PER_PAGE}
onActivePageChange={setActiveLeadAttachmentPage}
itemsPerPageControlHidden
/>
)}
</TabPanel>
{!hideOriginalPreview && (
<TabPanel
Expand Down
11 changes: 7 additions & 4 deletions app/components/entry/ExcerptInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react';
import { BsDownload } from 'react-icons/bs';
import { _cs } from '@togglecorp/fujs';
import {
_cs,
isDefined,
} from '@togglecorp/fujs';
import {
Container,
ImagePreview,
Expand Down Expand Up @@ -111,14 +114,14 @@ function ExcerptInput<N extends string>(props: Props<N>) {
return (
<Container
className={_cs(className, styles.excerptInput, styles.imageExcerptContainer)}
headerActions={fileType === 'XLSX' ? (
headerActions={fileType === 'XLSX' && isDefined(file) && isDefined(file.url) && (
<QuickActionLink
title="Open external"
to={file?.url || ''}
to={file.url}
>
<BsDownload />
</QuickActionLink>
) : undefined}
)}
>
{attachmentSrc ? (
<ImagePreview
Expand Down
36 changes: 20 additions & 16 deletions app/components/leadFilters/SourcesFilter/EntryFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ interface Props<K extends string> {
entryTypeOptions?: EnumEntity<string>[] | null;
frameworkFilters?: FrameworkFilterType[] | null;
disabled?: boolean;
hideEntryTypeFilter?: boolean;
}

function EntryFilter<K extends string>(props: Props<K>) {
Expand All @@ -86,6 +87,7 @@ function EntryFilter<K extends string>(props: Props<K>) {
optionsDisabled,
entryTypeOptions,
frameworkFilters,
hideEntryTypeFilter,
} = props;

const setFieldValue = useFormObject(name, onChange, defaultValue);
Expand Down Expand Up @@ -207,22 +209,24 @@ function EntryFilter<K extends string>(props: Props<K>) {
label="Has Comment"
disabled={disabled}
/>
<MultiSelectInput
variant="general"
className={_cs(
styles.input,
(doesObjectHaveNoData(value?.entryTypes) && !allFiltersVisible)
&& styles.hidden,
)}
name="entryTypes"
value={value?.entryTypes}
onChange={setFieldValue}
keySelector={enumKeySelector}
labelSelector={enumLabelSelector}
options={entryTypeOptions}
disabled={disabled || optionsDisabled}
label="Entry Type"
/>
{!hideEntryTypeFilter && (
<MultiSelectInput
variant="general"
className={_cs(
styles.input,
(doesObjectHaveNoData(value?.entryTypes) && !allFiltersVisible)
&& styles.hidden,
)}
name="entryTypes"
value={value?.entryTypes}
onChange={setFieldValue}
keySelector={enumKeySelector}
labelSelector={enumLabelSelector}
options={entryTypeOptions}
disabled={disabled || optionsDisabled}
label="Entry Type"
/>
)}
{frameworkFilters?.map((filter) => {
const filterValue = filterValuesMap[filter.key];
return (
Expand Down
4 changes: 4 additions & 0 deletions app/components/leadFilters/SourcesFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ interface Props {

optionsLoading: boolean;
optionsErrored: boolean;

hideEntryTypeFilter?: boolean;
}

function SourcesFilter(props: Props) {
Expand All @@ -182,6 +184,7 @@ function SourcesFilter(props: Props) {
onChange: setFieldValue,
optionsLoading,
optionsErrored,
hideEntryTypeFilter,
} = props;

const error = getErrorObject(formError);
Expand Down Expand Up @@ -412,6 +415,7 @@ function SourcesFilter(props: Props) {
optionsDisabled={optionsLoading || optionsErrored}
allFiltersVisible
disabled={disabled}
hideEntryTypeFilter={hideEntryTypeFilter}
/>
</TabPanel>
)}
Expand Down
Loading

0 comments on commit 35b17c4

Please sign in to comment.