Skip to content

Commit

Permalink
mod -> modMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamlangford committed Jul 1, 2024
1 parent 26229d1 commit e62f523
Show file tree
Hide file tree
Showing 42 changed files with 131 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ describe("PageStateAnalysis", () => {
},
]);

state.mod = { id: registryIdFactory() } as BaseFormState["mod"];
state.modMetadata = {
id: registryIdFactory(),
} as BaseFormState["modMetadata"];

const analysis = new PageStateAnalysis();
await analysis.run(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class PageStateVisitor extends AnalysisVisitorWithResolvedBricksABC {
}

override async run(formState: ModComponentFormState): Promise<void> {
this.isInMod = Boolean(formState.mod);
this.isInMod = Boolean(formState.modMetadata);
await super.run(formState);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/analysis/analysisVisitors/varAnalysis/varAnalysis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe("Collecting available vars", () => {
optionsArgs: {
foo: "bar",
},
mod: modMetadataFactory({
modMetadata: modMetadataFactory({
id: validateRegistryId("test/mod"),
}),
},
Expand Down Expand Up @@ -308,7 +308,7 @@ describe("Collecting available vars", () => {

const formState = formStateFactory(
{
mod: modMetadataFactory({
modMetadata: modMetadataFactory({
id: validateRegistryId("test/mod"),
}),
},
Expand Down Expand Up @@ -343,7 +343,7 @@ describe("Collecting available vars", () => {
bar: "qux",
baz: "quux",
},
mod: modMetadataFactory({
modMetadata: modMetadataFactory({
id: validateRegistryId("test/mod"),
}),
},
Expand Down Expand Up @@ -379,7 +379,7 @@ describe("Collecting available vars", () => {

const formState = formStateFactory(
{
mod: modMetadataFactory({
modMetadata: modMetadataFactory({
id: validateRegistryId("test/mod"),
}),
},
Expand Down Expand Up @@ -409,7 +409,7 @@ describe("Collecting available vars", () => {

const formState = formStateFactory(
{
mod: modMetadataFactory({
modMetadata: modMetadataFactory({
id: validateRegistryId("test/mod"),
}),
optionsArgs: {
Expand Down
4 changes: 2 additions & 2 deletions src/analysis/analysisVisitors/varAnalysis/varAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ async function setOptionsVars(
formState: ModComponentFormState,
contextVars: VarMap,
): Promise<void> {
if (formState.mod == null) {
if (formState.modMetadata == null) {
return;
}

const modId = formState.mod.id;
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 @@ -210,7 +210,7 @@ describe("selectVariables", () => {
permissions: emptyPermissionsFactory(),
optionsArgs: {},
type: "actionPanel",
mod: null,
modMetadata: null,
modComponent: {
blockPipeline: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const VarMenu: React.FunctionComponent<VarMenuProps> = ({
getPageState(inspectedTab, {
namespace: StateNamespaces.MOD,
modComponentId: null,
modId: activeModComponentFormState.mod?.id,
modId: activeModComponentFormState.modMetadata?.id,
}),
[],
);
Expand Down
8 changes: 4 additions & 4 deletions src/pageEditor/analysisManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ async function selectActiveModFormStates(
): Promise<ModComponentFormState[]> {
const activeModComponentFormState = selectActiveModComponentFormState(state);

if (activeModComponentFormState?.mod) {
if (activeModComponentFormState?.modMetadata) {
const dirtyModComponentFormStates =
state.editor.modComponentFormStates.filter(
(x) => x.mod?.id === activeModComponentFormState.mod.id,
(x) => x.modMetadata?.id === activeModComponentFormState.modMetadata.id,
);
const dirtyIds = new Set(dirtyModComponentFormStates.map((x) => x.uuid));

const activatedModComponents = selectActivatedModComponents(state);
const otherModComponents = activatedModComponents.filter(
(x) =>
x._recipe?.id === activeModComponentFormState.mod.id &&
x._recipe?.id === activeModComponentFormState.modMetadata.id &&
!dirtyIds.has(x.id),
);
const otherModComponentFormStates = await Promise.all(
Expand Down Expand Up @@ -215,7 +215,7 @@ async function varAnalysisFactory(
const modState = await getPageState(inspectedTab, {
namespace: StateNamespaces.MOD,
modComponentId: activeModComponentFormState.uuid,
modId: activeModComponentFormState.mod?.id,
modId: activeModComponentFormState.modMetadata?.id,
});

return new VarAnalysis({
Expand Down
13 changes: 9 additions & 4 deletions src/pageEditor/baseFormStateTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,25 @@ export type BaseFormStateV3<
* @since 2.0.5
* Part of the Page Editor renaming effort
* `extensionPoint` to `starterBrick`
* `extension` to `modComponent`
* `recipe` to `mod`
*/

starterBrick: TStarterBrick;

/**
* @since 2.0.5
* Part of the Page Editor renaming effort
* `extension` to `modComponent`
*/
modComponent: TModComponent;

/**
* @since 2.0.5
* Part of the Page Editor renaming effort
* `recipe` to `modMetadata`
* Information about the mod used to install the mod component, or `undefined`
* if the mod component is not part of a mod.
* @see ModComponentBase._recipe
*/
mod: ModComponentBase["_recipe"] | undefined;
modMetadata: ModComponentBase["_recipe"] | undefined;
};

export type BaseFormState<
Expand Down
2 changes: 1 addition & 1 deletion src/pageEditor/hooks/useBuildAndValidateMod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe("useBuildAndValidateMod", () => {
});

const dirtyFormState1 = formStateFactory({
mod: modMetadata,
modMetadata,
});

const { result, getReduxStore } = renderHook(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ describe("useCheckModStarterBrickInvariants", () => {
integrationDependencies: [],
});
const formState = await modComponentToFormState(activatedModComponent);
delete formState.mod;
delete formState.modMetadata;

const { result } = renderHook(() => useCheckModStarterBrickInvariants(), {
setupRedux(dispatch) {
Expand Down
20 changes: 10 additions & 10 deletions src/pageEditor/hooks/useCompareModComponentCounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("useCompareModComponentCounts", () => {
metadata: modMetadata,
});
const formState = formStateFactory({
mod: modMetadata,
modMetadata: modMetadata,

Check failure on line 54 in src/pageEditor/hooks/useCompareModComponentCounts.test.ts

View workflow job for this annotation

GitHub Actions / lint

Expected property shorthand
});

const { result } = renderHook(() => useCompareModComponentCounts(), {
Expand Down Expand Up @@ -95,7 +95,7 @@ describe("useCompareModComponentCounts", () => {
});

const dirtyFormState = formStateFactory({
mod: modMetadata,
modMetadata: modMetadata,

Check failure on line 98 in src/pageEditor/hooks/useCompareModComponentCounts.test.ts

View workflow job for this annotation

GitHub Actions / lint

Expected property shorthand
});

const { result } = renderHook(() => useCompareModComponentCounts(), {
Expand Down Expand Up @@ -130,10 +130,10 @@ describe("useCompareModComponentCounts", () => {
});

const dirtyFormState1 = formStateFactory({
mod: modMetadata,
modMetadata: modMetadata,

Check failure on line 133 in src/pageEditor/hooks/useCompareModComponentCounts.test.ts

View workflow job for this annotation

GitHub Actions / lint

Expected property shorthand
});
const dirtyFormState2 = formStateFactory({
mod: modMetadata,
modMetadata: modMetadata,

Check failure on line 136 in src/pageEditor/hooks/useCompareModComponentCounts.test.ts

View workflow job for this annotation

GitHub Actions / lint

Expected property shorthand
});

const { result } = renderHook(() => useCompareModComponentCounts(), {
Expand Down Expand Up @@ -163,7 +163,7 @@ describe("useCompareModComponentCounts", () => {
metadata: modMetadata,
});
const formState = formStateFactory({
mod: modMetadata,
modMetadata: modMetadata,

Check failure on line 166 in src/pageEditor/hooks/useCompareModComponentCounts.test.ts

View workflow job for this annotation

GitHub Actions / lint

Expected property shorthand
});

const { result } = renderHook(() => useCompareModComponentCounts(), {
Expand Down Expand Up @@ -193,7 +193,7 @@ describe("useCompareModComponentCounts", () => {
});

const formState = formStateFactory({
mod: modMetadata,
modMetadata: modMetadata,

Check failure on line 196 in src/pageEditor/hooks/useCompareModComponentCounts.test.ts

View workflow job for this annotation

GitHub Actions / lint

Expected property shorthand
});

const { result } = renderHook(() => useCompareModComponentCounts(), {
Expand Down Expand Up @@ -282,7 +282,7 @@ describe("useCompareModComponentCounts", () => {
});

const formState = formStateFactory({
mod: modMetadata,
modMetadata: modMetadata,

Check failure on line 285 in src/pageEditor/hooks/useCompareModComponentCounts.test.ts

View workflow job for this annotation

GitHub Actions / lint

Expected property shorthand
});

const { result } = renderHook(() => useCompareModComponentCounts(), {
Expand Down Expand Up @@ -313,7 +313,7 @@ describe("useCompareModComponentCounts", () => {
});

const formState = formStateFactory({
mod: modMetadata,
modMetadata: modMetadata,

Check failure on line 316 in src/pageEditor/hooks/useCompareModComponentCounts.test.ts

View workflow job for this annotation

GitHub Actions / lint

Expected property shorthand
});

const { result } = renderHook(() => useCompareModComponentCounts(), {
Expand Down Expand Up @@ -344,7 +344,7 @@ describe("useCompareModComponentCounts", () => {
});

const formState = formStateFactory({
mod: modMetadata,
modMetadata: modMetadata,

Check failure on line 347 in src/pageEditor/hooks/useCompareModComponentCounts.test.ts

View workflow job for this annotation

GitHub Actions / lint

Expected property shorthand
});

const { result } = renderHook(() => useCompareModComponentCounts(), {
Expand Down Expand Up @@ -375,7 +375,7 @@ describe("useCompareModComponentCounts", () => {
});

const formState = formStateFactory({
mod: modMetadata,
modMetadata: modMetadata,

Check failure on line 378 in src/pageEditor/hooks/useCompareModComponentCounts.test.ts

View workflow job for this annotation

GitHub Actions / lint

Expected property shorthand
});

const { result } = renderHook(() => useCompareModComponentCounts(), {
Expand Down
12 changes: 9 additions & 3 deletions src/pageEditor/hooks/useCreateModFromModComponent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ describe("useCreateModFromModComponent", () => {

it("saves with no dirty changes", async () => {
const metadata = modMetadataFactory();
const menuItemFormState = menuItemFormStateFactory({ mod: metadata });
const menuItemFormState = menuItemFormStateFactory({
modMetadata: metadata,
});

appApiMock
.onPost("/api/bricks/")
Expand All @@ -75,7 +77,9 @@ describe("useCreateModFromModComponent", () => {
it("does not throw an error if the mod fails the compareModComponentCounts check", async () => {
compareModComponentCountsMock.mockReturnValue(() => false);
const metadata = modMetadataFactory();
const menuItemFormState = menuItemFormStateFactory({ mod: metadata });
const menuItemFormState = menuItemFormStateFactory({
modMetadata: metadata,
});

appApiMock
.onPost("/api/bricks/")
Expand All @@ -95,7 +99,9 @@ describe("useCreateModFromModComponent", () => {
it("does not throw an error if the mod fails the checkModStarterBrickInvariants check", async () => {
checkModStarterBrickInvariantsMock.mockReturnValue(async () => false);
const metadata = modMetadataFactory();
const menuItemFormState = menuItemFormStateFactory({ mod: metadata });
const menuItemFormState = menuItemFormStateFactory({
modMetadata: metadata,
});

appApiMock
.onPost("/api/bricks/")
Expand Down
5 changes: 4 additions & 1 deletion src/pageEditor/hooks/useCreateModFromModComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ function useCreateModFromModComponent(
}).unwrap();

const newModComponent = produce(newModComponentFormState, (draft) => {
draft.mod = selectModMetadata(newModDefinition, upsertResponse);
draft.modMetadata = selectModMetadata(
newModDefinition,
upsertResponse,
);
});

dispatch(editorActions.addModComponentFormState(newModComponent));
Expand Down
3 changes: 2 additions & 1 deletion src/pageEditor/hooks/useResetMod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ function useResetMod(): (modId: RegistryId) => Promise<void> {
await Promise.all(
modComponentFormStates
.filter(
(modComponentFormState) => modComponentFormState.mod?.id === modId,
(modComponentFormState) =>
modComponentFormState.modMetadata?.id === modId,
)
.map(async (modComponentFormState) =>
resetModComponent({
Expand Down
6 changes: 3 additions & 3 deletions src/pageEditor/panes/EditorPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ const EditorPaneContent: React.VoidFunctionComponent<{
useEffect(() => {
const messageContext = {
extensionId: modComponentFormState.uuid,
blueprintId: modComponentFormState.mod
? modComponentFormState.mod.id
blueprintId: modComponentFormState.modMetadata
? modComponentFormState.modMetadata.id
: undefined,
};
dispatch(logActions.setContext(messageContext));
}, [modComponentFormState.uuid, modComponentFormState.mod, dispatch]);
}, [modComponentFormState.uuid, modComponentFormState.modMetadata, dispatch]);

return (
<IntegrationsSliceModIntegrationsContextAdapter>
Expand Down
2 changes: 1 addition & 1 deletion src/pageEditor/sidebar/ActivatedModComponentListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const ActivatedModComponentListItem: React.FunctionComponent<{
);
const isActive = activeModComponentFormState?.uuid === modComponent.id;
// Get the selected mod id, or the mod id of the selected mod component
const modId = activeModId ?? activeModComponentFormState?.mod?.id;
const modId = activeModId ?? activeModComponentFormState?.modMetadata?.id;
// Set the alternate background if this item isn't active, but either its mod or another item in its mod is active
const hasActiveModBackground =
!isActive && modId && modComponent._recipe?.id === modId;
Expand Down
16 changes: 8 additions & 8 deletions src/pageEditor/sidebar/DraftModComponentListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ const DraftModComponentListItem: React.FunctionComponent<

const isActive =
activeModComponentFormState?.uuid === modComponentFormState.uuid;
const modId = modComponentFormState.mod?.id;
const isSiblingOfActiveListItem = activeModComponentFormState?.mod?.id
? modId === activeModComponentFormState?.mod?.id
const modId = modComponentFormState.modMetadata?.id;
const isSiblingOfActiveListItem = activeModComponentFormState?.modMetadata?.id
? modId === activeModComponentFormState?.modMetadata?.id
: false;
const isChildOfActiveListItem = modId === activeModId;
const isRelativeOfActiveListItem =
Expand Down Expand Up @@ -125,14 +125,14 @@ const DraftModComponentListItem: React.FunctionComponent<
});

const onSave = async () => {
if (modComponentFormState.mod) {
await saveMod(modComponentFormState.mod?.id);
if (modComponentFormState.modMetadata) {
await saveMod(modComponentFormState.modMetadata?.id);
} else {
await saveStandaloneModComponent(modComponentFormState);
}
};

const isSaving = modComponentFormState.mod
const isSaving = modComponentFormState.modMetadata
? isSavingMod
: isSavingStandaloneModComponent;

Expand Down Expand Up @@ -209,14 +209,14 @@ const DraftModComponentListItem: React.FunctionComponent<
onReset={modComponentFormState.installed ? onReset : undefined}
isDirty={isDirty}
onAddToMod={
modComponentFormState.mod
modComponentFormState.modMetadata
? undefined
: async () => {
dispatch(actions.showAddToModModal());
}
}
onRemoveFromMod={
modComponentFormState.mod
modComponentFormState.modMetadata
? async () => {
dispatch(actions.showRemoveFromModModal());
}
Expand Down
3 changes: 2 additions & 1 deletion src/pageEditor/sidebar/ModListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ const ModListItem: React.FC<ModListItemProps> = ({
const latestModVersion = modDefinition?.metadata?.version;

// Set the alternate background if a mod component in this mod is active
const hasModBackground = activeModComponentFormState?.mod?.id === modId;
const hasModBackground =
activeModComponentFormState?.modMetadata?.id === modId;

const dirtyName = useSelector(selectDirtyMetadataForModId(modId))?.name;
const name = dirtyName ?? savedName ?? "Loading...";
Expand Down
Loading

0 comments on commit e62f523

Please sign in to comment.