Skip to content

Commit

Permalink
Fix left project visbility issue
Browse files Browse the repository at this point in the history
* Refetch regions when admin level is removed
* Disable assisted tagging if project is private
  • Loading branch information
AdityaKhatri committed Dec 10, 2024
1 parent f9ade2b commit cf023f5
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 79 deletions.
12 changes: 4 additions & 8 deletions app/components/LeftPaneEntries/AssistItem/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ type OrganigramWidgetAttribute = getType<PartialAttributeType, { widgetType: 'OR
type GeoLocationWidgetAttribute = getType<PartialAttributeType, { widgetType: 'GEO' }>;
*/

export function isValidObject(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && !Array.isArray(value) && value !== null && value !== undefined;
export function isValidObject(value: unknown | undefined): value is Record<string, unknown> {
return value !== null && typeof value === 'object' && !Array.isArray(value);
}

export function isValidStringArray(value: unknown): value is string[] {
const isArray = typeof value === 'object' && Array.isArray(value) && value !== null && value !== undefined;
if (!isArray) {
return false;
}
return value.every((item) => typeof item === 'string');
export function isValidStringArray(value: unknown | undefined): value is string[] {
return Array.isArray(value) && value.every((item) => typeof item === 'string');
}

// TODO: Write tests
Expand Down
5 changes: 4 additions & 1 deletion app/components/LeftPaneEntries/SimplifiedTextView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { GeoArea } from '#components/GeoMultiSelectInput';

import { PartialEntryType as EntryInput } from '#components/entry/schema';
import { Framework } from '#components/entry/types';
import ProjectContext from '#base/context/ProjectContext';

import useTextSelection from './useTextSelection';
import EntryItem from '../EntryItem';
Expand Down Expand Up @@ -207,6 +208,8 @@ function SimplifiedTextView(props: Props) {
setTextToAssist(undefined);
}, []);

const { project } = React.useContext(ProjectContext);

let children: React.ReactNode = null;
if (!text || splits.length === 0) {
children = text;
Expand Down Expand Up @@ -360,7 +363,7 @@ function SimplifiedTextView(props: Props) {
<IoAdd />
</QuickActionButton>
)}
{isDefined(onAssistedEntryAdd) && (
{isDefined(onAssistedEntryAdd) && !project?.isPrivate && (
<QuickActionButton
title="Assist"
name={textContent}
Expand Down
31 changes: 25 additions & 6 deletions app/components/LeftPaneEntries/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {
useMemo,
useEffect,
useCallback,
useContext,
useRef,
} from 'react';
import {
Expand Down Expand Up @@ -55,6 +56,7 @@ import {

import { GeoArea } from '#components/GeoMultiSelectInput';
import LeadPreview from '#components/lead/LeadPreview';
import { ProjectContext } from '#base/context/ProjectContext';
import Screenshot from '#components/Screenshot';
import {
LeadPreviewForTextQuery,
Expand Down Expand Up @@ -207,6 +209,7 @@ function LeftPaneEntries(props: Props) {
onAttachmentClick,
} = props;

const { project } = useContext(ProjectContext);
const alert = useAlert();
const entriesMappingByAttachment = useMemo(() => (
listToMap(
Expand Down Expand Up @@ -270,11 +273,22 @@ function LeftPaneEntries(props: Props) {
setAttachmentsWithEntriesHidden,
] = useState<boolean>(false);

const leadAttachmentIdsWithEntries = useMemo(() => (
Object.values(entryAttachmentsMap ?? {})
.map((entry) => entry?.leadAttachmentId)
.filter(isDefined)
), [
const currentEntryClientIds = useMemo(() => (
entries?.map((item) => item.clientId)
), [entries]);

const leadAttachmentIdsWithEntries = useMemo(() => {
if (!entryAttachmentsMap) {
return [];
}
return (
Object.keys(entryAttachmentsMap)
.filter((item) => currentEntryClientIds?.includes(item))
.map((entry) => entryAttachmentsMap[entry]?.leadAttachmentId)
.filter(isDefined)
);
}, [
currentEntryClientIds,
entryAttachmentsMap,
]);

Expand Down Expand Up @@ -714,12 +728,16 @@ function LeftPaneEntries(props: Props) {
});
}, []);

const isAutoExtractionCompatible = isDefined(leadPreview?.textExtractionId);
const isAutoExtractionCompatible = isDefined(leadPreview?.textExtractionId)
&& !project?.isPrivate;

const errorMessageForAutoExtraction = useMemo(() => {
if (isAutoExtractionCompatible) {
return undefined;
}
if (project?.isPrivate) {
return 'The feature to extract entries through Natural Language Processing (NLP) is currently unavailable for the selected source because the project is private.';
}
if (isDefined(leadPreviewData?.project?.lead?.connectorLead)) {
return 'The feature to extract entries through Natural Language Processing (NLP) is currently unavailable for the selected source. The connector associated with the chosen source may be outdated or incompatible with the NLP extraction functionality.';
}
Expand All @@ -729,6 +747,7 @@ function LeftPaneEntries(props: Props) {
return 'The feature to extract entries through Natural Language Processing (NLP) is currently unavailable for the selected source. The selected source appears to be outdated, and the NLP extraction feature is not compatible with older content formats.';
}, [
isAutoExtractionCompatible,
project?.isPrivate,
leadPreviewData?.project?.lead,
]);

Expand Down
18 changes: 0 additions & 18 deletions app/components/entry/CompactSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { IoAdd } from 'react-icons/io5';
import { GeoArea } from '#components/GeoMultiSelectInput';
import {
Widget,
WidgetHint,
getHiddenWidgetIds,
} from '#types/newAnalyticalFramework';
import CompactAttributeInput, { Props as AttributeInputProps } from '#components/framework/CompactAttributeInput';
Expand Down Expand Up @@ -50,7 +49,6 @@ export interface Props {
addButtonHidden?: boolean;
geoAreaOptions: GeoArea[] | undefined | null;
onGeoAreaOptionsChange: React.Dispatch<React.SetStateAction<GeoArea[] | undefined | null>>;
widgetsHints?: WidgetHint[];
recommendations?: PartialAttributeType[];
emptyMessageHidden?: boolean;
suggestionMode?: boolean;
Expand Down Expand Up @@ -78,7 +76,6 @@ function CompactSection(props: Props) {
geoAreaOptions,
onGeoAreaOptionsChange,
onApplyToAll,
widgetsHints,
emptyMessageHidden,
suggestionMode,
recommendations,
Expand All @@ -102,15 +99,6 @@ function CompactSection(props: Props) {

const error = getErrorObject(riskyError);

const hintsMap = useMemo(
() => listToMap(
widgetsHints?.filter((widgetHint) => widgetHint.hints.length > 0),
(widgetHint) => widgetHint.widgetPk,
(widgetHint) => widgetHint,
),
[widgetsHints],
);

const recommendationsMap = useMemo(
() => listToMap(
recommendations,
Expand All @@ -127,9 +115,6 @@ function CompactSection(props: Props) {
return filteredWidgets?.filter(
// FIXME: should only check into data, not value
(widget) => {
if ((hintsMap?.[widget.id]?.hints.length ?? 0) > 0) {
return true;
}
if (widget.widgetId === 'MATRIX1D') {
const hasValue = !doesObjectHaveNoData(
attributesMap?.[widget.clientId]?.value?.data?.value,
Expand Down Expand Up @@ -160,7 +145,6 @@ function CompactSection(props: Props) {
);
}, [
recommendationsMap,
hintsMap,
emptyValueHidden,
attributesMap,
filteredWidgets,
Expand Down Expand Up @@ -204,7 +188,6 @@ function CompactSection(props: Props) {
applyButtonsHidden: !onApplyToAll,
onApplyBelowClick: handleApplyBelowClick,
onApplyAllClick: handleApplyAllClick,
widgetsHints,
recommendations,
suggestionMode,
rightComponent,
Expand All @@ -213,7 +196,6 @@ function CompactSection(props: Props) {
[
recommendations,
suggestionMode,
widgetsHints,
onApplyToAll,
onAttributeChange,
attributesMap,
Expand Down
6 changes: 0 additions & 6 deletions app/components/entry/EntryInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { GeoArea } from '#components/GeoMultiSelectInput';
import ExcerptInput from '#components/entry/ExcerptInput';
import {
Widget,
WidgetHint,
} from '#types/newAnalyticalFramework';
import { DeepReplace } from '#utils/types';

Expand All @@ -63,7 +62,6 @@ interface EntryInputProps<T extends string | number | undefined> {
addButtonHidden?: boolean;
hideEntryId?: boolean;

widgetsHints?: WidgetHint[];
recommendations?: PartialAttributeType[];

sectionContainerClassName?: string;
Expand Down Expand Up @@ -112,7 +110,6 @@ function EntryInput<T extends string | number | undefined>(props: EntryInputProp
leadId,
variant = 'normal',
entryImage,
widgetsHints,
error: riskyError,
geoAreaOptions,
onGeoAreaOptionsChange,
Expand Down Expand Up @@ -172,7 +169,6 @@ function EntryInput<T extends string | number | undefined>(props: EntryInputProp
onAddButtonClick,
addButtonHidden,
entryClientId: value.clientId,
widgetsHints,
recommendations,
geoAreaOptions,
onGeoAreaOptionsChange,
Expand All @@ -185,7 +181,6 @@ function EntryInput<T extends string | number | undefined>(props: EntryInputProp
}), [
variant,
allWidgets,
widgetsHints,
recommendations,
geoAreaOptions,
onGeoAreaOptionsChange,
Expand Down Expand Up @@ -299,7 +294,6 @@ function EntryInput<T extends string | number | undefined>(props: EntryInputProp
onApplyToAll={onApplyToAll}
entryClientId={value.clientId}
allWidgets={allWidgets}
widgetsHints={widgetsHints}
recommendations={recommendations}
emptyMessageHidden={variant === 'nlp'}
suggestionMode={variant === 'nlp'}
Expand Down
5 changes: 1 addition & 4 deletions app/components/entry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {

WidgetType as WidgetRaw,
BulkEntryInputType,
AnalysisFrameworkPredictionMappingType as MappingsItemRaw,
AttributeType as WidgetAttributeRaw,
AttributeGqInputType as WidgetInputAttributeRaw,
} from '#generated/types';
Expand All @@ -20,7 +19,6 @@ import {
import { WidgetAttribute as WidgetAttributeFromEntry } from '#types/newEntry';
import {
Widget as WidgetFromAF,
MappingsItem,
} from '#types/newAnalyticalFramework';

export type EntryRaw = EntryResponseFragment;
Expand All @@ -38,7 +36,6 @@ export type EntryInput = DeepReplace<EntryInputRaw, WidgetInputAttributeRaw, Wid
// FIXME: 'key' is thought to be mandatory from server.
// Remove this DeepMandatory transformation after server sends key as mandatory
export type FrameworkRaw = DeepMandatory<FrameworkResponseFragment, 'key'>;
export type FrameworkWithWidgets = DeepReplace<FrameworkRaw, Omit<WidgetRaw, 'widgetIdDisplay' | 'widthDisplay'>, WidgetFromAF>;
export type Framework = DeepReplace<FrameworkWithWidgets, MappingsItemRaw, MappingsItem>;
export type Framework = DeepReplace<FrameworkRaw, Omit<WidgetRaw, 'widgetIdDisplay' | 'widthDisplay'>, WidgetFromAF>;
export type Section = NonNullable<Framework['primaryTagging']>[number];
export type Widget = WidgetFromAF;
13 changes: 0 additions & 13 deletions app/components/framework/CompactAttributeInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
import {
Widget,
getWidgetVersion,
WidgetHint,
} from '#types/newAnalyticalFramework';

import { PartialEntryType } from '#components/entry/schema';
Expand All @@ -45,8 +44,6 @@ import OrganigramWidgetInput from './OrganigramWidgetInput';
import GeoLocationWidgetInput from './GeoLocationWidgetInput';
import BaseWidgetInput from './BaseWidgetInput';
import {
filterSelectHints,
filterScaleHints,
filterGeoRecommendations,
filterMultiSelectRecommendations,
filterOrganigramRecommendations,
Expand Down Expand Up @@ -102,7 +99,6 @@ export interface Props<N extends string | number | undefined> {
onApplyAllClick?: (widgetId: string) => void;

applyButtonsHidden?: boolean;
widgetsHints?: WidgetHint[];
recommendations?: PartialAttributeType[];
suggestionMode?: boolean;

Expand All @@ -128,7 +124,6 @@ function CompactAttributeInput<N extends string | number | undefined>(props: Pro
onApplyAllClick,

applyButtonsHidden = true,
widgetsHints,
recommendations,

suggestionMode,
Expand Down Expand Up @@ -290,9 +285,6 @@ function CompactAttributeInput<N extends string | number | undefined>(props: Pro
);
} else if (widget.widgetId === 'SCALE' && (isNotDefined(value) || value.widgetType === widget.widgetId)) {
const data = value?.data;
const widgetHints = widgetsHints
?.filter(filterScaleHints)
?.find((hint) => hint.widgetPk === widget.id);

component = (
<ScaleWidgetInput
Expand All @@ -306,7 +298,6 @@ function CompactAttributeInput<N extends string | number | undefined>(props: Pro
widget={widget}
error={error?.data as Error<typeof data> | undefined}
actions={actions}
widgetHints={widgetHints?.hints}
/>
);
} else if (widget.widgetId === 'MULTISELECT' && (isNotDefined(value) || value.widgetType === widget.widgetId)) {
Expand Down Expand Up @@ -334,9 +325,6 @@ function CompactAttributeInput<N extends string | number | undefined>(props: Pro
);
} else if (widget.widgetId === 'SELECT' && (isNotDefined(value) || value.widgetType === widget.widgetId)) {
const data = value?.data;
const widgetHints = widgetsHints
?.filter(filterSelectHints)
?.find((hint) => hint.widgetPk === widget.id);

component = (
<SingleSelectWidgetInput
Expand All @@ -350,7 +338,6 @@ function CompactAttributeInput<N extends string | number | undefined>(props: Pro
widget={widget}
error={error?.data as Error<typeof data> | undefined}
actions={actions}
widgetHints={widgetHints?.hints}
suggestionMode={suggestionMode}
/>
);
Expand Down
21 changes: 0 additions & 21 deletions app/components/framework/CompactAttributeInput/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import {
WidgetHint,
} from '#types/newAnalyticalFramework';
import {
PartialAttributeType,
} from '#components/entry/schema';
Expand Down Expand Up @@ -45,21 +42,3 @@ export function filterGeoRecommendations(
): recommendation is GeoWidgetAttribute {
return recommendation.widgetType === 'GEO';
}

export function filterGeoHints(
hint: WidgetHint,
): hint is { hints: string[]; widgetPk: string; widgetType: 'GEO' } {
return hint.widgetType === 'GEO';
}

export function filterScaleHints(
hint: WidgetHint,
): hint is { hints: string[]; widgetPk: string; widgetType: 'SCALE' } {
return hint.widgetType === 'SCALE';
}

export function filterSelectHints(
hint: WidgetHint,
): hint is { hints: string[]; widgetPk: string; widgetType: 'SELECT' } {
return hint.widgetType === 'SELECT';
}
4 changes: 3 additions & 1 deletion app/views/Home/ProjectItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export interface RecentProjectItemProps {
isPinned?: boolean;
pinnedId: string | undefined;
onProjectPinChange: () => void;
onProjectLeaveSuccess: () => void;
disablePinButton: boolean;
}

Expand Down Expand Up @@ -169,6 +170,7 @@ function ProjectItem(props: RecentProjectItemProps) {
recentActiveUsers,
isPinned,
onProjectPinChange,
onProjectLeaveSuccess,
disablePinButton,
} = props;

Expand Down Expand Up @@ -248,7 +250,7 @@ function ProjectItem(props: RecentProjectItemProps) {
} = leaveProjectResponse;

if (ok) {
onProjectPinChange();
onProjectLeaveSuccess();
alert.show(
'Project successfully left.',
{ variant: 'success' },
Expand Down
Loading

0 comments on commit cf023f5

Please sign in to comment.