Skip to content

Commit 7a4275e

Browse files
authoredMay 23, 2023
fix(core): editing reference input in PTE does not show value (#4499)
* fix(core): editing reference input in PTE does not show value * fix(core): revert clearing on replace
1 parent a7ddef9 commit 7a4275e

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {defineType} from 'sanity'
2+
3+
export default defineType({
4+
name: 'ptReference',
5+
title: 'Portable Text Reference',
6+
type: 'document',
7+
fields: [
8+
{
9+
name: 'body',
10+
title: 'Body',
11+
type: 'array',
12+
of: [
13+
{
14+
type: 'block',
15+
marks: {
16+
annotations: [{type: 'reference', to: {type: 'author'}}],
17+
},
18+
of: [{type: 'reference', to: {type: 'author'}}],
19+
},
20+
{type: 'reference', to: {type: 'author'}},
21+
],
22+
},
23+
],
24+
})

‎dev/test-studio/schema/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ import crossDatasetReference, {crossDatasetSubtype} from './standard/crossDatase
107107
import {circularCrossDatasetReferenceTest} from './debug/circularCrossDatasetReference'
108108
import {allNativeInputComponents} from './debug/allNativeInputComponents'
109109
import fieldGroupsWithFieldsets from './debug/fieldGroupsWithFieldsets'
110+
import ptReference from './debug/ptReference'
110111

111112
// @todo temporary, until code input is v3 compatible
112113
const codeInputType = {
@@ -203,6 +204,7 @@ export const schemaTypes = [
203204
previewSelectBugRepro,
204205
ptAllTheBellsAndWhistlesType,
205206
ptCustomMarkersTestType,
207+
ptReference,
206208
radio,
207209
readOnly,
208210
recursive,

‎dev/test-studio/structure/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export const DEBUG_INPUT_TYPES = [
7272
'validationTest',
7373
'allNativeInputComponents',
7474
'scrollBug',
75+
'ptReference',
7576
]
7677

7778
export const CI_INPUT_TYPES = ['conditionalFieldset', 'validationCI']

‎packages/sanity/src/core/form/inputs/ReferenceInput/ReferenceInput.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ export function ReferenceInput(props: ReferenceInputProps) {
324324
renderValue={renderValue}
325325
openButton={{onClick: handleAutocompleteOpenButtonClick}}
326326
portalRef={autoCompletePortalRef}
327+
value={value?._ref}
327328
/>
328329

329330
{createOptions.length > 0 && (

‎packages/sanity/src/core/form/inputs/ReferenceInput/ReferenceItem.tsx

+10-4
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ export function ReferenceItem<Item extends ReferenceItemValue = ReferenceItemVal
186186
[refType?.name, value?._ref]
187187
)
188188

189+
const handleReplace = useCallback(() => {
190+
if (hasRef && isEditing) {
191+
onPathFocus([])
192+
} else {
193+
onPathFocus(['_ref'])
194+
}
195+
}, [hasRef, isEditing, onPathFocus])
196+
189197
const menu = useMemo(
190198
() =>
191199
readOnly ? null : (
@@ -201,9 +209,7 @@ export function ReferenceItem<Item extends ReferenceItemValue = ReferenceItemVal
201209
<MenuItem
202210
text={hasRef && isEditing ? 'Cancel replace' : 'Replace'}
203211
icon={hasRef && isEditing ? CloseIcon : ReplaceIcon}
204-
onClick={
205-
hasRef && isEditing ? () => onPathFocus([]) : () => onPathFocus(['_ref'])
206-
}
212+
onClick={handleReplace}
207213
/>
208214
<MenuItem text="Duplicate" icon={DuplicateIcon} onClick={handleDuplicate} />
209215
<InsertMenu onInsert={handleInsert} types={insertableTypes} />
@@ -231,11 +237,11 @@ export function ReferenceItem<Item extends ReferenceItemValue = ReferenceItemVal
231237
onRemove,
232238
hasRef,
233239
isEditing,
240+
handleReplace,
234241
handleDuplicate,
235242
handleInsert,
236243
insertableTypes,
237244
OpenLink,
238-
onPathFocus,
239245
]
240246
)
241247

0 commit comments

Comments
 (0)
Failed to load comments.