1
0
Fork 0
mirror of synced 2024-09-29 08:41:16 +13:00

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:
mike12345567 2021-11-24 18:20:52 +00:00
parent 05a8b47db9
commit 1f6644fc07
2 changed files with 36 additions and 15 deletions

View file

@ -1,6 +1,6 @@
<script>
import { goto } from "@roxi/routify"
import { datasources } from "stores/backend"
import { datasources, tables } from "stores/backend"
import { notifications } from "@budibase/bbui"
import { ActionMenu, MenuItem, Icon } from "@budibase/bbui"
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
@ -13,10 +13,16 @@
async function deleteDatasource() {
const wasSelectedSource = $datasources.selected
const wasSelectedTable = $tables.selected
await datasources.delete(datasource)
notifications.success("Datasource deleted")
// 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")
}
}

View file

@ -1,11 +1,11 @@
import { Knex, knex } from "knex"
import {
Operation,
Operation, PaginationJson,
QueryJson,
QueryOptions,
RelationshipsJson,
SearchFilters,
SortDirection,
SortDirection, SortJson,
} from "../../definitions/datasource"
import { isIsoDateString, SqlClients } from "../utils"
import SqlTableQueryBuilder from "./sqlTable"
@ -152,6 +152,25 @@ class InternalBuilder {
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(
knex: Knex,
query: KnexQuery,
@ -249,22 +268,18 @@ class InternalBuilder {
if (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)
// add sorting to pre-query
query = this.addSorting(query, sort, paginate)
// @ts-ignore
let preQuery: KnexQuery = knex({
let preQuery : KnexQuery = knex({
// @ts-ignore
[tableName]: query,
}).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
return this.addRelationships(
knex,