Skip to content

add toggle buttons to pub field form elements#665

Merged
3mcd merged 4 commits intomainfrom
em/form-field-toggle
Sep 26, 2024
Merged

add toggle buttons to pub field form elements#665
3mcd merged 4 commits intomainfrom
em/form-field-toggle

Conversation

@3mcd
Copy link
Copy Markdown
Collaborator

@3mcd 3mcd commented Sep 26, 2024

Issue(s) Resolved

Closes knowledgefutures/pubpub#3179

(Looks like this issue was accidentally created in the pubpub/pubpub repo)

High-level Explanation of PR

This PR adds a button to the left side of form elements within the pub create form. Clicking the button toggles the disabled state for that field. By default all fields are enabled.

Disabled fields are omitted from the form when submitted. This means that submitting a form with all fields disabled will create a pub with no pub values.

Test Plan

  1. Use the create pub button to create a pub.
  2. Create pubs with various configurations of disabled and enabled fields. Values of disabled fields should not be present on newly created pubs.
  3. The form's submit button should only be disabled when enabled buttons fail to validate. Invalid disabled fields should not be considered.
  4. Update a pub. The buttons should not be visible on the update form.

Screenshots (if applicable)

The pub creation form with a disabled title field and invalid email field. The "Create Pub" button is disabled because of the enabled, invalid field.

Screenshot 2024-09-26 at 1 40 43 PM

The same pub creation form after disabling the invalid email field. The "Create Pub" button is now enabled because the invalid field was disabled.

Screenshot 2024-09-26 at 1 40 49 PM

The pub page of the newly created pub. Notice that the only field associated with the pub is "Member ID": the only enabled field on the form in the previous screenshot.

Screenshot 2024-09-26 at 1 41 12 PM

Notes

@3mcd 3mcd marked this pull request as ready for review September 26, 2024 19:45
@3mcd 3mcd force-pushed the em/form-field-toggle branch from 1dac72f to 885ff73 Compare September 26, 2024 19:45
Copy link
Copy Markdown
Contributor

@allisonking allisonking left a comment

Choose a reason for hiding this comment

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

this looks good for the most part! just two things I found while playing around that may not be need to be addressed in this PR:

  1. I can't create a pub with all disabled fields (I get a db error)
[16:15:08.231] ERROR: syntax error at or near ")"
    package: "core"
    err: {
      "type": "DatabaseError",
      "message": "syntax error at or near \")\"",
      "stack":
          error: syntax error at or near ")"
              at /Users/allisonking/workspace/kf/v7/node_modules/.pnpm/pg@8.12.0/node_modules/pg/lib/client.js:526:17
              at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
              at async PostgresConnection.executeQuery (/Users/allisonking/workspace/kf/v7/core/.next/server/chunks/ssr/33c0b_kysely_dist_esm_85a464._.js:3973:28)
  1. The create form doesn't seem to close after submitting (not sure if that was introduced in this PR)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not needed?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

uhh yeah not sure where this came from, ty!

@3mcd 3mcd force-pushed the em/form-field-toggle branch from 885ff73 to 894aec4 Compare September 26, 2024 21:51
sql<PubValues>`(select coalesce(json_object_agg(${sql.ref(alias)}.slug, ${sql.ref(
alias
)}.value) from ${subquery})`;
)}.value), '{}') from ${subquery})`;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This just coalesces the value to {} in the case the pub has no pub values.

@3mcd 3mcd force-pushed the em/form-field-toggle branch from dcedeac to b0aa527 Compare September 26, 2024 22:17
@3mcd 3mcd merged commit 86a6fd7 into main Sep 26, 2024
@3mcd 3mcd deleted the em/form-field-toggle branch September 26, 2024 22:17
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.

Regression: Cannot create child pub with empty fields (e.g. a review invitation)

2 participants