Skip to content

Commit

Permalink
Merge branch 'master' into issue-4035-check-computed-field
Browse files Browse the repository at this point in the history
Resolve Conflicts:
	CHANGELOG.md
  • Loading branch information
rakeshkky committed Mar 12, 2020
2 parents 8c2b5ad + e031e99 commit 889f375
Show file tree
Hide file tree
Showing 210 changed files with 1,624 additions and 758 deletions.
18 changes: 17 additions & 1 deletion CHANGELOG.md
Expand Up @@ -6,9 +6,23 @@

- Introducing Actions: https://docs.hasura.io/1.0/graphql/manual/actions/index.html
- Downgrade command: https://hasura.io/docs/1.0/graphql/manual/deployment/downgrading.html#downgrading-hasura-graphql-engine
- console: add multi select to data table and bulk delete (#3735)

Added a checkbox to each row on Browse Rows view that allows selecting one or more rows from the table and bulk delete them.

- console: allow setting check constraints during table create (#3881)

Added a component that allows adding check constraints while creating a new table in the same way as it can be done on the `Modify` view.

### Select dropdown for Enum columns (console)

If a table has a field referencing an Enum table via a foreign key, then there will be a select dropdown with all possible enum values on `Insert Row` and `Edit Row` views on the Console.

(close #3748) (#3810)

### Other changes

- console: disable editing action relationships
- cli: fix typo in cli example for squash (fix #4047) (#4049)
- console: fix run_sql migration modal messaging (close #4020) (#4060)
- docs: add note on pg versions for actions (#4034)
Expand Down Expand Up @@ -38,7 +52,7 @@
- tag release v1.2.0-beta.1 (#3966)
- noop: replace subdomain links with subpath (#3869)
- docs: add reference to QualifiedTable to table args (#3880)
- update actions docs (#3953)
- update actions docs (#3953)
- cli: bug fixes related to actions (#3951)
- update docs (#3947)
- fix regression on tag release script (#3944)
Expand All @@ -64,6 +78,8 @@
- fix casting citext column type (fix #2818) (#3861)
- Add downgrade command (close #1156) (#3760)
- persist mix files only when coverage is enabled (#3844)
- add meta descriptions to actions docs (#4082)
- `HASURA_GRAPHQL_EVENTS_FETCH_INTERVAL` changes semantics slightly: we only sleep for the interval
when there were previously no events to process. Potential space leak fixed. (#3839)
- auto-include `__typename` field in custom types' objects (fix #4063)
- fix postgres query error when computed fields included in mutation response (fix #4035)
4 changes: 3 additions & 1 deletion console/cypress/integration/data/insert-browse/spec.js
Expand Up @@ -74,6 +74,7 @@ const checkOrder = order => {
.find('[role=gridcell]')
.first()
.next()
.next()
.contains(index);
}
});
Expand All @@ -84,6 +85,7 @@ const checkOrder = order => {
.find('[role=gridcell]')
.first()
.next()
.next()
.contains(22 - index);
}
});
Expand Down Expand Up @@ -231,7 +233,7 @@ export const checkPagination = () => {
cy.wait(3000);
// Check if the page changed
cy.get(
'.rt-tbody > div:nth-child(1) > div > div:nth-child(2) > div'
'.rt-tbody > div:nth-child(1) > div > div:nth-child(3) > div'
).contains('11');
cy.get('.-pageJump > input').should('have.value', '2');
cy.get('.-previous > button').click();
Expand Down
4 changes: 4 additions & 0 deletions console/cypress/integration/data/views/spec.js
Expand Up @@ -318,13 +318,15 @@ const checkOrder = order => {
.find('[role=gridcell]')
.first()
.next()
.next()
.contains(2);
}
if (index === 2) {
cy.wrap($el)
.find('[role=gridcell]')
.first()
.next()
.next()
.contains(userId);
}
});
Expand All @@ -335,13 +337,15 @@ const checkOrder = order => {
.find('[role=gridcell]')
.first()
.next()
.next()
.contains(2);
}
if (index === 1) {
cy.wrap($el)
.find('[role=gridcell]')
.first()
.next()
.next()
.contains(userId);
}
});
Expand Down
4 changes: 4 additions & 0 deletions console/src/components/Common/Common.scss
Expand Up @@ -522,6 +522,10 @@ input {
padding-left: 15px;
}

.add_padd_left_18 {
padding-left: 18px;
}

.add_mar_top_small {
margin-top: 10px;
}
Expand Down
24 changes: 21 additions & 3 deletions console/src/components/Common/TableCommon/Table.scss
@@ -1,4 +1,4 @@
@import "../Common.scss";
@import '../Common.scss';

.container {
padding: 0;
Expand Down Expand Up @@ -50,7 +50,7 @@
label.radioLabel {
padding-top: 0;

input[type="radio"] {
input[type='radio'] {
margin-top: 10px;
}
}
Expand All @@ -64,7 +64,7 @@
width: auto;

tr:nth-child(even) {
background: #f4f4f4
background: #f4f4f4;
}

th {
Expand Down Expand Up @@ -183,3 +183,21 @@ a.expanded {
.tableCellExpanded {
white-space: pre-wrap;
}

.tableCenterContent {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}

.bulkDeleteButton {
margin: 10px;
font-size: 16px;
padding: 0 6px;
}

.headerInputCheckbox {
height: 16px;
margin-bottom: 2px;
}
6 changes: 3 additions & 3 deletions console/src/components/Common/TableCommon/TableStyles.scss
Expand Up @@ -35,7 +35,7 @@
label.radioLabel {
padding-top: 0;

input[type="radio"] {
input[type='radio'] {
margin-top: 10px;
}
}
Expand Down Expand Up @@ -104,7 +104,7 @@ a.expanded {

i:hover {
cursor: pointer;
color: #B85C27;
color: #b85c27;
transition: 0.2s;
}
}
Expand All @@ -127,5 +127,5 @@ a.expanded {

.relEditButtons {
display: flex;
flex-direction:row;
flex-direction: row;
}
47 changes: 47 additions & 0 deletions console/src/components/Common/utils/pgUtils.js
Expand Up @@ -193,6 +193,53 @@ export function getRelationshipRefTable(table, relationship) {
return _refTable;
}

/**
* @param {string} currentSchema
* @param {string} currentTable
* @param {Array<{[key: string]: any}>} allSchemas
*
* @returns {Array<{
* columnName: string,
* enumTableName: string,
* enumColumnName: string,
* }>}
*/
export const getEnumColumnMappings = (allSchemas, tableName, tableSchema) => {
const currentTable = findTable(
allSchemas,
generateTableDef(tableName, tableSchema)
);

const relationsMap = [];
if (!currentTable.foreign_key_constraints.length) return;

currentTable.foreign_key_constraints.map(
({ ref_table, ref_table_table_schema, column_mapping }) => {
const refTableSchema = findTable(
allSchemas,
generateTableDef(ref_table, ref_table_table_schema)
);
if (!refTableSchema.is_enum) return;

const keys = Object.keys(column_mapping);
if (!keys.length) return;

const _columnName = keys[0];
const _enumColumnName = column_mapping[_columnName];

if (_columnName && _enumColumnName) {
relationsMap.push({
columnName: _columnName,
enumTableName: ref_table,
enumColumnName: _enumColumnName,
});
}
}
);

return relationsMap;
};

/*** Table/View permissions utils ***/

export const getTablePermissions = (table, role = null, action = null) => {
Expand Down
29 changes: 29 additions & 0 deletions console/src/components/Common/utils/v1QueryUtils.js
Expand Up @@ -209,3 +209,32 @@ export const getDropComputedFieldQuery = (tableDef, computedFieldName) => {
},
};
};

export const getDeleteQuery = (pkClause, tableName, schemaName) => {
return {
type: 'delete',
args: {
table: {
name: tableName,
schema: schemaName,
},
where: pkClause,
},
};
};

export const getBulkDeleteQuery = (pkClauses, tableName, schemaName) =>
pkClauses.map(pkClause => getDeleteQuery(pkClause, tableName, schemaName));

export const getEnumOptionsQuery = (request, currentSchema) => {
return {
type: 'select',
args: {
table: {
name: request.enumTableName,
schema: currentSchema,
},
columns: [request.enumColumnName],
},
};
};
Expand Up @@ -118,6 +118,15 @@ const RelationshipEditor = ({

// rel name input
const getRelNameInput = () => {
/*
There is no neat solution to renaming a relationship.
This is because name is the only unique identifier of a relationship.
TODO FIXME
*/
const isDisabled = !!existingRelConfig;
const relNameInputTitle = isDisabled
? 'A relationship cannot be renamed. Please drop and re-create if you really must.'
: undefined;
return (
<div className={`${styles.add_mar_bottom}`}>
<div className={`${styles.add_mar_bottom_mid}`}>
Expand All @@ -129,6 +138,8 @@ const RelationshipEditor = ({
className={`${styles.select} form-control ${styles.add_pad_left}`}
placeholder="Enter relationship name"
data-test="rel-name"
disabled={isDisabled}
title={relNameInputTitle}
value={name}
/>
</div>
Expand Down Expand Up @@ -180,17 +191,17 @@ const RelationshipEditor = ({
disabled={!name}
>
{// default unselected option
refSchema === '' && (
<option value={''} disabled>
{'-- reference schema --'}
</option>
)}
refSchema === '' && (
<option value={''} disabled>
{'-- reference schema --'}
</option>
)}
{// all reference schema options
orderedSchemaList.map((rs, j) => (
<option key={j} value={rs}>
{rs}
</option>
))}
orderedSchemaList.map((rs, j) => (
<option key={j} value={rs}>
{rs}
</option>
))}
</select>
</div>
);
Expand Down
38 changes: 36 additions & 2 deletions console/src/components/Services/Data/Add/AddActions.js
Expand Up @@ -36,11 +36,20 @@ const REQUEST_SUCCESS = 'AddTable/REQUEST_SUCCESS';
const REQUEST_ERROR = 'AddTable/REQUEST_ERROR';
const VALIDATION_ERROR = 'AddTable/VALIDATION_ERROR';
const RESET_VALIDATION_ERROR = 'AddTable/RESET_VALIDATION_ERROR';

const SET_CHECK_CONSTRAINTS = 'AddTable/SET_CHECK_CONSTRAINTS';
const REMOVE_CHECK_CONSTRAINT = 'AddTable/REMOVE_CHECK_CONSTRAINT';
/*
* For any action dispatched, the ability to notify the renderer that something is happening
* */

const setCheckConstraints = constraints => ({
type: SET_CHECK_CONSTRAINTS,
constraints,
});
const removeCheckConstraint = index => ({
type: REMOVE_CHECK_CONSTRAINT,
index,
});
const setDefaults = () => ({ type: SET_DEFAULTS });
const setTableName = value => ({ type: SET_TABLENAME, value });
const setTableComment = value => ({ type: SET_TABLECOMMENT, value });
Expand Down Expand Up @@ -146,7 +155,7 @@ const createTableSql = () => {
const state = getState().addTable.table;
const currentSchema = getState().tables.currentSchema;

const { foreignKeys, uniqueKeys } = state;
const { foreignKeys, uniqueKeys, checkConstraints } = state;
const tableName = state.tableName.trim();

// validations
Expand Down Expand Up @@ -272,6 +281,17 @@ const createTableSql = () => {
});
}

// add check constraints
if (checkConstraints.length > 0) {
checkConstraints.forEach(constraint => {
if (!constraint.name || !constraint.check) {
return;
}

tableDefSql += `, CONSTRAINT "${constraint.name}" CHECK (${constraint.check})`;
});
}

let sqlCreateTable =
'CREATE TABLE ' +
'"' +
Expand Down Expand Up @@ -543,6 +563,18 @@ const addTableReducerCore = (state = defaultState, action) => {
...state,
columns: action.columns,
};
case SET_CHECK_CONSTRAINTS:
return {
...state,
checkConstraints: action.constraints,
};
case REMOVE_CHECK_CONSTRAINT:
return {
...state,
checkConstraints: state.checkConstraints.filter(
(_, idx) => idx !== action.index
),
};
default:
return state;
}
Expand Down Expand Up @@ -596,5 +628,7 @@ export {
toggleFk,
clearFkToggle,
setFreqUsedColumn,
setCheckConstraints,
removeCheckConstraint,
};
export { resetValidation, validationError };

0 comments on commit 889f375

Please sign in to comment.