mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 06:06:00 +00:00
open sql link from markdown
This commit is contained in:
@@ -3,6 +3,7 @@ import Markdown from 'markdown-to-jsx';
|
||||
import styled from 'styled-components';
|
||||
import OpenChartLink from './OpenChartLink';
|
||||
import MarkdownLink from './MarkdownLink';
|
||||
import OpenSqlLink from './OpenSqlLink';
|
||||
|
||||
const Wrapper = styled.div`
|
||||
padding: 10px;
|
||||
@@ -19,6 +20,9 @@ export default function MarkdownExtendedView({ children }) {
|
||||
OpenChartLink: {
|
||||
component: OpenChartLink,
|
||||
},
|
||||
OpenSqlLink: {
|
||||
component: OpenSqlLink,
|
||||
},
|
||||
a: MarkdownLink,
|
||||
},
|
||||
}}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { useCurrentDatabase, useSetOpenedTabs } from '../utility/globalState';
|
||||
import { useCurrentDatabase } from '../utility/globalState';
|
||||
import axios from '../utility/axios';
|
||||
import useTheme from '../theme/useTheme';
|
||||
import { StyledThemedLink } from '../widgets/FormStyledButton';
|
||||
@@ -20,6 +20,7 @@ export default function OpenChartLink({ file, children }) {
|
||||
props: {
|
||||
conid: currentDb && currentDb.connection && currentDb.connection._id,
|
||||
database: currentDb && currentDb.name,
|
||||
savedFile: file,
|
||||
},
|
||||
},
|
||||
resp.data
|
||||
|
||||
26
packages/web/src/markdown/OpenSqlLink.js
Normal file
26
packages/web/src/markdown/OpenSqlLink.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import React from 'react';
|
||||
import axios from '../utility/axios';
|
||||
import useTheme from '../theme/useTheme';
|
||||
import { StyledThemedLink } from '../widgets/FormStyledButton';
|
||||
import useNewQuery from '../query/useNewQuery';
|
||||
|
||||
export default function OpenSqlLink({ file, children }) {
|
||||
const newQuery = useNewQuery();
|
||||
const theme = useTheme();
|
||||
|
||||
const handleClick = async () => {
|
||||
const resp = await axios.post('files/load', { folder: 'sql', file, format: 'text' });
|
||||
newQuery({
|
||||
title: file,
|
||||
initialData: resp.data,
|
||||
// @ts-ignore
|
||||
savedFile: file,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<StyledThemedLink theme={theme} onClick={handleClick}>
|
||||
{children}
|
||||
</StyledThemedLink>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user