Skip to content

Commit

Permalink
fix: use selectedReleaseId in assistDocument context and ImageContext
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Jan 3, 2025
1 parent 1d99988 commit b8a166d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
27 changes: 22 additions & 5 deletions plugin/src/assistDocument/hooks/useAssistDocumentContextValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,35 @@ export function useAssistDocumentContextValue(
documentId: string,
documentSchemaType: ObjectSchemaType,
) {
const {published, draft} = useEditState(
const {
openInspector,
closeInspector,
inspector,
onChange: documentOnChange,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore this is a valid option available in `corel` - Remove after corel is merged to next
selectedReleaseId,
} = useDocumentPane()

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore this is a valid option available in `corel` - Remove after corel is merged to next
const {published, draft, version} = useEditState(
getPublishedId(documentId),
documentSchemaType.name,
'low',
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore this is a valid option available in `corel` - Remove after corel is merged to next
selectedReleaseId,
)
const assistableDocumentId = draft?._id || published?._id || documentId
const documentIsNew = Boolean(!draft?._id && !published?._id)
const documentIsAssistable = isDocAssistable(documentSchemaType, published, draft)

const assistableDocumentId = version?._id || draft?._id || published?._id || documentId
const documentIsNew = selectedReleaseId ? !version?._id : !draft?._id && !published?._id
const documentIsAssistable = selectedReleaseId
? Boolean(version)
: isDocAssistable(documentSchemaType, published, draft)

const {params} = useAiPaneRouter()
const selectedPath = params[fieldPathParam]
const {openInspector, closeInspector, inspector, onChange: documentOnChange} = useDocumentPane()

const assistDocument = useStudioAssistDocument({
documentId,
Expand Down
11 changes: 7 additions & 4 deletions plugin/src/components/ImageContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ export const ImageContext = createContext<ImageContextValue>({})
export function ImageContextProvider(props: InputProps) {
const {schemaType, path, value, readOnly} = props
const assetRef = (value as any)?.asset?._ref
const pane = useDocumentPane()
const {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore this is a valid option available in `corel` - Remove after corel is merged to next
selectedReleaseId,
} = useDocumentPane()
const [assetRefState, setAssetRefState] = useState<string | undefined>(assetRef)

const {documentId, documentSchemaType} = useAssistDocumentContext()
const {config, status} = useAiAssistanceConfig()
const apiClient = useApiClient(config?.__customApiClient)
const {generateCaption} = useGenerateCaption(apiClient)

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore this is a valid option available in `corel` - Remove after corel is merged to next
const selectedReleaseId = pane.selectedReleaseName
const {isSyncing} = useSyncState(
getPublishedId(documentId),
documentSchemaType.name,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore this is a valid option available in `corel` - Remove after corel is merged to next
selectedReleaseId ? {version: selectedReleaseId} : undefined,
)

Expand Down

0 comments on commit b8a166d

Please sign in to comment.