Skip to content

Commit bc4551d

Browse files
vijayprasanna13iykekings
authored andcommitted
console: data sources code improvements
Co-authored-by: Ikechukwu Eze <[email protected]> GitOrigin-RevId: 225403e
1 parent 7f251d0 commit bc4551d

File tree

20 files changed

+389
-136
lines changed

20 files changed

+389
-136
lines changed

console/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,4 @@ npm run format
200200

201201
### Working with PRO console
202202

203-
Wiki page: https://github.com/hasura/graphql-engine-internal/wiki/Console:-Code-Sharing-Between-OSS-and-PRO
203+
Wiki page: https://github.com/hasura/graphql-engine-internal/wiki/Console:-Code-Sharing-Between-OSS-and-PRO

console/cypress/helpers/dataHelpers.ts

-12
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,4 @@ export const dropTable = (table = 'post', cascade = false) => {
259259
};
260260
};
261261

262-
export const dropTableIfExists = (
263-
table: { name: string; schema: string },
264-
source = 'default'
265-
) => ({
266-
type: 'run_sql',
267-
source,
268-
args: {
269-
sql: `DROP TABLE IF EXISTS "${table.schema}"."${table.name}";`,
270-
cascade: false,
271-
},
272-
});
273-
274262
export const getSchema = () => 'public';

console/cypress/integration/remote-schemas/create-remote-schema/spec.ts

