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

[chore] Refactored cloud provider flow for performance and multi provider support #2436

Merged
merged 4 commits into from Nov 17, 2023

Conversation

macrigiuseppe
Copy link
Collaborator

@macrigiuseppe macrigiuseppe commented Nov 12, 2023

In this PR i refactored the business logic to:

  • colocated tests next to their sources for better ergonomic
  • authentication into a cloud provider
  • fetching maps from cloud provider
  • saving maps into a cloud provider
  • sharing maps using a cloud provider
  • introduced support to connect to multiple providers at the same time
  • removed redux state and actions accordingly

refactor_cloud_provider

…ider support

Signed-off-by: Giuseppe Macri <gmacri@foursquare.com>
@macrigiuseppe macrigiuseppe changed the title [chore] refactored cloud provider flow for performance and multi provider support [chore] Refactored cloud provider flow for performance and multi provider support Nov 12, 2023
@@ -78,7 +84,6 @@ export default class Provider {
displayName: string;
icon: ComponentType<IconProps>;
thumbnail: Thumbnail;
getManagementUrl?: () => string;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

converted to an actual method

Comment on lines 423 to 432
availableProviders = createSelector(
(props: KeplerGLProps) => props.cloudProviders,
providers =>
Array.isArray(providers) && providers.length
? {
hasStorage: providers.some(p => p.hasPrivateStorage()),
hasShare: providers.some(p => p.hasSharingUrl())
}
: {}
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we no longer need to inject providers since components can use the custom hook to access cloud list provider

{...geoCoderPanelFields}
index={index}
unsyncedViewports={true}
<CloudListProvider providers={cloudProviders}>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

just wrapping the content using the CloudListProvider

@@ -355,9 +346,6 @@ export default function ModalContainerFactory(
onClose={this._closeModal}
onFileUpload={this._onFileUpload}
onLoadCloudMap={this._onLoadCloudMap}
cloudProviders={this.providerWithStorage(this.props)}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not needed anymore

}
`;

export const CloudHeader = ({provider, onBack}) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

extracted this content from load-storage-map

}
`;

export const CloudItem = ({vis, onClick}) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

extract from load-storage-map

}
`;

export const CloudMaps = ({provider, onSelectMap, isLoading, maps, error}) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

extract from load-storage-map

@@ -78,7 +79,7 @@ const StyledUserName = styled.div`
`;

interface OnClickProps {
onClick?: React.MouseEventHandler<HTMLDivElement>;
onClick?: React.MouseEventHandler<HTMLButtonElement>;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

since we are passing props to a button makes more sense to target HTMLButtonElement

Comment on lines +31 to +38
const notification = useMemo(
() => ({
type: 'error',
message: error,
id: 'cloud-export-error'
}),
[error]
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

performance improvement

Comment on lines -385 to -388

/**
* Set current cloudProvider
*/
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we no longer need these actions since we are handling everything through hooks and provider

Signed-off-by: Giuseppe Macri <gmacri@foursquare.com>
@@ -0,0 +1,59 @@
// @ts-nocheck
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we fine with placing .spec.tsx not in test/ folders?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

working on it. i want to make the case about colocating tests next to their source because it improves developer ergonomic and make writing tests much quicker and simpler.
I had no problem mocking custom hooks in this setup using jest but if i move the test in the Test folder i need to mock kepler.gl/components with several side effects

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we are good to go

if (provider.getAccessToken()) {
setError(null);
setIsLoading(true);
setError(null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this extra call to setError(null); required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is used to clear the error message when a user switch from a provider that triggered an error, e.g. timeout, to a different provider.
We hide the previous error and show the loading icon

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean the same setError(null); is called in the line 120 & 122

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh i didn't realize that. thank you for catching it


const onLogin = useCallback(async () => {
try {
const user = await provider.login();
Copy link
Collaborator

Choose a reason for hiding this comment

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

When I try to log into Dropbox but click Cancel, the popup doesn't close and redirects to the new kepler.gl view.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

let me look into this!

isReady={isReady}
/>
))}
</div>
</StyledExportSection>
{isProviderLoading || providerError ? (
<StatusPanel
isLoading={isProviderLoading}
error={providerError}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like an error error generated by one provider is displayed and not cleared when a user switches to the second provider.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will look into this as well

Giuseppe Macri added 2 commits November 16, 2023 20:31
Signed-off-by: Giuseppe Macri <gmacri@foursquare.com>
Signed-off-by: Giuseppe Macri <gmacri@foursquare.com>
@macrigiuseppe macrigiuseppe merged commit 82fc69e into master Nov 17, 2023
8 checks passed
@delete-merged-branch delete-merged-branch bot deleted the refactor_cloud_provider branch November 17, 2023 03:03
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.

None yet

2 participants