diff --git a/CHANGELOG.md b/CHANGELOG.md index 13cbcae5c4f..2cd2d71fc09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ $ hasura metadata export -o json - server: fix regression: `on_conflict` was missing in the schema for inserts in tables where the current user has no columns listed in their update permissions (fix #6804) - server: fix one-to-one relationship bug which prevented adding one-to-one relationships which didn't have the same column name for target and source - console: fix Postgres table creation when table has a non-lowercase name and a comment (#6760) +- console: allow editing sources configuration - cli: fix regression - `metadata apply —dry-run` was overwriting local metadata files with metadata on server when it should just display the differences. - server: decrease polling interval for scheduled triggers from 60 to 10 seconds - server: Change `HASURA_GRAPHQL_SCHEMA_POLL_INTERVAL` env var to `HASURA_GRAPHQL_SCHEMA_SYNC_POLL_INTERVAL` and `schema-poll-interval` option to `--schema-sync-poll-interval`. diff --git a/console/cypress/integration/data/manage-database/spec.ts b/console/cypress/integration/data/manage-database/spec.ts index a13c0a499ed..d4f5e54db8e 100644 --- a/console/cypress/integration/data/manage-database/spec.ts +++ b/console/cypress/integration/data/manage-database/spec.ts @@ -39,7 +39,7 @@ export const addsNewPostgresDatabaseWithUrl = () => { cy.getBySel('connect-database-btn').click(); cy.get('.notification-success', { timeout: 10000 }) .should('be.visible') - .and('contain', 'Database added successfully!'); + .and('contain', 'Data source added successfully!'); cy.url().should('eq', `${baseUrl}/data/manage`); }; @@ -59,7 +59,7 @@ export const addsNewPgDBWithConParams = () => { cy.getBySel('connect-database-btn').click(); cy.get('.notification-success', { timeout: 10000 }) .should('be.visible') - .and('contain', 'Database added successfully!'); + .and('contain', 'Data source added successfully!'); cy.url().should('eq', `${baseUrl}/data/manage`); }; @@ -73,7 +73,7 @@ export const addsNewPgDBWithEnvVar = () => { cy.getBySel('connect-database-btn').click(); cy.get('.notification-success', { timeout: 10000 }) .should('be.visible') - .and('contain', 'Database added successfully!'); + .and('contain', 'Data source added successfully!'); cy.url().should('eq', `${baseUrl}/data/manage`); }; diff --git a/console/src/components/Common/Common.scss b/console/src/components/Common/Common.scss index cc3d929f99b..78030057b78 100644 --- a/console/src/components/Common/Common.scss +++ b/console/src/components/Common/Common.scss @@ -547,6 +547,10 @@ input { margin-left: 10px; } +.add_pad_left_mid { + padding-left: 10px; +} + .add_mar_small { margin-right: 10px !important; } @@ -1512,6 +1516,10 @@ code { margin-right: 4px; } } +.label_disabled { + color: #4d4d4db3; + cursor: not-allowed; +} .connect_db_radio_label { margin-right: 24px; @@ -1560,7 +1568,7 @@ code { flex-direction: row; margin-top: 12px; align-items: center; - justify-content: space-between; + justify-content: flex-start; } .connection_settings_form_input_layout { diff --git a/console/src/components/Services/Data/DataSources/ConnectDBForm.tsx b/console/src/components/Services/Data/DataSources/ConnectDBForm.tsx index ea83187f12e..0e0603dad4f 100644 --- a/console/src/components/Services/Data/DataSources/ConnectDBForm.tsx +++ b/console/src/components/Services/Data/DataSources/ConnectDBForm.tsx @@ -4,37 +4,38 @@ import { ConnectDBActions, ConnectDBState, connectionTypes } from './state'; import { LabeledInput } from '../../../Common/LabeledInput'; import Tooltip from '../../../Common/Tooltip/Tooltip'; import { Driver, getSupportedDrivers } from '../../../../dataSources'; -import { readFile } from './utils'; import styles from './DataSources.scss'; +import JSONEditor from '../TablePermissions/JSONEditor'; +import { SupportedFeaturesType } from '../../../../dataSources/types'; +import { Path } from '../../../Common/utils/tsUtils'; -type ConnectDatabaseFormProps = { +export interface ConnectDatabaseFormProps { // Connect DB State Props connectionDBState: ConnectDBState; connectionDBStateDispatch: Dispatch; // Connection Type Props - for the Radio buttons updateConnectionTypeRadio: (e: ChangeEvent) => void; + changeConnectionType?: (value: string) => void; connectionTypeState: string; // Other Props isreadreplica?: boolean; + isEditState?: boolean; title?: string; -}; +} export const connectionRadios = [ { value: connectionTypes.CONNECTION_PARAMS, title: 'Connection Parameters', - disableOnEdit: true, }, { value: connectionTypes.DATABASE_URL, title: 'Database URL', - disableOnEdit: false, }, { value: connectionTypes.ENV_VAR, title: 'Environment Variable', - disableOnEdit: true, }, ]; @@ -48,11 +49,24 @@ const dbTypePlaceholders: Record = { const defaultTitle = 'Connect Database Via'; -const driverToLabel: Record = { - mysql: 'MySQL', - postgres: 'PostgreSQL', - mssql: 'MS Server', - bigquery: 'BigQuery', +const driverToLabel: Record< + Driver, + { label: string; defaultConnection: string; info?: string } +> = { + mysql: { label: 'MySQL', defaultConnection: 'DATABASE_URL' }, + postgres: { label: 'PostgreSQL', defaultConnection: 'DATABASE_URL' }, + mssql: { + label: 'MS Server', + defaultConnection: 'DATABASE_URL', + info: + 'Only Database URLs and Environment Variables are available using MSSQL', + }, + bigquery: { + label: 'BigQuery', + defaultConnection: 'CONNECTION_PARAMETERS', + info: + 'Only Connection Parameters and Environment Variables are available using BigQuery', + }, }; const supportedDrivers = getSupportedDrivers('connectDbForm.enabled'); @@ -60,9 +74,11 @@ const supportedDrivers = getSupportedDrivers('connectDbForm.enabled'); const ConnectDatabaseForm: React.FC = ({ connectionDBState, connectionDBStateDispatch, + changeConnectionType, updateConnectionTypeRadio, connectionTypeState, isreadreplica = false, + isEditState = false, title, }) => { const [currentConnectionParamState, toggleConnectionParamState] = useState( @@ -72,20 +88,29 @@ const ConnectDatabaseForm: React.FC = ({ toggleConnectionParamState(value); }; - const handleFileUpload = (e: React.ChangeEvent) => { - const file = e.target.files![0]; - const addFileQueries = (content: string) => { - try { - connectionDBStateDispatch({ - type: 'UPDATE_DB_BIGQUERY_SERVICE_ACCOUNT_FILE', - data: content, - }); - } catch (error) { - console.log(error); - } - }; + const isDBSupported = (driver: Driver, connectionType: string) => { + let ts = 'databaseURL'; + if (connectionType === 'CONNECTION_PARAMETERS') { + ts = 'connectionParameters'; + } + if (connectionType === 'ENVIRONMENT_VARIABLES') { + ts = 'environmentVariable'; + } + return getSupportedDrivers( + `connectDbForm.${ts}` as Path + ).includes(driver); + }; - readFile(file, addFileQueries); + const handleDBChange = (e: React.ChangeEvent) => { + const value = e.target.value as Driver; + const isSupported = isDBSupported(value, connectionTypeState); + connectionDBStateDispatch({ + type: 'UPDATE_DB_DRIVER', + data: value, + }); + if (!isSupported && changeConnectionType) { + changeConnectionType(driverToLabel[value].defaultConnection); + } }; return ( @@ -100,7 +125,11 @@ const ConnectDatabaseForm: React.FC = ({ {connectionRadios.map(radioBtn => ( ))} + {driverToLabel[connectionDBState.dbType].info && ( +
+