console: fix adding database with url from env (close #457)

GitOrigin-RevId: 0a732a20556feb4d810fc20ba623a6818c2cf45d
This commit is contained in:
Aleksandra Sikora 2021-02-03 14:14:55 +01:00 committed by hasura-bot
parent c14dcd5792
commit 1bca160d8e
6 changed files with 9 additions and 48 deletions

View File

@ -6,30 +6,6 @@ import DropdownButton from '../../../Common/DropdownButton/DropdownButton';
import CollapsibleToggle from '../../../Common/CollapsibleToggle/CollapsibleToggle';
import { DataSource } from '../../../../metadata/types';
// const customSelectBoxStyles = {
// control: {
// height: '34px',
// minHeight: '34px !important',
// },
// container: {
// width: '156px',
// height: '34px',
// minHeight: '34px !important',
// },
// dropdownIndicator: {
// padding: '5px',
// },
// placeholder: {
// top: '50%',
// fontSize: '12px',
// },
// singleValue: {
// fontSize: '12px',
// top: '44%',
// color: '#555555',
// },
// };
type AddDataSourceProps = {
onSubmit(data: DataSource, successCallback: () => void): void;
};
@ -49,9 +25,11 @@ const AddDataSource = ({ onSubmit }: AddDataSourceProps) => {
{
name: databaseName.trim(),
driver: 'postgres',
fromEnv: urlType === 'from-env',
connection_pool_settings: retryConf,
url: databaseUrl.trim(),
url:
urlType === 'from-env'
? { from_env: databaseUrl.trim() }
: databaseUrl.trim(),
},
() => {
setDatabaseUrl('');
@ -66,19 +44,6 @@ const AddDataSource = ({ onSubmit }: AddDataSourceProps) => {
const expandedContent = () => (
<div style={{ width: '100%' }}>
<form className={`form-inline ${styles.display_flex}`}>
{/* <span className={styles.add_mar_right_mid}>
<SearchableSelect
options={drivers}
onChange={(opt: any) =>
setDatabaseType(typeof opt === 'string' ? opt : opt.value)
}
value={databaseType || ''}
bsClass="modify_select"
styleOverrides={customSelectBoxStyles}
filterOption="prefix"
placeholder="database type"
/>
</span> */}
<input
placeholder="database name"
type="text"

View File

@ -162,7 +162,7 @@ const ManageDatabase: React.FC<ManageDatabaseProps> = ({
retries: data.connection_pool_settings.retries,
}),
},
dbUrl: typeof data.url === 'string' ? data.url : data.url.from_env,
dbUrl: data.url,
},
},
successCallback

View File

@ -97,7 +97,7 @@ export interface AddDataSourceRequest {
driver: Driver;
payload: {
name: string;
dbUrl: string;
dbUrl: string | { from_env: string };
connection_pool_settings: {
max_connections?: number;
idle_timeout?: number; // in seconds

View File

@ -338,10 +338,7 @@ export const getDataSources = createSelector(getMetadata, metadata => {
metadata?.sources.forEach(source => {
sources.push({
name: source.name,
url:
source.configuration?.connection_info?.database_url ||
'HASURA_GRAPHQL_DATABASE_URL',
fromEnv: false,
url: source.configuration?.connection_info?.database_url || '',
connection_pool_settings: source.configuration?.connection_info
?.pool_settings || {
retries: 1,

View File

@ -4,7 +4,7 @@ export const addSource = (
driver: Driver,
payload: {
name: string;
dbUrl: string;
dbUrl: string | { from_env: string };
connection_pool_settings?: {
max_connections?: number;
idle_timeout?: number;

View File

@ -4,7 +4,6 @@ import { PermissionsType } from '../components/Services/RemoteSchema/Permissions
export type DataSource = {
name: string;
url: string | { from_env: string };
fromEnv: boolean;
driver: Driver;
connection_pool_settings?: {
max_connections?: number;
@ -856,7 +855,7 @@ export interface MetadataDataSource {
kind?: 'postgres' | 'mysql';
configuration?: {
connection_info?: {
database_url?: string;
database_url: string | { from_env: string };
pool_settings?: {
max_connections: number;
idle_timeout: number;