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

add maxItems option to scope prompt #104

Merged
merged 3 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"license": "MIT",
"dependencies": {
"@clack/core": "^0.3.1",
"@clack/prompts": "^0.6.2",
"@clack/prompts": "^0.7.0",
"configstore": "^5.0.1",
"picocolors": "^1.0.0",
"valibot": "^0.30.0"
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Better-commits (& better-branch) are highly flexible with sane defaults. These o
"commit_type": {
"enable": true,
"initial_value": "feat",
"max_items": Infinity,
"infer_type_from_branch": true,
"append_emoji_to_label": false,
"append_emoji_to_commit": false,
Expand Down Expand Up @@ -168,6 +169,7 @@ Better-commits (& better-branch) are highly flexible with sane defaults. These o
"enable": true,
"custom_scope": false,
"initial_value": "app",
"max_items": Infinity
"options": [
{
"value": "app",
Expand Down Expand Up @@ -281,6 +283,7 @@ Expand to see explanations and possible values
| `check_status` | If true run interactive `git status` |
| `commit_type.enable` | If true include commit type |
| `commit_type.initial_value` | Initial selection of commit type |
| `commit_type.max_items` | Maximum number of type displayed on the screen |
| `commit_type.infer_type_from_branch` | If true infer type from branch name |
| `commit_type.append_emoji_to_label` | If true append emoji to prompt |
| `commit_type.append_emoji_to_commit` | If true append emoji to commit |
Expand All @@ -292,6 +295,7 @@ Expand to see explanations and possible values
| `commit_scope.enable` | If true include commit scope |
| `commit_scope.custom_scope` | If true allow custom scope at run-time |
| `commit_scope.initial_value` | Default commit scope selected |
| `commit_scope.max_items` | Maximum number of scope displayed on the screen |
| `commit_scope.options.value` | Commit scope value |
| `commit_scope.options.label` | Commit scope label |
| `check_ticket.infer_ticket` | If true infer ticket from branch name |
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export async function main(config: Output<typeof Config>) {
const commit_type = await p.select({
message,
initialValue: initial_value,
maxItems: config.commit_type.max_items,
options: config.commit_type.options,
});
if (p.isCancel(commit_type)) process.exit(0);
Expand All @@ -107,6 +108,7 @@ export async function main(config: Output<typeof Config>) {
let commit_scope = await p.select({
message: "Select a commit scope",
initialValue: config.commit_scope.initial_value,
maxItems: config.commit_scope.max_items,
Copy link
Owner

Choose a reason for hiding this comment

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

On most PRs I would say this is exactly what we want to do (thanks for taking the time to understand the repo!). - I think in this case we could just bump the version and put maxItems: Infinity (Or just a relatively high number lol) here and on commit_type.

IIRC (maybe it has changed) clack doesn't support filter / search on select. As an example, if we had 10 scopes but a max_items of 5, we don't have a way to filter where it would show any of the 5 hidden items.

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 added max_items for commit_type. Yes, we have the ability to specify what will be displayed, but if we specify initialValue then p.select will correctly move through the list:

image

Copy link
Owner

Choose a reason for hiding this comment

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

👀 I misunderstood how max-items works. - I'll merge :), thanks again!

options: config.commit_scope.options,
});
if (p.isCancel(commit_scope)) process.exit(0);
Expand Down
2 changes: 2 additions & 0 deletions src/valibot-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const Config = v.object({
{
enable: v.optional(v.boolean(), true),
initial_value: v.optional(v.string(), "feat"),
max_items: v.optional(v.number(), Infinity),
infer_type_from_branch: v.optional(v.boolean(), true),
append_emoji_to_label: v.optional(v.boolean(), false),
append_emoji_to_commit: v.optional(v.boolean(), false),
Expand Down Expand Up @@ -65,6 +66,7 @@ export const Config = v.object({
{
enable: v.optional(v.boolean(), true),
custom_scope: v.optional(v.boolean(), false),
max_items: v.optional(v.number(), Infinity),
initial_value: v.optional(v.string(), "app"),
options: v.optional(
v.array(
Expand Down