-
Notifications
You must be signed in to change notification settings - Fork 22
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
base: main
Are you sure you want to change the base?
Conversation
|
||
const activatedOptions = collectModOptions(activatedModComponentsForMod); | ||
const activatedIntegrationConfigs = Object.fromEntries( | ||
collectConfiguredIntegrationDependencies(activatedModComponentsForMod).map( |
There was a problem hiding this comment.
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", () => { |
There was a problem hiding this comment.
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
Playwright test resultsDetails Open report ↗︎ Flaky testschrome › tests/pageEditor/addStarterBrick.spec.ts › Add starter brick to mod Skipped testschrome › tests/regressions/doNotCloseSidebarOnPageEditorSave.spec.ts › #8104: Do not automatically close the sidebar when saving in the Page Editor |
const hasPersonalDeployment = activatedModComponentsForMod?.some( | ||
(x) => x._deployment?.isPersonalDeployment, | ||
); | ||
const hasPersonalDeployment = |
There was a problem hiding this comment.
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[]; |
There was a problem hiding this comment.
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)
Codecov ReportAttention: Patch coverage is
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. |
* @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( |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 }, |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
ModInstance
type and adapter applied to re-/activation code (1/3)
* | ||
* NOTE: at this time, a device can only have one instance of a mod active at a time. | ||
*/ | ||
id: UUID; |
There was a problem hiding this comment.
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
What does this PR do?
ModInstance
typeModInstance
to simplify some React code:useActivateMod
useReactivateMod
useActivateModWizard
Discussion
pixiebrix-extension/src/contentScript/lifecycle.ts
Line 442 in 955553c
Future Work
Prioritizing changes that simplify deployment code, doesn't require a migration, and avoids the Page Editor:
ModInstance[]
instead ofActivatedModComponent[]
: UseModInstance
type in mod deployment code (2/3) #9190ModInstance[]
instead of passing aroundActivatedModComponent[]
. E.g., see buildModsList, buildGetModActivationStatus, etc.: UseModInstance
type on the mods screen (3/3) #9191Consider adding a wrapper that wraps
ModInstance
with helper methods for derived data/properties. E.g.,modId
,isPaused
, etc. without duplicating the dataFor more information on our expectations for the PR process, see the
code review principles doc