Skip to content

Commit

Permalink
brings back actions for everything except lexical
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsfletch committed Oct 4, 2024
1 parent cc2cad3 commit 2cd9594
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 136 deletions.
39 changes: 16 additions & 23 deletions packages/next/src/views/Edit/Default/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import {
useDocumentEvents,
useDocumentInfo,
useEditDepth,
// useServerFunctions,
useServerFunctions,
useUploadEdits,
} from '@payloadcms/ui'
import { getFormStateFetch } from '@payloadcms/ui'
import {
formatAdminURL,
handleBackToDashboard,
Expand Down Expand Up @@ -80,14 +79,13 @@ export const DefaultEditView: React.FC = () => {

const { refreshCookieAsync, user } = useAuth()

// const { getFormState } = useServerFunctions()
const { getFormState } = useServerFunctions()

const {
config,
config: {
admin: { user: userSlug },
routes: { admin: adminRoute, api: apiRoute },
serverURL,
routes: { admin: adminRoute },
},
getEntityConfig,
} = useConfig()
Expand Down Expand Up @@ -245,20 +243,16 @@ export const DefaultEditView: React.FC = () => {

const docPreferences = await getDocPreferences()

const { lockedState, state } = await getFormStateFetch({
apiRoute,
body: {
id,
collectionSlug,
docPreferences,
formState: prevFormState,
globalSlug,
operation,
returnLockStatus: isLockingEnabled ? true : false,
schemaPath,
updateLastEdited,
},
serverURL,
const { lockedState, state } = await getFormState({
id,
collectionSlug,
docPreferences,
formState: prevFormState,
globalSlug,
operation,
returnLockStatus: isLockingEnabled ? true : false,
schemaPath,
updateLastEdited,
})

setDocumentIsLocked(true)
Expand All @@ -281,9 +275,9 @@ export const DefaultEditView: React.FC = () => {
documentLockStateRef.current = documentLockStateRef.current = {
hasShownLockedModal: documentLockStateRef.current?.hasShownLockedModal || false,
isLocked: true,
user: lockedState.user,
user: lockedState.user as ClientUser,
}
setCurrentEditor(lockedState.user)
setCurrentEditor(lockedState.user as ClientUser)
}
}
}
Expand All @@ -302,8 +296,7 @@ export const DefaultEditView: React.FC = () => {
isLockingEnabled,
setDocumentIsLocked,
lastUpdateTime,
apiRoute,
serverURL,
getFormState,
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useConfig,
useDocumentInfo,
useFieldProps,
useServerFunctions,
// useServerFunctions,
useTranslation,
} from '@payloadcms/ui'
import React, { useCallback, useEffect, useState } from 'react'
Expand Down Expand Up @@ -44,7 +44,7 @@ export const DrawerContent: React.FC<Omit<FieldsDrawerProps, 'drawerSlug' | 'dra
},
} = useConfig()

const { getFormState } = useServerFunctions()
// const { getFormState } = useServerFunctions()

const componentMapRenderedFieldsPath = `lexical_internal_feature.${featureKey}.fields${schemaPathSuffix ? `.${schemaPathSuffix}` : ''}`
const schemaFieldsPath =
Expand Down
26 changes: 10 additions & 16 deletions packages/ui/src/elements/BulkUpload/EditForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import { useDocumentEvents } from '../../../providers/DocumentEvents/index.js'
import { useDocumentInfo } from '../../../providers/DocumentInfo/index.js'
import { useEditDepth } from '../../../providers/EditDepth/index.js'
import { OperationProvider } from '../../../providers/Operation/index.js'
// import { useServerFunctions } from '../../../providers/ServerFunctions/index.js'
import { useServerFunctions } from '../../../providers/ServerFunctions/index.js'
import { useUploadEdits } from '../../../providers/UploadEdits/index.js'
import { formatAdminURL } from '../../../utilities/formatAdminURL.js'
import { getFormStateFetch } from '../../../utilities/getFormStateFetch.js'
import { DocumentFields } from '../../DocumentFields/index.js'
import { Upload } from '../../Upload/index.js'
import { useFormsManager } from '../FormsManager/index.js'
Expand Down Expand Up @@ -50,12 +49,11 @@ export function EditForm({ submitted }: EditFormProps) {
onSave: onSaveFromContext,
} = useDocumentInfo()

// const { getFormState } = useServerFunctions()
const { getFormState } = useServerFunctions()

const {
config: {
routes: { admin: adminRoute, api },
serverURL,
routes: { admin: adminRoute },
},
getEntityConfig,
} = useConfig()
Expand Down Expand Up @@ -117,21 +115,17 @@ export function EditForm({ submitted }: EditFormProps) {
const onChange: NonNullable<FormProps['onChange']>[0] = useCallback(
async ({ formState: prevFormState }) => {
const docPreferences = await getDocPreferences()
const { state: newFormState } = await getFormStateFetch({
apiRoute: api,
body: {
collectionSlug,
docPreferences,
formState: prevFormState,
operation: 'create',
schemaPath,
},
serverURL,
const { state: newFormState } = await getFormState({
collectionSlug,
docPreferences,
formState: prevFormState,
operation: 'create',
schemaPath,
})

return newFormState
},
[collectionSlug, schemaPath, getDocPreferences, api, serverURL],
[collectionSlug, schemaPath, getDocPreferences, getFormState],
)

return (
Expand Down
20 changes: 8 additions & 12 deletions packages/ui/src/elements/BulkUpload/FormsManager/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import type { State } from './reducer.js'
import { fieldReducer } from '../../../forms/Form/fieldReducer.js'
import { useConfig } from '../../../providers/Config/index.js'
import { useLocale } from '../../../providers/Locale/index.js'
import { useServerFunctions } from '../../../providers/ServerFunctions/index.js'
import { useTranslation } from '../../../providers/Translation/index.js'
import { getFormStateFetch } from '../../../utilities/getFormStateFetch.js'
import { hasSavePermission as getHasSavePermission } from '../../../utilities/hasSavePermission.js'
import { useLoadingOverlay } from '../../LoadingOverlay/index.js'
import { useBulkUpload } from '../index.js'
Expand Down Expand Up @@ -81,7 +81,7 @@ export function FormsManagerProvider({ children }: FormsManagerProps) {
const { code } = useLocale()
const { i18n, t } = useTranslation()

// const { getFormState } = useServerFunctions()
const { getFormState } = useServerFunctions()

const [hasSubmitted, setHasSubmitted] = React.useState(false)
const [docPermissions, setDocPermissions] = React.useState<DocumentPermissions>()
Expand Down Expand Up @@ -155,23 +155,19 @@ export function FormsManagerProvider({ children }: FormsManagerProps) {
}

try {
const { state: formStateWithoutFiles } = await getFormStateFetch({
apiRoute: api,
body: {
collectionSlug,
locale: code,
operation: 'create',
schemaPath: collectionSlug,
},
serverURL,
const { state: formStateWithoutFiles } = await getFormState({
collectionSlug,
locale: code,
operation: 'create',
schemaPath: collectionSlug,
})
initialStateRef.current = formStateWithoutFiles
setHasInitializedState(true)
} catch (_err) {
// swallow error
}
},
[code, collectionSlug, api, serverURL],
[code, collectionSlug, getFormState],
)

const setActiveIndex: FormsManagerContext['setActiveIndex'] = React.useCallback(
Expand Down
31 changes: 11 additions & 20 deletions packages/ui/src/elements/EditMany/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { useSearchParams } from '../../providers/SearchParams/index.js'
import { SelectAllStatus, useSelection } from '../../providers/Selection/index.js'
import { useServerFunctions } from '../../providers/ServerFunctions/index.js'
import { useTranslation } from '../../providers/Translation/index.js'
import { getFormStateFetch } from '../../utilities/getFormStateFetch.js'
import { Drawer, DrawerToggler } from '../Drawer/index.js'
import { FieldSelect } from '../FieldSelect/index.js'
import './index.scss'
Expand Down Expand Up @@ -132,15 +131,11 @@ export const EditMany: React.FC<EditManyProps> = (props) => {
React.useEffect(() => {
if (!hasInitializedState.current) {
const getInitialState = async () => {
const { state: result } = await getFormStateFetch({
apiRoute,
body: {
collectionSlug: slug,
data: {},
operation: 'update',
schemaPath: slug,
},
serverURL,
const { state: result } = await getFormState({
collectionSlug: slug,
data: {},
operation: 'update',
schemaPath: slug,
})

setInitialState(result)
Expand All @@ -153,20 +148,16 @@ export const EditMany: React.FC<EditManyProps> = (props) => {

const onChange: FormProps['onChange'][0] = useCallback(
async ({ formState: prevFormState }) => {
const { state } = await getFormStateFetch({
apiRoute,
body: {
collectionSlug: slug,
formState: prevFormState,
operation: 'update',
schemaPath: slug,
},
serverURL,
const { state } = await getFormState({
collectionSlug: slug,
formState: prevFormState,
operation: 'update',
schemaPath: slug,
})

return state
},
[slug, serverURL, apiRoute],
[slug, getFormState],
)

if (selectAll === SelectAllStatus.None || !hasUpdatePermission) {
Expand Down
45 changes: 15 additions & 30 deletions packages/ui/src/forms/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { useOperation } from '../../providers/Operation/index.js'
import { useServerFunctions } from '../../providers/ServerFunctions/index.js'
import { useTranslation } from '../../providers/Translation/index.js'
import { requests } from '../../utilities/api.js'
import { getFormStateFetch } from '../../utilities/getFormStateFetch.js'
import {
FormContext,
FormFieldsContext,
Expand Down Expand Up @@ -82,13 +81,7 @@ export const Form: React.FC<FormProps> = (props) => {
const { refreshCookie, user } = useAuth()
const operation = useOperation()

const {
config,
config: {
routes: { api: apiURL },
serverURL,
},
} = useConfig()
const { config } = useConfig()

const [disabled, setDisabled] = useState(disabledFromProps || false)
const [isMounted, setIsMounted] = useState(false)
Expand Down Expand Up @@ -455,24 +448,20 @@ export const Form: React.FC<FormProps> = (props) => {

const reset = useCallback(
async (data: unknown) => {
const { state: newState } = await getFormStateFetch({
apiRoute: apiURL,
body: {
id,
collectionSlug,
data,
globalSlug,
operation,
schemaPath: collectionSlug || globalSlug,
},
serverURL,
const { state: newState } = await getFormState({
id,
collectionSlug,
data,
globalSlug,
operation,
schemaPath: collectionSlug || globalSlug,
})

contextRef.current = { ...initContextState } as FormContextType
setModified(false)
dispatchFields({ type: 'REPLACE_STATE', state: newState })
},
[collectionSlug, dispatchFields, globalSlug, id, operation, serverURL, apiURL],
[collectionSlug, dispatchFields, globalSlug, id, operation, getFormState],
)

const replaceState = useCallback(
Expand All @@ -486,20 +475,16 @@ export const Form: React.FC<FormProps> = (props) => {

const getFieldStateBySchemaPath = useCallback(
async ({ data, schemaPath }) => {
const { state: fieldSchema } = await getFormStateFetch({
apiRoute: apiURL,
body: {
collectionSlug,
data,
globalSlug,
schemaPath,
},
serverURL,
const { state: fieldSchema } = await getFormState({
collectionSlug,
data,
globalSlug,
schemaPath,
})

return fieldSchema
},
[collectionSlug, globalSlug, serverURL, apiURL],
[collectionSlug, globalSlug, getFormState],
)

const addFieldRow: FormContextType['addFieldRow'] = useCallback(
Expand Down
Loading

0 comments on commit 2cd9594

Please sign in to comment.