Skip to content

Commit

Permalink
Add option to dry-run data load
Browse files Browse the repository at this point in the history
resolves #330
  • Loading branch information
paustint committed Aug 20, 2023
1 parent 45fd903 commit 96b6a45
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 70 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 resetDryRunState = useResetRecoilState(fromLoadRecordsState.dryRunState);
const resetDryRunSizeState = useResetRecoilState(fromLoadRecordsState.dryRunSizeState);

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

useEffect(() => {
Expand Down Expand Up @@ -382,10 +381,10 @@ export const LoadRecords: FunctionComponent<LoadRecordsProps> = ({ featureFlags
setExternalId('');
resetApiModeState();
resetBatchSizeState();
resetBatchSizeErrorState();
resetInsertNullsState();
resetSerialModeState();
resetDateFormatState();
resetDryRunState();
resetDryRunSizeState();
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
Expand Up @@ -169,11 +169,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 +179,26 @@ export const serialModeState = atom({
default: false,
});

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

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

export const dateFormatState = atom({
key: 'dateFormatState',
default: DATE_FORMATS.MM_DD_YYYY,
default: localStorage.getItem('LOADER_DATE_FORMAT') || DATE_FORMATS.MM_DD_YYYY,
effects: [
({ onSet }) => {
onSet((value) => {
localStorage.setItem('LOADER_DATE_FORMAT', value);
});
},
],
});

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

export const selectDryRunSizeError = selector<string | null>({
key: 'load.selectDryRunSizeError',
get: ({ get }) => {
const inputLength = get(inputFileDataState)?.length || 1;
const dryRunSize = get(dryRunSizeState) || 1;
if (!isNumber(dryRunSize) || dryRunSize <= 0 || dryRunSize >= 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 96b6a45

Please sign in to comment.