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

Initial code #1

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
Open

Initial code #1

wants to merge 13 commits into from

Conversation

Morsey187
Copy link
Owner

The PR adds the inital setup and functionaility for this package to work.

Custom draftail entity, client side code, wagtail hooks, and documentation around use and references to adding a link handler.

For testing I'd recommend cloning the repo locally, and then installing it inside the wagtail bakery demo for now, there is a test app within the repo, however I haven't commited any page models or data for it yet.

  1. Clone repo
  2. pip install -e ../wagtail-shortcode
  3. Setup by following readme
  4. Test within wagtail

Screenshots

ref 1 Screenshot 2024-01-04 at 12 42 12
ref 2 Screenshot 2024-01-04 at 12 42 36

@@ -1 +1,66 @@
# Contributing to shortcode
# Contributing
Copy link
Owner Author

Choose a reason for hiding this comment

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

Note:
I've moved the contributing docs here to keep the readme clean, as well as added a section # Tips on working with the package locally to share my own notes on using cookiecutter-wagtail-package.

@@ -12,6 +12,13 @@ declare module '*.svg' {
declare global {
// Wagtail globals

interface Window {
Copy link
Owner Author

@Morsey187 Morsey187 Jan 4, 2024

Choose a reason for hiding this comment

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

Note:
Some of these types aren't exported e.g. import type { TooltipEntity } from 'draftail';, so as not to waste time on resolving this i've defined them as any.

For example, I can't define:

const { TooltipEntity } = window.draftail;

as

import type { TooltipEntity as TooltipEntityType }  from 'draftail';`

const { TooltipEntity as TooltipEntityType} = window.draftail

@@ -0,0 +1,5 @@
/*
Copy link
Owner Author

Choose a reason for hiding this comment

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

Note:
Not needed but seemed like a waste to remove code that might be needed in the future?

helpText: string;
};

const getShortcodeConfig = (): WagtailShortcodeConfig => {
Copy link
Owner Author

@Morsey187 Morsey187 Jan 4, 2024

Choose a reason for hiding this comment

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

Note:
Defining this as a config with it's own type seems like a more future proof option, rather then specifyling this as help-text only

const { helpText } = getShortcodeConfig();

// eslint-disable-next-line no-alert
const shortcodeValue = window.prompt(helpText, defaultValue);
Copy link
Owner Author

Choose a reason for hiding this comment

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

Note:
As mentioned on slack, there are obvious limitations to basic text formating, if needed I'll open up a seperate PR with draft code for adding a model.

wagtail_shortcode/static_src/main.tsx Outdated Show resolved Hide resolved
wagtail_shortcode/wagtail_hooks.py Outdated Show resolved Hide resolved
wagtail_shortcode/wagtail_hooks.py Outdated Show resolved Hide resolved
wagtail_shortcode/wagtail_hooks.py Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
return DOM.create_element(
"a",
{
"shortcode": props.get("shortcode"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like you're storing it in the shortcode attribute rather than the href, which they originally suggested on the call. IMO this is fine, but worth double checking this afternoon with them that the db format for a shortcode will be x, any conversion to FE will be done by the LinkHandler + additional python code they write.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thats a good point.

I figured it could cause less confusion between creating the entity on the front-end (createEntity() in main.tsx), then passing that value as a prop here (shortcode_entity_decorator) and then getting the value from ShortcodeEntityElementHandler again to the content state.

However I've gone with href now as it's probably better to maintain a database state closer to what they're expecting. To try and tackle any potential confusion I've added comments and labeled variables like so:

"href": props.get("href"),  # the shortcode value
...
href: shortcodeValue,
...
const shortcodeValue = data.href || null;

Copy link
Owner Author

Choose a reason for hiding this comment

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

Scratch the above, using href conflicts with wagtail's default external link handler/entity, use of the shortcode attribute seems like the safer option.

README.md Outdated Show resolved Hide resolved
@Morsey187
Copy link
Owner Author

Hey @jacobtoppm,
Incase you have to alter or change anything whilst I'm away.
I've invited you to the repo and have been cherry picking all commits in this branch to main, so it should be safe to close this PR once you're happy with it and push straight to main. I opened these branches up orginally to help with reviewing and displaying diffs.

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.

2 participants