Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
twschiller committed Sep 22, 2024
1 parent 5f53bcc commit 4e69887
Showing 1 changed file with 1 addition and 80 deletions.
81 changes: 1 addition & 80 deletions src/store/modComponents/modInstanceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ import type {
ActivatedModComponent,
ModComponentBase,
} from "@/types/modComponentTypes";
import { omit, pick, zip } from "lodash";
import { omit, pick } from "lodash";
import { assertNotNullish } from "@/utils/nullishUtils";
import { pickModDefinitionMetadata } from "@/modDefinitions/util/pickModDefinitionMetadata";
import type { SetRequired } from "type-fest";
import getModDefinitionIntegrationIds from "@/integrations/util/getModDefinitionIntegrationIds";
import { emptyPermissionsFactory } from "@/permissions/permissionsUtils";
import { uuidv4 } from "@/types/helpers";
import {
collectIntegrationDependencies,
Expand All @@ -37,14 +33,6 @@ import { emptyModOptionsDefinitionFactory } from "@/utils/modUtils";
import { assertModComponentNotHydrated } from "@/runtime/runtimeUtils";
import type { ModComponentDefinition } from "@/types/modDefinitionTypes";

/**
* A version of ActivatedModComponent with stronger nullness guarantees to support type evolution in the future.
*/
type ModInstanceActivatedModComponent = SetRequired<
ActivatedModComponent,
"_recipe" | "definitions" | "integrationDependencies" | "permissions"
>;

/**
* Returns true if mod instance is defined and is associated with a personal deployment.
*/
Expand All @@ -54,73 +42,6 @@ export function getIsPersonalDeployment(
return Boolean(modInstance?.deploymentMetadata?.isPersonalDeployment);
}

/**
* Returns the activated mod component for a given mod instance. Is side effect free -- only maps the shape, does
* not persist the mod components or modify the UI.
*
* @see mapModComponentDefinitionToActivatedModComponent
*/
// XXX: this is dead code for now. Including for the initial PR review to illustrate the other adapter direction
export function mapModInstanceToActivatedModComponents(
modInstance: ModInstance,
): ModInstanceActivatedModComponent[] {
const { deploymentMetadata, integrationsArgs, updatedAt, definition } =
modInstance;

const modMetadata = pickModDefinitionMetadata(definition);

return zip(definition.extensionPoints, modInstance.modComponentIds).map(
([modComponentDefinition, modComponentId]) => {
assertNotNullish(
modComponentDefinition,
"extensionPoints mismatch with modComponentIds",
);
assertNotNullish(
modComponentId,
"extensionPoints mismatch with modComponentIds",
);

const componentIntegrationIds = getModDefinitionIntegrationIds({
extensionPoints: [modComponentDefinition],
});

const base = {
id: modComponentId,
active: true,
label: modComponentDefinition.label,
config: modComponentDefinition.config,
permissions:
modComponentDefinition.permissions ?? emptyPermissionsFactory(),
// Default to `v1` for backward compatability
apiVersion: definition.apiVersion ?? "v1",
_recipe: modMetadata,
// All definitions are pushed down into the mod components. That's OK because `resolveDefinitions` determines
// uniqueness based on the content of the definition. Therefore, bricks will be re-used as necessary
definitions: definition.definitions ?? {},
optionsArgs: modInstance.optionsArgs,
extensionPointId: modComponentDefinition.id,
createTimestamp: updatedAt,
updateTimestamp: updatedAt,
// XXX: do we have to filter to only the integrations referenced by this particular mod? Historically, was this
// only to simplify moving mod components in the Page Editor?
integrationDependencies: integrationsArgs.filter(({ integrationId }) =>
componentIntegrationIds.includes(integrationId),
),
} as ModInstanceActivatedModComponent;

if (modComponentDefinition.templateEngine) {
base.templateEngine = modComponentDefinition.templateEngine;
}

if (deploymentMetadata) {
base._deployment = deploymentMetadata;
}

return base;
},
);
}

export function mapModComponentBaseToModComponentDefinition(
modComponent: ModComponentBase,
): ModComponentDefinition {
Expand Down

0 comments on commit 4e69887

Please sign in to comment.