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

fix: Use correct category plugins to populate dev menu #897

Merged
merged 4 commits into from
Nov 24, 2020

Conversation

palpatim
Copy link
Member

Issue #, if available:
Refs: #850

Description of changes:

Several changes to correctly populate the dev menu:

  • Fix & refactor the PluginInfoHelper to simplify the call pattern & remove redundant calls that were easy to accidentally copy/paste incorrectly
  • Add AmplifyVersionable conformances to all AWS plugins
  • Make AmplifyVersionable public so it could be consumed by plugins
  • Made all members of EnvironmentInfo optional so missing fields wouldn't cause the entire thing to not display
  • Updated all pod dependencies

See screenshot below for populated menu. Note that I had to manually update the amplify/.config/local-env-info.json file, since the CLI is not yet populating those items (at least on my system).

image

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@palpatim palpatim requested a review from drochetti November 18, 2020 01:43
@codecov
Copy link

codecov bot commented Nov 18, 2020

Codecov Report

Merging #897 (335de93) into main (70970d2) will decrease coverage by 1.48%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #897      +/-   ##
==========================================
- Coverage   66.32%   64.84%   -1.49%     
==========================================
  Files         870      862       -8     
  Lines       34434    34207     -227     
==========================================
- Hits        22838    22181     -657     
- Misses      11596    12026     +430     
Flag Coverage Δ
API_plugin_unit_test 62.39% <0.00%> (-0.10%) ⬇️
Analytics_plugin_unit_test 72.15% <0.00%> (-0.24%) ⬇️
Auth_plugin_unit_test 15.77% <0.00%> (-23.35%) ⬇️
DataStore_plugin_unit_test 83.00% <0.00%> (-0.04%) ⬇️
Predictions_plugin_unit_test 42.03% <0.00%> (-0.08%) ⬇️
Storage_plugin_unit_test 74.66% <0.00%> (-0.09%) ⬇️
build_test_amplify 64.31% <0.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ify/DefaultPlugins/AWSHubPlugin/AWSHubPlugin.swift 85.71% <0.00%> (-14.29%) ⬇️
...UnifiedLoggingPlugin/AWSUnifiedLoggingPlugin.swift 91.11% <0.00%> (-8.89%) ⬇️
Amplify/DevMenu/Data/EnvironmentInfoHelper.swift 0.00% <0.00%> (ø)
Amplify/DevMenu/Data/PluginInfoHelper.swift 0.00% <0.00%> (ø)
...lify/DevMenu/Logging/PersistentLoggingPlugin.swift 60.00% <0.00%> (-15.00%) ⬇️
...lugins/API/AWSAPICategoryPlugin/AWSAPIPlugin.swift 84.00% <0.00%> (-16.00%) ⬇️
...ntAnalyticsPlugin/AWSPinpointAnalyticsPlugin.swift 42.85% <0.00%> (-57.15%) ⬇️
...th/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin.swift 25.00% <0.00%> (-12.50%) ⬇️
...WSDataStoreCategoryPlugin/AWSDataStorePlugin.swift 36.66% <0.00%> (-1.71%) ⬇️
...ns/AWSPredictionsPlugin/AWSPredictionsPlugin.swift 33.33% <0.00%> (-26.67%) ⬇️
... and 53 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 70970d2...833e35b. Read the comment docs.

Comment on lines 68 to 81
let pluginInfoItem: PluginInfoItem
if let versionable = versionable {
pluginInfoItem = PluginInfoItem(
displayName: pluginKey,
information: versionable.version
)
} else {
pluginInfoItem = PluginInfoItem(
displayName: pluginKey,
information: DevMenuStringConstants.versionNotAvailable
)
}
return pluginInfoItem
}
Copy link
Contributor

Choose a reason for hiding this comment

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

guard statement?

Suggested change
let pluginInfoItem: PluginInfoItem
if let versionable = versionable {
pluginInfoItem = PluginInfoItem(
displayName: pluginKey,
information: versionable.version
)
} else {
pluginInfoItem = PluginInfoItem(
displayName: pluginKey,
information: DevMenuStringConstants.versionNotAvailable
)
}
return pluginInfoItem
}
guard let versionable = versionable else {
return PluginInfoItem(
displayName: pluginKey,
information: DevMenuStringConstants.versionNotAvailable
)
}
return PluginInfoItem(displayName: pluginKey, information: versionable.version)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm. In this case, I'm less instinctively inclined to apply a guard because it's not actually an early exit. But thinking about it more, I like how it makes the "I need this info to do the happy path" intent easier to follow, so yeah! Guard! :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thinking about it even more though, it's even cleaner to just worry about the version:

let version = versionable?.version ?? DevMenuStringConstants.versionNotAvailable
return PluginInfoItem(displayName: pluginKey, information: version)

Comment on lines 105 to 107
let bundle = Bundle(for: type(of: self))
let version = bundle.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String
return version ?? "Not Available"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we give default behavior for this protocol, instead of repeating the same code?

Copy link
Member Author

Choose a reason for hiding this comment

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

When I originally thought about that I was stymied by type(of:) expecting a class, and AmplifyVersionable not being constrained to classes. But now that I'm thinking about it, I could write a conditional extension. Derp. Will fix.

Amplify/DevMenu/Data/PluginInfoHelper.swift Show resolved Hide resolved
Amplify/DevMenu/DevEnvironmentInfo.swift Show resolved Hide resolved
Copy link
Contributor

@drochetti drochetti left a comment

Choose a reason for hiding this comment

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

lgtm, I mostly +1 some Jithin's comments and your own comments, so I'm leaving my preemptive "ship it!"

Copy link
Contributor

@royjit royjit left a comment

Choose a reason for hiding this comment

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

LGTM

@palpatim palpatim merged commit a3bcd11 into main Nov 24, 2020
@palpatim palpatim deleted the palpatim.fix.dev-menu-bad-info branch November 24, 2020 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants