Skip to content

Commit

Permalink
#8613: rename remaining instances of term installed in the page editor (
Browse files Browse the repository at this point in the history
#8743)

* installed -> activated

* ts fixes

* fix mocks

* more renaming

* more renaming

* more renaming

* fix failing unit test; cleanup code

* more renaming

* removes pointless comment
  • Loading branch information
grahamlangford authored Jul 2, 2024
1 parent 04144c1 commit 4e46ac6
Show file tree
Hide file tree
Showing 44 changed files with 245 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export const uninstallMod = jest.fn();
export const uninstallModComponents = jest.fn();
export const deactivateMod = jest.fn();
export const deactivateModComponents = jest.fn();
export const removeModComponentsFromAllTabs = jest.fn();
2 changes: 1 addition & 1 deletion src/activation/activationLinkUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function createActivationRelativeUrl(
}

for (const mod of mods) {
// `id[]` syntax works in extension both single and multiple values
// `id[]` syntax works in mod component both single and multiple values
searchParams.append("id[]", mod.modId);
}

Expand Down
38 changes: 19 additions & 19 deletions src/activation/useActivateMod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import useActivateMod from "./useActivateMod";
import { validateRegistryId } from "@/types/helpers";
import { type StarterBrickDefinitionLike } from "@/starterBricks/types";
import { type ContextMenuDefinition } from "@/starterBricks/contextMenu/contextMenuTypes";
import { uninstallMod } from "@/store/uninstallUtils";
import { deactivateMod } from "@/store/deactivateUtils";
import { type ModDefinition } from "@/types/modDefinitionTypes";
import extensionsSlice from "@/store/extensionsSlice";
import modComponentsSlice from "@/store/extensionsSlice";
import { type InnerDefinitions } from "@/types/registryTypes";
import { checkModDefinitionPermissions } from "@/modDefinitions/modDefinitionPermissionsHelpers";
import { emptyPermissionsFactory } from "@/permissions/permissionsUtils";
Expand All @@ -43,15 +43,15 @@ import type MockAdapter from "axios-mock-adapter";
jest.mock("@/contentScript/messenger/api");

const checkPermissionsMock = jest.mocked(checkModDefinitionPermissions);
const uninstallModMock = jest.mocked(uninstallMod);
const deactivateModMock = jest.mocked(deactivateMod);
const reactivateEveryTabMock = jest.mocked(reloadModsEveryTab);

