chore: make TS enums strictly PascalCase (#26875)

This commit is contained in:
Ville Brofeldt
2024-01-31 17:40:44 -08:00
committed by GitHub
parent 959a5a5ad6
commit 19f8405bc0
362 changed files with 2002 additions and 2032 deletions

View File

@@ -26,8 +26,8 @@ import { FieldPropTypes } from '.';
import { infoTooltip, labelMarginBottom, CredentialInfoForm } from '../styles';
enum CredentialInfoOptions {
jsonUpload,
copyPaste,
JsonUpload,
CopyPaste,
}
// These are the columns that are going to be added to encrypted extra, they differ in name based
@@ -47,7 +47,7 @@ export const EncryptedField = ({
editNewDb,
}: FieldPropTypes) => {
const [uploadOption, setUploadOption] = useState<number>(
CredentialInfoOptions.jsonUpload.valueOf(),
CredentialInfoOptions.JsonUpload.valueOf(),
);
const [fileToUpload, setFileToUpload] = useState<string | null | undefined>(
null,
@@ -97,17 +97,17 @@ export const EncryptedField = ({
style={{ width: '100%' }}
onChange={option => setUploadOption(option)}
>
<AntdSelect.Option value={CredentialInfoOptions.jsonUpload}>
<AntdSelect.Option value={CredentialInfoOptions.JsonUpload}>
{t('Upload JSON file')}
</AntdSelect.Option>
<AntdSelect.Option value={CredentialInfoOptions.copyPaste}>
<AntdSelect.Option value={CredentialInfoOptions.CopyPaste}>
{t('Copy and Paste JSON credentials')}
</AntdSelect.Option>
</AntdSelect>
</>
)}
{uploadOption === CredentialInfoOptions.copyPaste ||
{uploadOption === CredentialInfoOptions.CopyPaste ||
isEditMode ||
editNewDb ? (
<div className="input-container">

View File

@@ -59,7 +59,7 @@ const SSHTunnelForm = ({
>;
setSSHTunnelLoginMethod: (method: AuthType) => void;
}) => {
const [usePassword, setUsePassword] = useState<AuthType>(AuthType.password);
const [usePassword, setUsePassword] = useState<AuthType>(AuthType.Password);
return (
<Form>
@@ -126,13 +126,13 @@ const SSHTunnelForm = ({
}}
>
<Radio
value={AuthType.password}
value={AuthType.Password}
data-test="ssh-tunnel-use_password-radio"
>
{t('Password')}
</Radio>
<Radio
value={AuthType.privateKey}
value={AuthType.PrivateKey}
data-test="ssh-tunnel-use_private_key-radio"
>
{t('Private Key & Password')}
@@ -142,7 +142,7 @@ const SSHTunnelForm = ({
</StyledDiv>
</Col>
</StyledRow>
{usePassword === AuthType.password && (
{usePassword === AuthType.Password && (
<StyledRow gutter={16}>
<Col xs={24}>
<StyledDiv>
@@ -172,7 +172,7 @@ const SSHTunnelForm = ({
</Col>
</StyledRow>
)}
{usePassword === AuthType.privateKey && (
{usePassword === AuthType.PrivateKey && (
<>
<StyledRow gutter={16}>
<Col xs={24}>

View File

@@ -41,7 +41,7 @@ const SSHTunnelSwitch = ({
setUseSSHTunneling(changed);
if (!changed) {
setDB({
type: ActionType.removeSSHTunnelConfig,
type: ActionType.RemoveSSHTunnelConfig,
});
}
}}

View File

@@ -30,7 +30,7 @@ import {
import { getExtensionsRegistry } from '@superset-ui/core';
import setupExtensions from 'src/setup/setupExtensions';
import * as hooks from 'src/views/CRUD/hooks';
import { DatabaseObject, CONFIGURATION_METHOD } from '../types';
import { DatabaseObject, ConfigurationMethod } from '../types';
import DatabaseModal, {
dbReducer,
DBReducerActionType,
@@ -304,7 +304,7 @@ fetchMock.post(VALIDATE_PARAMS_ENDPOINT, {
const databaseFixture: DatabaseObject = {
id: 123,
backend: 'postgres',
configuration_method: CONFIGURATION_METHOD.DYNAMIC_FORM,
configuration_method: ConfigurationMethod.DynamicForm,
database_name: 'Postgres',
name: 'PostgresDB',
is_managed_externally: false,
@@ -1639,14 +1639,14 @@ describe('DatabaseModal', () => {
describe('dbReducer', () => {
test('it will reset state to null', () => {
const action: DBReducerActionType = { type: ActionType.reset };
const action: DBReducerActionType = { type: ActionType.Reset };
const currentState = dbReducer(databaseFixture, action);
expect(currentState).toBeNull();
});
test('it will set state to payload from fetched', () => {
const action: DBReducerActionType = {
type: ActionType.fetched,
type: ActionType.Fetched,
payload: databaseFixture,
};
const currentState = dbReducer({}, action);
@@ -1661,7 +1661,7 @@ describe('dbReducer', () => {
test('it will set state to payload from extra editor', () => {
const action: DBReducerActionType = {
type: ActionType.extraEditorChange,
type: ActionType.ExtraEditorChange,
payload: { name: 'foo', json: JSON.stringify({ bar: 1 }) },
};
const currentState = dbReducer(databaseFixture, action);
@@ -1674,7 +1674,7 @@ describe('dbReducer', () => {
test('it will set state to payload from editor', () => {
const action: DBReducerActionType = {
type: ActionType.editorChange,
type: ActionType.EditorChange,
payload: { name: 'foo', json: JSON.stringify({ bar: 1 }) },
};
const currentState = dbReducer(databaseFixture, action);
@@ -1687,7 +1687,7 @@ describe('dbReducer', () => {
test('it will add extra payload to existing extra data', () => {
const action: DBReducerActionType = {
type: ActionType.extraEditorChange,
type: ActionType.ExtraEditorChange,
payload: { name: 'foo', json: JSON.stringify({ bar: 1 }) },
};
// extra should be a string
@@ -1707,7 +1707,7 @@ describe('dbReducer', () => {
test('it will set state to payload from extra input change', () => {
const action: DBReducerActionType = {
type: ActionType.extraInputChange,
type: ActionType.ExtraInputChange,
payload: { name: 'foo', value: 'bar' },
};
const currentState = dbReducer(databaseFixture, action);
@@ -1721,7 +1721,7 @@ describe('dbReducer', () => {
test('it will set state to payload from extra input change when checkbox', () => {
const action: DBReducerActionType = {
type: ActionType.extraInputChange,
type: ActionType.ExtraInputChange,
payload: { name: 'foo', type: 'checkbox', checked: true },
};
const currentState = dbReducer(databaseFixture, action);
@@ -1735,7 +1735,7 @@ describe('dbReducer', () => {
test('it will set state to payload from extra input change when schema_cache_timeout', () => {
const action: DBReducerActionType = {
type: ActionType.extraInputChange,
type: ActionType.ExtraInputChange,
payload: { name: 'schema_cache_timeout', value: 'bar' },
};
const currentState = dbReducer(databaseFixture, action);
@@ -1749,7 +1749,7 @@ describe('dbReducer', () => {
test('it will set state to payload from extra input change when table_cache_timeout', () => {
const action: DBReducerActionType = {
type: ActionType.extraInputChange,
type: ActionType.ExtraInputChange,
payload: { name: 'table_cache_timeout', value: 'bar' },
};
const currentState = dbReducer(databaseFixture, action);
@@ -1763,7 +1763,7 @@ describe('dbReducer', () => {
test('it will overwrite state to payload from extra input change when table_cache_timeout', () => {
const action: DBReducerActionType = {
type: ActionType.extraInputChange,
type: ActionType.ExtraInputChange,
payload: { name: 'table_cache_timeout', value: 'bar' },
};
const currentState = dbReducer(
@@ -1784,7 +1784,7 @@ describe('dbReducer', () => {
test(`it will set state to payload from extra
input change when schemas_allowed_for_file_upload`, () => {
const action: DBReducerActionType = {
type: ActionType.extraInputChange,
type: ActionType.ExtraInputChange,
payload: { name: 'schemas_allowed_for_file_upload', value: 'bar' },
};
const currentState = dbReducer(databaseFixture, action);
@@ -1799,7 +1799,7 @@ describe('dbReducer', () => {
test(`it will overwrite state to payload from extra
input change when schemas_allowed_for_file_upload`, () => {
const action: DBReducerActionType = {
type: ActionType.extraInputChange,
type: ActionType.ExtraInputChange,
payload: { name: 'schemas_allowed_for_file_upload', value: 'bar' },
};
const currentState = dbReducer(
@@ -1821,7 +1821,7 @@ describe('dbReducer', () => {
input change when schemas_allowed_for_file_upload
with blank list`, () => {
const action: DBReducerActionType = {
type: ActionType.extraInputChange,
type: ActionType.ExtraInputChange,
payload: { name: 'schemas_allowed_for_file_upload', value: 'bar,' },
};
const currentState = dbReducer(databaseFixture, action);
@@ -1835,7 +1835,7 @@ describe('dbReducer', () => {
test('it will set state to payload from input change', () => {
const action: DBReducerActionType = {
type: ActionType.inputChange,
type: ActionType.InputChange,
payload: { name: 'foo', value: 'bar' },
};
const currentState = dbReducer(databaseFixture, action);
@@ -1848,7 +1848,7 @@ describe('dbReducer', () => {
test('it will set state to payload from input change for checkbox', () => {
const action: DBReducerActionType = {
type: ActionType.inputChange,
type: ActionType.InputChange,
payload: { name: 'foo', type: 'checkbox', checked: true },
};
const currentState = dbReducer(databaseFixture, action);
@@ -1861,7 +1861,7 @@ describe('dbReducer', () => {
test('it will change state to payload from input change for checkbox', () => {
const action: DBReducerActionType = {
type: ActionType.inputChange,
type: ActionType.InputChange,
payload: { name: 'allow_ctas', type: 'checkbox', checked: false },
};
const currentState = dbReducer(
@@ -1880,7 +1880,7 @@ describe('dbReducer', () => {
test('it will add a parameter', () => {
const action: DBReducerActionType = {
type: ActionType.parametersChange,
type: ActionType.ParametersChange,
payload: { name: 'host', value: '127.0.0.1' },
};
const currentState = dbReducer(databaseFixture, action);
@@ -1895,7 +1895,7 @@ describe('dbReducer', () => {
test('it will add a parameter with existing parameters', () => {
const action: DBReducerActionType = {
type: ActionType.parametersChange,
type: ActionType.ParametersChange,
payload: { name: 'port', value: '1234' },
};
const currentState = dbReducer(
@@ -1919,7 +1919,7 @@ describe('dbReducer', () => {
test('it will change a parameter with existing parameters', () => {
const action: DBReducerActionType = {
type: ActionType.parametersChange,
type: ActionType.ParametersChange,
payload: { name: 'host', value: 'localhost' },
};
const currentState = dbReducer(
@@ -1942,7 +1942,7 @@ describe('dbReducer', () => {
test('it will set state to payload from parametersChange with catalog', () => {
const action: DBReducerActionType = {
type: ActionType.parametersChange,
type: ActionType.ParametersChange,
payload: { name: 'name', type: 'catalog-0', value: 'bar' },
};
const currentState = dbReducer(
@@ -1963,7 +1963,7 @@ describe('dbReducer', () => {
test('it will add a new catalog array when empty', () => {
const action: DBReducerActionType = {
type: ActionType.addTableCatalogSheet,
type: ActionType.AddTableCatalogSheet,
};
const currentState = dbReducer(databaseFixture, action);
@@ -1975,7 +1975,7 @@ describe('dbReducer', () => {
test('it will add a new catalog array when one exists', () => {
const action: DBReducerActionType = {
type: ActionType.addTableCatalogSheet,
type: ActionType.AddTableCatalogSheet,
};
const currentState = dbReducer(
{ ...databaseFixture, catalog: [{ name: 'foo', value: 'baz' }] },
@@ -1993,7 +1993,7 @@ describe('dbReducer', () => {
test('it will remove a catalog when one exists', () => {
const action: DBReducerActionType = {
type: ActionType.removeTableCatalogSheet,
type: ActionType.RemoveTableCatalogSheet,
payload: { indexToDelete: 0 },
};
const currentState = dbReducer(
@@ -2010,7 +2010,7 @@ describe('dbReducer', () => {
test('it will add db information when one is selected', () => {
const { backend, ...db } = databaseFixture;
const action: DBReducerActionType = {
type: ActionType.dbSelected,
type: ActionType.DbSelected,
payload: {
engine_information: {
supports_file_upload: true,
@@ -2042,7 +2042,7 @@ describe('dbReducer', () => {
test('it will add a SSH Tunnel config parameter', () => {
const action: DBReducerActionType = {
type: ActionType.parametersSSHTunnelChange,
type: ActionType.ParametersSSHTunnelChange,
payload: { name: 'server_address', value: '127.0.0.1' },
};
const currentState = dbReducer(databaseFixture, action);
@@ -2057,7 +2057,7 @@ describe('dbReducer', () => {
test('it will add a SSH Tunnel config parameter with existing configs', () => {
const action: DBReducerActionType = {
type: ActionType.parametersSSHTunnelChange,
type: ActionType.ParametersSSHTunnelChange,
payload: { name: 'server_port', value: '22' },
};
const currentState = dbReducer(
@@ -2081,7 +2081,7 @@ describe('dbReducer', () => {
test('it will change a SSH Tunnel config parameter with existing configs', () => {
const action: DBReducerActionType = {
type: ActionType.parametersSSHTunnelChange,
type: ActionType.ParametersSSHTunnelChange,
payload: { name: 'server_address', value: 'localhost' },
};
const currentState = dbReducer(
@@ -2104,7 +2104,7 @@ describe('dbReducer', () => {
test('it will remove the SSH Tunnel config parameters', () => {
const action: DBReducerActionType = {
type: ActionType.removeSSHTunnelConfig,
type: ActionType.RemoveSSHTunnelConfig,
};
const currentState = dbReducer(databaseFixture, action);
expect(currentState).toEqual({

View File

@@ -61,7 +61,7 @@ import { isEmpty, pick } from 'lodash';
import {
DatabaseObject,
DatabaseForm,
CONFIGURATION_METHOD,
ConfigurationMethod,
CatalogObject,
Engines,
ExtraJson,
@@ -145,27 +145,27 @@ interface DatabaseModalProps {
}
export enum ActionType {
addTableCatalogSheet,
configMethodChange,
dbSelected,
editorChange,
extraEditorChange,
extraInputChange,
fetched,
inputChange,
parametersChange,
queryChange,
removeTableCatalogSheet,
reset,
textChange,
parametersSSHTunnelChange,
setSSHTunnelLoginMethod,
removeSSHTunnelConfig,
AddTableCatalogSheet,
ConfigMethodChange,
DbSelected,
EditorChange,
ExtraEditorChange,
ExtraInputChange,
Fetched,
InputChange,
ParametersChange,
QueryChange,
RemoveTableCatalogSheet,
Reset,
TextChange,
ParametersSSHTunnelChange,
SetSSHTunnelLoginMethod,
RemoveSSHTunnelConfig,
}
export enum AuthType {
password,
privateKey,
Password,
PrivateKey,
}
interface DBReducerPayloadType {
@@ -180,26 +180,26 @@ interface DBReducerPayloadType {
export type DBReducerActionType =
| {
type:
| ActionType.extraEditorChange
| ActionType.extraInputChange
| ActionType.textChange
| ActionType.queryChange
| ActionType.inputChange
| ActionType.editorChange
| ActionType.parametersChange
| ActionType.parametersSSHTunnelChange;
| ActionType.ExtraEditorChange
| ActionType.ExtraInputChange
| ActionType.TextChange
| ActionType.QueryChange
| ActionType.InputChange
| ActionType.EditorChange
| ActionType.ParametersChange
| ActionType.ParametersSSHTunnelChange;
payload: DBReducerPayloadType;
}
| {
type: ActionType.fetched;
type: ActionType.Fetched;
payload: Partial<DatabaseObject>;
}
| {
type: ActionType.dbSelected;
type: ActionType.DbSelected;
payload: {
database_name?: string;
engine?: string;
configuration_method: CONFIGURATION_METHOD;
configuration_method: ConfigurationMethod;
engine_information?: {};
driver?: string;
sqlalchemy_uri_placeholder?: string;
@@ -207,26 +207,26 @@ export type DBReducerActionType =
}
| {
type:
| ActionType.reset
| ActionType.addTableCatalogSheet
| ActionType.removeSSHTunnelConfig;
| ActionType.Reset
| ActionType.AddTableCatalogSheet
| ActionType.RemoveSSHTunnelConfig;
}
| {
type: ActionType.removeTableCatalogSheet;
type: ActionType.RemoveTableCatalogSheet;
payload: {
indexToDelete: number;
};
}
| {
type: ActionType.configMethodChange;
type: ActionType.ConfigMethodChange;
payload: {
database_name?: string;
engine?: string;
configuration_method: CONFIGURATION_METHOD;
configuration_method: ConfigurationMethod;
};
}
| {
type: ActionType.setSSHTunnelLoginMethod;
type: ActionType.SetSSHTunnelLoginMethod;
payload: {
login_method: AuthType;
};
@@ -251,7 +251,7 @@ export function dbReducer(
const extraJson: ExtraJson = JSON.parse(trimmedState.extra || '{}');
switch (action.type) {
case ActionType.extraEditorChange:
case ActionType.ExtraEditorChange:
// "extra" payload in state is a string
try {
// we don't want to stringify encoded strings twice
@@ -266,7 +266,7 @@ export function dbReducer(
[action.payload.name]: actionPayloadJson,
}),
};
case ActionType.extraInputChange:
case ActionType.ExtraInputChange:
// "extra" payload in state is a string
if (
action.payload.name === 'schema_cache_timeout' ||
@@ -329,7 +329,7 @@ export function dbReducer(
: action.payload.value,
}),
};
case ActionType.inputChange:
case ActionType.InputChange:
if (action.payload.type === 'checkbox') {
return {
...trimmedState,
@@ -340,7 +340,7 @@ export function dbReducer(
...trimmedState,
[action.payload.name]: action.payload.value,
};
case ActionType.parametersChange:
case ActionType.ParametersChange:
// catalog params will always have a catalog state for
// dbs that use a catalog, i.e., gsheets, even if the
// fields are empty strings
@@ -382,7 +382,7 @@ export function dbReducer(
},
};
case ActionType.parametersSSHTunnelChange:
case ActionType.ParametersSSHTunnelChange:
return {
...trimmedState,
ssh_tunnel: {
@@ -390,7 +390,7 @@ export function dbReducer(
[action.payload.name]: action.payload.value,
},
};
case ActionType.setSSHTunnelLoginMethod: {
case ActionType.SetSSHTunnelLoginMethod: {
let ssh_tunnel = {};
if (trimmedState?.ssh_tunnel) {
// remove any attributes that are considered sensitive
@@ -401,7 +401,7 @@ export function dbReducer(
'username',
]);
}
if (action.payload.login_method === AuthType.privateKey) {
if (action.payload.login_method === AuthType.PrivateKey) {
return {
...trimmedState,
ssh_tunnel: {
@@ -412,7 +412,7 @@ export function dbReducer(
},
};
}
if (action.payload.login_method === AuthType.password) {
if (action.payload.login_method === AuthType.Password) {
return {
...trimmedState,
ssh_tunnel: {
@@ -425,12 +425,12 @@ export function dbReducer(
...trimmedState,
};
}
case ActionType.removeSSHTunnelConfig:
case ActionType.RemoveSSHTunnelConfig:
return {
...trimmedState,
ssh_tunnel: undefined,
};
case ActionType.addTableCatalogSheet:
case ActionType.AddTableCatalogSheet:
if (trimmedState.catalog !== undefined) {
return {
...trimmedState,
@@ -441,17 +441,17 @@ export function dbReducer(
...trimmedState,
catalog: [{ name: '', value: '' }],
};
case ActionType.removeTableCatalogSheet:
case ActionType.RemoveTableCatalogSheet:
trimmedState.catalog?.splice(action.payload.indexToDelete, 1);
return {
...trimmedState,
};
case ActionType.editorChange:
case ActionType.EditorChange:
return {
...trimmedState,
[action.payload.name]: action.payload.json,
};
case ActionType.queryChange:
case ActionType.QueryChange:
return {
...trimmedState,
parameters: {
@@ -460,12 +460,12 @@ export function dbReducer(
},
query_input: action.payload.value,
};
case ActionType.textChange:
case ActionType.TextChange:
return {
...trimmedState,
[action.payload.name]: action.payload.value,
};
case ActionType.fetched:
case ActionType.Fetched:
// convert query to a string and store in query_input
query = action.payload?.parameters?.query || {};
query_input = Object.entries(query)
@@ -474,8 +474,7 @@ export function dbReducer(
if (
action.payload.masked_encrypted_extra &&
action.payload.configuration_method ===
CONFIGURATION_METHOD.DYNAMIC_FORM
action.payload.configuration_method === ConfigurationMethod.DynamicForm
) {
// "extra" payload from the api is a string
const extraJsonPayload: ExtraJson = {
@@ -510,19 +509,19 @@ export function dbReducer(
query_input,
};
case ActionType.dbSelected:
case ActionType.DbSelected:
// set initial state for blank form
return {
...action.payload,
extra: DEFAULT_EXTRA,
expose_in_sqllab: true,
};
case ActionType.configMethodChange:
case ActionType.ConfigMethodChange:
return {
...action.payload,
};
case ActionType.reset:
case ActionType.Reset:
default:
return null;
}
@@ -626,12 +625,11 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
) as DatabaseObject
)?.engine_information?.disable_ssh_tunneling;
const isSSHTunneling =
isFeatureEnabled(FeatureFlag.SSH_TUNNELING) &&
!disableSSHTunnelingForEngine;
isFeatureEnabled(FeatureFlag.SshTunneling) && !disableSSHTunnelingForEngine;
const hasAlert =
connectionAlert || !!(db?.engine && engineSpecificAlertMapping[db.engine]);
const useSqlAlchemyForm =
db?.configuration_method === CONFIGURATION_METHOD.SQLALCHEMY_URI;
db?.configuration_method === ConfigurationMethod.SqlalchemyUri;
const useTabLayout = isEditMode || useSqlAlchemyForm;
const isDynamic = (engine: string | undefined) =>
availableDbs?.databases?.find(
@@ -690,7 +688,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
};
const onClose = () => {
setDB({ type: ActionType.reset });
setDB({ type: ActionType.Reset });
setHasConnectedDb(false);
setValidationErrors(null); // reset validation errors on close
clearError();
@@ -752,7 +750,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
// Clone DB object
const dbToUpdate = { ...(db || {}) };
if (dbToUpdate.configuration_method === CONFIGURATION_METHOD.DYNAMIC_FORM) {
if (dbToUpdate.configuration_method === ConfigurationMethod.DynamicForm) {
// Validate DB before saving
if (dbToUpdate?.parameters?.catalog) {
// need to stringify gsheets catalog to allow it to be serialized
@@ -836,7 +834,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
const result = await updateResource(
db.id as number,
dbToUpdate as DatabaseObject,
dbToUpdate.configuration_method === CONFIGURATION_METHOD.DYNAMIC_FORM, // onShow toast on SQLA Forms
dbToUpdate.configuration_method === ConfigurationMethod.DynamicForm, // onShow toast on SQLA Forms
);
if (result) {
if (onDatabaseAdd) onDatabaseAdd();
@@ -861,7 +859,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
// Create
const dbId = await createResource(
dbToUpdate as DatabaseObject,
dbToUpdate.configuration_method === CONFIGURATION_METHOD.DYNAMIC_FORM, // onShow toast on SQLA Forms
dbToUpdate.configuration_method === ConfigurationMethod.DynamicForm, // onShow toast on SQLA Forms
);
if (dbId) {
setHasConnectedDb(true);
@@ -934,10 +932,10 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
if (database_name === 'Other') {
// Allow users to connect to DB via legacy SQLA form
setDB({
type: ActionType.dbSelected,
type: ActionType.DbSelected,
payload: {
database_name,
configuration_method: CONFIGURATION_METHOD.SQLALCHEMY_URI,
configuration_method: ConfigurationMethod.SqlalchemyUri,
engine: undefined,
engine_information: {
supports_file_upload: true,
@@ -957,13 +955,13 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
} = selectedDbModel;
const isDynamic = parameters !== undefined;
setDB({
type: ActionType.dbSelected,
type: ActionType.DbSelected,
payload: {
database_name,
engine,
configuration_method: isDynamic
? CONFIGURATION_METHOD.DYNAMIC_FORM
: CONFIGURATION_METHOD.SQLALCHEMY_URI,
? ConfigurationMethod.DynamicForm
: ConfigurationMethod.SqlalchemyUri,
engine_information,
driver: default_driver,
sqlalchemy_uri_placeholder,
@@ -972,7 +970,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
if (engine === Engines.GSheet) {
// only create a catalog if the DB is Google Sheets
setDB({ type: ActionType.addTableCatalogSheet });
setDB({ type: ActionType.AddTableCatalogSheet });
}
}
};
@@ -1086,7 +1084,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
setSSHTunnelPrivateKeys({});
setSSHTunnelPrivateKeyPasswords({});
}
setDB({ type: ActionType.reset });
setDB({ type: ActionType.Reset });
setFileList([]);
};
@@ -1238,7 +1236,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
useEffect(() => {
if (dbFetched) {
setDB({
type: ActionType.fetched,
type: ActionType.Fetched,
payload: dbFetched,
});
// keep a copy of the name separate for display purposes
@@ -1545,7 +1543,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
const fetchAndSetDB = () => {
setLoading(true);
fetchResource(dbFetched?.id as number).then(r => {
setItem(LocalStorageKeys.db, r);
setItem(LocalStorageKeys.Database, r);
});
};
@@ -1557,7 +1555,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
}: {
target: HTMLInputElement | HTMLTextAreaElement;
}) =>
onChange(ActionType.parametersSSHTunnelChange, {
onChange(ActionType.ParametersSSHTunnelChange, {
type: target.type,
name: target.name,
value: target.value,
@@ -1565,7 +1563,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
}
setSSHTunnelLoginMethod={(method: AuthType) =>
setDB({
type: ActionType.setSSHTunnelLoginMethod,
type: ActionType.SetSSHTunnelLoginMethod,
payload: { login_method: method },
})
}
@@ -1605,28 +1603,28 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
sslForced={false}
dbModel={dbModel}
onAddTableCatalog={() => {
setDB({ type: ActionType.addTableCatalogSheet });
setDB({ type: ActionType.AddTableCatalogSheet });
}}
onQueryChange={({ target }: { target: HTMLInputElement }) =>
onChange(ActionType.queryChange, {
onChange(ActionType.QueryChange, {
name: target.name,
value: target.value,
})
}
onExtraInputChange={({ target }: { target: HTMLInputElement }) =>
onChange(ActionType.extraInputChange, {
onChange(ActionType.ExtraInputChange, {
name: target.name,
value: target.value,
})
}
onRemoveTableCatalog={(idx: number) => {
setDB({
type: ActionType.removeTableCatalogSheet,
type: ActionType.RemoveTableCatalogSheet,
payload: { indexToDelete: idx },
});
}}
onParametersChange={({ target }: { target: HTMLInputElement }) =>
onChange(ActionType.parametersChange, {
onChange(ActionType.ParametersChange, {
type: target.type,
name: target.name,
checked: target.checked,
@@ -1634,7 +1632,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
})
}
onChange={({ target }: { target: HTMLInputElement }) =>
onChange(ActionType.textChange, {
onChange(ActionType.TextChange, {
name: target.name,
value: target.value,
})
@@ -1657,7 +1655,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
extraExtension={dbConfigExtraExtension}
db={db as DatabaseObject}
onInputChange={({ target }: { target: HTMLInputElement }) =>
onChange(ActionType.inputChange, {
onChange(ActionType.InputChange, {
type: target.type,
name: target.name,
checked: target.checked,
@@ -1665,16 +1663,16 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
})
}
onTextChange={({ target }: { target: HTMLTextAreaElement }) =>
onChange(ActionType.textChange, {
onChange(ActionType.TextChange, {
name: target.name,
value: target.value,
})
}
onEditorChange={(payload: { name: string; json: any }) =>
onChange(ActionType.editorChange, payload)
onChange(ActionType.EditorChange, payload)
}
onExtraInputChange={({ target }: { target: HTMLInputElement }) => {
onChange(ActionType.extraInputChange, {
onChange(ActionType.ExtraInputChange, {
type: target.type,
name: target.name,
checked: target.checked,
@@ -1682,7 +1680,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
});
}}
onExtraEditorChange={(payload: { name: string; json: any }) =>
onChange(ActionType.extraEditorChange, payload)
onChange(ActionType.ExtraEditorChange, payload)
}
/>
);
@@ -1782,7 +1780,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
<SqlAlchemyForm
db={db as DatabaseObject}
onInputChange={({ target }: { target: HTMLInputElement }) =>
onChange(ActionType.inputChange, {
onChange(ActionType.InputChange, {
type: target.type,
name: target.name,
checked: target.checked,
@@ -1810,11 +1808,10 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
buttonStyle="link"
onClick={() =>
setDB({
type: ActionType.configMethodChange,
type: ActionType.ConfigMethodChange,
payload: {
database_name: db?.database_name,
configuration_method:
CONFIGURATION_METHOD.DYNAMIC_FORM,
configuration_method: ConfigurationMethod.DynamicForm,
engine: db?.engine,
},
})
@@ -1869,7 +1866,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
extraExtension={dbConfigExtraExtension}
db={db as DatabaseObject}
onInputChange={({ target }: { target: HTMLInputElement }) =>
onChange(ActionType.inputChange, {
onChange(ActionType.InputChange, {
type: target.type,
name: target.name,
checked: target.checked,
@@ -1877,16 +1874,16 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
})
}
onTextChange={({ target }: { target: HTMLTextAreaElement }) =>
onChange(ActionType.textChange, {
onChange(ActionType.TextChange, {
name: target.name,
value: target.value,
})
}
onEditorChange={(payload: { name: string; json: any }) =>
onChange(ActionType.editorChange, payload)
onChange(ActionType.EditorChange, payload)
}
onExtraInputChange={({ target }: { target: HTMLInputElement }) => {
onChange(ActionType.extraInputChange, {
onChange(ActionType.ExtraInputChange, {
type: target.type,
name: target.name,
checked: target.checked,
@@ -1894,7 +1891,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
});
}}
onExtraEditorChange={(payload: { name: string; json: any }) => {
onChange(ActionType.extraEditorChange, payload);
onChange(ActionType.ExtraEditorChange, payload);
}}
/>
</Tabs.TabPane>
@@ -1993,11 +1990,11 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
buttonStyle="link"
onClick={() =>
setDB({
type: ActionType.configMethodChange,
type: ActionType.ConfigMethodChange,
payload: {
engine: db.engine,
configuration_method:
CONFIGURATION_METHOD.SQLALCHEMY_URI,
ConfigurationMethod.SqlalchemyUri,
database_name: db.database_name,
},
})