Skip to content

Commit

Permalink
auto-fill name while suggesting relationships (closes #1095) (#1437)
Browse files Browse the repository at this point in the history
  • Loading branch information
wawhal authored and shahidhk committed Jan 24, 2019
1 parent a673464 commit 46fdfc9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
4 changes: 3 additions & 1 deletion console/cypress/integration/data/insert-browse/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,9 @@ export const checkViewRelationship = () => {
// Add relationship
cy.get(getElementFromAlias('add-rel-mod')).click();
cy.get(getElementFromAlias('obj-rel-add-0')).click();
cy.get(getElementFromAlias('suggested-rel-name')).type('someRel');
cy.get(getElementFromAlias('suggested-rel-name'))
.clear()
.type('someRel');
cy.get(getElementFromAlias('obj-rel-save-0')).click();
cy.wait(300);
// Insert a row
Expand Down
21 changes: 16 additions & 5 deletions console/cypress/integration/data/relationships/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ export const passRTAddSuggestedRel = () => {
cy.get(getElementFromAlias('article_table_rt')).click();
cy.get(getElementFromAlias('table-relationships')).click();
cy.get(getElementFromAlias('obj-rel-add-0')).click();
cy.get(getElementFromAlias('suggested-rel-name')).type('author');
cy.get(getElementFromAlias('suggested-rel-name'))
.clear()
.type('author');
cy.get(getElementFromAlias('obj-rel-save-0')).click();
cy.wait(15000);
validateColumn(
Expand All @@ -183,7 +185,9 @@ export const passRTAddSuggestedRel = () => {
cy.get(getElementFromAlias('article_table_rt')).click();
cy.get(getElementFromAlias('table-relationships')).click();
cy.get(getElementFromAlias('arr-rel-add-0')).click();
cy.get(getElementFromAlias('suggested-rel-name')).type('comments');
cy.get(getElementFromAlias('suggested-rel-name'))
.clear()
.type('comments');
cy.get(getElementFromAlias('arr-rel-save-0')).click();
cy.wait(15000);
validateColumn(
Expand All @@ -197,10 +201,13 @@ export const failRTAddSuggestedRel = () => {
cy.get(getElementFromAlias('article_table_rt')).click();
cy.get(getElementFromAlias('table-relationships')).click();
cy.get(getElementFromAlias('obj-rel-add-0')).click();
cy.get(getElementFromAlias('suggested-rel-name')).clear();
cy.get(getElementFromAlias('obj-rel-save-0')).click();
// cy.get('.notification-error');
cy.wait(15000);
cy.get(getElementFromAlias('suggested-rel-name')).type(123123);
cy.get(getElementFromAlias('suggested-rel-name'))
.clear()
.type(123123);
cy.get('button')
.contains('Save')
.click();
Expand All @@ -214,7 +221,9 @@ export const failRTAddSuggestedRel = () => {
cy.get(getElementFromAlias('article_table_rt')).click();
cy.get(getElementFromAlias('table-relationships')).click();
cy.get(getElementFromAlias('obj-rel-add-0')).click();
cy.get(getElementFromAlias('suggested-rel-name')).type('author');
cy.get(getElementFromAlias('suggested-rel-name'))
.clear()
.type('author');
cy.get(getElementFromAlias('obj-rel-save-0')).click();
cy.wait(15000);
validateColumn(
Expand All @@ -225,7 +234,9 @@ export const failRTAddSuggestedRel = () => {
cy.get(getElementFromAlias('article_table_rt')).click();
cy.get(getElementFromAlias('table-relationships')).click();
cy.get(getElementFromAlias('arr-rel-add-0')).click();
cy.get(getElementFromAlias('suggested-rel-name')).type('author');
cy.get(getElementFromAlias('suggested-rel-name'))
.clear()
.type('author');
cy.get(getElementFromAlias('arr-rel-save-0')).click();
cy.wait(15000);
// cy.get('.notification-error');
Expand Down
32 changes: 18 additions & 14 deletions console/src/components/Services/Data/TableRelationships/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,21 +336,25 @@ const sanitizeRelName = arg =>
});

const formRelName = relMeta => {
let finalRelName;
// remove special chars and change first letter after underscore to uppercase
const targetTable = sanitizeRelName(relMeta.rTable);
if (relMeta.isObjRel) {
const objLCol = sanitizeRelName(relMeta.lcol.join(','));
finalRelName = `${targetTable}By${objLCol}`;
} else {
const arrRCol = sanitizeRelName(relMeta.rcol.join(','));
finalRelName =
`${
targetTable
// (targetTable[targetTable.length - 1] !== 's' ? 's' : '') + // add s only if the last char is not s
}s` + `By${arrRCol}`;
try {
let finalRelName;
// remove special chars and change first letter after underscore to uppercase
const targetTable = sanitizeRelName(relMeta.rTable);
if (relMeta.isObjRel) {
const objLCol = sanitizeRelName(relMeta.lcol.join(','));
finalRelName = `${targetTable}By${objLCol}`;
} else {
const arrRCol = sanitizeRelName(relMeta.rcol.join(','));
finalRelName =
`${
targetTable
// (targetTable[targetTable.length - 1] !== 's' ? 's' : '') + // add s only if the last char is not s
}s` + `By${arrRCol}`;
}
return finalRelName;
} catch (e) {
return '';
}
return finalRelName;
};

const getAllUnTrackedRelations = (allSchemas, currentSchema) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
relNameChanged,
resetRelationshipForm,
relManualAddClicked,
formRelName,
} from './Actions';
import { findAllFromRel } from '../utils';
import { showErrorNotification } from '../Notification';
Expand Down Expand Up @@ -111,6 +112,7 @@ const addRelationshipCellView = (
const onAdd = e => {
e.preventDefault();
dispatch(relSelectionChanged(rel));
dispatch(relNameChanged(formRelName(rel)));
};

const onRelationshipNameChanged = e => {
Expand Down

0 comments on commit 46fdfc9

Please sign in to comment.