function setupInputs(): {
formValues: WizardValues;
modDefinition: ModDefinition;
} {
const formValues: WizardValues = {
extensions: { 0: true },
modComponents: { 0: true },
integrationDependencies: [],
optionsArgs: {},
};
Expand Down Expand Up @@ -115,23 +115,23 @@ describe("useActivateMod", () => {
setUserAcceptedPermissions(false);

const {
result: { current: activateRecipe },
result: { current: activateMod },
getReduxStore,
} = renderHook(() => useActivateMod("marketplace"), {
setupRedux(dispatch, { store }) {
jest.spyOn(store, "dispatch");
},
});

const { success, error } = await activateRecipe(formValues, modDefinition);
const { success, error } = await activateMod(formValues, modDefinition);

expect(success).toBe(false);
expect(error).toBe("You must accept browser permissions to activate.");

const { dispatch } = getReduxStore();

expect(dispatch).not.toHaveBeenCalled();
expect(uninstallModMock).not.toHaveBeenCalled();
expect(deactivateModMock).not.toHaveBeenCalled();
expect(reactivateEveryTabMock).not.toHaveBeenCalled();
});

Expand All @@ -141,7 +141,7 @@ describe("useActivateMod", () => {
setUserAcceptedPermissions(false);

const {
result: { current: activateRecipe },
result: { current: activateMod },
} = renderHook(
() => useActivateMod("marketplace", { checkPermissions: false }),
{
Expand All @@ -151,19 +151,19 @@ describe("useActivateMod", () => {
},
);

const { success, error } = await activateRecipe(formValues, modDefinition);
const { success, error } = await activateMod(formValues, modDefinition);

expect(success).toBe(true);
expect(error).toBeUndefined();
});

it("calls uninstallRecipe, installs to extensionsSlice, and calls reactivateEveryTab, if permissions are granted", async () => {
it("calls deactivateMod, activates to modComponentsSlice, and calls reactivateEveryTab, if permissions are granted", async () => {
const { formValues, modDefinition } = setupInputs();
setModHasPermissions(false);
setUserAcceptedPermissions(true);

const {
result: { current: activateRecipe },
result: { current: activateMod },
getReduxStore,
act,
} = renderHook(() => useActivateMod("extensionConsole"), {
Expand All @@ -175,7 +175,7 @@ describe("useActivateMod", () => {
let success: boolean;
let error: unknown;
await act(async () => {
const result = await activateRecipe(formValues, modDefinition);
const result = await activateMod(formValues, modDefinition);
success = result.success;
error = result.error;
});
Expand All @@ -185,14 +185,14 @@ describe("useActivateMod", () => {

const { dispatch } = getReduxStore();

expect(uninstallModMock).toHaveBeenCalledWith(
expect(deactivateModMock).toHaveBeenCalledWith(
modDefinition.metadata.id,
expect.toBeArray(),
dispatch,
);

expect(dispatch).toHaveBeenCalledWith(
extensionsSlice.actions.activateMod({
modComponentsSlice.actions.activateMod({
modDefinition,
configuredDependencies: [],
optionsArgs: {},
Expand Down Expand Up @@ -237,7 +237,7 @@ describe("useActivateMod", () => {
appApiMock.onPost("/api/databases/").reply(201, createdDatabase);

const {
result: { current: activateRecipe },
result: { current: activateMod },
getReduxStore,
act,
} = renderHook(() => useActivateMod("marketplace"), {
Expand All @@ -249,7 +249,7 @@ describe("useActivateMod", () => {
let success: boolean;
let error: unknown;
await act(async () => {
const result = await activateRecipe(formValues, modDefinition);
const result = await activateMod(formValues, modDefinition);
success = result.success;
error = result.error;
});
Expand All @@ -260,7 +260,7 @@ describe("useActivateMod", () => {
const { dispatch } = getReduxStore();

expect(dispatch).toHaveBeenCalledWith(
extensionsSlice.actions.activateMod({
modComponentsSlice.actions.activateMod({
modDefinition,
configuredDependencies: [],
optionsArgs: {
Expand Down Expand Up @@ -311,7 +311,7 @@ describe("useActivateMod", () => {
const errorMessage = "Error creating database";

const {
result: { current: activateRecipe },
result: { current: activateMod },
act,
} = renderHook(() => useActivateMod("marketplace"), {
setupRedux(dispatch, { store }) {
Expand All @@ -322,7 +322,7 @@ describe("useActivateMod", () => {
let success: boolean;
let error: unknown;
await act(async () => {
const result = await activateRecipe(formValues, modDefinition);
const result = await activateMod(formValues, modDefinition);
success = result.success;
error = result.error;
});
Expand Down
14 changes: 7 additions & 7 deletions src/activation/useActivateMod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import { type WizardValues } from "@/activation/wizardTypes";
import { type ModDefinition } from "@/types/modDefinitionTypes";
import { useCallback } from "react";
import { useDispatch, useSelector } from "react-redux";
import extensionsSlice from "@/store/extensionsSlice";
import modComponentsSlice from "@/store/extensionsSlice";
import reportEvent from "@/telemetry/reportEvent";
import { getErrorMessage } from "@/errors/errorHelpers";
import { uninstallMod } from "@/store/uninstallUtils";
import { deactivateMod } from "@/store/deactivateUtils";
import { selectActivatedModComponents } from "@/store/extensionsSelectors";
import { ensurePermissionsFromUserGesture } from "@/permissions/permissionsUtils";
import { checkModDefinitionPermissions } from "@/modDefinitions/modDefinitionPermissionsHelpers";
Expand Down Expand Up @@ -59,7 +59,7 @@ function selectActivateEventData(modDefinition: ModDefinition) {
}

/**
* React hook to install a mod.
* React hook to activate a mod.
*
* Prompts the user to grant permissions if PixieBrix does not already have the required permissions.
* @param source The source of the activation, only used for reporting purposes
Expand All @@ -85,7 +85,7 @@ function useActivateMod(
if (source === "extensionConsole") {
// Note: The prefix "Marketplace" on the telemetry event name
// here is legacy terminology from before the public marketplace
// was created. It refers to the mod-list part of the extension
// was created. It refers to the mod-list part of the mod component
// console, to distinguish that from the workshop.
// It's being kept to keep our metrics history clean.
reportEvent(Events.MARKETPLACE_ACTIVATE, {
Expand All @@ -112,7 +112,7 @@ function useActivateMod(
if (source === "extensionConsole") {
// Note: The prefix "Marketplace" on the telemetry event name
// here is legacy terminology from before the public marketplace
// was created. It refers to the mod-list part of the extension
// was created. It refers to the mod-list part of the mod component
// console, to distinguish that from the workshop.
// It's being kept like this so our metrics history stays clean.
reportEvent(Events.MARKETPLACE_REJECT_PERMISSIONS, {
Expand Down Expand Up @@ -143,14 +143,14 @@ function useActivateMod(
(x) => x._recipe?.id === modDefinition.metadata.id,
);

await uninstallMod(
await deactivateMod(
modDefinition.metadata.id,
existingModComponents,
dispatch,
);

dispatch(
extensionsSlice.actions.activateMod({
modComponentsSlice.actions.activateMod({
modDefinition,
configuredDependencies: integrationDependencies,
optionsArgs,
Expand Down
2 changes: 1 addition & 1 deletion src/activation/useActivateModWizard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jest.mock("@/hooks/useAsyncModOptionsValidationSchema", () => ({
default: jest.fn(() => valueToAsyncState({})),
}));

describe("useActivateRecipeWizard", () => {
describe("useActivateModWizard", () => {
test("show personalized tab", () => {
const spy = jest.spyOn(redux, "useSelector");
spy.mockReturnValue([]);
Expand Down
40 changes: 20 additions & 20 deletions src/activation/useActivateModWizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function forcePrimitive(value: unknown): Primitive | undefined {
return isPrimitive(value) ? value : undefined;
}

export type UseActivateRecipeWizardResult = {
export type UseActivateModWizardResult = {
wizardSteps: WizardStep[];
initialValues: WizardValues;
validationSchema: Yup.AnyObjectSchema;
Expand All @@ -75,26 +75,26 @@ export function wizardStateFactory({
modDefinition,
defaultAuthOptions = {},
databaseOptions,
installedExtensions,
activatedModComponents,
optionsValidationSchema,
initialModOptions,
}: {
modDefinition: ModDefinition;
defaultAuthOptions: Record<RegistryId, AuthOption>;
databaseOptions: Option[];
installedExtensions: ActivatedModComponent[];
activatedModComponents: ActivatedModComponent[];
optionsValidationSchema: AnyObjectSchema;
initialModOptions: UnknownObject;
}): UseActivateRecipeWizardResult {
}): UseActivateModWizardResult {
const modComponentDefinitions = modDefinition.extensionPoints ?? [];

const activatedModComponents = installedExtensions?.filter(
(extension) => extension._recipe?.id === modDefinition.metadata.id,
const activatedModComponentsForMod = activatedModComponents?.filter(
(x) => x._recipe?.id === modDefinition.metadata.id,
);

const installedOptions = collectModOptions(activatedModComponents);
const installedIntegrationConfigs = Object.fromEntries(
collectConfiguredIntegrationDependencies(activatedModComponents).map(
const activatedOptions = collectModOptions(activatedModComponentsForMod);
const activatedIntegrationConfigs = Object.fromEntries(
collectConfiguredIntegrationDependencies(activatedModComponentsForMod).map(
({ integrationId, configId }) => [integrationId, configId],
),
);
Expand All @@ -103,9 +103,9 @@ export function wizardStateFactory({
const integrationDependencies = unconfiguredIntegrationDependencies.map(
(unconfiguredDependency) => ({
...unconfiguredDependency,
// Prefer the installed dependency for reinstall cases, otherwise use the default
// Prefer the activated dependency for reactivate cases, otherwise use the default
configId:
installedIntegrationConfigs[unconfiguredDependency.integrationId] ??
activatedIntegrationConfigs[unconfiguredDependency.integrationId] ??
defaultAuthOptions[unconfiguredDependency.integrationId]?.value,
}),
);
Expand All @@ -129,17 +129,17 @@ export function wizardStateFactory({
});

const initialValues: WizardValues = {
extensions: Object.fromEntries(
// By default, all extensions in the recipe should be toggled on
modComponents: Object.fromEntries(
// By default, all mod components in the mod should be toggled on
modComponentDefinitions.map((_, index) => [index, true]),
),
integrationDependencies,
optionsArgs: mapValues(
modDefinition.options?.schema?.properties ?? {},
(optionSchema: Schema, name: string) => {
const installedValue = installedOptions[name];
if (installedValue) {
return forcePrimitive(installedValue);
const activatedValue = activatedOptions[name];
if (activatedValue) {
return forcePrimitive(activatedValue);
}

if (
Expand Down Expand Up @@ -167,7 +167,7 @@ export function wizardStateFactory({
};

const validationSchema = Yup.object().shape({
extensions: Yup.object().shape(
modComponents: Yup.object().shape(
Object.fromEntries(
modComponentDefinitions.map((_, index) => [
index,
Expand Down Expand Up @@ -199,8 +199,8 @@ function useActivateModWizard(
modDefinition: ModDefinition,
defaultAuthOptions: Record<RegistryId, AuthOption> = {},
initialOptions: UnknownObject = {},
): FetchableAsyncState<UseActivateRecipeWizardResult> {
const installedExtensions = useSelector(selectActivatedModComponents);
): FetchableAsyncState<UseActivateModWizardResult> {
const activatedModComponents = useSelector(selectActivatedModComponents);
const optionsValidationSchemaState = useAsyncModOptionsValidationSchema(
modDefinition.options?.schema,
);
Expand All @@ -216,7 +216,7 @@ function useActivateModWizard(
modDefinition,
defaultAuthOptions,
databaseOptions,
installedExtensions,
activatedModComponents,
optionsValidationSchema,
initialModOptions: initialOptions,
}),
Expand Down
5 changes: 2 additions & 3 deletions src/activation/wizardTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ export type WizardStep = {
label: string;
Component: React.FunctionComponent<{
mod: ModDefinition;
reinstall: boolean;
}>;
};

export type WizardValues = {
/**
* Mapping from extension index to whether or not it's toggled.
* Mapping from mod component index to whether or not it's toggled.
*/
extensions: Record<string, boolean>;
modComponents: Record<string, boolean>;

/**
* Integration dependencies for the mod
Expand Down
Loading

0 comments on commit 4e46ac6

Please sign in to comment.