Skip to content

Commit

Permalink
#9242: migrate unsaved standalone mod components in the Page Editor (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
twschiller authored Oct 8, 2024
1 parent b0027a6 commit 91ceceb
Show file tree
Hide file tree
Showing 48 changed files with 477 additions and 1,190 deletions.
7 changes: 5 additions & 2 deletions src/analysis/analysisVisitors/varAnalysis/varAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { getOutputReference, isOutputKey } from "@/runtime/runtimeTypes";
import { assertNotNullish } from "@/utils/nullishUtils";
import { BusinessError } from "@/errors/businessErrors";
import { adapterForComponent } from "@/pageEditor/starterBricks/adapter";
import { isInnerDefinitionRegistryId } from "@/types/helpers";

export const INVALID_VARIABLE_GENERIC_MESSAGE = "Invalid variable name";

Expand Down Expand Up @@ -305,11 +306,13 @@ async function setOptionsVars(
formState: ModComponentFormState,
contextVars: VarMap,
): Promise<void> {
if (formState.modMetadata == null) {
const modId = formState.modMetadata.id;

// Mod is unsaved, so definition won't be in the registry
if (isInnerDefinitionRegistryId(modId)) {
return;
}

const modId = formState.modMetadata.id;
const mod = await modRegistry.lookup(modId);
const optionsSchema = mod?.options?.schema;
if (isEmpty(optionsSchema)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import { validateOutputKey } from "@/runtime/runtimeTypes";
import { toExpression } from "@/utils/expressionUtils";
import { normalizeAvailability } from "@/bricks/available";
import { StarterBrickTypes } from "@/types/starterBrickTypes";
import { emptyModVariablesDefinitionFactory } from "@/utils/modUtils";
import {
createNewUnsavedModMetadata,
emptyModVariablesDefinitionFactory,
} from "@/utils/modUtils";

describe("selectVariables", () => {
test("selects nothing when no services used", () => {
Expand Down Expand Up @@ -224,7 +227,7 @@ describe("selectVariables", () => {
permissions: emptyPermissionsFactory(),
optionsArgs: {},
variablesDefinition: emptyModVariablesDefinitionFactory(),
modMetadata: undefined,
modMetadata: createNewUnsavedModMetadata({ modName: "Document Mod" }),
modComponent: {
brickPipeline: [
{
Expand Down
19 changes: 10 additions & 9 deletions src/pageEditor/hooks/useAddNewModComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,20 @@ function useAddNewModComponent(modMetadata?: ModMetadata): AddNewModComponent {
setInsertingStarterBrickType(null);
}

const url = await getCurrentInspectedURL();
const metadata = internalStarterBrickMetaFactory();
const initialFormState = fromNativeElement(url, metadata, element);
const initialFormState = fromNativeElement({
url: await getCurrentInspectedURL(),
starterBrickMetadata: internalStarterBrickMetaFactory(),
modMetadata:
modMetadata ??
createNewUnsavedModMetadata({
modName: generateFreshModName(),
}),
element,
});

initialFormState.modComponent.brickPipeline =
getExampleBrickPipeline(starterBrickType);

initialFormState.modMetadata =
modMetadata ??
createNewUnsavedModMetadata({
modName: generateFreshModName(),
});

return initialFormState as ModComponentFormState;
},
[
Expand Down
2 changes: 1 addition & 1 deletion src/pageEditor/hooks/useClearModChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function useClearModChanges(): (modId: RegistryId) => Promise<void> {

await Promise.all(
modComponentFormStates
.filter((x) => x.modMetadata?.id === modId)
.filter((x) => x.modMetadata.id === modId)
.map(async (modComponentFormState) =>
clearModComponentChanges({
modComponentId: modComponentFormState.uuid,
Expand Down
277 changes: 0 additions & 277 deletions src/pageEditor/hooks/useMigrateStandaloneComponentsToMods.test.ts

This file was deleted.

Loading

0 comments on commit 91ceceb

Please sign in to comment.