+13-18
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ export const deleteSimpleRemoteSchemaFailUserConfirmationError = () => {
9696
setPromptValue(null);
9797
cy.get(getElementFromAlias('remote-schema-edit-delete-btn')).click();
9898
cy.wait(5000);
99-
cy.window()
100-
.its('prompt')
101-
.should('be.called');
99+
cy.window().its('prompt').should('be.called');
102100

103101
cy.url().should(
104102
'eq',
@@ -118,9 +116,7 @@ export const deleteSimpleRemoteSchema = () => {
118116
cy.wait(5000);
119117
setPromptValue(getRemoteSchemaName(1, testName));
120118
cy.get(getElementFromAlias('remote-schema-edit-delete-btn')).click();
121-
cy.window()
122-
.its('prompt')
123-
.should('be.called');
119+
cy.window().its('prompt').should('be.called');
124120
cy.wait(5000);
125121
cy.get(getElementFromAlias('delete-confirmation-error')).should('not.exist');
126122
cy.wait(5000);
@@ -258,9 +254,7 @@ export const deleteRemoteSchema = () => {
258254
cy.wait(5000);
259255
setPromptValue(getRemoteSchemaName(5, testName));
260256
cy.get(getElementFromAlias('remote-schema-edit-delete-btn')).click();
261-
cy.window()
262-
.its('prompt')
263-
.should('be.called');
257+
cy.window().its('prompt').should('be.called');
264258
cy.wait(5000);
265259

266260
cy.get(getElementFromAlias('delete-confirmation-error')).should('not.exist');
@@ -280,17 +274,18 @@ export const createSimpleRemoteSchemaPermission = () => {
280274
cy.get(getElementFromAlias('role-textbox'))
281275
.clear()
282276
.type(getRemoteSchemaRoleName(1, testName));
283-
cy.get(getElementFromAlias(`${getRemoteSchemaRoleName(1, testName)}-Permission`))
284-
.click();
277+
cy.get(
278+
getElementFromAlias(`${getRemoteSchemaRoleName(1, testName)}-Permission`)
279+
).click();
285280
cy.wait(2000);
286-
cy.get(getElementFromAlias('field-__query_root'))
287-
.click();
288-
cy.get(getElementFromAlias('checkbox-test')).click()
289-
cy.get(getElementFromAlias('pen-limit')).click()
290-
cy.get(getElementFromAlias('input-limit')).type('1')
281+
cy.get(getElementFromAlias('field-__query_root')).click();
282+
cy.get(getElementFromAlias('checkbox-test')).click();
283+
cy.get(getElementFromAlias('pen-limit')).click();
284+
cy.get(getElementFromAlias('input-limit')).type('1');
291285

292-
cy.get(getElementFromAlias('save-remote-schema-permissions'))
293-
.click({ force: true });
286+
cy.get(getElementFromAlias('save-remote-schema-permissions')).click({
287+
force: true,
288+
});
294289
cy.wait(15000);
295290
cy.url().should(
296291
'eq',

console/src/components/Common/utils/tsUtils.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ type PathImpl<T, Key extends keyof T> = Key extends string
2222

2323
type PathImpl2<T> = PathImpl<T, keyof T> | keyof T;
2424

25-
type Path<T> = PathImpl2<T> extends string | keyof T ? PathImpl2<T> : keyof T;
25+
export type Path<T> = PathImpl2<T> extends string | keyof T
26+
? PathImpl2<T>
27+
: keyof T;
2628

2729
export type PathValue<
2830
T,
@@ -37,4 +39,14 @@ export type PathValue<
3739
? T[P]
3840
: never;
3941

40-
// declare function get<T, P extends Path<T>>(obj: T, path: P): PathValue<T, P>;
42+
export function get<T extends Record<string, any>, P extends Path<T>>(
43+
obj: T,
44+
path: P
45+
): PathValue<T, P> {
46+
const keys = (path as string).split('.');
47+
if (!keys.length) return obj as PathValue<T, P>;
48+
const new_obj = keys.reduce((acc, key) => {
49+
return acc[key] || false;
50+
}, obj);
51+
return new_obj as PathValue<T, P>;
52+
}

console/src/components/Services/Actions/Relationships/Components/TypeRelationship.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { addActionRel, removeActionRel } from '../../ServerIO';
1919
import { showErrorNotification } from '../../../Common/Notification';
2020
import tableStyles from '../../../../Common/TableCommon/TableStyles.scss';
21+
import { getSupportedDrivers } from '../../../../../dataSources';
2122

2223
const RelationshipEditor = ({
2324
objectType,
@@ -29,7 +30,8 @@ const RelationshipEditor = ({
2930
const [relConfig, setRelConfig] = React.useState(
3031
existingRelConfig || defaultRelConfig
3132
);
32-
const supportedDrivers = ['postgres'];
33+
34+
const supportedDrivers = getSupportedDrivers('actions.relationships');
3335
const [currentDatabaseInfo, setCurrentDatabaseInfo] = React.useState({});
3436

3537
// if it is an existing relationship, fetch the pg schemas metadata

console/src/components/Services/Data/TableBrowseRows/ViewActions.js

+31-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
generateTableDef,
2020
dataSource,
2121
findTableFromRel,
22-
currentDriver,
22+
isFeatureSupported,
2323
} from '../../../../dataSources';
2424

2525
/* ****************** View actions *************/
@@ -59,10 +59,22 @@ const vMakeRowsRequest = () => {
5959
const headers = dataHeaders(getState);
6060
dispatch({ type: V_REQUEST_PROGRESS, data: true });
6161

62-
return dispatch(dataSource.getTableRowRequest(tables, headers)).then(
62+
const {
63+
endpoint,
64+
getTableRowRequestBody,
65+
processTableRowData,
66+
} = dataSource.generateTableRowRequest();
67+
const options = {
68+
method: 'POST',
69+
body: JSON.stringify(getTableRowRequestBody(tables)),
70+
headers,
71+
credentials: globalCookiePolicy,
72+
};
73+
74+
return dispatch(requestAction(endpoint, options)).then(
6375
data => {
6476
const { currentSchema, currentTable: originalTable } = tables;
65-
const { rows, estimatedCount } = dataSource.processTableRowData(data, {
77+
const { rows, estimatedCount } = processTableRowData(data, {
6678
currentSchema,
6779
originalTable,
6880
});
@@ -94,11 +106,22 @@ const vMakeExportRequest = () => {
94106
return (dispatch, getState) => {
95107
const { tables } = getState();
96108
const headers = dataHeaders(getState);
109+
const {
110+
endpoint,
111+
getTableRowRequestBody,
112+
processTableRowData,
113+
} = dataSource.generateTableRowRequest();
114+
const options = {
115+
method: 'POST',
116+
body: JSON.stringify(getTableRowRequestBody(tables)),
117+
headers,
118+
credentials: globalCookiePolicy,
119+
};
97120
return new Promise((resolve, reject) => {
98-
dispatch(dataSource.getTableRowRequest(tables, headers))
121+
dispatch(requestAction(endpoint, options))
99122
.then(data => {
100123
const { currentSchema, currentTable: originalTable } = tables;
101-
const { rows } = dataSource.processTableRowData(data, {
124+
const { rows } = processTableRowData(data, {
102125
currentSchema,
103126
originalTable,
104127
});
@@ -108,11 +131,11 @@ const vMakeExportRequest = () => {
108131
});
109132
};
110133
};
134+
111135
const vMakeCountRequest = () => {
112-
// TODO: fix when aggregate is available
113-
if (currentDriver === 'mssql')
136+
// For datasources that do not supported aggregation like count
137+
if (!isFeatureSupported('tables.browse.aggregation'))
114138
return (dispatch, getState) => {
115-
// This is just for the moment, until aggregators for mssql is ready
116139
const { estimatedCount } = getState().tables.view;
117140
dispatch({
118141
type: V_COUNT_REQUEST_SUCCESS,

console/src/components/Services/Data/TableBrowseRows/ViewRows.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import {
4545
findTable,
4646
getRelationshipRefTable,
4747
dataSource,
48-
currentDriver,
4948
} from '../../../../dataSources';
5049
import { updateSchemaInfo } from '../DataActions';
5150
import {
@@ -83,6 +82,7 @@ const ViewRows = props => {
8382
readOnlyMode,
8483
shouldHidePagination,
8584
currentSource,
85+
useCustomPagination,
8686
} = props;
8787
const [invokedRow, setInvokedRow] = useState(null);
8888
const [invocationFunc, setInvocationFunc] = useState(null);
@@ -981,9 +981,9 @@ const ViewRows = props => {
981981
);
982982
};
983983

984-
const mssqlProps = {};
985-
if (currentDriver === 'mssql') {
986-
mssqlProps.PaginationComponent = PaginationWithOnlyNav;
984+
const paginationProps = {};
985+
if (useCustomPagination) {
986+
paginationProps.PaginationComponent = PaginationWithOnlyNav;
987987
}
988988

989989
return (
@@ -1017,7 +1017,7 @@ const ViewRows = props => {
10171017
}
10181018
defaultReorders={columnsOrder}
10191019
showPagination={!shouldHidePagination}
1020-
{...mssqlProps}
1020+
{...paginationProps}
10211021
/>
10221022
);
10231023
};

console/src/components/Services/Data/TableBrowseRows/ViewTable.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ import TableHeader from '../TableCommon/TableHeader';
77
import ViewRows from './ViewRows';
88
import { NotFoundError } from '../../../Error/PageNotFound';
99
import { exists } from '../../../Common/utils/jsUtils';
10-
import { currentDriver, dataSource } from '../../../../dataSources';
10+
import {
11+
currentDriver,
12+
dataSource,
13+
isFeatureSupported,
14+
} from '../../../../dataSources';
1115
import { RightContainer } from '../../../Common/Layout/RightContainer';
1216
import { getPersistedPageSize } from './tableUtils';
1317
import { getManualEventsTriggers } from '../../../../metadata/selector';
18+
import FeatureDisabled from '../FeatureDisabled';
1419

1520
class ViewTable extends Component {
1621
constructor(props) {
@@ -32,6 +37,10 @@ class ViewTable extends Component {
3237
getInitialData(tableName) {
3338
const { dispatch, currentSchema } = this.props;
3439

40+
if (!isFeatureSupported('tables.browse.enabled')) {
41+
dispatch(setTable(tableName));
42+
}
43+
3544
const limit = getPersistedPageSize(tableName, currentSchema);
3645
Promise.all([
3746
dispatch(setTable(tableName)),
@@ -90,6 +99,16 @@ class ViewTable extends Component {
9099
currentSource,
91100
} = this.props;
92101

102+
if (!isFeatureSupported('tables.browse.enabled')) {
103+
return (
104+
<FeatureDisabled
105+
tab="browse"
106+
tableName={tableName}
107+
schemaName={currentSchema}
108+
/>
109+
);
110+
}
111+
93112
// check if table exists
94113
const tableSchema = schemas.find(
95114
s => s.table_name === tableName && s.table_schema === currentSchema
@@ -129,6 +148,9 @@ class ViewTable extends Component {
129148
location={location}
130149
readOnlyMode={readOnlyMode}
131150
currentSource={currentSource}
151+
useCustomPagination={isFeatureSupported(
152+
'tables.browse.customPagination'
153+
)}
132154
/>
133155
);
134156

console/src/components/Services/Data/TableCommon/TableHeader.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { capitalize, exists } from '../../../Common/utils/jsUtils';
66
import EditableHeading from '../../../Common/EditableHeading/EditableHeading';
77
import BreadCrumb from '../../../Common/Layout/BreadCrumb/BreadCrumb';
88
import { tabNameMap } from '../utils';
9-
import { currentDriver, dataSource } from '../../../../dataSources';
9+
import {
10+
currentDriver,
11+
dataSource,
12+
isFeatureSupported,
13+
} from '../../../../dataSources';
1014
import {
1115
getSchemaBaseRoute,
1216
getTableBrowseRoute,
@@ -101,7 +105,11 @@ const TableHeader = ({
101105
{getTab(
102106
'browse',
103107
getTableBrowseRoute(tableSchema, source, tableName, isTableType),
104-
`Browse Rows ${currentDriver !== 'mssql' ? countDisplay : ''}`,
108+
`Browse Rows ${
109+
isFeatureSupported('tables.browse.aggregation')
110+
? countDisplay
111+
: ''
112+
}`,
105113
'table-browse-rows'
106114
)}
107115
{!readOnlyMode &&

console/src/components/Services/Data/TableInsertItem/InsertItem.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { ordinalColSort } from '../utils';
88
import { insertItem, I_RESET, fetchEnumOptions } from './InsertActions';
99
import { setTable } from '../DataActions';
1010
import { NotFoundError } from '../../../Error/PageNotFound';
11-
import { currentDriver, findTable } from '../../../../dataSources';
11+
import { findTable, isFeatureSupported } from '../../../../dataSources';
1212
import styles from '../../../Common/TableCommon/Table.scss';
1313
import { TableRow } from '../Common/Components/TableRow';
1414
import { generateTableDef } from '../../../../dataSources';
@@ -18,8 +18,6 @@ import globals from '../../../../Globals';
1818
import { CLI_CONSOLE_MODE } from '../../../../constants';
1919
import FeatureDisabled from '../FeatureDisabled';
2020

21-
const supportedDrivers = ['postgres'];
22-
2321
class InsertItem extends Component {
2422
constructor() {
2523
super();
@@ -71,7 +69,7 @@ class InsertItem extends Component {
7169
generateTableDef(tableName, currentSchema)
7270
);
7371

74-
if (!supportedDrivers.includes(currentDriver)) {
72+
if (!isFeatureSupported('tables.insert.enabled')) {
7573
return (
7674
<FeatureDisabled
7775
tab="insert"
@@ -82,7 +80,7 @@ class InsertItem extends Component {
8280
}
8381

8482
// check if table exists
85-
if (!currentTable && supportedDrivers.includes(currentDriver)) {
83+
if (!currentTable && isFeatureSupported('tables.insert.enabled')) {
8684
// throw a 404 exception
8785
throw new NotFoundError();
8886
}

0 commit comments

Comments
 (0)