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(next,ui): improves loading states #6434

Merged
merged 70 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
42c897d
poc: better loading states
jacobsfletch May 20, 2024
f45cebb
removes loading overlays
jacobsfletch May 20, 2024
47665c6
detects admin theme server-side
jacobsfletch May 20, 2024
40bf759
server-renders the dashboard view
jacobsfletch May 20, 2024
47bac9e
unwraps logout view from template
jacobsfletch May 20, 2024
b40a148
defers rendering title until document is ready
jacobsfletch May 20, 2024
ba403d4
fixes cookies
jacobsfletch May 20, 2024
32c1be5
properly deletes theme cookie
jacobsfletch May 20, 2024
58a0442
scaffolds theme e2e tests
jacobsfletch May 20, 2024
0a87920
fixes vertical layout shift in document edit view
jacobsfletch May 21, 2024
9e5e5e3
waits for document to initialize before setting edit view step nav
jacobsfletch May 21, 2024
f93e62e
Merge branch 'beta' into chore/loading-states
jacobsfletch May 22, 2024
24a0abe
cleanup
jacobsfletch May 22, 2024
caba206
fix account auth redirect
jacobsfletch May 22, 2024
fcb5a96
fix: ssr hydration errors in react-select
jacobsfletch May 22, 2024
1ed01e3
fix: properly 404s when entity lacks read access
jacobsfletch May 22, 2024
c7564e8
fully client-renders language selector to avoid react-select hydratio…
jacobsfletch May 22, 2024
062e602
fully client-side renders locale selector in api view
jacobsfletch May 22, 2024
5245b6f
fixes list test to watch proper url
jacobsfletch May 22, 2024
43fa602
passing admin tests
jacobsfletch May 22, 2024
a2c5581
passing auth e2e
jacobsfletch May 22, 2024
35674bc
passing relationship tests
jacobsfletch May 23, 2024
d431842
properly initializes json field value
jacobsfletch May 23, 2024
a6f6335
fix type import
jacobsfletch May 23, 2024
8adf610
disables fields when form initializing
jacobsfletch May 23, 2024
4d6a8d6
passing localization e2e
jacobsfletch May 23, 2024
26d821e
passing rich text e2e
jacobsfletch May 23, 2024
1cb3fde
properly sets disabled html attribute on rich text toolbar buttons wh…
jacobsfletch May 23, 2024
727cdad
Merge branch 'beta' into chore/loading-states
jacobsfletch May 23, 2024
095f584
cleanup
jacobsfletch May 23, 2024
231ee95
fully client-renders version controls
jacobsfletch May 23, 2024
478c808
attemps to pass CI
jacobsfletch May 23, 2024
bc837a0
removes form processing overlay and disables fields on submit
jacobsfletch May 23, 2024
598d9f2
removes loading overlay from login view
jacobsfletch May 23, 2024
7064866
initializes root documents server-side
jacobsfletch May 24, 2024
585bf1d
initializes doc permissions from props
jacobsfletch May 24, 2024
87ac778
initializes doc from props
jacobsfletch May 24, 2024
14a9022
extracts buildFormState logic from endpoint for reuse
jacobsfletch May 24, 2024
7d19f8d
gets form state directly
jacobsfletch May 24, 2024
f9b2239
adds back changes to provider
jacobsfletch May 24, 2024
ab09ea8
cleanup
jacobsfletch May 24, 2024
124497c
Merge branch 'beta' into chore/loading-states
jacobsfletch May 24, 2024
35d8612
fix: downgrades react-select to v5.7.7 and adds instanceID
jacobsfletch May 27, 2024
d8327a7
bumps react-select back to 5.8
jacobsfletch May 27, 2024
4f7e803
types
jacobsfletch May 28, 2024
6be4493
fix doc permissions initial state
jacobsfletch May 28, 2024
76ba3a7
prevents cls in version tab
jacobsfletch May 28, 2024
38a3b8c
feat: allows force render of fields to n index
jacobsfletch May 28, 2024
728d79b
fix doc drawer disabled state
jacobsfletch May 28, 2024
e8435e9
prevents select component cls
jacobsfletch May 28, 2024
15e0326
fix flaky versions test
jacobsfletch May 28, 2024
f7d92c8
fix: refreshes doc info state when locale changes
jacobsfletch May 28, 2024
557c68f
passing versions test
jacobsfletch May 28, 2024
50714c0
Merge branch 'beta' into chore/loading-states
jacobsfletch May 28, 2024
928851f
passing fields test
jacobsfletch May 28, 2024
f7e0516
passing flaky fields test
jacobsfletch May 28, 2024
2bc909a
renders root loader
jacobsfletch May 28, 2024
4c1ed64
renders doc title immediately
jacobsfletch May 28, 2024
d0dfbcf
initializes account view props
jacobsfletch May 28, 2024
462681e
properly ensures auto login is complete
jacobsfletch May 28, 2024
91e69d6
waits for template classname instead of login
jacobsfletch May 28, 2024
7b7c3fa
deflakes some tests
jacobsfletch May 29, 2024
313bd7c
poc: renders icon as loader
jacobsfletch May 29, 2024
1a7ce95
removes root suspense
jacobsfletch May 29, 2024
01945b8
disables form while mounting
jacobsfletch May 29, 2024
935f4ff
adds stale-times warning
jacobsfletch May 29, 2024
312058b
removes stale times from base config
jacobsfletch May 29, 2024
fc5e013
cleanup
jacobsfletch May 29, 2024
48eeacd
cleanup
jacobsfletch May 29, 2024
27f2c8b
Merge branch 'beta' into chore/loading-states
jacobsfletch May 29, 2024
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 next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default withBundleAnalyzer(
ignoreBuildErrors: true,
},
experimental: {
reactCompiler: false
reactCompiler: false,
},
async redirects() {
return [
Expand Down
2 changes: 2 additions & 0 deletions packages/next/src/layouts/Root/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ export const RootLayout = async ({
})

const payload = await getPayloadHMR({ config })

const i18n: I18nClient = await initI18n({
config: config.i18n,
context: 'client',
language: languageCode,
})

const clientConfig = await createClientConfig({ config, t: i18n.t })

const dir = (rtlLanguages as unknown as AcceptedLanguages[]).includes(languageCode)
Expand Down
15 changes: 15 additions & 0 deletions packages/next/src/utilities/initPage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ export const initPage = async ({
language,
})

const languageOptions = Object.entries(payload.config.i18n.supportedLanguages || {}).reduce(
(acc, [language, languageConfig]) => {
if (Object.keys(payload.config.i18n.supportedLanguages).includes(language)) {
acc.push({
label: languageConfig.translations.general.thisLanguage,
value: language,
})
}

return acc
},
[],
)

const req = await createLocalReq(
{
fallbackLocale: null,
Expand Down Expand Up @@ -98,6 +112,7 @@ export const initPage = async ({
cookies,
docID,
globalConfig,
languageOptions,
locale,
permissions,
req,
Expand Down
1 change: 0 additions & 1 deletion packages/next/src/utilities/initPage/shared.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { SanitizedConfig } from 'payload/types'

const authRouteKeys: (keyof SanitizedConfig['admin']['routes'])[] = [
'account',
'createFirstUser',
'forgot',
'login',
Expand Down
23 changes: 23 additions & 0 deletions packages/next/src/views/API/LocaleSelector/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Select } from '@payloadcms/ui/fields/Select'
import { useTranslation } from '@payloadcms/ui/providers/Translation'
import React from 'react'

export const LocaleSelector: React.FC<{
localeOptions: {
label: Record<string, string> | string
value: string
}[]
onChange: (value: string) => void
}> = ({ localeOptions, onChange }) => {
const { t } = useTranslation()

return (
<Select
label={t('general:locale')}
name="locale"
onChange={(value) => onChange(value)}
options={localeOptions}
path="locale"
/>
)
}
12 changes: 2 additions & 10 deletions packages/next/src/views/API/index.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { CopyToClipboard } from '@payloadcms/ui/elements/CopyToClipboard'
import { Gutter } from '@payloadcms/ui/elements/Gutter'
import { Checkbox } from '@payloadcms/ui/fields/Checkbox'
import { NumberField as NumberInput } from '@payloadcms/ui/fields/Number'
import { Select } from '@payloadcms/ui/fields/Select'
import { Form } from '@payloadcms/ui/forms/Form'
import { MinimizeMaximize } from '@payloadcms/ui/icons/MinimizeMaximize'
import { SetViewActions } from '@payloadcms/ui/providers/Actions'
Expand All @@ -19,6 +18,7 @@ import * as React from 'react'
import { toast } from 'react-toastify'

import { SetDocumentStepNav } from '../Edit/Default/SetDocumentStepNav/index.js'
import { LocaleSelector } from './LocaleSelector/index.js'
import { RenderJSON } from './RenderJSON/index.js'
import './index.scss'

Expand Down Expand Up @@ -173,15 +173,7 @@ export const APIViewClient: React.FC = () => {
path="authenticated"
/>
</div>
{localeOptions && (
<Select
label={t('general:locale')}
name="locale"
onChange={(value) => setLocale(value)}
options={localeOptions}
path="locale"
/>
)}
{localeOptions && <LocaleSelector localeOptions={localeOptions} onChange={setLocale} />}
<NumberInput
label={t('general:depth')}
max={10}
Expand Down
25 changes: 25 additions & 0 deletions packages/next/src/views/Account/Settings/LanguageSelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use client'
import type { LanguageOptions } from 'payload/types'

import { ReactSelect } from '@payloadcms/ui/elements/ReactSelect'
import { useTranslation } from '@payloadcms/ui/providers/Translation'
import React from 'react'

export const LanguageSelector: React.FC<{
languageOptions: LanguageOptions
}> = (props) => {
const { languageOptions } = props

const { i18n, switchLanguage } = useTranslation()

return (
<ReactSelect
inputId="language-select"
onChange={async ({ value }) => {
await switchLanguage(value)
}}
options={languageOptions}
value={languageOptions.find((language) => language.value === i18n.language)}
/>
)
}
26 changes: 10 additions & 16 deletions packages/next/src/views/Account/Settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
'use client'
import { ReactSelect } from '@payloadcms/ui/elements/ReactSelect'
import type { I18n } from '@payloadcms/translations'
import type { LanguageOptions } from 'payload/types'

import { FieldLabel } from '@payloadcms/ui/forms/FieldLabel'
import { useTranslation } from '@payloadcms/ui/providers/Translation'
import React from 'react'

import { ToggleTheme } from '../ToggleTheme/index.js'
import { LanguageSelector } from './LanguageSelector.js'
import './index.scss'

const baseClass = 'payload-settings'

export const Settings: React.FC<{
className?: string
i18n: I18n
languageOptions: LanguageOptions
}> = (props) => {
const { className } = props

const { i18n, languageOptions, switchLanguage, t } = useTranslation()
const { className, i18n, languageOptions } = props

return (
<div className={[baseClass, className].filter(Boolean).join(' ')}>
<h3>{t('general:payloadSettings')}</h3>
<h3>{i18n.t('general:payloadSettings')}</h3>
<div className={`${baseClass}__language`}>
<FieldLabel htmlFor="language-select" label={t('general:language')} />
<ReactSelect
inputId="language-select"
onChange={async ({ value }) => {
await switchLanguage(value)
}}
options={languageOptions}
value={languageOptions.find((language) => language.value === i18n.language)}
/>
<FieldLabel htmlFor="language-select" label={i18n.t('general:language')} />
<LanguageSelector languageOptions={languageOptions} />
</div>
<ToggleTheme />
</div>
Expand Down
13 changes: 12 additions & 1 deletion packages/next/src/views/Account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { FormQueryParamsProvider } from '@payloadcms/ui/providers/FormQueryParam
import { notFound } from 'next/navigation.js'
import React from 'react'

import { getDocumentData } from '../Document/getDocumentData.js'
import { getDocumentPermissions } from '../Document/getDocumentPermissions.js'
import { EditView } from '../Edit/index.js'
import { Settings } from './Settings/index.js'
Expand All @@ -21,6 +22,7 @@ export const Account: React.FC<AdminViewProps> = async ({
searchParams,
}) => {
const {
languageOptions,
locale,
permissions,
req,
Expand Down Expand Up @@ -49,6 +51,13 @@ export const Account: React.FC<AdminViewProps> = async ({
req,
})

const { data, formState } = await getDocumentData({
id: user.id,
collectionConfig,
locale,
req,
})

const viewComponentProps: ServerSideEditViewProps = {
initPageResult,
params,
Expand All @@ -58,14 +67,16 @@ export const Account: React.FC<AdminViewProps> = async ({

return (
<DocumentInfoProvider
AfterFields={<Settings />}
AfterFields={<Settings i18n={i18n} languageOptions={languageOptions} />}
action={`${serverURL}${api}/${userSlug}${user?.id ? `/${user.id}` : ''}`}
apiURL={`${serverURL}${api}/${userSlug}${user?.id ? `/${user.id}` : ''}`}
collectionSlug={userSlug}
docPermissions={docPermissions}
hasPublishPermission={hasPublishPermission}
hasSavePermission={hasSavePermission}
id={user?.id.toString()}
initialData={data}
initialState={formState}
isEditing
>
<DocumentHeader
Expand Down
144 changes: 0 additions & 144 deletions packages/next/src/views/Dashboard/Default/index.client.tsx

This file was deleted.

Loading