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

Custom Views context hook adjustment #3292

Merged
merged 10 commits into from
Nov 14, 2023
Merged

Conversation

CarlosCortizasCT
Copy link
Contributor

Summary

Custom Views context hook adjustment

Description

In this PR I propose refactoring the useCustomView hook to not only return the Custom Views context but also the internal Application context. This way, Custom Views developers requirement some data from any of the context can access to them from the same hook (dedicated to Custom Views) without them needing to know we manage two context internally.

Copy link

changeset-bot bot commented Nov 7, 2023

🦋 Changeset detected

Latest commit: 36dae62

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 37 packages
Name Type
@commercetools-frontend/application-config Minor
@commercetools-applications/merchant-center-custom-view-template-starter-typescript Minor
@commercetools-frontend/application-shell Minor
@commercetools-frontend/application-shell-connectors Minor
@commercetools-frontend/application-components Minor
@commercetools-frontend/cypress Minor
@commercetools-frontend/mc-dev-authentication Minor
@commercetools-frontend/mc-html-template Minor
@commercetools-frontend/mc-scripts Minor
@commercetools-applications/merchant-center-template-starter-typescript Minor
@commercetools-local/visual-testing-app Minor
@commercetools-website/components-playground Minor
@commercetools-applications/merchant-center-template-starter Minor
@commercetools-local/playground Minor
@commercetools-frontend/permissions Minor
@commercetools-frontend/codemod Minor
@commercetools-backend/eslint-config-node Minor
@commercetools-backend/express Minor
@commercetools-backend/loggers Minor
@commercetools-frontend/actions-global Minor
@commercetools-frontend/assets Minor
@commercetools-frontend/babel-preset-mc-app Minor
@commercetools-frontend/browser-history Minor
@commercetools-frontend/constants Minor
@commercetools-frontend/create-mc-app Minor
@commercetools-frontend/eslint-config-mc-app Minor
@commercetools-frontend/i18n Minor
@commercetools-frontend/jest-preset-mc-app Minor
@commercetools-frontend/jest-stylelint-runner Minor
@commercetools-frontend/l10n Minor
@commercetools-frontend/notifications Minor
@commercetools-frontend/react-notifications Minor
@commercetools-frontend/sdk Minor
@commercetools-frontend/sentry Minor
@commercetools-frontend/url-utils Minor
@commercetools-website/custom-applications Minor
@commercetools-website/custom-views Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -45,6 +49,10 @@ export const renderCustomView = (
locale: props.locale,
project: {
key: props.projectKey,
allAppliedPermissions: props.projectAllAppliedPermissions || [],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Writing the docs I found out we allow for custom permissions in Custom Application testing so I'm adding that possibility for Custom Views as well.

Copy link
Contributor

github-actions bot commented Nov 7, 2023

Deploy preview for application-kit-custom-views ready!

✅ Preview
https://application-kit-custom-views-l7wh2n2i7-commercetools.vercel.app
https://appkit-cv-sha-c0d63e2cf2c867d27d1da076eef3be47af8303ef.commercetools.vercel.app
https://appkit-cv-pr-3292.commercetools.vercel.app

Built with commit 36dae62.
This pull request is being automatically deployed with vercel-action

Copy link
Contributor

github-actions bot commented Nov 7, 2023

Deploy preview for merchant-center-application-kit ready!

✅ Preview
https://merchant-center-application-n0zth3zx7-commercetools.vercel.app
https://appkit-sha-c0d63e2cf2c867d27d1da076eef3be47af8303ef.commercetools.vercel.app
https://appkit-pr-3292.commercetools.vercel.app

Built with commit 36dae62.
This pull request is being automatically deployed with vercel-action

@CarlosCortizasCT CarlosCortizasCT marked this pull request as ready for review November 7, 2023 09:29
@CarlosCortizasCT CarlosCortizasCT requested a review from a team November 7, 2023 09:29
Copy link
Member

@emmenko emmenko left a comment

Choose a reason for hiding this comment

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

Nice, thanks for following up on this! 🤗

PS: changeset

allAppliedPermissions: props.projectAllAppliedPermissions || [],
},
environment: {
entryPointUriPath: CUSTOM_VIEW_HOST_ENTRY_POINT_URI_PATH,
Copy link
Member

Choose a reason for hiding this comment

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

💯

import {
type TApplicationContext,
useApplicationContext,
} from '../application-context';

export type TCustomViewContext = {
hostUrl: string;
config: CustomViewData;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: now that we have the data together, should we rename this to customViewConfig?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that makes sense. Thanks 👍

Updated here: fa5fa67

@@ -44,6 +45,7 @@ type THostEventData = {
};

type TCustomViewShellProps = {
apolloClient?: ApolloClient<NormalizedCacheObject>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also allow consumers to provide their custom Apollo client (same as with Custom Applications)

Copy link
Contributor

@Rhotimee Rhotimee left a comment

Choose a reason for hiding this comment

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

💯 💯

Thanks

Copy link
Contributor

@kark kark left a comment

Choose a reason for hiding this comment

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

Thanks for the enhancements 🙌
Just a reminder about the changeset 🤗

@@ -118,6 +122,15 @@ function entryPointUriPathToResourceAccesses<
};
}

function resolveCustomViewResourceAccesses<PermissionGroupName extends string>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When writing the docs for Custom Views I noticed if a developer needs to calculate the permissions he would need to use something like this:

export const PERMISSIONS = entryPointUriPathToPermissionKeys(CUSTOM_VIEW_HOST_ENTRY_POINT_URI_PATH);

It seems confusing to me as the concept of entry point does not exist for Custom Views, so I decided to propose the inclusion of this new helper target for Custom Views where they can get both the basic resource accesses and also the one for the additional groups.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@emmenko please let me knot what you think about this 🙏

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, thanks for thinking about that!

In the example you refer to "permission keys" but here the helper is about "resource accesses".
Maybe we can provide 2 helper functions for both:

computeCustomViewResourceAccesses
computeCustomViewPermissionKeys

Nit: compute sounds a bit more appropriate than resolve.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion.

I updated this part here: 96cc64e

Comment on lines +37 to +38
environment?: Partial<TProviderProps<{}>['environment']>;
user?: Partial<TProviderProps<{}>['user']>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm also adding the environment and the user as they also seem quite helpful when testing Custom Views with different permissions.

Copy link
Member

@emmenko emmenko left a comment

Choose a reason for hiding this comment

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

Sorry for the late review 🙃

@@ -118,6 +122,15 @@ function entryPointUriPathToResourceAccesses<
};
}

function resolveCustomViewResourceAccesses<PermissionGroupName extends string>(
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, thanks for thinking about that!

In the example you refer to "permission keys" but here the helper is about "resource accesses".
Maybe we can provide 2 helper functions for both:

computeCustomViewResourceAccesses
computeCustomViewPermissionKeys

Nit: compute sounds a bit more appropriate than resolve.

.changeset/cuddly-clouds-pull.md Outdated Show resolved Hide resolved
Co-authored-by: Nicola Molinari <nicola.molinari@commercetools.com>
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.

4 participants