mirror of
				https://github.com/chartdb/chartdb.git
				synced 2025-11-04 05:53:15 +00:00 
			
		
		
		
	add loader for loading scripts (#265)
This commit is contained in:
		@@ -8,6 +8,7 @@ export interface CodeSnippetProps {
 | 
				
			|||||||
    codeProps?: CopyBlockProps;
 | 
					    codeProps?: CopyBlockProps;
 | 
				
			||||||
    code: string;
 | 
					    code: string;
 | 
				
			||||||
    language?: 'sql' | 'bash';
 | 
					    language?: 'sql' | 'bash';
 | 
				
			||||||
 | 
					    loading?: boolean;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const CopyBlock = React.lazy(() =>
 | 
					const CopyBlock = React.lazy(() =>
 | 
				
			||||||
@@ -19,21 +20,25 @@ const CopyBlock = React.lazy(() =>
 | 
				
			|||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const CodeSnippet: React.FC<CodeSnippetProps> = React.memo(
 | 
					export const CodeSnippet: React.FC<CodeSnippetProps> = React.memo(
 | 
				
			||||||
    ({ className, codeProps, code, language = 'sql' }) => (
 | 
					    ({ className, codeProps, code, loading, language = 'sql' }) => (
 | 
				
			||||||
        <div className={cn('flex flex-1 justify-center', className)}>
 | 
					        <div className={cn('flex flex-1 justify-center', className)}>
 | 
				
			||||||
            <Suspense fallback={<Spinner />}>
 | 
					            {loading ? (
 | 
				
			||||||
                <CopyBlock
 | 
					                <Spinner />
 | 
				
			||||||
                    language={language}
 | 
					            ) : (
 | 
				
			||||||
                    text={code}
 | 
					                <Suspense fallback={<Spinner />}>
 | 
				
			||||||
                    customStyle={{
 | 
					                    <CopyBlock
 | 
				
			||||||
                        display: 'flex',
 | 
					                        language={language}
 | 
				
			||||||
                        flex: '1',
 | 
					                        text={code}
 | 
				
			||||||
                        fontSize: '14px',
 | 
					                        customStyle={{
 | 
				
			||||||
                        width: '100%',
 | 
					                            display: 'flex',
 | 
				
			||||||
                    }}
 | 
					                            flex: '1',
 | 
				
			||||||
                    {...codeProps}
 | 
					                            fontSize: '14px',
 | 
				
			||||||
                />
 | 
					                            width: '100%',
 | 
				
			||||||
            </Suspense>
 | 
					                        }}
 | 
				
			||||||
 | 
					                        {...codeProps}
 | 
				
			||||||
 | 
					                    />
 | 
				
			||||||
 | 
					                </Suspense>
 | 
				
			||||||
 | 
					            )}
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -71,12 +71,7 @@ export const ImportDatabase: React.FC<ImportDatabaseProps> = ({
 | 
				
			|||||||
    >();
 | 
					    >();
 | 
				
			||||||
    const { t } = useTranslation();
 | 
					    const { t } = useTranslation();
 | 
				
			||||||
    const [importMetadataScripts, setImportMetadataScripts] =
 | 
					    const [importMetadataScripts, setImportMetadataScripts] =
 | 
				
			||||||
        useState<ImportMetadataScripts>(
 | 
					        useState<ImportMetadataScripts | null>(null);
 | 
				
			||||||
            Object.values(DatabaseType).reduce((acc, val) => {
 | 
					 | 
				
			||||||
                acc[val] = () => '';
 | 
					 | 
				
			||||||
                return acc;
 | 
					 | 
				
			||||||
            }, {} as ImportMetadataScripts)
 | 
					 | 
				
			||||||
        );
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    useEffect(() => {
 | 
					    useEffect(() => {
 | 
				
			||||||
        const loadScripts = async () => {
 | 
					        const loadScripts = async () => {
 | 
				
			||||||
@@ -252,19 +247,25 @@ export const ImportDatabase: React.FC<ImportDatabaseProps> = ({
 | 
				
			|||||||
                            </div>
 | 
					                            </div>
 | 
				
			||||||
                            <CodeSnippet
 | 
					                            <CodeSnippet
 | 
				
			||||||
                                className="max-h-40 w-full"
 | 
					                                className="max-h-40 w-full"
 | 
				
			||||||
                                code={importMetadataScripts[databaseType]({
 | 
					                                loading={!importMetadataScripts}
 | 
				
			||||||
                                    databaseEdition,
 | 
					                                code={
 | 
				
			||||||
                                    databaseClient,
 | 
					                                    importMetadataScripts?.[databaseType]?.({
 | 
				
			||||||
                                })}
 | 
					                                        databaseEdition,
 | 
				
			||||||
 | 
					                                        databaseClient,
 | 
				
			||||||
 | 
					                                    }) ?? ''
 | 
				
			||||||
 | 
					                                }
 | 
				
			||||||
                                language={databaseClient ? 'bash' : 'sql'}
 | 
					                                language={databaseClient ? 'bash' : 'sql'}
 | 
				
			||||||
                            />
 | 
					                            />
 | 
				
			||||||
                        </Tabs>
 | 
					                        </Tabs>
 | 
				
			||||||
                    ) : (
 | 
					                    ) : (
 | 
				
			||||||
                        <CodeSnippet
 | 
					                        <CodeSnippet
 | 
				
			||||||
                            className="max-h-40 w-full"
 | 
					                            className="max-h-40 w-full"
 | 
				
			||||||
                            code={importMetadataScripts[databaseType]({
 | 
					                            loading={!importMetadataScripts}
 | 
				
			||||||
                                databaseEdition,
 | 
					                            code={
 | 
				
			||||||
                            })}
 | 
					                                importMetadataScripts?.[databaseType]?.({
 | 
				
			||||||
 | 
					                                    databaseEdition,
 | 
				
			||||||
 | 
					                                }) ?? ''
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
                        />
 | 
					                        />
 | 
				
			||||||
                    )}
 | 
					                    )}
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user