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

Initial ModInstance type and adapter applied to re-/activation code (1/3) #9182

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

twschiller
Copy link
Contributor

@twschiller twschiller commented Sep 22, 2024

What does this PR do?

Discussion

  • By using adapters, we can evaluate the ergonomics of the shape before migrating the persisted mod component slice shape
  • Using the mod instance selector in the lifecycle is a bit tricky due to draft behavior:
    const modComponentsToActivate = options.activatedModComponents.filter(
    • We may want to punt on that until we change Page Editor behavior to use drafts for all mod components when a mod is selected vs. only drafts for mod components that have been interacted with in the Page Editor
  • A benefit of doing this work now is that it simplifies some of the deployment code that @fungairino is doing

Future Work

Prioritizing changes that simplify deployment code, doesn't require a migration, and avoids the Page Editor:

  1. Rewrite deployment updater to pass around ModInstance[] instead of ActivatedModComponent[]: Use ModInstance type in mod deployment code (2/3) #9190
  2. Rewrite Mods Screen / Launcher to pass around ModInstance[] instead of passing around ActivatedModComponent[]. E.g., see buildModsList, buildGetModActivationStatus, etc.: Use ModInstance type on the mods screen (3/3) #9191

Consider adding a wrapper that wraps ModInstance with helper methods for derived data/properties. E.g., modId, isPaused, etc. without duplicating the data

For more information on our expectations for the PR process, see the
code review principles doc


const activatedOptions = collectModOptions(activatedModComponentsForMod);
const activatedIntegrationConfigs = Object.fromEntries(
collectConfiguredIntegrationDependencies(activatedModComponentsForMod).map(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: see if we still need to filter activatedIntegrationConfigs to exclude the PixieBrix integration and unconfigured dependencies

@@ -890,115 +883,3 @@ describe("buildNewMod", () => {
},
);
});

describe("findMaxIntegrationDependencyApiVersion", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to utility folder test file

@twschiller twschiller changed the title [WIP] mod instance type and adapters [WIP] initial mod instance type and adapters Sep 22, 2024
Copy link

github-actions bot commented Sep 22, 2024

Playwright test results

passed  128 passed
flaky  2 flaky
skipped  4 skipped

Details

report  Open report ↗︎
stats  134 tests across 44 suites
duration  12 minutes, 44 seconds
commit  4e69887
info  For more information on how to debug and view this report, see our readme

Flaky tests

chrome › tests/pageEditor/addStarterBrick.spec.ts › Add starter brick to mod
msedge › tests/pageEditor/addStarterBrick.spec.ts › Add starter brick to mod

Skipped tests

chrome › tests/regressions/doNotCloseSidebarOnPageEditorSave.spec.ts › #8104: Do not automatically close the sidebar when saving in the Page Editor
msedge › tests/regressions/doNotCloseSidebarOnPageEditorSave.spec.ts › #8104: Do not automatically close the sidebar when saving in the Page Editor
chrome › tests/runtime/googleSheetsIntegration.spec.ts › can activate a google spreadsheet mod with config options
msedge › tests/runtime/googleSheetsIntegration.spec.ts › can activate a google spreadsheet mod with config options

@twschiller twschiller changed the title [WIP] initial mod instance type and adapters [WIP] initial mod instance type and adapter applies to activation code Sep 22, 2024
@twschiller twschiller changed the title [WIP] initial mod instance type and adapter applies to activation code [WIP] initial mod instance type and adapter applied to re-/activation code Sep 22, 2024
const hasPersonalDeployment = activatedModComponentsForMod?.some(
(x) => x._deployment?.isPersonalDeployment,
);
const hasPersonalDeployment =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of simplifying personal deployment code

* In the future, we might consider eliminating by using a predictable id based on the mod instance id and position
* in the mod definition. But that's not possible today because the ids use a UUID format.
*/
modComponentIds: UUID[];
Copy link
Contributor Author

@twschiller twschiller Sep 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A key insight I didn't originally anticipate is that ModInstance has to track the mod component ids. (See comment in code for why)

@twschiller twschiller changed the title [WIP] initial mod instance type and adapter applied to re-/activation code Initial mod instance type and adapter applied to re-/activation code Sep 22, 2024
@twschiller twschiller marked this pull request as ready for review September 22, 2024 13:09
Copy link

codecov bot commented Sep 22, 2024

Codecov Report

Attention: Patch coverage is 91.89189% with 12 lines in your changes missing coverage. Please review.

Project coverage is 74.81%. Comparing base (8318d74) to head (4e69887).
Report is 306 commits behind head on main.

Files with missing lines Patch % Lines
src/activation/useActivateModWizard.ts 92.10% 3 Missing ⚠️
src/store/modComponents/modComponentUtils.ts 90.62% 3 Missing ⚠️
src/store/modComponents/modInstanceSelectors.ts 85.71% 2 Missing ⚠️
src/utils/registryUtils.ts 33.33% 2 Missing ⚠️
.../sidebar/activateMod/ActivateMultipleModsPanel.tsx 66.66% 1 Missing ⚠️
src/store/modComponents/modInstanceUtils.ts 96.42% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9182      +/-   ##
==========================================
+ Coverage   74.24%   74.81%   +0.56%     
==========================================
  Files        1332     1363      +31     
  Lines       40817    41955    +1138     
  Branches     7634     7830     +196     
==========================================
+ Hits        30306    31387    +1081     
- Misses      10511    10568      +57     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@twschiller twschiller changed the title Initial mod instance type and adapter applied to re-/activation code Initial mod instance type and adapter applied to re-/activation code (1/2) Sep 22, 2024
@twschiller twschiller changed the title Initial mod instance type and adapter applied to re-/activation code (1/2) Initial mod instance type and adapter applied to re-/activation code (1/3) Sep 22, 2024
* @since 1.7.37
* @note This function is just for safety, there's currently no way for a mod to end up with "mixed" integration api versions.
*/
export function findMaxIntegrationDependencyApiVersion(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the methods out of page editor directory to where they can be used cross-context

/**
* Returns a sharing object private package defined in the user's scope.
*/
export function createPrivateSharing(): Sharing {
Copy link
Contributor Author

@twschiller twschiller Sep 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a sharing factory. But in general, I think we want to keep prod data creation separate from test factories to avoid dummy data accidentally finding its way into production code

It would be good to align on naming conventions to distinguish, e.g., using create prefix in prod code vs. factory suffix

@@ -62,7 +62,6 @@ function setupInputs(): {
modDefinition: ModDefinition;
} {
const formValues: WizardValues = {
modComponents: { 0: true },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped unused modComponents toggle field from the type

export type UseActivateModWizardResult = {
wizardSteps: WizardStep[];
initialValues: WizardValues;
validationSchema: Yup.AnyObjectSchema;
};

function getInitialIntegrationDependencies(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted these 2 from other method because they're both quite long

@@ -60,8 +60,6 @@ function useModNotFoundRedirectEffect(error: unknown): void {

/**
* Common page for activating a mod definition
*
* @param modDefinitionQuery The mod definition to activate
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid documentation

* Maps activated mod components to a mod instance.
* @param modComponents mod components from the mod
*/
export function mapActivatedModComponentsToModInstance(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The primary adapter to review in this PR

// definition vs. looking up the definition
options: emptyModOptionsDefinitionFactory(),
sharing: modMetadata.sharing ?? createPrivateSharing(),
updated_at: modMetadata.updated_at ?? firstComponent.updateTimestamp,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might consider this line of refactoring as an opportunity to fix the snake case and/or perform other reshaping

@twschiller twschiller changed the title Initial mod instance type and adapter applied to re-/activation code (1/3) Initial ModInstance type and adapter applied to re-/activation code (1/3) Sep 22, 2024
*
* NOTE: at this time, a device can only have one instance of a mod active at a time.
*/
id: UUID;
Copy link
Contributor Author

@twschiller twschiller Sep 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider renaming to instanceId to better from mod registry id and ActivatedModComponent.id. Or consider tagging as an opaque type to prevent invalid assignments with ActivatedModComponent.id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant