From 5c7b341f70813f9266a00dc60205e95bf5128561 Mon Sep 17 00:00:00 2001 From: Austin Turner Date: Tue, 28 Feb 2023 18:06:13 -0700 Subject: [PATCH] Fix SObject list Ensure empty state is now shown on load instead of loading Ensure empty state does not flash on page --- .../AutomationControlSelection.tsx | 2 +- .../query/QueryBuilder/QueryBuilder.tsx | 2 +- .../sobject-field-list/SobjectFieldList.tsx | 31 +++++++------------ .../sobject-field-list-utils.tsx | 7 ++--- .../lib/sobject-list/ConnectedSobjectList.tsx | 2 +- libs/ui/src/lib/sobject-list/SobjectList.tsx | 8 ++--- 6 files changed, 21 insertions(+), 31 deletions(-) diff --git a/apps/jetstream/src/app/components/automation-control/AutomationControlSelection.tsx b/apps/jetstream/src/app/components/automation-control/AutomationControlSelection.tsx index 010a7affc..dd7588eac 100644 --- a/apps/jetstream/src/app/components/automation-control/AutomationControlSelection.tsx +++ b/apps/jetstream/src/app/components/automation-control/AutomationControlSelection.tsx @@ -107,7 +107,7 @@ export const AutomationControlSelection: FunctionComponent = () => { , queryFields: QueryFields, activeFilters: FilterTypes) { + return Array.from(visibleFields) + .map((key) => queryFields?.fields?.[key]) + .filter(Boolean) + .filter(filterFieldsFn(activeFilters)) as FieldWrapper[]; +} + export interface SobjectFieldListProps { org: SalesforceOrgUi; serverUrl: string; @@ -69,12 +76,7 @@ export const SobjectFieldList: FunctionComponent = ({ } return null; }); - const [visibleFields, setVisibleFields] = useState | null>(() => { - if (isString(itemKey) && queryFieldsMap[itemKey]) { - return queryFieldsMap[itemKey].visibleFields; - } - return null; - }); + const [selectAll, setSelectAll] = useState(false); const [searchInputId] = useState(`object-field-${sobject}-filter-${Date.now()}`); const [searchTerm, setSearchTerm] = useState(''); @@ -85,20 +87,9 @@ export const SobjectFieldList: FunctionComponent = ({ const queryFields = queryFieldsMap[itemKey]; setQueryFields(queryFields); setFieldLength(Object.keys(queryFields.fields).length); - setVisibleFields(queryFields.visibleFields); // instance only changes if filtered fields was actually modified - } - }, [itemKey, queryFieldsMap]); - - useNonInitialEffect(() => { - if (visibleFields) { - setFilteredFields( - Array.from(visibleFields) - .map((key) => queryFields?.fields?.[key]) - .filter(Boolean) - .filter(filterFieldsFn(activeFilters)) as FieldWrapper[] - ); + setFilteredFields(getFilteredFields(queryFields.visibleFields, queryFields, activeFilters)); } - }, [visibleFields, activeFilters, queryFields?.fields]); + }, [activeFilters, itemKey, queryFieldsMap]); // when filtered fields changes, see if handleFieldFilterChanged fields are selected and possibly update allSelected state useEffect(() => { @@ -269,7 +260,7 @@ export const SobjectFieldList: FunctionComponent = ({ onSelected={handleFieldSelected} getContent={getFieldContent} /> - {!filteredFields.length && ( + {!queryFields.loading && !filteredFields.length && ( 0} headline="There are no matching fields" diff --git a/libs/ui/src/lib/sobject-field-list/sobject-field-list-utils.tsx b/libs/ui/src/lib/sobject-field-list/sobject-field-list-utils.tsx index 4bb60c949..6b1485d69 100644 --- a/libs/ui/src/lib/sobject-field-list/sobject-field-list-utils.tsx +++ b/libs/ui/src/lib/sobject-field-list/sobject-field-list-utils.tsx @@ -1,8 +1,8 @@ import { REGEX } from '@jetstream/shared/utils'; -import { FieldWrapper } from '@jetstream/types'; +import { FieldWrapper, Maybe } from '@jetstream/types'; import { FilterTypes } from './SobjectFieldListFilterNew'; -export function getBgColor(level: number): string { +export function getBgColor(level: number): string | undefined { switch (level) { case 1: { return '#eef1f6'; @@ -16,8 +16,7 @@ export function getBgColor(level: number): string { case 4: { return '#96c5f7'; } - case 5: - default: { + case 5: { return '#758ecd'; } } diff --git a/libs/ui/src/lib/sobject-list/ConnectedSobjectList.tsx b/libs/ui/src/lib/sobject-list/ConnectedSobjectList.tsx index 0bb7255d4..b90be9309 100644 --- a/libs/ui/src/lib/sobject-list/ConnectedSobjectList.tsx +++ b/libs/ui/src/lib/sobject-list/ConnectedSobjectList.tsx @@ -26,7 +26,7 @@ export function filterToolingSobjectFn(sobject: DescribeGlobalSObjectResult): bo export interface ConnectedSobjectListProps { label?: string; selectedOrg: SalesforceOrgUi; - sobjects: DescribeGlobalSObjectResult[]; + sobjects: Maybe; selectedSObject: Maybe; isTooling?: boolean; initialSearchTerm?: string; diff --git a/libs/ui/src/lib/sobject-list/SobjectList.tsx b/libs/ui/src/lib/sobject-list/SobjectList.tsx index 52d327be8..2573e659d 100644 --- a/libs/ui/src/lib/sobject-list/SobjectList.tsx +++ b/libs/ui/src/lib/sobject-list/SobjectList.tsx @@ -12,7 +12,7 @@ import Spinner from '../widgets/Spinner'; export interface SobjectListProps { isTooling?: boolean; - sobjects: DescribeGlobalSObjectResult[]; + sobjects: Maybe; selectedSObject: Maybe; loading: boolean; errorMessage?: Maybe; @@ -38,7 +38,7 @@ export const SobjectList: FunctionComponent = ({ if (sobjects && sobjects.length > 0 && searchTerm) { return sobjects.filter(multiWordObjectFilter(['name', 'label'], searchTerm)); } else { - return sobjects; + return sobjects || []; } }); const [searchInputId] = useState(`object-filter-${Date.now()}`); @@ -48,7 +48,7 @@ export const SobjectList: FunctionComponent = ({ if (sobjects && sobjects.length > 0 && searchTerm) { setFilteredSobjects(sobjects.filter(multiWordObjectFilter(['name', 'label'], searchTerm))); } else { - setFilteredSobjects(sobjects); + setFilteredSobjects(sobjects || []); } }, [sobjects, searchTerm]); @@ -119,7 +119,7 @@ export const SobjectList: FunctionComponent = ({ searchTerm={searchTerm} highlightText /> - {!filteredSobjects.length && ( + {!loading && !filteredSobjects.length && ( )}