Skip to content

web: clear "blanked" placeholder when present (#15)#5948

Merged
BeryJu merged 5 commits intomainfrom
0015-remove-search-placeholder-2
Jan 17, 2024
Merged

web: clear "blanked" placeholder when present (#15)#5948
BeryJu merged 5 commits intomainfrom
0015-remove-search-placeholder-2

Conversation

@kensternberg-authentik
Copy link
Copy Markdown
Contributor

This commit:

  • Renames "SearchSelect.ts" to "ak-search-select.ts", the better to reflect that it is a web component.
  • Moves it into an independent folder named "SearchSelect" so that all existing folders that use it don't need any renaming or manipulation.
  • Refactors SearchSelect.ts in the following ways:
    • Re-arranges the properties declaration so the seven properties actually used by callers are at the top; comments and documents every property.
    • Separates out the renderItem and renderEmptyItem HTML blocks into their own templates.
    • Separates renderItem further into renderItemWithDescription and RenderItemWithoutDescription; prior to this, there were multiple conditionals handling the description issue
    • Separates renderItems into renderItemsAsGroups and renderItems; this documents what each function does and removes multiple conditionals
    • Isolates the groupedItems() logic into a single method, moving the how away from the what.
    • Replaces the manual styling of renderMenu() into a lit-element styleMap(). This makes the actual render a lot more readable!
    • Refactors the value logic into its own method, as a getter.
    • Refactors the ad-hoc handlers for focus, input, and blur into functions on the render() method itself.
      • Alternatively, I could have put the handlers as methods on the ak-search-select Node itself; Lit would automatically bind this correctly if referenced through the @event syntax. Moving them out of the render() method would require significantly more testing, however, as that would change the code flow enough it might have risked the original behavior. By leaving them in the render() scope, this guarantees their original behavior -- whether that behavior is correct or not.
  • FIXES build(deps-dev): bump bumpversion from 0.5.3 to 0.6.0 #15
    • Having isolated as much functionality as was possible, it was easy to change the onFocus() event so that when the user focuses on the <input> object, if it's currently populated with the empty option and the user specified isBlankable, clear it.
    • Notice: This creates a new, possibly undesirable behavior; since it's not possible to know why the input object is currently empty, in the event that it is currently empty as a result of this clearing there is no way to know when the "empty option" marker needs to be put back.

This is an incredibly complex bit of code, the sort that really shouldn't be written by application teams. The behavior is undefined in a number of cases, and although none of those cases are fatal, some of them are quite annoying. I recommend that we seriously consider adopting a third-party solution.

Selects (and DataLists) are notoriously difficult to get right on the desktop; they are almost impossible to get right on mobile. Every responsible implementation of Selects has a "default-to-native" experience on mobile because, for the most part, the mobile native experience is excellent -- delta wanting two-line <option> blocks and <optiongroup>s, both of which we do want.

This component implements:

  • Rendering the <input> element and handling its behavior
  • Rendering the <select> element and handling its behavior
  • Mediating between these two components
  • Fetching the data for the <select> component from the back-end
  • Filtering the data via a partial-match search through the <input> element
  • Distinguishing between hard-affirm and soft-affirm "No choice" options
  • Dispatching the <select> element via a portal, the better to control rendering.

That's a lot of responsibilities! And it makes Storybooking this component non-viable. I recommend breaking this up further, but I've already spent a lot of time just doing the refactoring and getting the new behavior as right as possible, so for now I'm just going to submit the clean-up and come back to this later.

Details

Checklist

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)

No API Changes have been made.

If changes to the frontend have been made

  • The code has been formatted (make web)
  • The translation files have been updated (make i18n-extract)

No new dialog was added.

@netlify
Copy link
Copy Markdown

netlify bot commented Jun 13, 2023

Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 235debd
🔍 Latest deploy log https://app.netlify.com/sites/authentik-storybook/deploys/6584b6377358fc000820c9c5
😎 Deploy Preview https://deploy-preview-5948--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 13, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (48e5823) 92.60% compared to head (235debd) 92.43%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5948      +/-   ##
==========================================
- Coverage   92.60%   92.43%   -0.18%     
==========================================
  Files         593      593              
  Lines       29397    29397              
==========================================
- Hits        27222    27172      -50     
- Misses       2175     2225      +50     
Flag Coverage Δ
e2e 49.39% <ø> (-1.33%) ⬇️
integration 26.14% <ø> (ø)
unit 89.70% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 13, 2023

authentik PR Installation instructions

Instructions for docker-compose

Add the following block to your .env file:

AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-0015-remove-search-placeholder-2-1686695111-bc31ace
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s

For arm64, use these values:

AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-0015-remove-search-placeholder-2-1686695111-bc31ace-arm64
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s

Afterwards, run the upgrade commands from the latest release notes.

Instructions for Kubernetes

Add the following block to your values.yml file:

authentik:
    outposts:
        container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
image:
    repository: ghcr.io/goauthentik/dev-server
    tag: gh-0015-remove-search-placeholder-2-1686695111-bc31ace

For arm64, use these values:

authentik:
    outposts:
        container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
image:
    repository: ghcr.io/goauthentik/dev-server
    tag: gh-0015-remove-search-placeholder-2-1686695111-bc31ace-arm64

Afterwards, run the upgrade commands from the latest release notes.

@netlify
Copy link
Copy Markdown

netlify bot commented Jun 21, 2023

Deploy Preview for authentik ready!

Name Link
🔨 Latest commit 7195068
🔍 Latest deploy log https://app.netlify.com/sites/authentik/deploys/64932d6fd58b8f000891b049
😎 Deploy Preview https://deploy-preview-5948--authentik.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@@ -0,0 +1,4 @@
import { SearchSelect } from "./ak-search-select";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should probably rip the bandaid off and update all the imports to use the new file instead of keeping this "wrapper" around

@BeryJu
Copy link
Copy Markdown
Member

BeryJu commented Jul 11, 2023

After some more discussion, it seems that we actually want to separate the null state and the placeholder, for the placeholder it is probably to use the html placeholder attribute, and have a separate option for null, for which we need to make sure it's slightly differently rendered so it looks different

- Renames "SearchSelect.ts" to "ak-search-select.ts", the better to reflect that it is a web
  component.
- Moves it into an independent folder named "SearchSelect" so that all existing folders that use it
  don't need any renaming or manipulation.
- Refactors SearchSelect.ts in the following ways:
  - Re-arranges the properties declaration so the seven properties actually used by callers are at
    the top; comments and documents every property.
  - Separates out the `renderItem` and `renderEmptyItem` HTML blocks into their own templates.
  - Separates `renderItem` further into `renderItemWithDescription` and
    `RenderItemWithoutDescription`; prior to this, there were multiple conditionals handling the
    description issue
  - Separates `renderItems` into `renderItemsAsGroups` and `renderItems`; this documents what each
    function does and removes multiple conditionals
  - Isolates the `groupedItems()` logic into a single method, moving the *how* away from the *what*.
  - Replaces the manual styling of `renderMenu()` into a lit-element `styleMap()`.  This makes the
    actual render a lot more readable!
  - Refactors the `value` logic into its own method, as a _getter_.
  - Refactors the ad-hoc handlers for `focus`, `input`, and `blur` into functions on the `render()`
    method itself.
    - Alternatively, I could have put the handlers as methods on the ak-search-select Node itself;
      Lit would automatically bind `this` correctly if referenced through the `@event` syntax.
      Moving them *out* of the `render()` method would require significantly more testing, however,
      as that would change the code flow enough it might have risked the original behavior.  By
      leaving them in the `render()` scope, this guarantees their original behavior -- whether that
      behavior is correct or not.
- FIXES #15
  - Having isolated as much functionality as was possible, it was easy to change the `onFocus()`
    event so that when the user focuses on the `<input>` object, if it's currently populated with
    the empty option and the user specified `isBlankable`, clear it.
  - **Notice**: This creates a new, possibly undesirable behavior; since it's not possible to know
    *why* the input object is currently empty, in the event that it is currently empty as a result
    of this clearing there is no way to know when the "empty option" marker needs to be put back.

This is an incredibly complex bit of code, the sort that really shouldn't be written by application
teams. The behavior is undefined in a number of cases, and although none of those cases are fatal,
some of them are quite annoying. I recommend that we seriously consider adopting a third-party
solution.

Selects (and DataLists) are notoriously difficult to get right on the desktop; they are almost
impossible to get right on mobile. Every responsible implementation of Selects has a
"default-to-native" experience on mobile because, for the most part, the mobile native experience is
excellent -- delta wanting two-line `<option>` blocks and `<optiongroup>`s, both of which we do
want.

This component implements:

- Rendering the `<input>` element and handling its behavior
- Rendering the `<select>` element and handling its behavior
- Mediating between these two components
- Fetching the data for the `<select>` component from the back-end
- Filtering the data via a partial-match search through the `<input>` element
- Distinguishing between hard-affirm and soft-affirm "No choice" options
- Dispatching the `<select>` element via a portal, the better to control rendering.

That's a *lot* of responsibilities! And it makes Storybooking this component non-viable. I recommend
breaking this up further, but I've already spent a lot of time just doing the refactoring and
getting the new behavior as right as possible, so for now I'm just going to submit the clean-up and
come back to this later.
@BeryJu BeryJu force-pushed the 0015-remove-search-placeholder-2 branch from 7195068 to 0043f1e Compare December 21, 2023 21:38
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
@kensternberg-authentik kensternberg-authentik marked this pull request as ready for review December 21, 2023 21:47
@kensternberg-authentik kensternberg-authentik requested a review from a team as a code owner December 21, 2023 21:47
Copy link
Copy Markdown
Member

@BeryJu BeryJu left a comment

Choose a reason for hiding this comment

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

Even though we're still not 100% happy with the implementation for this, let's still merge this for now for the usability improvements

@BeryJu BeryJu merged commit 493cefa into main Jan 17, 2024
@BeryJu BeryJu deleted the 0015-remove-search-placeholder-2 branch January 17, 2024 12:44
kensternberg-authentik added a commit that referenced this pull request Jan 17, 2024
* main: (82 commits)
  translate: Updates for file web/xliff/en.xlf in fr (#8212)
  translate: Updates for file web/xliff/en.xlf in zh-Hans (#8211)
  translate: Updates for file web/xliff/en.xlf in zh_CN (#8210)
  web/flows: update flow background (#8209)
  web: clear "blanked" placeholder when present (#15) (#5948)
  web: bump prettier from 3.2.3 to 3.2.4 in /web (#8207)
  web: bump prettier from 3.2.2 to 3.2.3 in /tests/wdio (#8200)
  web: bump the wdio group in /tests/wdio with 4 updates (#8199)
  web: bump @formatjs/intl-listformat from 7.5.4 to 7.5.5 in /web (#8203)
  core: bump uvicorn from 0.25.0 to 0.26.0 (#8198)
  web: bump prettier from 3.2.2 to 3.2.3 in /web (#8201)
  web: bump vite-tsconfig-paths from 4.2.3 to 4.3.1 in /web (#8202)
  website: bump prettier from 3.2.2 to 3.2.3 in /website (#8204)
  website: fix styling on pricing page on firefox
  website: update pricing page (#8197)
  website: bump @types/react from 18.2.47 to 18.2.48 in /website (#8184)
  website: bump react-tooltip from 5.25.1 to 5.25.2 in /website (#8185)
  web: bump the eslint group in /tests/wdio with 2 updates (#8186)
  web: bump the eslint group in /web with 2 updates (#8187)
  web: bump mermaid from 10.6.1 to 10.7.0 in /web (#8189)
  ...
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