Skip to content

Commit

Permalink
undo input changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Loe committed Sep 9, 2024
1 parent de4db2a commit 3956ee7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 35 deletions.
52 changes: 24 additions & 28 deletions src/pageEditor/hooks/useBuildAndValidateMod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,37 +80,33 @@ function useBuildAndValidateMod(): UseBuildAndValidateModReturn {
dirtyModMetadata,
});

if (sourceMod != null) {
const modComponentDefinitionCountsMatch =
compareModComponentCountsToModDefinition(newMod, {
sourceModDefinition: sourceMod,
newModComponentFormState,
});
const modComponentDefinitionCountsMatch =
compareModComponentCountsToModDefinition(newMod, {
sourceModDefinition: sourceMod,
newModComponentFormState,
});

const modComponentStarterBricksMatch =
await checkModStarterBrickInvariants(newMod, {
sourceModDefinition: sourceMod,
newModComponentFormState,
});
const modComponentStarterBricksMatch =
await checkModStarterBrickInvariants(newMod, {
sourceModDefinition: sourceMod,
newModComponentFormState,
});

if (
!modComponentDefinitionCountsMatch ||
!modComponentStarterBricksMatch
) {
// Not including modDefinition because it can be 1.5MB+ in some rare cases
// See discussion: https://github.com/pixiebrix/pixiebrix-extension/pull/7629/files#r1492864349
reportEvent(Events.PAGE_EDITOR_MOD_SAVE_ERROR, {
// Metadata is an object, but doesn't extend JsonObject so typescript doesn't like it
modMetadata: newMod.metadata as unknown as JsonObject,
modComponentDefinitionCountsMatch,
modComponentStarterBricksMatch,
});
dispatch(editorActions.showSaveDataIntegrityErrorModal());
if (
!modComponentDefinitionCountsMatch ||
!modComponentStarterBricksMatch
) {
// Not including modDefinition because it can be 1.5MB+ in some rare cases
// See discussion: https://github.com/pixiebrix/pixiebrix-extension/pull/7629/files#r1492864349
reportEvent(Events.PAGE_EDITOR_MOD_SAVE_ERROR, {
// Metadata is an object, but doesn't extend JsonObject so typescript doesn't like it
modMetadata: newMod.metadata as unknown as JsonObject,
modComponentDefinitionCountsMatch,
modComponentStarterBricksMatch,
});
dispatch(editorActions.showSaveDataIntegrityErrorModal());

throw new BusinessError(
"Mod save failed due to data integrity error",
);
}
throw new BusinessError("Mod save failed due to data integrity error");
}

return newMod;
Expand Down
14 changes: 7 additions & 7 deletions src/pageEditor/hooks/useCompareModComponentCounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ type SourceModParts = {
newModComponentFormState?: ModComponentFormState;
};

type RequiredModParts = Required<
Pick<SourceModParts, "sourceModDefinition" | "newModComponentFormState">
>;

/**
* @returns A function that compares the number of mod components in the redux state and the mod definition
*/
function useCompareModComponentCounts(): (
unsavedModDefinition: UnsavedModDefinition,
{ sourceModDefinition, newModComponentFormState }: RequiredModParts,
{ sourceModDefinition, newModComponentFormState }: SourceModParts,
) => boolean {
const getCleanComponentsAndDirtyFormStatesForMod = useSelector(
selectGetCleanComponentsAndDirtyFormStatesForMod,
Expand All @@ -47,9 +43,13 @@ function useCompareModComponentCounts(): (
return useCallback(
(
unsavedModDefinition: UnsavedModDefinition,
{ sourceModDefinition, newModComponentFormState }: RequiredModParts,
{ sourceModDefinition, newModComponentFormState }: SourceModParts,
) => {
const modId = sourceModDefinition.metadata.id;
// Always compare to the pre-existing mod if it exists
const modId = sourceModDefinition
? sourceModDefinition.metadata.id
: // See useCreateModFromModComponent.ts for an example where there is no sourceModDefinition
unsavedModDefinition.metadata.id;
const { cleanModComponents, dirtyModComponentFormStates } =
getCleanComponentsAndDirtyFormStatesForMod(modId);

Expand Down

0 comments on commit 3956ee7

Please sign in to comment.