Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#9242: migrate unsaved standalone mod components in the Page Editor #9246

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 0 additions & 2 deletions src/background/deploymentUpdater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,9 @@ describe("syncDeployments", () => {
};
registryFindMock.mockResolvedValue(brick);

// An extension without a recipe. Exclude _recipe entirely to handle the case where the property is missing
const modComponent = modComponentFactory({
extensionPointId: starterBrick.metadata!.id,
}) as ActivatedModComponent;
delete modComponent._recipe;
delete modComponent._deployment;

await saveModComponentState({
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
Loading