Skip to content

Conversation

@evwilkin
Copy link
Member

@evwilkin evwilkin commented Aug 9, 2022

Closes #2737

This PR:

  • Parses the full relative import path (which we already have in build process) from node_modules directory to convert relative imports in examples on the website to absolute import paths from npm packages on Codesandbox.

Ex:
import DashboardWrapper from './examples/DashboardWrapper' => import DashboardWrapper from '@patternfly/react-core/src/demos/./examples/DashboardWrapper'

Notes:

  • This method should work on relative image imports and can replace this code that points image imports back to patternfly.org URLs, but in practice images were not displaying correctly. May be error in base64 image parsing, as image src looked to populate correctly when removing code linked above.
  • Relative import paths need to be correct in the example code in order to match correctly to absolute URL. For example, the primary detail demo - primary detail card view correctly imports images at the top of the .md file (import pfIcon from './Card/pf-logo-small.svg';) but has incorrect import path in the example code (import pfIcon from './pf-logo-small.svg';) which previously did not break Codesandbox images but would now (if this PR code applied to images as noted above).

@patternfly-build
Copy link
Collaborator

patternfly-build commented Aug 9, 2022

@nicolethoen
Copy link
Collaborator

So far looking good!
I see that the images still are not working - though i cant find a demo where that seems to be particularly problematic. The codesandbox and a consumer's ability to play with the demo is still all in tact, even without the images.

@evwilkin
Copy link
Member Author

evwilkin commented Sep 2, 2022

So far looking good! I see that the images still are not working - though i cant find a demo where that seems to be particularly problematic. The codesandbox and a consumer's ability to play with the demo is still all in tact, even without the images.

@nicolethoen I'm still wrapping this work up, can you clarify which images you're referring to? Is it just the PF logo on the Codesandbox link, seen broken below?
Screen Shot 2022-09-02 at 9 45 55 AM

@nicolethoen
Copy link
Collaborator

yeah that and I peeked at the Card view demo since I knew it had so many images
Screen Shot 2022-09-02 at 2 43 19 PM

@evwilkin evwilkin marked this pull request as ready for review September 4, 2022 00:10
@evwilkin
Copy link
Member Author

evwilkin commented Sep 6, 2022

@nicolethoen thanks for the call out, it looks like the broken images bug already exists on the site today for examples that have a relative image import, so I've split that out into a new issue to fix the React example/demo images and will focus this PR as-is on enabling the relative imported components such as DashboardWrapper to not break the Codesandbox examples.

Note that there is currently a pending PR to update the relative image import within the DashboardHeader to an absolute import path, which should resolve the PatternFly brand logo at the top of these examples not rendering correctly.

@evwilkin evwilkin merged commit fbecd9d into patternfly:main Sep 7, 2022
jessiehuff pushed a commit to jessiehuff/patternfly-org that referenced this pull request Oct 24, 2022
…ernfly#3122)

* fix(docs): codesandbox relative imports point to package import

* fix(docs): remove console logs

* fix relativeImports throwing syntax error when being attached to scope

* fix regex to allow for /../ in addition to /./

* update hast regex

* replace import based on name rather than relative path, allow for imported examples to have different rel paths

* remove console log

* cleanup comments

* add pathPrefix for image src urls

* revert pathPrefix
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.

codesandbox link not working when example loads other files

3 participants