Skip to content

Commit

Permalink
#8605: link directly to mod re-activation
Browse files Browse the repository at this point in the history
  • Loading branch information
twschiller committed Jun 16, 2024
1 parent f811b97 commit aba3dfe
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 14 deletions.
5 changes: 2 additions & 3 deletions src/extensionConsole/pages/mods/hooks/useActivateAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { isModDefinition } from "@/utils/modUtils";
import reportEvent from "@/telemetry/reportEvent";
import { Events } from "@/telemetry/events";
import { push } from "connected-react-router";
import { getActivateModHashRoute } from "@/extensionConsole/shared/routeHelpers";

function useActivateAction(modViewItem: ModViewItem): (() => void) | null {
const dispatch = useDispatch();
Expand All @@ -33,9 +34,7 @@ function useActivateAction(modViewItem: ModViewItem): (() => void) | null {
reinstall: false,
});

dispatch(
push(`/marketplace/activate/${encodeURIComponent(mod.metadata.id)}`),
);
dispatch(push(getActivateModHashRoute(mod.metadata.id)));
} else {
reportEvent(Events.START_MOD_ACTIVATE, {
blueprintId: null,
Expand Down
25 changes: 25 additions & 0 deletions src/extensionConsole/shared/routeHelpers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*

Check failure on line 1 in src/extensionConsole/shared/routeHelpers.tsx

View workflow job for this annotation

GitHub Actions / strictNullChecks

strictNullChecks

src/extensionConsole/shared/routeHelpers.tsx was not found in tsconfig.strictNullChecks.json
* Copyright (C) 2024 PixieBrix, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { type RegistryId } from "@/types/registryTypes";

/**
* Returns the Extension Console hash route to activate a mod in the Extension Console.
*/
export function getActivateModHashRoute(modId: RegistryId): string {
return `/marketplace/activate/${encodeURIComponent(modId)}`;
}
45 changes: 34 additions & 11 deletions src/pageEditor/tabs/modMetadata/ModMetadataEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import { FieldDescriptions } from "@/modDefinitions/modDefinitionConstants";
import IntegrationsSliceModIntegrationsContextAdapter from "@/integrations/store/IntegrationsSliceModIntegrationsContextAdapter";
import cx from "classnames";
import { assertNotNullish } from "@/utils/nullishUtils";
import { type RegistryId } from "@/types/registryTypes";
import { getActivateModHashRoute } from "@/extensionConsole/shared/routeHelpers";

// TODO: This should be yup.SchemaOf<RecipeMetadataFormState> but we can't set the `id` property to `RegistryId`
// see: https://github.com/jquense/yup/issues/1183#issuecomment-749186432
Expand All @@ -65,6 +67,33 @@ const selectFirstModComponent = createSelector(
modComponents.find((x) => x._recipe?.id === activeModId),
);

const OldModVersionAlert: React.FunctionComponent<{
modId: RegistryId;
installedModVersion: string;
latestModVersion: string;
}> = ({
modId,
installedModVersion,
latestModVersion,
}: {
modId: RegistryId;
installedModVersion: string;
latestModVersion: string;
}) => (
<Alert variant="warning">
You are editing version {installedModVersion} of this mod, the latest
version is {latestModVersion}. To get the latest version,{" "}
<a
href={`/options.html#${getActivateModHashRoute(modId)}`}
target="_blank"
title="Re-activate the mod"
rel="noreferrer"
>
re-activate the mod
</a>
</Alert>
);

const ModMetadataEditor: React.VoidFunctionComponent = () => {
const modId = useSelector(selectActiveModId);

Expand Down Expand Up @@ -126,17 +155,11 @@ const ModMetadataEditor: React.VoidFunctionComponent = () => {
<Card.Header>Mod Metadata</Card.Header>
<Card.Body>
{showOldModVersionWarning && (
<Alert variant="warning">
You are editing version {installedModVersion} of this mod, the
latest version is {latestModVersion}. To get the latest version,{" "}
<a
href="/options.html#/mods"
target="_blank"
title="Re-activate the mod"
>
re-activate the mod
</a>
</Alert>
<OldModVersionAlert
modId={modId}
installedModVersion={installedModVersion}
latestModVersion={latestModVersion}
/>
)}
<ConnectedFieldTemplate
name="id"
Expand Down

0 comments on commit aba3dfe

Please sign in to comment.