-
Notifications
You must be signed in to change notification settings - Fork 1
Unify navigation tabs with displayMode and use built in pages for autofilled links
#1002
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
Open
rchlfryn
wants to merge
38
commits into
main
Choose a base branch
from
nav-updates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
85d5589
Update donate enable option to be the same as other topLevelNav
rchlfryn 4a650e7
Add banner description components to replace overlooked descriptions
rchlfryn 9a74a54
Update donate button
rchlfryn a451a32
Replace top level automated nav items with built-in pages (minus fore…
rchlfryn 616e1d7
Add ability for nav item to not have subnav items (purely UI change)
rchlfryn 1c400f1
Update forecast tab to use built in pages
rchlfryn 4503f60
Sort pages, built-in pages, and posts by title in reference dropdown
rchlfryn 49d192c
Add migration
rchlfryn c134389
Add script to add built in pages on prod
rchlfryn b6eba56
Change read only nav items to be editable by superAdmin
rchlfryn 1572b6b
Update nav to actually use built-in pages with hardcoded as fallback …
rchlfryn bab3fe3
Update one time script to use sql instead of update
rchlfryn 4e7fda4
Add isInNav boolean to prevent users from accidentally deleting built…
rchlfryn a829fd1
Update migration to include isInNav
rchlfryn 018e820
TODO - figure out why nav is incorrect after one time seed
rchlfryn e4e34c5
Merge branch 'main' into nav-updates
rchlfryn 35efe60
Redo migration to fix json
rchlfryn 60a9781
Remove unnecessary fallback for migration
rchlfryn 6d186fc
Remove type assertions
rchlfryn 1590fc2
Add obs fallback
rchlfryn 4b3811b
Make tenant slug immutable after creation
rchlfryn b1f932b
Revert "Make tenant slug immutable after creation"
rchlfryn 6a8dae9
Rename/restructure readonly functionality to be hasLandingPage
rchlfryn 7d5d3f2
Remove deletion warning
rchlfryn 83ab063
Merge branch 'main' into nav-updates
rchlfryn 3cbaa09
Redo migration and use backfill migration to avoid using fallbacks
rchlfryn 95c5af0
Fix bad migration
rchlfryn 9cafb76
Clean up use of hasLandingPage & add singleLinkNavTab
rchlfryn 17413de
Update migrations
rchlfryn fd24c2c
Unify navigation helper files into navTab adding displayMode
rchlfryn 86efaf0
Merge branch 'main' into nav-updates
rchlfryn 158e76a
Update migrations
rchlfryn f02d029
Treat donate button the same as other tabs and allow button to be put…
rchlfryn 714762c
Add hook to clean unused tab data
rchlfryn 130a514
Merge branch 'main' into nav-updates
rchlfryn d71d920
Merge branch 'main' into nav-updates
rchlfryn 3f166f1
Refactor and move topLevelNavItem to be in utils-pure
rchlfryn 28b4127
Fix migration for #1011
rchlfryn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import { navLink } from '@/fields/navLink' | ||
| import { Field, Tab, toWords } from 'payload' | ||
| import { itemsField } from './itemsField' | ||
|
|
||
| export type DisplayMode = 'dropdown' | 'link' | 'button' | ||
|
|
||
| const isDisplayMode = (value: unknown): value is DisplayMode => | ||
| value === 'dropdown' || value === 'link' || value === 'button' | ||
|
|
||
| const MODE_OPTIONS: { label: string; value: DisplayMode }[] = [ | ||
| { label: 'Dropdown — a menu of sub-items', value: 'dropdown' }, | ||
| { label: 'Link — a single clickable link to one page', value: 'link' }, | ||
| { label: 'Button — a styled call-to-action button', value: 'button' }, | ||
| ] | ||
|
|
||
| const getMode = (siblingData: unknown): DisplayMode | null => { | ||
| if (typeof siblingData !== 'object' || siblingData === null) return null | ||
| if (!('options' in siblingData)) return null | ||
| const options = siblingData.options | ||
| if (typeof options !== 'object' || options === null) return null | ||
| if (!('displayMode' in options)) return null | ||
| return isDisplayMode(options.displayMode) ? options.displayMode : null | ||
| } | ||
|
|
||
| /** | ||
| * Unified helper for navigation tabs. Every tab has the same shape; its rendering | ||
| * (dropdown, single link, or button) is controlled by the `options.displayMode` field. | ||
| */ | ||
| export const navTab = ({ | ||
| name, | ||
| description, | ||
| defaultMode = 'dropdown', | ||
| hasEnabledToggle = true, | ||
| enabledToggleDescription = 'If hidden, pages with links in this nav item will not be accessible at their navigation-nested URLs.', | ||
| }: { | ||
| name: string | ||
| description?: string | ||
| defaultMode?: DisplayMode | ||
| hasEnabledToggle?: boolean | ||
| enabledToggleDescription?: string | ||
| }): Tab => { | ||
| const displayModeField: Field = { | ||
| name: 'displayMode', | ||
| type: 'radio', | ||
| defaultValue: defaultMode, | ||
| options: MODE_OPTIONS, | ||
| admin: { | ||
| layout: 'vertical', | ||
| }, | ||
| } | ||
|
|
||
| const enabledField: Field = { | ||
| type: 'checkbox', | ||
| defaultValue: true, | ||
| name: 'enabled', | ||
| label: 'Show in navigation', | ||
| admin: { description: enabledToggleDescription }, | ||
| } | ||
|
|
||
| const optionsGroup: Field = { | ||
| type: 'group', | ||
| name: 'options', | ||
| fields: hasEnabledToggle ? [displayModeField, enabledField] : [displayModeField], | ||
| } | ||
|
|
||
| const linkField: Field = { | ||
| ...navLink, | ||
| label: '', | ||
| admin: { | ||
| ...navLink.admin, | ||
| condition: (_, siblingData) => { | ||
| const mode = getMode(siblingData) | ||
| return mode === 'link' || mode === 'button' | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| const items: Field = itemsField({ | ||
| label: `${toWords(name)} Nav Items`, | ||
| description: `Dropdown items under ${toWords(name)}`, | ||
| overrides: { | ||
| admin: { | ||
| condition: (_, siblingData) => getMode(siblingData) === 'dropdown', | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| let fields: Field[] = [optionsGroup, linkField, items] | ||
|
|
||
| if (description) { | ||
| const descriptionField: Field = { | ||
| type: 'ui', | ||
| name: `${name}Description`, | ||
| admin: { | ||
| components: { | ||
| Field: { | ||
| path: '@/components/BannerDescription#BannerDescription', | ||
| clientProps: { message: description, type: 'info' }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| fields = [descriptionField, ...fields] | ||
| } | ||
|
|
||
| return { name, fields } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.