This commit is contained in:
Jan Prochazka
2021-01-23 07:22:09 +01:00
parent 37cc86f8d2
commit 451af5d09f
141 changed files with 763 additions and 787 deletions

View File

@@ -19,7 +19,7 @@ export default function ChangeDownloadUrlModal({ modalState, url = '', onConfirm
// };
const handleSubmit = React.useCallback(
async (values) => {
async values => {
onConfirm(values.url);
modalState.close();
},

View File

@@ -14,10 +14,10 @@ import { FormProvider, useForm } from '../utility/FormProvider';
function DriverFields({ extensions }) {
const { values, setFieldValue } = useForm();
const { authType, engine } = values;
const driver = extensions.drivers.find((x) => x.engine == engine);
const driver = extensions.drivers.find(x => x.engine == engine);
// const { authTypes } = driver || {};
const [authTypes, setAuthTypes] = React.useState(null);
const currentAuthType = authTypes && authTypes.find((x) => x.name == authType);
const currentAuthType = authTypes && authTypes.find(x => x.name == authType);
const loadAuthTypes = async () => {
const resp = await axios.post('plugins/auth-types', { engine });
@@ -39,7 +39,7 @@ function DriverFields({ extensions }) {
<>
{!!authTypes && (
<FormSelectField label="Authentication" name="authType">
{authTypes.map((auth) => (
{authTypes.map(auth => (
<option value={auth.name} key={auth.name}>
{auth.title}
</option>
@@ -66,7 +66,7 @@ export default function ConnectionModal({ modalState, connection = undefined })
const [isTesting, setIsTesting] = React.useState(false);
const testIdRef = React.useRef(0);
const handleTest = async (values) => {
const handleTest = async values => {
setIsTesting(true);
testIdRef.current += 1;
const testid = testIdRef.current;
@@ -82,7 +82,7 @@ export default function ConnectionModal({ modalState, connection = undefined })
setIsTesting(false);
};
const handleSubmit = async (values) => {
const handleSubmit = async values => {
axios.post('connections/save', values);
modalState.close();
};
@@ -93,7 +93,7 @@ export default function ConnectionModal({ modalState, connection = undefined })
<ModalContent>
<FormSelectField label="Database engine" name="engine">
<option value="(select driver)"></option>
{extensions.drivers.map((driver) => (
{extensions.drivers.map(driver => (
<option value={driver.engine} key={driver.engine}>
{driver.title}
</option>

View File

@@ -8,7 +8,7 @@ import ModalFooter from './ModalFooter';
import { FormProvider } from '../utility/FormProvider';
export default function CreateDatabaseModal({ modalState, conid }) {
const handleSubmit = async (values) => {
const handleSubmit = async values => {
const { name } = values;
axios.post('server-connections/create-database', { conid, name });

View File

@@ -48,7 +48,7 @@ export default function FavoriteModal({ modalState, editingData = undefined, sav
const canWriteFavorite = hasPermission('files/favorites/write');
const getTabSaveData = async (values) => {
const getTabSaveData = async values => {
const tabdata = {};
const skipEditor = !!savedFile && values.whatToSave != 'content';
@@ -78,7 +78,7 @@ export default function FavoriteModal({ modalState, editingData = undefined, sav
};
};
const saveTab = async (values) => {
const saveTab = async values => {
const data = await getTabSaveData(values);
axios.post('files/save', {
@@ -89,7 +89,7 @@ export default function FavoriteModal({ modalState, editingData = undefined, sav
});
};
const saveFile = async (values) => {
const saveFile = async values => {
const oldDataResp = await axios.post('files/load', {
folder: 'favorites',
file: editingData.file,
@@ -107,7 +107,7 @@ export default function FavoriteModal({ modalState, editingData = undefined, sav
});
};
const handleSubmit = async (values) => {
const handleSubmit = async values => {
modalState.close();
if (savingTab) {
saveTab(values);
@@ -117,7 +117,7 @@ export default function FavoriteModal({ modalState, editingData = undefined, sav
}
};
const handleCopyLink = async (values) => {
const handleCopyLink = async values => {
const tabdata = await getTabSaveData(values);
copyTextToClipboard(`${document.location.origin}#tabdata=${encodeURIComponent(JSON.stringify(tabdata))}`);
};
@@ -136,7 +136,7 @@ export default function FavoriteModal({ modalState, editingData = undefined, sav
{!!savingTab && !electron && canWriteFavorite && (
<FormCheckboxField label="Share as link" name="shareAsLink" />
)}
<FormCondition condition={(values) => !values.shareAsLink && canWriteFavorite}>
<FormCondition condition={values => !values.shareAsLink && canWriteFavorite}>
<FormCheckboxField label="Show in toolbar" name="showInToolbar" />
<FormCheckboxField label="Open on startup" name="openOnStartup" />
</FormCondition>
@@ -148,10 +148,10 @@ export default function FavoriteModal({ modalState, editingData = undefined, sav
)}
</ModalContent>
<ModalFooter>
<FormCondition condition={(values) => !values.shareAsLink && canWriteFavorite}>
<FormCondition condition={values => !values.shareAsLink && canWriteFavorite}>
<FormSubmit value="OK" onClick={handleSubmit} />
</FormCondition>
<FormCondition condition={(values) => values.shareAsLink || !canWriteFavorite}>
<FormCondition condition={values => values.shareAsLink || !canWriteFavorite}>
<FormButton value="Copy link" onClick={handleCopyLink} />
</FormCondition>
<FormButton value="Cancel" onClick={() => modalState.close()} />

View File

@@ -49,7 +49,7 @@ export default function FilterMultipleValuesModal({ modalState, onFilter }) {
<ModalHeader modalState={modalState}>Filter multiple values</ModalHeader>
<ModalContent>
<Wrapper>
<textarea rows={10} ref={editorRef} value={text} onChange={(e) => setText(e.target.value)} />
<textarea rows={10} ref={editorRef} value={text} onChange={e => setText(e.target.value)} />
<OptionsWrapper>
<RadioGroupItem text="Is one of line" value="is" defaultChecked setMode={setMode} />
<RadioGroupItem text="Is not one of line" value="is_not" setMode={setMode} />

View File

@@ -52,7 +52,7 @@ const WidgetColumnWrapper = styled.div`
display: flex;
flex: 1;
overflow: hidden;
border-left: 1px solid ${(props) => props.theme.border};
border-left: 1px solid ${props => props.theme.border};
`;
const FormWrapper = styled.div`
@@ -67,7 +67,7 @@ const FormWrapper = styled.div`
`;
const ContentWrapper = styled.div`
border-top: 1px solid ${(props) => props.theme.border};
border-top: 1px solid ${props => props.theme.border};
flex: 1;
display: flex;
flex-direction: column;
@@ -80,9 +80,9 @@ const Footer = styled.div`
left: 0;
right: 0;
bottom: 0px;
background-color: ${(props) => props.theme.modalheader_background};
background-color: ${props => props.theme.modalheader_background};
border-top: 1px solid ${(props) => props.theme.border};
border-top: 1px solid ${props => props.theme.border};
// padding: 15px;
`;
@@ -155,13 +155,13 @@ export default function ImportExportModal({
}
}, [runnerId, socket]);
const handleExecute = async (values) => {
const handleExecute = async values => {
if (busy) return;
setBusy(true);
const script = await createImpExpScript(extensions, values);
setExecuteNumber((num) => num + 1);
setExecuteNumber(num => num + 1);
let runid = runnerId;
const resp = await axios.post('runners/start', { script });

View File

@@ -7,7 +7,7 @@ import ModalFooter from './ModalFooter';
import { FormProvider } from '../utility/FormProvider';
export default function InputTextModal({ header, label, value, modalState, onConfirm }) {
const handleSubmit = async (values) => {
const handleSubmit = async values => {
const { value } = values;
modalState.close();
onConfirm(value);

View File

@@ -34,7 +34,7 @@ const JOIN_TYPES = ['INNER JOIN', 'LEFT JOIN', 'RIGHT JOIN'];
export default function InsertJoinModal({ sql, modalState, engine, dbinfo, onInsert }) {
const sources = React.useMemo(
() => analyseQuerySources(sql, [...dbinfo.tables.map((x) => x.pureName), ...dbinfo.views.map((x) => x.pureName)]),
() => analyseQuerySources(sql, [...dbinfo.tables.map(x => x.pureName), ...dbinfo.views.map(x => x.pureName)]),
[sql, dbinfo]
);
@@ -51,22 +51,22 @@ export default function InsertJoinModal({ sql, modalState, engine, dbinfo, onIns
const source = sources[sourceIndex];
if (!source) return [];
/** @type {import('dbgate-types').TableInfo} */
const table = dbinfo.tables.find((x) => x.pureName == sources[sourceIndex].name);
const table = dbinfo.tables.find(x => x.pureName == sources[sourceIndex].name);
if (!table) return [];
return [
...table.foreignKeys.map((fk) => ({
baseColumns: fk.columns.map((x) => x.columnName).join(', '),
...table.foreignKeys.map(fk => ({
baseColumns: fk.columns.map(x => x.columnName).join(', '),
refTable: fk.refTableName,
refColumns: fk.columns.map((x) => x.refColumnName).join(', '),
refColumns: fk.columns.map(x => x.refColumnName).join(', '),
constraintName: fk.constraintName,
columnMap: fk.columns,
})),
...table.dependencies.map((fk) => ({
baseColumns: fk.columns.map((x) => x.refColumnName).join(', '),
...table.dependencies.map(fk => ({
baseColumns: fk.columns.map(x => x.refColumnName).join(', '),
refTable: fk.pureName,
refColumns: fk.columns.map((x) => x.columnName).join(', '),
refColumns: fk.columns.map(x => x.columnName).join(', '),
constraintName: fk.constraintName,
columnMap: fk.columns.map((x) => ({
columnMap: fk.columns.map(x => ({
columnName: x.refColumnName,
refColumnName: x.columnName,
})),
@@ -79,18 +79,18 @@ export default function InsertJoinModal({ sql, modalState, engine, dbinfo, onIns
const target = targets[targetIndex];
if (source && target) {
return `${JOIN_TYPES[joinIndex]} ${target.refTable}${alias ? ` ${alias}` : ''} ON ${target.columnMap
.map((col) => `${source.name}.${col.columnName} = ${alias || target.refTable}.${col.refColumnName}`)
.map(col => `${source.name}.${col.columnName} = ${alias || target.refTable}.${col.refColumnName}`)
.join(' AND ')}`;
}
return '';
}, [joinIndex, sources, targets, sourceIndex, targetIndex, alias]);
const sourceKeyDown = React.useCallback((event) => {
const sourceKeyDown = React.useCallback(event => {
if (event.keyCode == keycodes.enter || event.keyCode == keycodes.rightArrow) {
targetRef.current.focus();
}
}, []);
const targetKeyDown = React.useCallback((event) => {
const targetKeyDown = React.useCallback(event => {
if (event.keyCode == keycodes.leftArrow) {
sourceRef.current.focus();
}
@@ -98,7 +98,7 @@ export default function InsertJoinModal({ sql, modalState, engine, dbinfo, onIns
joinRef.current.focus();
}
}, []);
const joinKeyDown = React.useCallback((event) => {
const joinKeyDown = React.useCallback(event => {
if (event.keyCode == keycodes.leftArrow) {
targetRef.current.focus();
}
@@ -107,7 +107,7 @@ export default function InsertJoinModal({ sql, modalState, engine, dbinfo, onIns
}
}, []);
const aliasKeyDown = React.useCallback(
(event) => {
event => {
if (event.keyCode == keycodes.enter) {
event.preventDefault();
modalState.close();
@@ -154,7 +154,7 @@ export default function InsertJoinModal({ sql, modalState, engine, dbinfo, onIns
<FlexColumn>
<Label>Join</Label>
<TableControl
rows={JOIN_TYPES.map((name) => ({ name }))}
rows={JOIN_TYPES.map(name => ({ name }))}
selectedIndex={joinIndex}
setSelectedIndex={setJoinIndex}
tableRef={joinRef}
@@ -165,7 +165,7 @@ export default function InsertJoinModal({ sql, modalState, engine, dbinfo, onIns
<Label>Alias</Label>
<TextField
value={alias}
onChange={(e) => setAlias(e.target.value)}
onChange={e => setAlias(e.target.value)}
editorRef={aliasRef}
onKeyDown={aliasKeyDown}
/>

View File

@@ -20,13 +20,13 @@ import ErrorBoundary from '../utility/ErrorBoundary';
// `;
const StyledModal = styled(Modal)`
border: 1px solid ${(props) => props.theme.border};
background: ${(props) => props.theme.modal_background};
border: 1px solid ${props => props.theme.border};
background: ${props => props.theme.modal_background};
overflow: auto;
webkitoverflowscrolling: touch;
outline: none;
${(props) =>
${props =>
props.fullScreen &&
`
position: fixed;
@@ -38,7 +38,7 @@ const StyledModal = styled(Modal)`
// height: 100%;
`}
${(props) =>
${props =>
!props.fullScreen &&
`
border-radius: 10px;
@@ -50,7 +50,7 @@ const StyledModal = styled(Modal)`
// z-index:1200;
${(props) =>
${props =>
props.isFlex &&
`
display: flex;

View File

@@ -3,8 +3,8 @@ import styled from 'styled-components';
import useTheme from '../theme/useTheme';
const Wrapper = styled.div`
border-bottom: 1px solid ${(props) => props.theme.border};
border-top: 1px solid ${(props) => props.theme.border};
border-bottom: 1px solid ${props => props.theme.border};
border-top: 1px solid ${props => props.theme.border};
padding: 15px;
`;

View File

@@ -3,9 +3,9 @@ import styled from 'styled-components';
import useTheme from '../theme/useTheme';
const Wrapper = styled.div`
border-bottom: 1px solid ${(props) => props.theme.border};
border-bottom: 1px solid ${props => props.theme.border};
padding: 15px;
background-color: ${(props) => props.theme.modalheader_background};
background-color: ${props => props.theme.modalheader_background};
`;
export default function ModalFooter({ children }) {

View File

@@ -8,13 +8,13 @@ const Wrapper = styled.div`
padding: 15px;
display: flex;
justify-content: space-between;
background-color: ${(props) => props.theme.modalheader_background};
background-color: ${props => props.theme.modalheader_background};
`;
const CloseWrapper = styled.div`
font-size: 12pt;
&:hover {
background-color: ${(props) => props.theme.modalheader_background2};
background-color: ${props => props.theme.modalheader_background2};
}
padding: 5px 10px;
border-radius: 10px;

View File

@@ -14,7 +14,7 @@ const SelectWrapper = styled.div`
`;
export default function SaveArchiveModal({ file = 'new-table', folder = 'default', modalState, onSave }) {
const handleSubmit = async (values) => {
const handleSubmit = async values => {
const { file, folder } = values;
modalState.close();
if (onSave) onSave(folder, file);

View File

@@ -8,7 +8,7 @@ import ModalFooter from './ModalFooter';
import { FormProvider } from '../utility/FormProvider';
export default function SaveFileModal({ data, folder, format, modalState, name, onSave = undefined }) {
const handleSubmit = async (values) => {
const handleSubmit = async values => {
const { name } = values;
await axios.post('files/save', { folder, file: name, data, format });
modalState.close();
@@ -19,7 +19,7 @@ export default function SaveFileModal({ data, folder, format, modalState, name,
<ModalHeader modalState={modalState}>Save file</ModalHeader>
<FormProvider initialValues={{ name }}>
<ModalContent>
<FormTextField label="File name" name="name" focused/>
<FormTextField label="File name" name="name" focused />
</ModalContent>
<ModalFooter>
<FormSubmit value="Save" onClick={handleSubmit} />

View File

@@ -8,9 +8,9 @@ export default function SaveTabModal({ data, folder, format, modalState, tabid,
const setOpenedTabs = useSetOpenedTabs();
const openedTabs = useOpenedTabs();
const { savedFile } = openedTabs.find((x) => x.tabid == tabid).props || {};
const onSave = (name) =>
changeTab(tabid, setOpenedTabs, (tab) => ({
const { savedFile } = openedTabs.find(x => x.tabid == tabid).props || {};
const onSave = name =>
changeTab(tabid, setOpenedTabs, tab => ({
...tab,
title: name,
props: {
@@ -22,7 +22,7 @@ export default function SaveTabModal({ data, folder, format, modalState, tabid,
}));
const handleKeyboard = React.useCallback(
(e) => {
e => {
if (e.keyCode == keycodes.s && e.ctrlKey) {
e.preventDefault();
modalState.open();

View File

@@ -93,7 +93,7 @@ export default function SetFilterModal({ modalState, onFilter, filterType, condi
return `${condition}${value}`;
};
const handleOk = (values) => {
const handleOk = values => {
const { value1, condition1, value2, condition2, joinOperator } = values;
const term1 = createTerm(condition1, value1);
const term2 = createTerm(condition2, value2);

View File

@@ -22,11 +22,7 @@ export function ModalLayer() {
return (
<div>
{modals.map((modal, index) => (
<ShowModalComponent
key={index}
renderModal={modal}
onClose={() => setModals((x) => x.filter((y) => y != modal))}
/>
<ShowModalComponent key={index} renderModal={modal} onClose={() => setModals(x => x.filter(y => y != modal))} />
))}
</div>
);
@@ -34,7 +30,7 @@ export function ModalLayer() {
export default function useShowModal() {
const [modals, setModals] = React.useContext(Context);
const showModal = (renderModal) => {
const showModal = renderModal => {
setModals([...modals, renderModal]);
};
return showModal;