Skip to content

Commit

Permalink
Require strict null checks
Browse files Browse the repository at this point in the history
Added strict null checks for all libraries
  • Loading branch information
paustint committed Feb 27, 2023
1 parent 0fcf2f5 commit b14cca4
Show file tree
Hide file tree
Showing 208 changed files with 927 additions and 752 deletions.
1 change: 1 addition & 0 deletions .nxignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apps/electron/Readme.md
34 changes: 32 additions & 2 deletions apps/jetstream/src/app/app-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@jetstream/types';
import localforage from 'localforage';
import isString from 'lodash/isString';
import { atom, selector, useRecoilValue, useSetRecoilState } from 'recoil';
import { atom, selector, selectorFamily, useRecoilValue, useSetRecoilState } from 'recoil';

export const STORAGE_KEYS = {
SELECTED_ORG_STORAGE_KEY: `SELECTED_ORG`,
Expand Down Expand Up @@ -135,7 +135,7 @@ export const selectedOrgIdState = atom<string>({
default: getSelectedOrgFromStorage(),
});

export const selectedOrgState = selector({
export const selectedOrgStateWithoutPlaceholder = selector({
key: 'selectedOrgState',
get: ({ get }) => {
const salesforceOrgs = get(salesforceOrgsState);
Expand All @@ -147,6 +147,36 @@ export const selectedOrgState = selector({
},
});

/**
* If no org is selected, this returns a placeholder
* it is expected that any component with an org required
* will be wrapped in an <OrgSelectionRequired> component to guard against this
*/
export const selectedOrgState = selector({
key: 'selectedOrgState',
get: ({ get }) => {
const PLACEHOLDER: SalesforceOrgUi = {
uniqueId: '',
label: '',
filterText: '',
accessToken: '',
instanceUrl: '',
loginUrl: '',
userId: '',
email: '',
organizationId: '',
username: '',
displayName: '',
};
const salesforceOrgs = get(salesforceOrgsState);
const selectedOrgId = get(selectedOrgIdState);
if (isString(selectedOrgId) && Array.isArray(salesforceOrgs)) {
return salesforceOrgs.find((org) => org.uniqueId === selectedOrgId) || PLACEHOLDER;
}
return PLACEHOLDER;
},
});

export const salesforceOrgsOmitSelectedState = selector({
key: 'salesforceOrgsOmitSelectedState',
get: ({ get }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface AnonymousApexProps {}

export const AnonymousApex: FunctionComponent<AnonymousApexProps> = () => {
useTitle(TITLES.ANON_APEX);
const isMounted = useRef(null);
const isMounted = useRef(true);
const apexRef = useRef<editor.IStandaloneCodeEditor>(null);
const logRef = useRef<editor.IStandaloneCodeEditor>(null);
const { trackEvent } = useAmplitude();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// * @returns
// */
// export function useApexCompletions(org: SalesforceOrgUi) {
// const isMounted = useRef(null);
// const isMounted = useRef(true);
// const [_completions, setCompletions] = useState<MapOf<ApexCompletion>>(null);
// const [loading, setLoading] = useState(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const AutomationControlEditor: FunctionComponent<AutomationControlEditorP

const [dirtyRows, setDirtyRows] = useState<TableRowItem[]>([]);
const [saveModalOpen, setSaveModalOpen] = useState(false);
const [quickFilterText, setQuickFilterText] = useState<string>(null);
const [quickFilterText, setQuickFilterText] = useState<string | null>(null);

const [exportDataModalOpen, setExportDataModalOpen] = useState<boolean>(false);
const [exportDataModalData, setExportDataModalData] = useState<any[]>([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ export function useAutomationControlData({
selectedSObjects: string[];
selectedAutomationTypes: AutomationMetadataType[];
}) {
const isMounted = useRef(null);
const isMounted = useRef(true);
const { trackEvent } = useAmplitude();
const rollbar = useRollbar();

Expand Down
2 changes: 1 addition & 1 deletion apps/jetstream/src/app/components/core/AppLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FunctionComponent, useEffect, useRef, useState } from 'react';
const delayMs = 300;

export const AppLoading: FunctionComponent = () => {
const isMounted = useRef(null);
const isMounted = useRef(true);
const [isActive, setIsActive] = useState(false);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface AppStateResetOnOrgChangeProps {}

export const AppStateResetOnOrgChange: FunctionComponent<AppStateResetOnOrgChangeProps> = () => {
const selectedOrg = useRecoilValue<SalesforceOrgUi>(fromAppState.selectedOrgState);
const [priorSelectedOrg, setPriorSelectedOrg] = useState<string>(null);
const [priorSelectedOrg, setPriorSelectedOrg] = useState<string | null>(null);

const resetFns: Resetter[] = [
// QUERY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FunctionComponent, useEffect, useRef } from 'react';
export interface HeaderDonatePopoverProps {}

export const HeaderDonatePopover: FunctionComponent<HeaderDonatePopoverProps> = () => {
const isMounted = useRef(null);
const isMounted = useRef(true);
const popoverRef = useRef<PopoverRef>(null);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FunctionComponent, useEffect, useRef } from 'react';
export interface HeaderHelpPopoverProps {}

export const HeaderHelpPopover: FunctionComponent<HeaderHelpPopoverProps> = () => {
const isMounted = useRef(null);
const isMounted = useRef(true);
const popoverRef = useRef<PopoverRef>(null);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const ViewEditCloneRecord: FunctionComponent<ViewEditCloneRecordProps> =
onFetch,
onFetchError,
}) => {
const isMounted = useRef(null);
const isMounted = useRef(true);
const [{ google_apiKey, google_appId, google_clientId }] = useRecoilState(applicationCookieState);
const [sobjectFields, setSobjectFields] = useState<Field[]>();
const [picklistValues, setPicklistValues] = useState<PicklistFieldValues>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const RecordLookupPopover: FunctionComponent = () => {
const selectedOrg = useRecoilValue<SalesforceOrgUi>(selectedOrgState);

const [loading, setLoading] = useState<boolean>();
const [errorMessage, setErrorMessage] = useState<string>(null);
const [errorMessage, setErrorMessage] = useState<string | null>(null);

const [recentRecords, setRecentRecords] = useState<RecentRecord[]>();
const [modalOpen, setModalOpen] = useState<boolean>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const CreateNewGlobalPicklistModal: FunctionComponent<CreateNewGlobalPick
const rollbar = useRollbar();
const [{ defaultApiVersion }] = useRecoilState(applicationCookieState);
const [isOpen, setIsOpen] = useState(false);
const [errorMessage, setErrorMessage] = useState<string>(null);
const [errorMessage, setErrorMessage] = useState<string | null>(null);

const [picklistData, setPicklistData] = useState<PicklistData>({ ...defaultValues });
const [isValid, setIsValid] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const CreateObjectAndFields: FunctionComponent<CreateObjectAndFieldsProps
const resetSObjectsState = useResetRecoilState(fromCreateFieldsState.sObjectsState);
const resetSelectedSObjectsState = useResetRecoilState(fromCreateFieldsState.selectedSObjectsState);
const resetFieldRowsState = useResetRecoilState(fromCreateFieldsState.fieldRowsState);
const [priorSelectedOrg, setPriorSelectedOrg] = useState<string>(null);
const [priorSelectedOrg, setPriorSelectedOrg] = useState<string | null>(null);

const hasSelectionsMade = useRecoilValue(fromCreateFieldsState.hasSelectionsMade);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface DebugLogViewerProps {}

export const DebugLogViewer: FunctionComponent<DebugLogViewerProps> = () => {
useTitle(TITLES.DEBUG_LOGS);
const isMounted = useRef(null);
const isMounted = useRef(true);
const logCache = useRef<MapOf<string>>({});
const logRef = useRef<editor.IStandaloneCodeEditor>(null);
const [{ serverUrl }] = useRecoilState(applicationCookieState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export interface DebugLogViewerTableProps {
}

export const DebugLogViewerTable: FunctionComponent<DebugLogViewerTableProps> = ({ logs, onRowSelection }) => {
const isMounted = useRef(null);
const isMounted = useRef(true);

useEffect(() => {
isMounted.current = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface DebugLogViewerTraceProps {
}

export const DebugLogViewerTrace: FunctionComponent<DebugLogViewerTraceProps> = ({ org }) => {
const isMounted = useRef(null);
const isMounted = useRef(true);
const popoverRef = useRef<PopoverRef>(null);
const { changeLogLevel, loading, errorMessage, activeDebugLevel, debugLevels } = useSetTraceFlag(org);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface PurgeLogsModalProps {
}

export const PurgeLogsModal: FunctionComponent<PurgeLogsModalProps> = ({ selectedOrg, onModalClose }) => {
const isMounted = useRef(null);
const isMounted = useRef(true);
const [status, setStatus] = useState<Status>('NOT_STARTED');
const [whichUsers, setWhichUsers] = useState<WhichUsers>('ALL');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ const MAX_POLL_ATTEMPTS = 25;

export function useDebugLogs(org: SalesforceOrgUi, { limit, pollInterval, userId }: UseDebugLogsOptions) {
pollInterval = pollInterval || DEFAULT_POLL_INTERVAL;
const isMounted = useRef(null);
const isMounted = useRef(true);
/** Used so that if multiple requests come in at about the same time, we can ignore results from intermediate requests as they may not be valid */
const currentFetchToken = useRef<number>(new Date().getTime());
const numPollErrors = useRef<number>(0);
const [loading, setLoading] = useState(false);
const [errorMessage, setErrorMessage] = useState();
const [logs, setLogs] = useState<ApexLog[]>([]);
/** If provided, will only fetch the most resent logs */
const [asOfId, setAsOfId] = useState<string>(null);
const [asOfId, setAsOfId] = useState<string | null>(null);
const [intervalDelay, setIntervalDelay] = useState<number | null>(null);
const [lastChecked, setLastChecked] = useState<Date>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const DeployMetadata: FunctionComponent<DeployMetadataProps> = () => {
const resetChangesetPackage = useResetRecoilState(fromDeployMetadataState.changesetPackage);
const resetChangesetPackages = useResetRecoilState(fromDeployMetadataState.changesetPackages);

const [priorSelectedOrg, setPriorSelectedOrg] = useState<string>(null);
const [priorSelectedOrg, setPriorSelectedOrg] = useState<string | null>(null);

// reset everything if the selected org changes
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const DeployMetadataDeploymentTable: FunctionComponent<DeployMetadataDepl
}) => {
const [columns, setColumns] = useState<ColumnWithFilter<DeployMetadataTableRow>[]>([]);
const [visibleRows, setVisibleRows] = useState<DeployMetadataTableRow[]>(rows);
const [globalFilter, setGlobalFilter] = useState<string>(null);
const [globalFilter, setGlobalFilter] = useState<string | null>(null);
const [selectedRowIds, setSelectedRowIds] = useState(new Set<any>());
const [expandedGroupIds, setExpandedGroupIds] = useState(new Set<any>());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const DeployMetadataHistoryModal = ({ className }: DeployMetadataHistoryM
});
const [historyItems, setHistoryItems] = useState<SalesforceDeployHistoryItem[]>([]);
const [isLoading, setIsLoading] = useState(false);
const [errorMessage, setError] = useState<string>(null);
const [errorMessage, setError] = useState<string | null>(null);
const orgsById = useRecoilValue(fromAppState.salesforceOrgsById);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const DeployMetadataPackageConfigModal: FunctionComponent<DeployMetadataP
const [filename, setFileName] = useState<string>(initialFilename);
const [fileContents, setFileContents] = useState<string[]>(initialFileContents);
const [isConfigValid, setIsConfigValid] = useState(true);
const [zipFileError, setZipFileError] = useState<string>(null);
const [zipFileError, setZipFileError] = useState<string | null>(null);
const [{ isSinglePackage, missingPackageXml }, setPackageDetection] = useState({
isSinglePackage: initialIsSinglePackage ?? true,
missingPackageXml: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface RadioButtonSelectionProps {
items: RadioButtonItem[];
checkedValue: string;
disabled?: boolean;
labelHelp?: string;
labelHelp?: string | null;
onChange: (value: string) => void;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function useAddItemsToChangeset(
selectedMetadata,
}: { changesetName: string; changesetDescription: string; selectedMetadata: MapOf<ListMetadataResult[]> }
) {
const isMounted = useRef(null);
const isMounted = useRef(true);

const [{ hasLoaded, loading, hasError, errorMessage, status, deployId, results }, dispatch] = useReducer(reducer, {
hasLoaded: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ChangeSet, ListItem, SalesforceOrgUi } from '@jetstream/types';
import { useCallback, useEffect, useReducer, useRef } from 'react';

export function useChangesetList(selectedOrg: SalesforceOrgUi, initialPackages?: ListItem<string, ChangeSet>[]) {
const isMounted = useRef(null);
const isMounted = useRef(true);

const [{ hasLoaded, loading, data, hasError, errorMessage }, dispatch] = useReducer(useReducerFetchFn<ListItem<string, ChangeSet>[]>(), {
hasLoaded: !!initialPackages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function useDeployMetadataBetweenOrgs(
selectedMetadata: MapOf<ListMetadataResult[]>,
deployOptions: DeployOptions
) {
const isMounted = useRef(null);
const isMounted = useRef(true);

const [{ hasLoaded, loading, hasError, errorMessage, status, deployId, results }, dispatch] = useReducer(reducer, {
hasLoaded: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function reducer(state: State, action: Action): State {
* @param changesetName
*/
export function useDeployMetadataPackage(destinationOrg: SalesforceOrgUi, deployOptions: DeployOptions, file: ArrayBuffer) {
const isMounted = useRef(null);
const isMounted = useRef(true);

const [{ hasLoaded, loading, hasError, errorMessage, status, deployId, results }, dispatch] = useReducer(reducer, {
hasLoaded: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function useUsers(
sortCurrentUserFirst = true,
loadOnInit = true
) {
const isMounted = useRef(null);
const isMounted = useRef(true);
const [lastRefreshed, setLastRefreshed] = useState<string>(_lastRefreshed);

const [{ hasLoaded, loading, data, hasError, errorMessage }, dispatch] = useReducer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export const ViewOrCompareMetadataModal: FunctionComponent<ViewOrCompareMetadata

const [activeFile, setActiveFile] = useState<TreeItems<FileItemMetadata | null>>(null);
const [activeFileType, setActiveFileType] = useState<string>('xml');
const [activeSourceContent, setActiveSourceContent] = useState<string>(null);
const [activeTargetContent, setActiveTargetContent] = useState<string>(null);
const [activeSourceContent, setActiveSourceContent] = useState<string | null>(null);
const [activeTargetContent, setActiveTargetContent] = useState<string | null>(null);
const [editorType, setEditorType] = useState<EditorType>('SOURCE');
const [swapped, setSwapped] = useState(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function reducer(state: State, action: Action): State {
* @param changesetName
*/
export function useViewOrCompareMetadata({ selectedMetadata }: { selectedMetadata: MapOf<ListMetadataResult[]> }) {
const isMounted = useRef(null);
const isMounted = useRef(true);

const [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ export interface FormulaEvaluatorProps {}

export const FormulaEvaluator: FunctionComponent<FormulaEvaluatorProps> = () => {
useTitle(TITLES.FORMULA_EVALUATOR);
const isMounted = useRef(null);
const isMounted = useRef(true);
const editorRef = useRef<editor.IStandaloneCodeEditor>(null);
const sobjectComboRef = useRef<SobjectComboboxRef>(null);
const fieldsComboRef = useRef<SobjectFieldComboboxRef>(null);
const { trackEvent } = useAmplitude();
const selectedOrg = useRecoilValue<SalesforceOrgUi>(selectedOrgState);
const [loading, setLoading] = useState(false);
const [refreshLoading, setRefreshLoading] = useState(false);
const [fieldErrorMessage, setFieldErrorMessage] = useState<string>(null);
const [errorMessage, setErrorMessage] = useState<string>(null);
const [fieldErrorMessage, setFieldErrorMessage] = useState<string | null>(null);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [formulaValue, setFormulaValue] = useRecoilState(fromFormulaState.formulaValueState);
const [selectedSObject, setSelectedSobject] = useRecoilState(fromFormulaState.selectedSObjectState);
const [selectedField, setSelectedField] = useRecoilState(fromFormulaState.selectedFieldState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface LoadRecordsMultiObjectProps {

export const LoadRecordsMultiObject: FunctionComponent<LoadRecordsMultiObjectProps> = ({ featureFlags }) => {
useTitle(TITLES.LOAD);
const isMounted = useRef(null);
const isMounted = useRef(true);
const { trackEvent } = useAmplitude();
const selectedOrg = useRecoilValue<SalesforceOrgUi>(selectedOrgState);
const orgType = useRecoilValue(selectedOrgType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const useLoadFile = (org: SalesforceOrgUi, serverUrl: string, apiVersion:
finished: false,
});

const isMounted = useRef<boolean>(null);
const isMounted = useRef(true);

useEffect(() => {
isMounted.current = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const useValidateLoadFile = (org: SalesforceOrgUi, apiVersion: string, op
errors: [],
});

const isMounted = useRef<boolean>(null);
const isMounted = useRef(true);

useEffect(() => {
isMounted.current = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface LoadRecordsProps {

export const LoadRecords: FunctionComponent<LoadRecordsProps> = ({ featureFlags }) => {
useTitle(TITLES.LOAD);
const isMounted = useRef(null);
const isMounted = useRef(true);
const { trackEvent } = useAmplitude();
const [{ defaultApiVersion, serverUrl, google_apiKey, google_appId, google_clientId }] = useRecoilState(applicationCookieState);
const googleApiConfig = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const LoadRecordsAssignmentRules: FunctionComponent<LoadRecordsAssignment
selectedSObject,
onAssignmentRule,
}) => {
const isMounted = useRef(null);
const isMounted = useRef(true);
const [picklistKey, setPickListKey] = useState(currKey);
const [loading, setLoading] = useState(false);
const [useAssignmentRules, setUseAssignmentRules] = useState(false);
Expand Down
Loading

0 comments on commit b14cca4

Please sign in to comment.