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

fix(ui): populate default values in join related doc drawer #8791

Closed
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: 2 additions & 0 deletions packages/ui/src/elements/DocumentDrawer/DrawerContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const DocumentDrawerContent: React.FC<DocumentDrawerProps> = ({
collectionSlug,
disableActions,
drawerSlug,
fetchInitialState,
Header,
initialData,
initialState,
Expand Down Expand Up @@ -137,6 +138,7 @@ export const DocumentDrawerContent: React.FC<DocumentDrawerProps> = ({
collectionSlug={collectionConfig.slug}
disableActions={disableActions}
disableLeaveWithoutSaving
fetchInitialState={fetchInitialState}
id={docID}
initialData={initialData}
initialState={initialState}
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/elements/DocumentDrawer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type DocumentDrawerProps = {
readonly collectionSlug: string
readonly disableActions?: boolean
readonly drawerSlug?: string
readonly fetchInitialState?: boolean
readonly id?: null | number | string
readonly initialData?: Data
readonly initialState?: FormState
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/src/elements/RelationshipTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { RelationshipTableWrapper } from './TableWrapper.js'
const baseClass = 'relationship-table'

type RelationshipTableComponentProps = {
readonly fetchInitialState?: boolean
readonly field: JoinFieldClient
readonly filterOptions?: boolean | Where
readonly initialData?: PaginatedDocs
Expand All @@ -47,6 +48,7 @@ type RelationshipTableComponentProps = {

export const RelationshipTable: React.FC<RelationshipTableComponentProps> = (props) => {
const {
fetchInitialState,
field,
filterOptions,
initialData: initialDataFromProps,
Expand Down Expand Up @@ -319,6 +321,7 @@ export const RelationshipTable: React.FC<RelationshipTableComponentProps> = (pro
</RelationshipProvider>
)}
<DocumentDrawer
fetchInitialState={fetchInitialState}
initialData={{
category: docID,
}}
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/fields/Join/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const JoinFieldComponent: JoinFieldClientComponent = (props) => {
return (
<div className={[fieldBaseClass, 'join'].filter(Boolean).join(' ')}>
<RelationshipTable
fetchInitialState
field={field as JoinFieldClient}
filterOptions={filterOptions}
initialData={docID && value ? value : ({ docs: [] } as PaginatedDocs)}
Expand Down
14 changes: 12 additions & 2 deletions packages/ui/src/providers/DocumentInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const DocumentInfo: React.FC<
id,
collectionSlug,
docPermissions: docPermissionsFromProps,
fetchInitialState,
globalSlug,
hasPublishPermission: hasPublishPermissionFromProps,
hasSavePermission: hasSavePermissionFromProps,
Expand Down Expand Up @@ -537,7 +538,8 @@ const DocumentInfo: React.FC<
if (
initialStateFromProps === undefined ||
initialDataFromProps === undefined ||
localeChanged
localeChanged ||
fetchInitialState
) {
if (localeChanged) {
prevLocale.current = locale
Expand Down Expand Up @@ -569,7 +571,14 @@ const DocumentInfo: React.FC<
void getDocPermissions(data)
}

setInitialState(result)
setInitialState(
initialStateFromProps
? {
...result,
...initialStateFromProps,
}
: result,
)
} catch (err) {
if (!abortController.signal.aborted) {
if (typeof onLoadError === 'function') {
Expand Down Expand Up @@ -604,6 +613,7 @@ const DocumentInfo: React.FC<
initialDataFromProps,
initialStateFromProps,
getDocPermissions,
fetchInitialState,
])

useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/providers/DocumentInfo/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type DocumentInfoProps = {
readonly disableCreate?: boolean
readonly disableLeaveWithoutSaving?: boolean
readonly docPermissions?: DocumentPermissions
readonly fetchInitialState?: boolean
readonly globalSlug?: SanitizedGlobalConfig['slug']
readonly hasPublishPermission?: boolean
readonly hasSavePermission?: boolean
Expand Down
Loading