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

[Doc] Targetables #2966

Merged
merged 20 commits into from
Jan 28, 2021
Merged

[Doc] Targetables #2966

merged 20 commits into from
Jan 28, 2021

Conversation

jcalcaben
Copy link
Contributor

Description

Create documentation for Targetables, this includes:

  • A brief explainer
  • An overview for how to use it
  • Reference documentation with code examples

Related Issue

Closes PWA-796

Acceptance

Any core developer

Verification Stakeholders

Any core developer

Specification

Verification Steps

  1. Navigate to the pwa-devdocs project: cd pwa-devdocs
  2. Run the HTML preview server: yarn develop
  3. Verify site builds
  4. Navigate to /pwa-buildpack/extensibility-framework/
  5. Verify Targetables section exists on the page with accurate information
  6. Navigate to /tutorials/targetables/
  7. Verify page exists, contains accurate information and listed on the left navigation
  8. Navigate to /pwa-buildpack/reference/targetables/TargetableSet/
  9. Verify Targetables section listed on the left navigation with working links to individual reference doc pages

Screenshots / Screen Captures (if appropriate)

Checklist

  • I have added tests to cover my changes, if necessary.
  • I have added translations for new strings, if necessary.
  • I have updated the documentation accordingly, if necessary.

@jcalcaben jcalcaben added pkg:pwa-devdocs documentation This pertains to documentation. version: Patch This changeset includes backwards compatible bug fixes. docs documentation labels Jan 22, 2021
@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Jan 22, 2021

Messages
📖

Associated JIRA tickets: PWA-796.

📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next nightly build run (assuming they are fixed).
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

Generated by 🚫 dangerJS against 20020e8

Copy link
Contributor

@revanth0212 revanth0212 left a comment

Choose a reason for hiding this comment

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

Wonderful work @jcalcaben. Love the way you have structured the docs.

I have provided minor change requests/questions. Let me know what you think of them?

*
* @alias TargetableESModuleObject#add
* @param {string} importString A static import declaration
*
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 add a @return here?

* Adds a module or modules to the object using the `addImport()` function.
*
* @param {...string} args Static import declaration(s)
*
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 add a @return here?

#### Extensions security

For security reasons, PWA Studio restrict the scope of Targetable modifications within an extension's intercept file to source files in the extension package.
This prevents third party extensions from making source code changes to a storefront project without the developer's knowledge.
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 elaborate on this? From an extension point of view, what is the targetable scope (its own files, storefront files, other extensions etc)?

Use this to reference the component's local name when adding custom code with Targetables.

```jsx
let Button = new SingleImportStatement("Button from './button'");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let Button = new SingleImportStatement("Button from './button'");
let Button = new SingleImportStatement("import Button from './button'");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fun Fact: You can skip import here and the class is smart enough to infer what you mean.

See: https://github.com/magento/pwa-studio/blob/develop/packages/pwa-buildpack/lib/WebpackTools/targetables/__tests__/SingleImportStatement.spec.js#L34-L46

I'll add that note in the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good to know. Nicee.

Pass in an import statement to the constructor to create a new `SingleImportStatement` object.

```js
const useQueryImport = new SingleImportStatement("import { useQuery } from '@apollo/react-hooks'");
Copy link
Contributor

Choose a reason for hiding this comment

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

useQueryImport sounds like a hook/talon.

Suggested change
const useQueryImport = new SingleImportStatement("import { useQuery } from '@apollo/react-hooks'");
const queryHookImport = new SingleImportStatement("import { useQuery } from '@apollo/react-hooks'");

Use the `changeBinding()` function to rename the variable bound to the imported object.

```js
const useQueryImport = new SingleImportStatement("import { useQuery } from '@apollo/react-hooks'");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const useQueryImport = new SingleImportStatement("import { useQuery } from '@apollo/react-hooks'");
const queryHookImport = new SingleImportStatement("import { useQuery } from '@apollo/react-hooks'");

```js
const useQueryImport = new SingleImportStatement("import { useQuery } from '@apollo/react-hooks'");

const useQueryImport2 = useQueryImport.changeBinding('useQuery2');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const useQueryImport2 = useQueryImport.changeBinding('useQuery2');
const queryHookImport2 = useQueryImport.changeBinding('useQuery2');


#### Import statement limits

The `addImport()` function can only handle import statements with a single binding.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's nice that you have mentioned this. Do we have a plan to handle/support multiple imports? If so, I guess it makes sense to mention that here for curious devs.

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 not aware of any plans

'div className={pageClass}',
'<span>appendJSX succeeded!</span>'
)
.addJSXClassName('div className={pageClass}', 'pageClass')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.addJSXClassName('div className={pageClass}', 'pageClass')
.addJSXClassName('div className={pageClass}', 'newClass')

This class is available as a named import from `@magento/pwa-buildpack`.

```js
const { Targetables } = require('@magento/pwa-buildpack')
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you mention that Targetables and TargetableSet are the same because nowhere in the following examples we are using TargetableSet?

@jcalcaben jcalcaben requested a review from revanth0212 January 26, 2021 22:35
revanth0212
revanth0212 previously approved these changes Jan 27, 2021
Copy link
Contributor

@revanth0212 revanth0212 left a comment

Choose a reason for hiding this comment

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

Wonderful work. Approved.

@dpatil-magento dpatil-magento self-requested a review January 28, 2021 15:18
Copy link
Contributor

@dpatil-magento dpatil-magento left a comment

Choose a reason for hiding this comment

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

Approved latest commits.

@dpatil-magento dpatil-magento merged commit cf11495 into develop Jan 28, 2021
@dpatil-magento dpatil-magento deleted the jimothy/pwa-796_targetables-docs branch January 28, 2021 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs documentation documentation This pertains to documentation. pkg:pwa-buildpack pkg:pwa-devdocs Progress: done version: Patch This changeset includes backwards compatible bug fixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants