Skip to content

Commit

Permalink
Merge pull request #530 from jetstreamapp/feat/330
Browse files Browse the repository at this point in the history
Allow dry run of data load #330
  • Loading branch information
paustint authored Dec 3, 2023
2 parents 27b6298 + 1a61343 commit 75a0522
Show file tree
Hide file tree
Showing 10 changed files with 308 additions and 85 deletions.
25 changes: 12 additions & 13 deletions apps/jetstream/src/app/components/load-records/LoadRecords.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ export const LoadRecords: FunctionComponent<LoadRecordsProps> = ({ featureFlags

const resetApiModeState = useResetRecoilState(fromLoadRecordsState.apiModeState);
const resetBatchSizeState = useResetRecoilState(fromLoadRecordsState.batchSizeState);
const resetBatchSizeErrorState = useResetRecoilState(fromLoadRecordsState.batchSizeErrorState);
const resetInsertNullsState = useResetRecoilState(fromLoadRecordsState.insertNullsState);
const resetSerialModeState = useResetRecoilState(fromLoadRecordsState.serialModeState);
const resetDateFormatState = useResetRecoilState(fromLoadRecordsState.dateFormatState);
const resetTrialRunState = useResetRecoilState(fromLoadRecordsState.trialRunState);
const resetTrialRunSizeState = useResetRecoilState(fromLoadRecordsState.trialRunSizeState);

useEffect(() => {
isMounted.current = true;
Expand All @@ -137,17 +137,16 @@ export const LoadRecords: FunctionComponent<LoadRecordsProps> = ({ featureFlags
setBatchSize(getMaxBatchSize(apiMode));
setSerialMode(apiMode === 'BATCH');

resetBatchSizeErrorState();
resetInsertNullsState();
resetDateFormatState();
resetTrialRunState();
resetTrialRunSizeState();
}, [
inputFileData,
inputZipFileData,
resetBatchSizeErrorState,
resetBatchSizeState,
resetDateFormatState,
resetTrialRunSizeState,
resetTrialRunState,
resetInsertNullsState,
resetSerialModeState,
setApiMode,
setBatchSize,
setSerialMode,
Expand All @@ -168,10 +167,10 @@ export const LoadRecords: FunctionComponent<LoadRecordsProps> = ({ featureFlags
resetInputZipFilename();
resetApiModeState();
resetBatchSizeState();
resetBatchSizeErrorState();
resetInsertNullsState();
resetSerialModeState();
resetDateFormatState();
resetTrialRunState();
resetTrialRunSizeState();
}
};
}, [
Expand All @@ -187,10 +186,10 @@ export const LoadRecords: FunctionComponent<LoadRecordsProps> = ({ featureFlags
resetInputZipFilename,
resetApiModeState,
resetBatchSizeState,
resetBatchSizeErrorState,
resetInsertNullsState,
resetSerialModeState,
resetDateFormatState,
resetTrialRunState,
resetTrialRunSizeState,
]);

useEffect(() => {
Expand Down Expand Up @@ -382,10 +381,10 @@ export const LoadRecords: FunctionComponent<LoadRecordsProps> = ({ featureFlags
setExternalId('');
resetApiModeState();
resetBatchSizeState();
resetBatchSizeErrorState();
resetInsertNullsState();
resetSerialModeState();
resetDateFormatState();
resetTrialRunState();
resetTrialRunSizeState();
trackEvent(ANALYTICS_KEYS.load_StartOver, { page: currentStep.name });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const LoadRecordsResults: FunctionComponent<LoadRecordsResultsProps> = ({
onFinish,
}) => {
return (
<div>
<div className="slds-m-bottom_medium">
{apiMode === 'BULK' && (
<LoadRecordsBulkApiResults
selectedOrg={selectedOrg}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logger } from '@jetstream/shared/client-logger';
import { DATE_FORMATS, INDEXED_DB } from '@jetstream/shared/constants';
import { formatNumber } from '@jetstream/shared/ui-utils';
import { INDEXED_DB } from '@jetstream/shared/constants';
import { detectDateFormatForLocale, formatNumber } from '@jetstream/shared/ui-utils';
import { InsertUpdateUpsertDelete, MapOf, Maybe } from '@jetstream/types';
import type { DescribeGlobalSObjectResult } from 'jsforce';
import localforage from 'localforage';
Expand All @@ -20,6 +20,7 @@ const SUPPORTED_ATTACHMENT_OBJECTS = new Map<string, { bodyField: string }>();
SUPPORTED_ATTACHMENT_OBJECTS.set('Attachment', { bodyField: 'Body' });
SUPPORTED_ATTACHMENT_OBJECTS.set('Document', { bodyField: 'Body' });
SUPPORTED_ATTACHMENT_OBJECTS.set('ContentVersion', { bodyField: 'VersionData' });
const DATE_FIELDS = new Set(['date', 'datetime']);

export interface LoadSavedMappingItem {
key: string; // object:createdDate
Expand Down Expand Up @@ -169,11 +170,6 @@ export const batchSizeState = atom<Maybe<number>>({
default: MAX_BULK,
});

export const batchSizeErrorState = atom<Maybe<string>>({
key: 'batchSizeErrorState',
default: null,
});

export const insertNullsState = atom({
key: 'insertNullsState',
default: false,
Expand All @@ -184,9 +180,24 @@ export const serialModeState = atom({
default: false,
});

export const trialRunState = atom({
key: 'trialRunState',
default: false,
});

export const trialRunSizeState = atom<Maybe<number>>({
key: 'trialRunSizeState',
default: 1,
});

export const dateFormatState = atom({
key: 'dateFormatState',
default: DATE_FORMATS.MM_DD_YYYY,
default: detectDateFormatForLocale(),
});

export const selectHasDateFieldMapped = selector({
key: 'load.selectHasDateFieldMapped',
get: ({ get }) => Object.values(get(fieldMappingState)).some((item) => item.fieldMetadata && DATE_FIELDS.has(item.fieldMetadata.type)),
});

export const selectBatchSizeError = selector<string | null>({
Expand Down Expand Up @@ -218,6 +229,18 @@ export const selectBatchApiLimitError = selector<string | null>({
},
});

export const selectTrialRunSizeError = selector<string | null>({
key: 'load.selectTrialRunSizeError',
get: ({ get }) => {
const inputLength = get(inputFileDataState)?.length || 1;
const trialRunSize = get(trialRunSizeState) || 1;
if (!isNumber(trialRunSize) || trialRunSize <= 0 || trialRunSize >= inputLength) {
return `Must be between 1 and ${formatNumber(inputLength - 1)}`;
}
return null;
},
});

export const selectBulkApiModeLabel = selector<string | JSX.Element>({
key: 'load.selectBulkApiModeLabel',
get: ({ get }) => {
Expand Down
Loading

0 comments on commit 75a0522

Please sign in to comment.