11import React , { useCallback } from 'react' ;
22import PropTypes from 'prop-types' ;
33import { CreateCollectionForm } from 'create-collection-form' ;
4- import { AppBar , Dialog , Toolbar , Typography , IconButton } from '@mui/material' ;
4+ import { AppBar , Dialog , Toolbar , Typography , IconButton , Box } from '@mui/material' ;
55import { ArrowLeft } from 'lucide-react' ;
66import { useTheme } from '@mui/material/styles' ;
77import { useClient } from '../../../context/client-context' ;
8- import { createCollection } from './create-collection.js' ;
8+ import {
9+ createCollection ,
10+ getCreateCollectionConfiguration ,
11+ createCollectionParams ,
12+ createPayloadIndexParams ,
13+ } from './create-collection.js' ;
914import { closeSnackbar , enqueueSnackbar } from 'notistack' ;
1015import { getSnackbarOptions } from '../../Common/utils/snackbarOptions' ;
16+ import { Highlight , Prism } from 'prism-react-renderer' ;
1117import DialogContent from '@mui/material/DialogContent' ;
18+ import createPrismTheme from '../../../theme/prism-theme' ;
19+
20+ const convertToRequest = ( outputData ) => {
21+ const collectionName = outputData ?. collection_name || '<name>' ;
22+
23+ const params = getCreateCollectionConfiguration ( collectionName , outputData ) ;
24+ const collectionParams = createCollectionParams ( params ) ;
25+
26+ let result = `PUT /collections/${ collectionName } \n` + JSON . stringify ( collectionParams , null , 2 ) + '\n' ;
27+
28+ if ( params . payload_indexes ) {
29+ result += '\n// Payload Indexes' ;
30+ for ( const fieldConfig of params . payload_indexes ) {
31+ result += `\nPUT /collections/${ collectionName } /payload_indexes \n` ;
32+ const payloadIndexParams = createPayloadIndexParams ( fieldConfig ) ;
33+ result += JSON . stringify ( payloadIndexParams , null , 2 ) + '\n' ;
34+ }
35+ }
36+
37+ return result ;
38+ } ;
1239
1340const CreateCollectionDialog = ( { open, handleClose } ) => {
1441 const { client : qdrantClient } = useClient ( ) ;
@@ -22,6 +49,51 @@ const CreateCollectionDialog = ({ open, handleClose }) => {
2249 return window ;
2350 } ;
2451
52+ const customPrismTheme = createPrismTheme ( theme ) ;
53+
54+ const renderJsonPreview = ( outputData ) => {
55+ const request = convertToRequest ( outputData ) ;
56+
57+ return (
58+ < Box >
59+ < Typography variant = "subtitle1" sx = { { fontWeight : '600' } } >
60+ Equivalent Requests
61+ </ Typography >
62+ < Box >
63+ < Highlight Prism = { Prism } theme = { customPrismTheme } code = { request } language = "json" >
64+ { ( { className, style, tokens, getLineProps, getTokenProps } ) => (
65+ < pre
66+ className = { className }
67+ style = { {
68+ ...style ,
69+ backgroundColor : 'transparent' ,
70+ whiteSpace : 'pre-wrap' ,
71+ wordBreak : 'break-all' ,
72+ fontSize : '12px' ,
73+ marginTop : '8px' ,
74+ } }
75+ >
76+ { tokens . map ( ( line , i ) => {
77+ const lineProps = getLineProps ( { line, key : i } ) ;
78+ const { key : lineKey , ...restLineProps } = lineProps ;
79+ return (
80+ < div key = { lineKey ?? i } { ...restLineProps } >
81+ { line . map ( ( token , tIdx ) => {
82+ const tokenProps = getTokenProps ( { token, key : tIdx } ) ;
83+ const { key : tokenKey , ...restTokenProps } = tokenProps ;
84+ return < span key = { tokenKey ?? tIdx } { ...restTokenProps } /> ;
85+ } ) }
86+ </ div >
87+ ) ;
88+ } ) }
89+ </ pre >
90+ ) }
91+ </ Highlight >
92+ </ Box >
93+ </ Box >
94+ ) ;
95+ } ;
96+
2597 // This function has to return a promise that resolves to a value,
2698 // as it is used as `onFinish` prop for CreateCollectionForm.
2799 // otherwise, the form will not be cleared (for example, if an error occurs).
@@ -52,8 +124,8 @@ const CreateCollectionDialog = ({ open, handleClose }) => {
52124 >
53125 < Toolbar
54126 sx = { {
55- width : '848px ' ,
56- maxWidth : '848px' ,
127+ width : '100% ' ,
128+ maxWidth : { xs : '100%' , lg : '1424px' } ,
57129 minHeight : '48px' ,
58130 px : 2 ,
59131 py : 0.5 ,
@@ -85,13 +157,21 @@ const CreateCollectionDialog = ({ open, handleClose }) => {
85157 backgroundColor : theme . palette . background . default ,
86158 } }
87159 >
88- < CreateCollectionForm
89- onFinish = { handleFinish }
90- hideSidebar = { true }
91- scrollableParent = { getScrollableParent }
92- aria-label = "Create Collection Form"
93- aria-role = "dialog"
94- />
160+ < Box
161+ sx = { {
162+ maxWidth : { xs : '100%' , lg : '1440px' } ,
163+ p : '0 24px' ,
164+ mx : 'auto' ,
165+ } }
166+ >
167+ < CreateCollectionForm
168+ onFinish = { handleFinish }
169+ onPreviewFormOutput = { renderJsonPreview }
170+ scrollableParent = { getScrollableParent }
171+ aria-label = "Create Collection Form"
172+ aria-role = "dialog"
173+ />
174+ </ Box >
95175 </ DialogContent >
96176 </ Dialog >
97177 ) ;
0 commit comments