Published on

Release: Template tag for Ant menu

Authors
  • Name
    Dave Coates

This release contains changes up until release/2022-08-30.

To upgrade any existing projects it's recommended to pull in the relevant commits from upstream.

git remote add upstream git@gitlab.internal.alliancesoftware.com.au:alliance/template-django.git
git cherry-pick XXX1 XXX2

In cases where you are significantly behind it may be easier to pull the whole app (eg. common_audit) in but you'll need to review the relevant branch.


In this release

Honing the craft: closing the loop

  • /admin/ or /app/? Most projects use /admin/ so will remain the default.
    • Somtimes need different sections based on user type. One option is to limit access with django middleware. A common pattern & some examples will be documented for this.
  • Code reviews
    • As a reviewer make the intention clear if a change isn't required. It's good to share knowledge and reviews are probably the most effective place for this as it directly relates to something you are implementing yourself.
  • Don't use assert for production code
    • Use if / raise pattern
  • Estimation including testing & code review time
    • Keep in mind the why
      • So PM's know how much work is in the backlog
      • To assist with planning & set cost/timeline expectations with client
    • How?
      • No hard rule; it varies wildly
      • Use best judgement based on complexity of card; doesn't need to be super scientific
    • Remember:
      • Estimates aren't a contract; they're a best guess based on incomplete information
      • Estimate doing the job right (including updating docs, necessary refactoring etc) - try your best to avoid feeling pressure to low ball numbers.
        • Sometimes it's necessary but we should aim for it to be a conscious compromise after discussion
      • If it's obvious an estimate is wrong communicate that to the PM (the degree matters - 2 hours over on a 1 hour task matters more than on a 2 day task)
    • Training
      • Some content will be added to training project about the spirit & our approach to estimating

Ant Menus

There's now a template tag for rendering an antd menu. The purpose of this is to render the menu in static HTML so loads immediately without needing to be rendered by React.

{% load ant_menu %}

{% menu html_id="menu" class="main-menu" %}
    {% menu_item "my_app:my_list" %}My List 1{% endmenu_item %}
    {% menu_item "my_app:another_list" %}My List 2{% endmenu_item %}
    {% sub_menu "Users" %}
      {% menu_item "xenopus_frog_app:adminprofile_list" %}Admin{% endmenu_item%}
      {% menu_item "xenopus_frog_app:customerprofile_list" %}Customers{% endmenu_item%}
    {% endsub_menu %}
{% endsub_menu %}

Features / differences from the React component:

  • Use django named URLs for items. Supports permission checks like the link template tag.
  • Supports sub menus
  • Auto hides menu items user has no permission for (including empty sub menus due to permission checks)
  • Horizontal/vertical/inline support
  • Dark / light support
  • Template automatically switches to mobile version on smaller screens

To upgrade see the original MR.

See the documentation for more

Presto 0.0.32

  • Added AsyncChoices.parseValue
    • This solves a bug where drop down may show the id rather than label for an existing value
    • See commit 203b4836 for changes to codegen to support this.
  • EmailWidget now uses type="email"
  • Fixed useAsyncValue existingValues to work with complex keys
  • Fix bug in view model caching when retrieving nested records with many related fields with no values set. Previously if it was initialised with an empty array retrieving from the cache explicitly naming those fields (or using *) would result in a cache miss.
  • UrlPattern now supports specifying options in the constructor. All options can be overridden in the call to resolve.
    • baseUrl - if specified this will be prefixed to resolved pattern
    • query - any query parameters to be included in any urls resolved from this pattern
    • mergeQuery - If true (the default) then any query parameters provided to the constructor will be merged with any provided to resolve.
  • Endpoint.prepare now returns a function that can be called directly (previously it was an object with an execute method).
    • This changes usage from endpoint.prepare().execute() to endpoint.prepare()() (but the former will still work with a deprecation notice)
    • This makes usage with useAsync much easier, eg. useAsync(endpoint.prepare(), { trigger: 'SHALLOW' }) will work now
  • Endpoint now accepts a string or UrlPattern as the URL. If a string is passed it will be converted to a UrlPattern.

Simple usage of useAsync with Endpoint:

const endpoint = new Endpoint<{ id: number; name: string }[]>('/api/users')

export default function QueryParamsExample() {
  const [filter, setFilter] = React.useState('')
  const { result, isLoading } = useAsync(endpoint.prepare({ query: { filter } }), {
    trigger: 'SHALLOW',
  })
  return (
    <div>
      <Input
        disabled={isLoading}
        type="search"
        placeholder="Search"
        // @ts-ignore
        onPressEnter={({ target: { value } }) => setFilter(value)}
        style={{ maxWidth: 300 }}
      />
      {result?.result.map((user) => (
        <div key={user.id}>{user.name}</div>
      ))}
    </div>
  )
}

See changelog.

Replace django-inlinecss with css-inline

This is used to inline css in HTML emails. django-inlinecss is unmaintained and breaks in Django >= 4

It has been replaced with css-inline which resolves these issues and is faster.

See the original MR for the changes required to upgrade.

Other changes

See all commits since last release for other smaller changes.