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

Update filename/function names in the mods screen #8779

Merged
merged 2 commits into from
Jul 9, 2024
Merged
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
4 changes: 2 additions & 2 deletions src/extensionConsole/pages/mods/modals/Modals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

import React from "react";
import ConvertToModModal from "./convertToModModal/ConvertToModModal";
import ExtensionLogsModal from "./extensionLogsModal/ExtensionLogsModal";
import ModLogsModal from "./modLogsModal/ModLogsModal";
import PublishModModals from "./shareModals/PublishModModals";
import ShareModModal from "./shareModals/ShareModModal";

const Modals: React.FunctionComponent = () => (
<>
<ExtensionLogsModal />
<ModLogsModal />
<ConvertToModModal />
<ShareModModal />
<PublishModModals />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
useGetAllStandaloneModDefinitionsQuery,
} from "@/data/service/api";
import { type FormikHelpers } from "formik";
import { makeBlueprint } from "@/extensionConsole/pages/mods/utils/exportBlueprint";
import mapModComponentToModDefinition from "@/extensionConsole/pages/mods/utils/mapModComponentToModDefinition";
import extensionsSlice from "@/store/extensionsSlice";
import notify from "@/utils/notify";
import ConnectedFieldTemplate from "@/components/form/ConnectedFieldTemplate";
Expand Down Expand Up @@ -156,12 +156,15 @@ const ConvertToModModalBody: React.FunctionComponent = () => {
helpers: FormikHelpers<ConvertModFormState>,
) => {
try {
const unsavedModDefinition = makeBlueprint(modComponent, {
id: formValues.blueprintId,
name: formValues.name,
description: formValues.description,
version: formValues.version,
});
const unsavedModDefinition = mapModComponentToModDefinition(
modComponent,
{
id: formValues.blueprintId,
name: formValues.name,
description: formValues.description,
version: formValues.version,
},
);

const response = await createMod({
modDefinition: unsavedModDefinition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import styles from "./ExtensionLogsModal.module.scss";
import styles from "./ModLogsModal.module.scss";

import React, { useEffect } from "react";
import { Modal } from "react-bootstrap";
Expand All @@ -26,7 +26,7 @@ import { modModalsSlice } from "@/extensionConsole/pages/mods/modals/modModalsSl
import ModalLayout from "@/components/ModalLayout";
import { selectShowLogsContext } from "@/extensionConsole/pages/mods/modals/modModalsSelectors";

const ExtensionLogsModal: React.FunctionComponent = () => {
const ModLogsModal: React.FunctionComponent = () => {
const dispatch = useDispatch();

const closeModal = () => {
Expand Down Expand Up @@ -59,4 +59,4 @@ const ExtensionLogsModal: React.FunctionComponent = () => {
);
};

export default ExtensionLogsModal;
export default ModLogsModal;
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ import { defaultModDefinitionFactory } from "@/testUtils/factories/modDefinition
import { metadataFactory } from "@/testUtils/factories/metadataFactory";
import { authStateFactory } from "@/testUtils/factories/authFactories";

let blueprint: ModDefinition;
let modDefinition: ModDefinition;
let auth: AuthState;

jest.mock("@/modDefinitions/modDefinitionHooks", () => ({
useOptionalModDefinition: jest.fn().mockImplementation(() => ({
data: blueprint,
data: modDefinition,
isFetching: false,
})),
}));
Expand All @@ -50,7 +50,7 @@ const MarketplaceListingsWrapper: React.FC = ({ children }) => {

beforeEach(() => {
auth = authStateFactory();
blueprint = defaultModDefinitionFactory({
modDefinition = defaultModDefinitionFactory({
metadata: metadataFactory({
id: validateRegistryId(`${auth.scope}/test`),
}),
Expand All @@ -75,7 +75,7 @@ test("renders publish modal", async () => {

dispatch(
modModalsSlice.actions.setPublishContext({
blueprintId: blueprint.metadata.id,
blueprintId: modDefinition.metadata.id,
}),
);
},
Expand All @@ -88,7 +88,7 @@ test("renders publish modal", async () => {
});

test("renders edit publish modal", async () => {
blueprint.sharing.public = true;
modDefinition.sharing.public = true;

render(
<MarketplaceListingsWrapper>
Expand All @@ -100,7 +100,7 @@ test("renders edit publish modal", async () => {

dispatch(
modModalsSlice.actions.setPublishContext({
blueprintId: blueprint.metadata.id,
blueprintId: modDefinition.metadata.id,
}),
);
},
Expand All @@ -113,7 +113,7 @@ test("renders edit publish modal", async () => {
});

test("renders cancel publish modal", async () => {
blueprint.sharing.public = true;
modDefinition.sharing.public = true;

render(
<MarketplaceListingsWrapper>
Expand All @@ -125,7 +125,7 @@ test("renders cancel publish modal", async () => {

dispatch(
modModalsSlice.actions.setPublishContext({
blueprintId: blueprint.metadata.id,
blueprintId: modDefinition.metadata.id,
cancelingPublish: true,
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useSelector } from "react-redux";

const editorRoles = new Set<number>([UserRole.admin, UserRole.developer]);

export default function useHasEditPermissions(modId: RegistryId) {
export default function useHasEditPermissions(modId: RegistryId): boolean {
const { scope: userScope } = useSelector(selectAuth);
const { scope: modIdScope } = getScopeAndId(modId);
const sortedOrganizations = useSortOrganizations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { makeBlueprint } from "@/extensionConsole/pages/mods/utils/exportBlueprint";
import mapModComponentToModDefinition from "@/extensionConsole/pages/mods/utils/mapModComponentToModDefinition";
import { validateRegistryId } from "@/types/helpers";
import { type SerializedModComponent } from "@/types/modComponentTypes";
import { modComponentFactory } from "@/testUtils/factories/modComponentFactories";
import { DefinitionKinds } from "@/types/registryTypes";

describe("makeBlueprint", () => {
describe("mapModComponentToModDefinition", () => {
it("smoke test", () => {
const result = makeBlueprint(
const result = mapModComponentToModDefinition(
modComponentFactory() as SerializedModComponent,
{
id: validateRegistryId("test/blueprint"),
Expand All @@ -45,7 +45,7 @@ describe("makeBlueprint", () => {
},
}) as SerializedModComponent;

const result = makeBlueprint(modComponent, {
const result = mapModComponentToModDefinition(modComponent, {
id: validateRegistryId("test/blueprint"),
name: "test",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ function inferOptionsSchema(
};
}

export function makeBlueprint(
extension: SerializedModComponent,
function mapModComponentToModDefinition(
modComponent: SerializedModComponent,
metadata: Metadata,
): UnsavedModDefinition {
const {
Expand All @@ -62,21 +62,21 @@ export function makeBlueprint(
integrationDependencies,
optionsArgs,
config,
} = extension;
} = modComponent;

if (isInnerDefinitionRegistryId(extensionPointId)) {
throw new Error("Expected UnresolvedExtension");
}

const extensionPoint: ModComponentDefinition = {
const modComponentDefinition: ModComponentDefinition = {
id: extensionPointId,
label,
templateEngine,
permissions,
config,
};
if (integrationDependencies) {
extensionPoint.services = Object.fromEntries(
modComponentDefinition.services = Object.fromEntries(
integrationDependencies
.filter(({ outputKey }) => !isNullOrBlank(outputKey))
.map(({ outputKey, integrationId }) => [outputKey, integrationId]),
Expand All @@ -88,7 +88,7 @@ export function makeBlueprint(
kind: DefinitionKinds.MOD,
metadata,
definitions,
extensionPoints: [extensionPoint],
extensionPoints: [modComponentDefinition],
};

const options = inferOptionsSchema(optionsArgs);
Expand All @@ -98,3 +98,5 @@ export function makeBlueprint(

return modDefinition;
}

export default mapModComponentToModDefinition;
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { renderHook } from "@/extensionConsole/testHelpers";
import useReinstall from "./useReinstall";
import useReactivateMod from "./useReactivateMod";
import { actions as extensionActions } from "@/store/extensionsSlice";
import { deactivateMod } from "@/store/deactivateUtils";
import { type ModComponentsRootState } from "@/store/extensionsTypes";
Expand All @@ -27,7 +27,7 @@ beforeEach(() => {
jest.resetAllMocks();
});

test("uninstalls mod components", async () => {
test("deactivates mod components", async () => {
const modDefinition = defaultModDefinitionFactory();
const standaloneModDefinition = standaloneModDefinitionFactory({
_recipe: {
Expand All @@ -41,7 +41,7 @@ test("uninstalls mod components", async () => {
result: { current: reinstall },
act,
getReduxStore,
} = renderHook(() => useReinstall(), {
} = renderHook(() => useReactivateMod(), {
setupRedux(dispatch) {
dispatch(
extensionActions.activateStandaloneModDefinition(
Expand Down Expand Up @@ -82,7 +82,7 @@ test("dispatches activate mod action", async () => {
const {
result: { current: reinstall },
act,
} = renderHook(() => useReinstall(), {
} = renderHook(() => useReactivateMod(), {
setupRedux(dispatch) {
dispatch(
extensionActions.activateStandaloneModDefinition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import { collectModOptions } from "@/store/extensionsUtils";
import { deactivateMod } from "@/store/deactivateUtils";
import collectExistingConfiguredDependenciesForMod from "@/integrations/util/collectExistingConfiguredDependenciesForMod";

type Reinstall = (modDefinition: ModDefinition) => Promise<void>;
type ReactivateMod = (modDefinition: ModDefinition) => Promise<void>;

function useReinstall(): Reinstall {
function useReactivateMod(): ReactivateMod {
const dispatch = useDispatch();
const allComponents = useSelector(selectActivatedModComponents);

Expand All @@ -38,7 +38,7 @@ function useReinstall(): Reinstall {
);

if (activatedModComponents.length === 0) {
throw new Error(`No bricks to re-activate for ${modId}`);
throw new Error(`No mod components to re-activate for ${modId}`);
}

const currentOptions = collectModOptions(activatedModComponents);
Expand All @@ -65,4 +65,4 @@ function useReinstall(): Reinstall {
);
}

export default useReinstall;
export default useReactivateMod;
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { uuidv4 } from "@/types/helpers";
import { ModalContext } from "@/components/ConfirmationModal";

jest.mock("@/utils/notify");
jest.mock("@/extensionConsole/pages/mods/utils/useReinstall");
jest.mock("@/extensionConsole/pages/mods/utils/useReactivateMod");

const errorMock = jest.mocked(notify.error);

Expand Down
4 changes: 2 additions & 2 deletions src/extensionConsole/pages/packageEditor/useSubmitPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { useDispatch } from "react-redux";
import { type EditorValues } from "./Editor";
import { type BrickValidationResult, validateSchema } from "./validate";
import useRefreshRegistries from "@/hooks/useRefreshRegistries";
import useReinstall from "@/extensionConsole/pages/mods/utils/useReinstall";
import useReactivateMod from "@/extensionConsole/pages/mods/utils/useReactivateMod";
import notify from "@/utils/notify";
import { Events } from "@/telemetry/events";
import { clearServiceCache } from "@/background/messenger/api";
Expand Down Expand Up @@ -58,7 +58,7 @@ type SubmitCallbacks = {
function useSubmitPackage({ create = false }: SubmitOptions): SubmitCallbacks {
const [, refresh] = useRefreshRegistries({ refreshOnMount: false });
const modals = useModals();
const reinstall = useReinstall();
const reinstall = useReactivateMod();
const history = useHistory();
const dispatch = useDispatch();

Expand Down
10 changes: 5 additions & 5 deletions src/tsconfig.strictNullChecks.json
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@
"./extensionConsole/pages/mods/labels/SharingLabel.tsx",
"./extensionConsole/pages/mods/listView/ListGroupHeader.tsx",
"./extensionConsole/pages/mods/listView/ListItemErrorBoundary.tsx",
"./extensionConsole/pages/mods/modals/extensionLogsModal/ExtensionLogsModal.tsx",
"./extensionConsole/pages/mods/modals/modLogsModal/ModLogsModal.tsx",
"./extensionConsole/pages/mods/modals/modModalsSelectors.ts",
"./extensionConsole/pages/mods/modals/modModalsSlice.ts",
"./extensionConsole/pages/mods/modals/shareModals/ModOwnerLabel.tsx",
Expand All @@ -846,10 +846,10 @@
"./extensionConsole/pages/mods/modsPageSelectors.ts",
"./extensionConsole/pages/mods/modsPageSlice.ts",
"./extensionConsole/pages/mods/modsPageTypes.ts",
"./extensionConsole/pages/mods/utils/exportBlueprint.test.ts",
"./extensionConsole/pages/mods/utils/exportBlueprint.ts",
"./extensionConsole/pages/mods/utils/useReinstall.test.ts",
"./extensionConsole/pages/mods/utils/useReinstall.ts",
"./extensionConsole/pages/mods/utils/mapModComponentToModDefinition.test.ts",
"./extensionConsole/pages/mods/utils/mapModComponentToModDefinition.ts",
"./extensionConsole/pages/mods/utils/useReactivateMod.test.ts",
"./extensionConsole/pages/mods/utils/useReactivateMod.ts",
"./extensionConsole/pages/onboarding/DefaultSetupCard.stories.tsx",
"./extensionConsole/pages/onboarding/DefaultSetupCard.tsx",
"./extensionConsole/pages/onboarding/SetupPage.test.tsx",
Expand Down
Loading