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

feat(elements): add file picker #3404

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open

Conversation

xandervedder
Copy link
Contributor

@xandervedder xandervedder commented Sep 13, 2024

Adds a file picker to the report, which allows for easier keyboard traversing over the report.

afbeelding

related #3370


ToDo:

  1. When report does not have any test files, it still shows 'all tests" in the picker but it redirects to an empty page.

@xandervedder xandervedder added the enhancement New feature or request label Sep 13, 2024
Copy link

nx-cloud bot commented Sep 13, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit c130092. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


🟥 Failed Commands
nx run-many --target=stryker --projects=metrics,elements,real-time -- --incremental
✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@xandervedder
Copy link
Contributor Author

It seems like we cannot update the screenshots anymore due to Nx Cloud:

https://github.com/stryker-mutator/mutation-testing-elements/actions/runs/11070168343/job/30759261813

NX Nx Cloud: Workspace is disabled

@hugo-vrijswijk
Copy link
Member

It seems like we cannot update the screenshots anymore due to Nx Cloud:

https://github.com/stryker-mutator/mutation-testing-elements/actions/runs/11070168343/job/30759261813

NX Nx Cloud: Workspace is disabled

You still can. Nx cloud is IMO not very friendly for open-source projects. Everything still works the same. You can update screenshots by running the workflow action on your branch. You might have to bring your branch up to date with master first

Copy link

bundlemon bot commented Oct 18, 2024

BundleMon (elements)

Files updated (3)
Status Path Size Limits
index.js
250.93KB (+9.9KB +4.11%) -
mutation-test-elements.js
207.21KB (+8.85KB +4.46%) -
index.cjs
187.57KB (+8.82KB +4.93%) -

Total files change +27.56KB +4.46%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

#handleKeyDown(event: KeyboardEvent) {
this.#currentPressedKeys.add(event.key);

if (this.#currentPressedKeys.has('Control') && this.#currentPressedKeys.has('k')) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't really understand the need for the currentPressedKeys here. The KeyboardEvent already has a e.ctrlKey, e.metaKey and e.key with which you have all you need, I think.

For the content of the search bar, it can be cleaner by using the input element value instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the content of the search bar, it can be cleaner by using the input element value instead

By using a ref?

Copy link
Member

Choose a reason for hiding this comment

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

event.target.value should also work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wait, but we are doing that already, no?

  #handleSearch(event: KeyboardEvent) {
    if (!this.openPicker) {
      return;
    }

    if (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Tab') {
      return;
    }

    this.#filter((event.target as HTMLInputElement).value);
    this.fileIndex = 0;
  }

document.body.style.overflow = 'hidden';
}

setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Is this setTimeout needed because you are waiting for a re-render? I think it should be possible without and to let lit figure out the rendering from the state. Either by some state attributes or other matters

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think about this:

this.updateComplete.then(() => this.#focusInput());

}

#closePicker() {
document.body.style.overflow = 'auto';
Copy link
Member

Choose a reason for hiding this comment

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

Rather than setting style directly I think it would be cleaner to have a state attribute of the mode, and render based on the value of the state. If you are mutating style directly you run the risk of forgetting to clean them up properly and having a "drift" as your component is being used

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 see, but I'm not sure what the implementation would look like for this.

Copy link
Member

Choose a reason for hiding this comment

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

closePicker could set a state attribute this.mode = 'closed';. And based on the mode you could set tailwind classes. Similar to the drawer component

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But how would I set tailwind classes on the document element inside this component like that?

Sorry I am confusion 😅

Copy link
Member

Choose a reason for hiding this comment

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

Oh wait. It's on document.body. You are confusion, but I am no paying attention

});

async function openPicker() {
document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Control' }));
Copy link
Member

Choose a reason for hiding this comment

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

This is a very low-level way of emulating user input. You can use the vitest API to more closely resemble actual user input in the browser: https://vitest.dev/guide/browser/interactivity-api.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants