Fixing issue with datasource deletion not navigating if was on data source plus table and fixing #3523 where relationships would cause sorting to breaking postgres/oracle.
This commit is contained in:
parent
05a8b47db9
commit
1f6644fc07
|
@ -1,6 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { goto } from "@roxi/routify"
|
import { goto } from "@roxi/routify"
|
||||||
import { datasources } from "stores/backend"
|
import { datasources, tables } from "stores/backend"
|
||||||
import { notifications } from "@budibase/bbui"
|
import { notifications } from "@budibase/bbui"
|
||||||
import { ActionMenu, MenuItem, Icon } from "@budibase/bbui"
|
import { ActionMenu, MenuItem, Icon } from "@budibase/bbui"
|
||||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||||
|
@ -13,10 +13,16 @@
|
||||||
|
|
||||||
async function deleteDatasource() {
|
async function deleteDatasource() {
|
||||||
const wasSelectedSource = $datasources.selected
|
const wasSelectedSource = $datasources.selected
|
||||||
|
const wasSelectedTable = $tables.selected
|
||||||
await datasources.delete(datasource)
|
await datasources.delete(datasource)
|
||||||
notifications.success("Datasource deleted")
|
notifications.success("Datasource deleted")
|
||||||
// navigate to first index page if the source you are deleting is selected
|
// navigate to first index page if the source you are deleting is selected
|
||||||
if (wasSelectedSource === datasource._id) {
|
const entities = Object.values(datasource.entities)
|
||||||
|
if (
|
||||||
|
wasSelectedSource === datasource._id ||
|
||||||
|
(entities &&
|
||||||
|
entities.find(entity => entity._id === wasSelectedTable?._id))
|
||||||
|
) {
|
||||||
$goto("./datasource")
|
$goto("./datasource")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { Knex, knex } from "knex"
|
import { Knex, knex } from "knex"
|
||||||
import {
|
import {
|
||||||
Operation,
|
Operation, PaginationJson,
|
||||||
QueryJson,
|
QueryJson,
|
||||||
QueryOptions,
|
QueryOptions,
|
||||||
RelationshipsJson,
|
RelationshipsJson,
|
||||||
SearchFilters,
|
SearchFilters,
|
||||||
SortDirection,
|
SortDirection, SortJson,
|
||||||
} from "../../definitions/datasource"
|
} from "../../definitions/datasource"
|
||||||
import { isIsoDateString, SqlClients } from "../utils"
|
import { isIsoDateString, SqlClients } from "../utils"
|
||||||
import SqlTableQueryBuilder from "./sqlTable"
|
import SqlTableQueryBuilder from "./sqlTable"
|
||||||
|
@ -152,6 +152,25 @@ class InternalBuilder {
|
||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addSorting(
|
||||||
|
query: KnexQuery,
|
||||||
|
sort: SortJson | undefined,
|
||||||
|
paginate: PaginationJson | undefined
|
||||||
|
): KnexQuery {
|
||||||
|
if (!sort) {
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
for (let [key, value] of Object.entries(sort)) {
|
||||||
|
const direction = value === SortDirection.ASCENDING ? "asc" : "desc"
|
||||||
|
query = query.orderBy(key, direction)
|
||||||
|
}
|
||||||
|
if (this.client === SqlClients.MS_SQL && !sort && paginate?.limit) {
|
||||||
|
// @ts-ignore
|
||||||
|
query = query.orderBy(json.meta?.table?.primary[0])
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
addRelationships(
|
addRelationships(
|
||||||
knex: Knex,
|
knex: Knex,
|
||||||
query: KnexQuery,
|
query: KnexQuery,
|
||||||
|
@ -249,22 +268,18 @@ class InternalBuilder {
|
||||||
if (foundOffset) {
|
if (foundOffset) {
|
||||||
query = query.offset(foundOffset)
|
query = query.offset(foundOffset)
|
||||||
}
|
}
|
||||||
if (sort) {
|
|
||||||
for (let [key, value] of Object.entries(sort)) {
|
|
||||||
const direction = value === SortDirection.ASCENDING ? "asc" : "desc"
|
|
||||||
query = query.orderBy(key, direction)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (this.client === SqlClients.MS_SQL && !sort && paginate?.limit) {
|
|
||||||
// @ts-ignore
|
|
||||||
query = query.orderBy(json.meta?.table?.primary[0])
|
|
||||||
}
|
|
||||||
query = this.addFilters(tableName, query, filters)
|
query = this.addFilters(tableName, query, filters)
|
||||||
|
// add sorting to pre-query
|
||||||
|
query = this.addSorting(query, sort, paginate)
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
let preQuery : KnexQuery = knex({
|
let preQuery : KnexQuery = knex({
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
[tableName]: query,
|
[tableName]: query,
|
||||||
}).select(selectStatement)
|
}).select(selectStatement)
|
||||||
|
// have to add after as well (this breaks MS-SQL)
|
||||||
|
if (this.client !== SqlClients.MS_SQL) {
|
||||||
|
preQuery = this.addSorting(preQuery, sort, paginate)
|
||||||
|
}
|
||||||
// handle joins
|
// handle joins
|
||||||
return this.addRelationships(
|
return this.addRelationships(
|
||||||
knex,
|
knex,
|
||||||
|
|
Loading…
Reference in New Issue