Skip to content

Commit 602fd20

Browse files
authored
Merge pull request #2451 from digitallyinduced/fix/ide-data-add-edit-records
Fix IDE Data view bugs (#2408)
2 parents 6d63921 + 6591321 commit 602fd20

File tree

7 files changed

+31
-19
lines changed

7 files changed

+31
-19
lines changed

ihp-ide/IHP/IDE/Data/Controller.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ instance Controller DataController where
7474
primaryKeyFields <- tablePrimaryKeyFields tableName
7575
let primaryKeyValues = T.splitOn "---" primaryKey
7676
let whereClause = mconcat $ List.intersperse (Snippet.sql " AND ") $
77-
zipWith (\field val -> quoteIdentifier field <> Snippet.sql " = " <> Snippet.param val) primaryKeyFields primaryKeyValues
77+
zipWith (\field val -> quoteIdentifier field <> Snippet.sql "::text = " <> Snippet.param val) primaryKeyFields primaryKeyValues
7878
let snippet = Snippet.sql "DELETE FROM " <> quoteIdentifier tableName <> Snippet.sql " WHERE " <> whereClause
7979
runSnippetExec snippet
8080
redirectTo ShowTableRowsAction { .. }
@@ -116,7 +116,7 @@ instance Controller DataController where
116116
let setClause = mconcat $ List.intersperse (Snippet.sql ", ") $
117117
zipWith (\col val -> quoteIdentifier col <> Snippet.sql " = " <> val) columns values
118118
let whereClause = mconcat $ List.intersperse (Snippet.sql " AND ") $
119-
map (\pkey -> quoteIdentifier pkey <> Snippet.sql " = " <> Snippet.param (param @Text (cs pkey <> "-pk"))) primaryKeyFields
119+
map (\pkey -> quoteIdentifier pkey <> Snippet.sql "::text = " <> Snippet.param (param @Text (cs pkey <> "-pk"))) primaryKeyFields
120120

121121
let snippet = Snippet.sql "UPDATE " <> quoteIdentifier tableName <> Snippet.sql " SET " <> setClause <> Snippet.sql " WHERE " <> whereClause
122122
runSnippetExec snippet
@@ -135,7 +135,7 @@ instance Controller DataController where
135135
primaryKeyFields <- tablePrimaryKeyFields tableName
136136
let targetPrimaryKeyValues = T.splitOn "---" targetPrimaryKey
137137
let whereClause = mconcat $ List.intersperse (Snippet.sql " AND ") $
138-
zipWith (\field val -> quoteIdentifier field <> Snippet.sql " = " <> Snippet.param val) primaryKeyFields targetPrimaryKeyValues
138+
zipWith (\field val -> quoteIdentifier field <> Snippet.sql "::text = " <> Snippet.param val) primaryKeyFields targetPrimaryKeyValues
139139
let snippet = Snippet.sql "UPDATE " <> quoteIdentifier tableName <> Snippet.sql " SET " <> quoteIdentifier targetName <> Snippet.sql " = NOT " <> quoteIdentifier targetName <> Snippet.sql " WHERE " <> whereClause
140140
runSnippetExec snippet
141141
redirectTo ShowTableRowsAction { .. }
@@ -145,7 +145,7 @@ instance Controller DataController where
145145
let tableName = param "tableName"
146146
let targetCol = param @Text "targetName"
147147
let targetValue = param @Text "targetValue"
148-
let snippet = Snippet.sql "UPDATE " <> quoteIdentifier tableName <> Snippet.sql " SET " <> quoteIdentifier targetCol <> Snippet.sql " = " <> Snippet.param targetValue <> Snippet.sql " WHERE id = " <> Snippet.param (cs id :: Text)
148+
let snippet = Snippet.sql "UPDATE " <> quoteIdentifier tableName <> Snippet.sql " SET " <> quoteIdentifier targetCol <> Snippet.sql " = " <> Snippet.param targetValue <> Snippet.sql " WHERE " <> quoteIdentifier "id" <> Snippet.sql "::text = " <> Snippet.param (cs id :: Text)
149149
runSnippetExec snippet
150150
redirectTo ShowTableRowsAction { .. }
151151

@@ -167,7 +167,7 @@ instance Controller DataController where
167167

168168
action ShowForeignKeyHoverCardAction { tableName, id, columnName } = do
169169
hovercardData <- do
170-
let fetchIdSnippet = Snippet.sql "SELECT " <> quoteIdentifier columnName <> Snippet.sql "::text FROM " <> quoteIdentifier tableName <> Snippet.sql " WHERE id = " <> Snippet.param id <> Snippet.sql "::uuid"
170+
let fetchIdSnippet = Snippet.sql "SELECT " <> quoteIdentifier columnName <> Snippet.sql "::text FROM " <> quoteIdentifier tableName <> Snippet.sql " WHERE " <> quoteIdentifier "id" <> Snippet.sql "::text = " <> Snippet.param id
171171
foreignIdResult <- runSnippetQuery fetchIdSnippet (Decoders.rowList (Decoders.column (Decoders.nonNullable Decoders.text)))
172172

173173
case foreignIdResult of
@@ -176,7 +176,7 @@ instance Controller DataController where
176176

177177
case foreignKeyInfo of
178178
Just (foreignTable, foreignColumn) -> do
179-
let fetchRecordSnippet = wrapDynamicQuery (Snippet.sql "SELECT * FROM " <> quoteIdentifier foreignTable <> Snippet.sql " WHERE " <> quoteIdentifier foreignColumn <> Snippet.sql " = " <> Snippet.param foreignId <> Snippet.sql "::uuid LIMIT 1")
179+
let fetchRecordSnippet = wrapDynamicQuery (Snippet.sql "SELECT * FROM " <> quoteIdentifier foreignTable <> Snippet.sql " WHERE " <> quoteIdentifier foreignColumn <> Snippet.sql "::text = " <> Snippet.param foreignId <> Snippet.sql " LIMIT 1")
180180
records <- runSnippetQuery fetchRecordSnippet dynamicFieldDecoder
181181
case records of
182182
[record] -> pure $ Just (record, foreignTable)
@@ -226,7 +226,7 @@ fetchRow :: (?modelContext :: ModelContext) => Text -> [Text] -> IO [[DynamicFie
226226
fetchRow tableName primaryKeyValues = do
227227
pkFields <- tablePrimaryKeyFields tableName
228228
let whereClause = mconcat $ List.intersperse (Snippet.sql " AND ") $
229-
zipWith (\field val -> quoteIdentifier field <> Snippet.sql " = " <> Snippet.param val) pkFields primaryKeyValues
229+
zipWith (\field val -> quoteIdentifier field <> Snippet.sql "::text = " <> Snippet.param val) pkFields primaryKeyValues
230230
let snippet = wrapDynamicQuery (Snippet.sql "SELECT * FROM " <> quoteIdentifier tableName <> Snippet.sql " WHERE " <> whereClause)
231231
runSnippetQuery snippet dynamicFieldDecoder
232232

ihp-ide/IHP/IDE/Data/View/EditRow.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ instance View EditRowView where
3737
where
3838
id = (cs (fromMaybe "" ((fromJust (headMay fields)).fieldValue)))
3939
renderField id DynamicField { .. } | fieldName == "id" = [hsx|<td><span data-fieldname={fieldName}><a class="no-link border rounded p-1" href={EditRowValueAction tableName (cs fieldName) id}>{renderId (sqlValueToText fieldValue)}</a></span></td>|]
40-
renderField id DynamicField { .. } | isBoolField fieldName tableCols && not (isNothing fieldValue) = [hsx|<td><span data-fieldname={fieldName}><input type="checkbox" onclick={onClick tableName fieldName id} checked={sqlValueToText fieldValue == "t"} /></span></td>|]
40+
renderField id DynamicField { .. } | isBoolField fieldName tableCols && not (isNothing fieldValue) = [hsx|<td><span data-fieldname={fieldName}><input type="checkbox" onclick={onClick tableName fieldName id} checked={sqlValueToText fieldValue == "true"} /></span></td>|]
4141
renderField id DynamicField { .. } = [hsx|<td><span data-fieldname={fieldName}><a class="no-link" href={EditRowValueAction tableName (cs fieldName) id}>{sqlValueToText fieldValue}</a></span></td>|]
4242

4343

ihp-ide/IHP/IDE/Data/View/EditValue.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ instance View EditValueView where
3535
</tr>
3636
<div class="custom-menu menu-for-column shadow backdrop-blur" id={contextMenuId}>
3737
<a href={EditRowAction tableName id}>Edit Row</a>
38-
<a href={DeleteEntryAction tableName id} class="js-delete">Delete Row</a>
38+
<a href={DeleteEntryAction id tableName} class="js-delete">Delete Row</a>
3939
<div></div>
4040
<a href={NewRowAction tableName}>Add Row</a>
4141
</div>|]

ihp-ide/IHP/IDE/Data/View/Layout.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ tableHead rows tableName =
3535
<a
3636
href={NewRowAction tableName}
3737
class="btn btn-link btn-add"
38-
data-bs-toggle="tooltip"
39-
data-bs-placement="bottom"
40-
title={"Add " <> tableNameToModelName tableName}
4138
>{addIcon}</a>
4239
</div>
4340
</th>

ihp-ide/IHP/IDE/Data/View/NewRow.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ instance View NewRowView where
5858
<a class="text-muted row-form">{col.columnType}</a>
5959
</span>
6060

61-
<div class="d-flex">
61+
<div class="input-group">
6262
{renderInputMethod col}
6363
</div>
6464
</div>|]

ihp-ide/data/static/IDE/data-hovercard.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@ $(document).on('ready turbolinks:load', function () {
22
initDataHoverCard();
33
});
44

5+
// Dispose hovercards before Turbolinks replaces the page to prevent orphaned tooltip elements
6+
document.addEventListener('turbolinks:before-render', function () {
7+
document.querySelectorAll('td[data-foreign-key-column]').forEach(function (el) {
8+
var existing = bootstrap.Tooltip.getInstance(el);
9+
if (existing) existing.dispose();
10+
});
11+
});
12+
513
function initDataHoverCard() {
614
document.querySelectorAll('td[data-foreign-key-column]').forEach(function (element) {
715
var bsTooltip = new bootstrap.Tooltip(element, {
816
title: "Loading",
917
html: true,
1018
placement: 'left',
11-
template: '<div class="tooltip foreign-key-hovercard" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',
12-
boundary: 'window'
19+
container: 'body',
20+
popperConfig: { strategy: 'fixed' },
21+
template: '<div class="tooltip foreign-key-hovercard" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
1322
});
1423

1524
var hoverCard = null;

ihp-ide/data/static/IDE/ihp-schemadesigner.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ function initSchemaDesigner() {
4949
$('#typeSelector').val('DATE').trigger('change');
5050
}
5151
});
52-
$('.select2').select2({ tags: true });
53-
$('.select2-simple').select2();
52+
var $modal = $('.modal');
53+
var select2Options = $modal.length ? { tags: true, dropdownParent: $modal } : { tags: true };
54+
var select2SimpleOptions = $modal.length ? { dropdownParent: $modal } : {};
55+
$('.select2').select2(select2Options);
56+
$('.select2-simple').select2(select2SimpleOptions);
5457
$('#typeSelector').change(function () {
5558
switch (this.value) {
5659
case "UUID":
@@ -352,8 +355,9 @@ function checkBeforeUnload() {
352355
function initDataEditorForeignKeyAutocomplete() {
353356
const elements = document.querySelectorAll('.form-control.is-foreign-key-column');
354357

358+
var $modal = $('.modal');
355359
for (const element of elements) {
356-
$(element).select2({
360+
var options = {
357361
ajax: {
358362
url: element.dataset.selectUrl,
359363
processResults: data => ({ results: data }),
@@ -394,6 +398,8 @@ function initDataEditorForeignKeyAutocomplete() {
394398
return row.id;
395399
},
396400
placeholder:' Search ...'
397-
})
401+
};
402+
if ($modal.length) options.dropdownParent = $modal;
403+
$(element).select2(options);
398404
}
399405
}

0 commit comments

Comments
 (0)