-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat : Foreign key feature in ToolJet database #9544
Merged
akshaysasidrn
merged 163 commits into
release/database-1.1
from
feature/tjdb-create-foreignkey
May 8, 2024
Merged
Changes from all commits
Commits
Show all changes
163 commits
Select commit
Hold shift + click to select a range
0e09e1c
feat: added support for creating primarykey and unique constraint whi…
ganesh8056 59308d0
feat : primary key with unique constraint
S-Abdul-Rahman 6db9ea4
feat : able to create primary key on table creation
S-Abdul-Rahman f276f17
minor changes for backend
S-Abdul-Rahman d3e8a8d
checked and added constraints for primary key
S-Abdul-Rahman 4d11a1c
Added tooltips for primary key columns and added a fix for autofocus …
S-Abdul-Rahman 235ec35
Added a new component named TableSchema so that we can use this same …
S-Abdul-Rahman 538898c
fix: fetching tjdb table metadata query has been updated to support u…
ganesh8056 7f7a4da
Merge branch 'feature/tjdb-create-primarykey' of https://github.com/t…
ganesh8056 c73c50e
feat : primary key in edit table
S-Abdul-Rahman 866e5ed
mariadb library update
ganesh8056 d0e7682
Merge branch 'feature/tjdb-create-primarykey' of https://github.com/t…
ganesh8056 99e241d
atleast one primarky should be mandatory for each field
S-Abdul-Rahman e16b3cc
Merge branch 'feature/tjdb-create-primarykey' into feature/tjdb-creat…
S-Abdul-Rahman 480bfec
fix: list tjdb table data api due to id column sort by default
ganesh8056 c261a3e
fix: tjdb dashboard table column datatype icon and name was missing w…
ganesh8056 3710c49
fix: tjdb create row operation made compatible with Primary key
ganesh8056 80c0fcd
fix: add column operation will now suport serail and unique constraint
ganesh8056 0009199
fix: Edit column operation support unique constraints
ganesh8056 5f09422
fix: added primary key icon is tjdb dashboard table
ganesh8056 ea3fb7a
feat : foreign key drawer ui
S-Abdul-Rahman 1394cdf
fix: dynamic tooltip text in table for serial datatype and primarykey
ganesh8056 029f27b
fix: cell edit menu should not open for primary key column and serial…
ganesh8056 ca6aa45
fix: cell edit menu save flow and boolean toggle update flow will now…
ganesh8056 d9c5b7f
minor ui change in nested drawer for foreign key relation
S-Abdul-Rahman eb663a8
fix: edit row operation now supports and works based on primary key f…
ganesh8056 36a50f4
fix: add row operation refetch query works based on primary key
ganesh8056 98fd960
Added foreign key active state icon
S-Abdul-Rahman 5189cd0
feat: API to edit table schema
ganesh8056 f7a53b4
Added fixes for primary constraints
S-Abdul-Rahman aee9a15
fix: edit table allows to add new columns and delete old columns as well
ganesh8056 830eb45
Merge branch 'feature/tjdb-create-primarykey' of https://github.com/t…
ganesh8056 7a75d58
fixes related to primary key
S-Abdul-Rahman c3d5b2d
fix: primary key mandatory check on edit table API
ganesh8056 3a1963b
fix: moved table rename inside db transaction
ganesh8056 30e83e3
fix: on editing a primary key column it will not remove primary key c…
ganesh8056 23986ab
changes and fixes in primary key integration
S-Abdul-Rahman ccd8984
edit table api integration
S-Abdul-Rahman aa8772b
fix: primary key mandatory validation was wrongly placed in edit tabl…
ganesh8056 3fef516
fix: edit tooljetdb table dto validation modified
ganesh8056 ab5d022
edit table api integration
S-Abdul-Rahman d0e9a69
edit table success toast update message
S-Abdul-Rahman 2a3b823
Added tooltip for serial datatype defaultvalue and design change of A…
S-Abdul-Rahman 024378b
Merge branch 'feature/tjdb-create-primarykey' into feature/tjdb-creat…
ganesh8056 ed0da14
added scrollbar to tableschema and added a hover effect to column whi…
S-Abdul-Rahman 70c28fe
feat: Foreign key creation support in create table Inprogress
ganesh8056 7e869f9
Merge branch 'feature/tjdb-create-foreignkey' of https://github.com/t…
ganesh8056 3dda827
fix: code review comments for backend fix inprogress
ganesh8056 4216274
fix: in edit table operation in tooljetdb for serial datatype default…
ganesh8056 f79a212
fix: edit table payload naming convention changed
ganesh8056 b617afc
fix : review comments and ui fixes
S-Abdul-Rahman d8c2ae7
fix : undefined check error in renameTable function
S-Abdul-Rahman 19fddf5
fix: unique constraint will be false by default on version less than …
ganesh8056 8504bd4
added primary key icon in edit column header
S-Abdul-Rahman 9539e52
fix: unable to change single primary key to composite primary key whe…
ganesh8056 50c2e50
Merge branch 'feature/tjdb-create-primarykey' of https://github.com/t…
ganesh8056 dcf1c57
added regex check for serial datatype's default value
S-Abdul-Rahman 56d2f61
feat : in edit table the primary columns should be group together and…
S-Abdul-Rahman 5b2abf9
fix: custom exception filter for tooljetdb and optimized cell edit sa…
ganesh8056 2bbab55
Merge branch 'feature/tjdb-create-primarykey' of https://github.com/t…
ganesh8056 a9bb1c9
fix: primarykey column default value of character varying datatype is…
ganesh8056 fb5be7f
fix: tjdb exception filter is added at controller level and it can gr…
ganesh8056 84045ac
fix: on a exception postgrest error message has been sent as response
ganesh8056 d29bf6f
fix: edit-table api payload details were mis-matching
ganesh8056 e3798c0
fix: on editing serial datatype column default value is not necessary
ganesh8056 57880f3
fix: in create and edit table drawer datatype dropdown selection was…
ganesh8056 a547163
fix: multiple exceptions can be handled together
ganesh8056 c5f500f
removed the code comments
ganesh8056 f86ec99
fix : primary key columns should in top of the order in edit table an…
S-Abdul-Rahman 82dcbc0
revert back the changes of primary key column group together in edit …
S-Abdul-Rahman b9ace34
Add null value for default value when we change the datatype in edit …
S-Abdul-Rahman dc939a3
Merge branch 'feature/tjdb-create-primarykey' into feature/tjdb-creat…
ganesh8056 400d53e
Merge branch 'feature/tjdb-create-primarykey' into feature/tjdb-creat…
ganesh8056 eb4a336
fix: feature to create foreign key while creating a new table
ganesh8056 bd78b08
integrated source table details and source column details
S-Abdul-Rahman 0f854bb
fix : serial data type cause error in default value when there is mor…
S-Abdul-Rahman 9454b0c
Merge branch 'feature/tjdb-create-primarykey' into feature/tjdb-creat…
ganesh8056 b549674
Merge branch 'feature/tjdb-create-foreignkey' of https://github.com/t…
ganesh8056 a85a888
feat: tooljet database table metadata api now includes foreign key de…
ganesh8056 622521a
feat : foreign key designs for create and edit table
S-Abdul-Rahman 0fb5b8b
fix : view table api error issue
S-Abdul-Rahman 22d2813
feat : foreign key designs for create and edit column
S-Abdul-Rahman a2075aa
feat: added support for creating foreign key in add column api
ganesh8056 8d6b4d3
Merge branch 'feature/tjdb-create-foreignkey' of https://github.com/t…
ganesh8056 f1e2ed4
feat: api to create edit and delete foreign key has been added to too…
ganesh8056 35ca144
feat : foreign key designs in create and edit row as well as cell edi…
S-Abdul-Rahman 051c688
resolved conflicts
S-Abdul-Rahman f0f4cd6
resolved conflicts
S-Abdul-Rahman a28d135
fix : cell click issue in cell edit for boolean type
S-Abdul-Rahman b249002
feat: added support to select specific columns in the postgrest query
ganesh8056 e1634aa
Merge branch 'feature/tjdb-create-foreignkey' of https://github.com/t…
ganesh8056 15329f0
feat: added foreign key referenced table id in metadata details
ganesh8056 fe1cfd5
fix: naming convention changed for foriegn key apis
ganesh8056 2a5d293
fix: updated DTO to check on-delete and on-update operation of foreig…
ganesh8056 155c59c
completed api integration and remaining ui popups for delete and chan…
S-Abdul-Rahman a5bcd83
added routing logic for navigate to reference table from source table
S-Abdul-Rahman f8a22ee
implemented infinite scroll logic for cell edit foreign key column va…
S-Abdul-Rahman f102563
moved scroll logic to selectBox component
S-Abdul-Rahman c6d2dab
fix: removed the scroll for column schema section in create and edit …
ganesh8056 484fe4b
fix : major bugs
S-Abdul-Rahman f01deb2
fix: added support to delete FK in Edit Column API
ganesh8056 3e16287
feat: Join FK columns auto populate on query manager
ganesh8056 c8cad3c
feat : allowing to create multiple foreign keys in single table
S-Abdul-Rahman 622e11b
feat: auto suggestion on joins
ganesh8056 ba59be2
fix: foreign key column must be rearranged to top of the list
ganesh8056 ef8bc27
fix : major bugs
S-Abdul-Rahman b93fcb2
fix : bugs list
S-Abdul-Rahman 60e04fb
fix: foreignkey details on tjdb context were not updated properly
ganesh8056 5f7bd3b
Merge branch 'feature/tjdb-create-foreignkey' of https://github.com/t…
ganesh8056 1eb2917
fix : bugs in calling selectQuery api
S-Abdul-Rahman 0aec3e5
completed missed routing logic in cell edit dropdown
S-Abdul-Rahman 882a412
fix: cell edit menu on clicking search closes
ganesh8056 87129a1
fix : bugs list
S-Abdul-Rahman 873823d
fix: cellEdit drop down menu provides wrong values for FK
ganesh8056 da42093
Merge branch 'feature/tjdb-create-foreignkey' of https://github.com/t…
ganesh8056 ffe3334
fix: fk values is made to default onClosing CellEditMenu
ganesh8056 4c9530f
fix: on table cell click foreign key details are made to default state
ganesh8056 6107ead
fix : bugs in edit row and in all dropdown which is showing reference…
S-Abdul-Rahman 474fa76
fix: infinite scroll for listing foreign key drop down
ganesh8056 c7910f1
Merge branch 'feature/tjdb-create-foreignkey' of https://github.com/t…
ganesh8056 9983cba
fix: infinite scroll in FK data dropdown goes unresponsive
ganesh8056 fae99d0
fix : width of tooltip in showing foreign key relation and throwing e…
S-Abdul-Rahman e7db8bd
fix : the search api needs to hit only for the referenced column name…
S-Abdul-Rahman 11b3a43
fix: basic lint fixes
ganesh8056 12d64bb
fix : default value preselect value is passing as empty in create row…
S-Abdul-Rahman ebc90b3
fix : create row sort logic and fix for edit foreign key relation
S-Abdul-Rahman 550a734
solved merge conflict
S-Abdul-Rahman a0ad113
fix : merge conflict stylings collapsed
S-Abdul-Rahman 29dfb2a
feat: implemented infinite scrolling for listing down FK data in cell…
ganesh8056 e179720
Merge branch 'feature/tjdb-create-foreignkey' of https://github.com/t…
ganesh8056 609d5bb
fix: in edit column while we create a new foreign key it was not refl…
ganesh8056 67e6df3
fix: join query when auto populated with columns table name was missing
ganesh8056 6c13d30
fix: Not able to edit a table when a column has been referenced for f…
ganesh8056 e32c0dc
fix: serial data-type column will have placeholder as auto-generated
ganesh8056 3614576
fix : bugs from design review
S-Abdul-Rahman bb1aa31
fix : icon mismatch in source and target column
S-Abdul-Rahman b786811
Feature: Import Export revison for TJDB relations (#9597)
akshaysasidrn 10bd1f9
fix: cell edit drop down search issue and drop down misses the values…
ganesh8056 f586a34
Merge branch 'feature/tjdb-create-foreignkey' of https://github.com/t…
ganesh8056 a64c0b8
fix : disabling serial type in source column and removing strict rul…
S-Abdul-Rahman dba6f75
fix : validation issue for save changes button in foreign key drawer
S-Abdul-Rahman 28e5f79
disabled creation of foreign key from create and edit column and enab…
S-Abdul-Rahman 361286f
fix : edit column foreign key relation is becomes false when we close…
S-Abdul-Rahman 1ec08fb
fix: composite primary key columns cannot be mapped to foreign key
ganesh8056 0b5a368
fix : create column and edit column : previous column values are popu…
S-Abdul-Rahman 97f1949
fix : Unable to see the column menu icon when column name has 32 char…
S-Abdul-Rahman f72d012
Merge branch 'release/database-1.1' into feature/tjdb-create-foreignkey
akshaysasidrn dcee602
fix : edit column delete is not working when we chnage the foreign ke…
S-Abdul-Rahman da24ef0
fix bulk upload for case sensitive columns
akshaysasidrn 1ad591c
fix : while selecting different table in target table, the target col…
S-Abdul-Rahman cfe980b
Fix : Bugs from Foreign key feature (#9552)
manishkushare 1f64a3f
Merge branch 'release/database-1.1' into feature/tjdb-create-foreignkey
akshaysasidrn 74c5594
fix: When we create a FK relation, and then if we change a source col…
ganesh8056 622ed2f
Merge branch 'feature/tjdb-create-foreignkey' of https://github.com/t…
ganesh8056 9f10ee6
Feature: Add setup to standardise TJDB error handling (#9629)
akshaysasidrn 188bd1f
fix: add column api dto validation updated
ganesh8056 fb1f51c
Merge branch 'feature/tjdb-create-foreignkey' of https://github.com/t…
ganesh8056 5eca563
return records to throw errors from postgrest
akshaysasidrn 390f3d7
fix type
akshaysasidrn 1e15c96
Chore: Primary key backward compatibility migration (#9636)
akshaysasidrn 66fe6e0
handle unique name error on table create
akshaysasidrn a6fb2f2
Fix : Bug fixes from foreign key feature (#9637)
manishkushare 8e703f6
fix : placeholder text in foreign key drawer and error handleing text…
S-Abdul-Rahman File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,13 +24,37 @@ const DropDownSelect = ({ | |
showPlaceHolder = false, | ||
highlightSelected = true, | ||
buttonClasses = '', | ||
foreignKeyAccess = false, | ||
showRedirection = false, | ||
columnInfoForTable, | ||
showColumnInfo = false, | ||
showDescription = false, | ||
foreignKeyAccessInRowForm = false, | ||
topPlaceHolder = '', | ||
showPlaceHolderInForeignKeyDrawer = false, | ||
isCellEdit = false, | ||
scrollEventForColumnValus, | ||
organizationId, | ||
foreignKeys, | ||
setReferencedColumnDetails, | ||
shouldShowForeignKeyIcon = false, | ||
cellColumnName, | ||
tableName, | ||
targetTable, | ||
actions, | ||
actionName, | ||
fetchTables, | ||
onTableClick, | ||
}) => { | ||
const popoverId = useRef(`dd-select-${uuidv4()}`); | ||
const popoverBtnId = useRef(`dd-select-btn-${uuidv4()}`); | ||
const [showMenu, setShowMenu] = useShowPopover(false, `#${popoverId.current}`, `#${popoverBtnId.current}`); | ||
const [selected, setSelected] = useState(value); | ||
const selectRef = useRef(); | ||
const [isOverflown, setIsOverflown] = useState(false); | ||
// Applicable when drop down is used to list FK data | ||
const [isInitialForeignKeyDataLoaded, setIsInitialForeignKeyDataLoaded] = useState(false); | ||
const [totalRecords, setTotalRecords] = useState(0); | ||
const [pageNumber, setPageNumber] = useState(1); | ||
|
||
useEffect(() => { | ||
if (showMenu) { | ||
|
@@ -42,6 +66,7 @@ const DropDownSelect = ({ | |
if (Array.isArray(value) || selected?.value !== value?.value || selected?.label !== value?.label) { | ||
setSelected(value); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [value]); | ||
|
||
useEffect(() => { | ||
|
@@ -61,6 +86,7 @@ const DropDownSelect = ({ | |
if (isNewOverFlown !== isOverflown) { | ||
setIsOverflown(isNewOverFlown); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [selected]); | ||
|
||
function checkElementPosition() { | ||
|
@@ -70,14 +96,9 @@ const DropDownSelect = ({ | |
} | ||
|
||
const elementRect = selectControl.getBoundingClientRect(); | ||
|
||
// Check proximity to top | ||
const halfScreenHeight = window.innerHeight / 2; | ||
|
||
if (elementRect.top <= halfScreenHeight) { | ||
return 'bottom-start'; | ||
} | ||
|
||
if (elementRect.top <= halfScreenHeight) return 'bottom-start'; | ||
return 'top-start'; | ||
} | ||
|
||
|
@@ -98,17 +119,26 @@ const DropDownSelect = ({ | |
<OverlayTrigger | ||
show={showMenu && !disabled} | ||
placement={checkElementPosition()} | ||
// placement="auto" | ||
// arrowOffsetTop={90} | ||
// arrowOffsetLeft={90} | ||
overlay={ | ||
<Popover | ||
key={'page.i'} | ||
id={popoverId.current} | ||
className={`${darkMode && 'popover-dark-themed dark-theme tj-dark-mode'}`} | ||
style={{ | ||
width: '244px', | ||
maxWidth: '246px', | ||
width: foreignKeyAccess | ||
? '403px' | ||
: foreignKeyAccessInRowForm === true | ||
? '494px' | ||
: isCellEdit | ||
? '266px' | ||
: '244px', | ||
maxWidth: foreignKeyAccess | ||
? '403px' | ||
: foreignKeyAccessInRowForm === true | ||
? '494px' | ||
: isCellEdit | ||
? '266px' | ||
: '246px', | ||
overflow: 'hidden', | ||
boxShadow: '0px 2px 4px -2px rgba(16, 24, 40, 0.06), 0px 4px 8px -2px rgba(16, 24, 40, 0.10)', | ||
}} | ||
|
@@ -127,6 +157,29 @@ const DropDownSelect = ({ | |
addBtnLabel={addBtnLabel} | ||
emptyError={emptyError} | ||
highlightSelected={highlightSelected} | ||
foreignKeyAccess={foreignKeyAccess} | ||
showRedirection={showRedirection} | ||
columnInfoForTable={columnInfoForTable} | ||
showColumnInfo={showColumnInfo} | ||
showDescription={showDescription} | ||
foreignKeyAccessInRowForm={foreignKeyAccessInRowForm} | ||
isCellEdit={isCellEdit} | ||
scrollEventForColumnValus={scrollEventForColumnValus} | ||
organizationId={organizationId} | ||
foreignKeys={foreignKeys} | ||
setReferencedColumnDetails={setReferencedColumnDetails} | ||
shouldShowForeignKeyIcon={shouldShowForeignKeyIcon} | ||
cellColumnName={cellColumnName} | ||
isInitialForeignKeyDataLoaded={isInitialForeignKeyDataLoaded} | ||
setIsInitialForeignKeyDataLoaded={setIsInitialForeignKeyDataLoaded} | ||
totalRecords={totalRecords} | ||
setTotalRecords={setTotalRecords} | ||
pageNumber={pageNumber} | ||
setPageNumber={setPageNumber} | ||
Comment on lines
+160
to
+178
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm concerned about the number of props piling up, can we group them based on context to have better readability? pagination={{
pageNumber,
setPageNumber,
totalRecords,
setTotalRecords
}}
foreignKeyProps={{
foreignKeyAccess,
foreignKeyAccessInRowForm,
foreignKeys,
setReferencedColumnDetails,
shouldShowForeignKeyIcon,
isInitialForeignKeyDataLoaded,
setIsInitialForeignKeyDataLoaded
}} |
||
tableName={tableName} | ||
targetTable={targetTable} | ||
actions={actions} | ||
actionName={actionName} | ||
/> | ||
</Popover> | ||
} | ||
|
@@ -142,16 +195,19 @@ const DropDownSelect = ({ | |
return; | ||
} | ||
setShowMenu((show) => !show); | ||
if (onTableClick === true) { | ||
fetchTables(); | ||
} | ||
}} | ||
className={cx( | ||
{ | ||
'justify-content-start': !shouldCenterAlignText, | ||
'justify-content-centre': shouldCenterAlignText, | ||
'border-1 tdb-dropdown-btn-foreignKeyAccess': foreignKeyAccess || foreignKeyAccessInRowForm, | ||
'border-0 tdb-dropdown-btn': !foreignKeyAccess || !foreignKeyAccessInRowForm, | ||
}, | ||
'tdb-dropdown-btn', | ||
'gap-0', | ||
'w-100', | ||
'border-0', | ||
'rounded-0', | ||
'position-relative', | ||
'font-weight-normal', | ||
|
@@ -176,7 +232,9 @@ const DropDownSelect = ({ | |
selected?.label | ||
) | ||
) : showPlaceHolder ? ( | ||
<span style={{ color: '#9e9e9e' }}>Select..</span> | ||
<span style={{ color: '#9e9e9e' }}> | ||
{foreignKeyAccessInRowForm || showPlaceHolderInForeignKeyDrawer ? topPlaceHolder : 'Select...'} | ||
</span> | ||
) : ( | ||
'' | ||
)} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,8 @@ import { useNavigate } from 'react-router-dom'; | |
import useConfirm from './Confirm'; | ||
|
||
const JoinConstraint = ({ darkMode, index, onRemove, onChange, data }) => { | ||
const { selectedTableId, tables, joinOptions, findTableDetails } = useContext(TooljetDatabaseContext); | ||
const { selectedTableId, tables, joinOptions, findTableDetails, tableForeignKeyInfo } = | ||
useContext(TooljetDatabaseContext); | ||
const joinType = data?.joinType; | ||
const baseTableDetails = (selectedTableId && findTableDetails(selectedTableId)) || {}; | ||
const conditionsList = isEmpty(data?.conditions?.conditionsList) ? [{}] : data?.conditions?.conditionsList; | ||
|
@@ -45,19 +46,150 @@ const JoinConstraint = ({ darkMode, index, onRemove, onChange, data }) => { | |
}); | ||
tableSet.add(selectedTableId); | ||
|
||
const leftTableList = [...tableSet] | ||
// In Joins-Query, the table on the LHS should be the ones which we already selected for base table or the tables which we selected on RHS | ||
const leftTableList = []; | ||
[...tableSet] | ||
.filter((table) => table !== rightFieldTable) | ||
.map((t) => { | ||
.forEach((t) => { | ||
const tableDetails = findTableDetails(t); | ||
return { label: tableDetails?.table_name ?? '', value: t }; | ||
const targetTableFKListWithAdjacentTable = checkIfAdjacentTableHasForeignKey(true, t?.table_id); | ||
if (targetTableFKListWithAdjacentTable.length) { | ||
leftTableList.unshift({ | ||
label: tableDetails?.table_name ?? '', | ||
value: t, | ||
isTargetTable: !!targetTableFKListWithAdjacentTable.length, | ||
}); | ||
} else { | ||
leftTableList.push({ | ||
label: tableDetails?.table_name ?? '', | ||
value: t, | ||
isTargetTable: !!targetTableFKListWithAdjacentTable.length, | ||
}); | ||
} | ||
}); | ||
|
||
const tableList = tables | ||
// Tables to list on Right-Hand-Side of Join operation, Omits already selected table | ||
const tableList = []; | ||
tables | ||
.filter((table) => ![...tableSet, leftFieldTable].includes(table.table_id)) | ||
.map((t) => { | ||
return { label: t?.table_name ?? '', value: t.table_id }; | ||
.forEach((t) => { | ||
const targetTableFKListWithAdjacentTable = checkIfAdjacentTableHasForeignKey(false, t?.table_id); | ||
if (targetTableFKListWithAdjacentTable.length) { | ||
tableList.unshift({ | ||
label: t?.table_name ?? '', | ||
value: t?.table_id, | ||
isTargetTable: !!targetTableFKListWithAdjacentTable.length, | ||
}); | ||
} else { | ||
tableList.push({ | ||
label: t?.table_name ?? '', | ||
value: t?.table_id, | ||
isTargetTable: !!targetTableFKListWithAdjacentTable.length, | ||
}); | ||
} | ||
}); | ||
|
||
// OnSelecting LHS ro RHS table on Join Operation, Checking if Adjacent table has FK relation and Auto Fill the column values | ||
function checkIfAdjacentTableHasForeignKey(isChoosingLHStable, tableId) { | ||
if (isChoosingLHStable && rightFieldTable) { | ||
const rightFieldTableDetails = findTableDetails(rightFieldTable); | ||
if (rightFieldTableDetails?.table_name && tableForeignKeyInfo[rightFieldTableDetails.table_name]) { | ||
return tableForeignKeyInfo[rightFieldTableDetails.table_name].filter( | ||
(foreignKeyDetail) => foreignKeyDetail.referenced_table_id === tableId | ||
); | ||
} | ||
} | ||
|
||
if (!isChoosingLHStable && leftFieldTable) { | ||
const leftFieldTableTableDetails = findTableDetails(leftFieldTable); | ||
if (leftFieldTableTableDetails?.table_name && tableForeignKeyInfo[leftFieldTableTableDetails.table_name]) { | ||
return tableForeignKeyInfo[leftFieldTableTableDetails.table_name].filter( | ||
(foreignKeyDetail) => foreignKeyDetail.referenced_table_id === tableId | ||
); | ||
} | ||
} | ||
|
||
return []; | ||
} | ||
|
||
function autoFillColumnIfForeignKeyExists(tableId, isChoosingLHStable) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nicely done! |
||
const adjacentTableForeignKeyDetails = checkIfAdjacentTableHasForeignKey(isChoosingLHStable, tableId); | ||
if (isChoosingLHStable) { | ||
if (adjacentTableForeignKeyDetails.length) { | ||
const newData = cloneDeep({ ...data }); | ||
const newConditionsList = adjacentTableForeignKeyDetails.map((adjacentTableForeignKey) => { | ||
const { referenced_column_names = [], column_names = [] } = adjacentTableForeignKey; | ||
const newCondition = { | ||
leftField: { | ||
table: tableId, | ||
type: 'Column', | ||
...(referenced_column_names[0] && { columnName: referenced_column_names[0] }), | ||
}, | ||
operator: '=', | ||
rightField: { | ||
table: rightFieldTable, | ||
type: 'Column', | ||
...(column_names[0] && { columnName: column_names[0] }), | ||
}, | ||
}; | ||
|
||
return newCondition; | ||
}); | ||
set(newData, 'conditions.conditionsList', newConditionsList); | ||
onChange(newData); | ||
} else { | ||
const newData = cloneDeep({ ...data }); | ||
const { conditionsList = [{}] } = newData?.conditions || {}; | ||
const newConditionsList = conditionsList.map((condition) => { | ||
const newCondition = { ...condition }; | ||
set(newCondition, 'leftField.table', tableId); | ||
set(newCondition, 'operator', '='); //should we removed when we have more options | ||
return newCondition; | ||
}); | ||
set(newData, 'conditions.conditionsList', newConditionsList); | ||
// set(newData, 'table', value?.value); | ||
onChange(newData); | ||
} | ||
} else { | ||
if (adjacentTableForeignKeyDetails.length) { | ||
const newData = cloneDeep({ ...data }); | ||
const newConditionsList = adjacentTableForeignKeyDetails.map((adjacentTableForeignKey) => { | ||
const { referenced_column_names = [], column_names = [] } = adjacentTableForeignKey; | ||
const newCondition = { | ||
leftField: { | ||
table: leftFieldTable, | ||
type: 'Column', | ||
...(column_names[0] && { columnName: column_names[0] }), | ||
}, | ||
operator: '=', | ||
rightField: { | ||
table: tableId, | ||
type: 'Column', | ||
...(referenced_column_names[0] && { columnName: referenced_column_names[0] }), | ||
}, | ||
}; | ||
|
||
return newCondition; | ||
}); | ||
set(newData, 'conditions.conditionsList', newConditionsList); | ||
set(newData, 'table', tableId); | ||
onChange(newData); | ||
} else { | ||
const newData = cloneDeep({ ...data }); | ||
const { conditionsList = [] } = newData?.conditions || {}; | ||
const newConditionsList = conditionsList.map((condition) => { | ||
const newCondition = { ...condition }; | ||
set(newCondition, 'rightField.table', tableId); | ||
set(newCondition, 'operator', '='); //should we removed when we have more options | ||
return newCondition; | ||
}); | ||
set(newData, 'conditions.conditionsList', newConditionsList); | ||
set(newData, 'table', tableId); | ||
onChange(newData); | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<Container fluid className="p-0"> | ||
<Row className={`mx-0 ${index === 0 && 'pb-2'}`}> | ||
|
@@ -118,23 +250,12 @@ const JoinConstraint = ({ darkMode, index, onRemove, onChange, data }) => { | |
result = true; | ||
} | ||
|
||
if (result) { | ||
const newData = cloneDeep({ ...data }); | ||
const { conditionsList = [{}] } = newData?.conditions || {}; | ||
const newConditionsList = conditionsList.map((condition) => { | ||
const newCondition = { ...condition }; | ||
set(newCondition, 'leftField.table', value?.value); | ||
set(newCondition, 'operator', '='); //should we removed when we have more options | ||
return newCondition; | ||
}); | ||
set(newData, 'conditions.conditionsList', newConditionsList); | ||
// set(newData, 'table', value?.value); | ||
onChange(newData); | ||
} | ||
if (result) autoFillColumnIfForeignKeyExists(value?.value, true); | ||
}} | ||
onAdd={() => navigate(getPrivateRoute('database'))} | ||
addBtnLabel={'Add new table'} | ||
value={leftTableList.find((val) => val?.value === leftFieldTable)} | ||
shouldShowForeignKeyIcon | ||
/> | ||
) : ( | ||
<div | ||
|
@@ -182,23 +303,12 @@ const JoinConstraint = ({ darkMode, index, onRemove, onChange, data }) => { | |
); | ||
} | ||
|
||
if (result) { | ||
const newData = cloneDeep({ ...data }); | ||
const { conditionsList = [] } = newData?.conditions || {}; | ||
const newConditionsList = conditionsList.map((condition) => { | ||
const newCondition = { ...condition }; | ||
set(newCondition, 'rightField.table', value?.value); | ||
set(newCondition, 'operator', '='); //should we removed when we have more options | ||
return newCondition; | ||
}); | ||
set(newData, 'conditions.conditionsList', newConditionsList); | ||
set(newData, 'table', value?.value); | ||
onChange(newData); | ||
} | ||
if (result) autoFillColumnIfForeignKeyExists(value?.value, false); | ||
}} | ||
onAdd={() => navigate(getPrivateRoute('database'))} | ||
addBtnLabel={'Add new table'} | ||
value={tableList.find((val) => val?.value === rightFieldTable)} | ||
shouldShowForeignKeyIcon | ||
/> | ||
</Col> | ||
</Row> | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer using classnames