Skip to content

Commit

Permalink
Merge branch 'master' into BUDI-8986/ground-work
Browse files Browse the repository at this point in the history
  • Loading branch information
adrinr authored Jan 17, 2025
2 parents ed35acc + 01a47bb commit 16222f0
Show file tree
Hide file tree
Showing 28 changed files with 581 additions and 236 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "3.2.44",
"version": "3.2.45",
"npmClient": "yarn",
"concurrency": 20,
"command": {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend-core/src/db/couch/connections.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import env from "../../environment"

export const getCouchInfo = (connection?: string) => {
export const getCouchInfo = (connection?: string | null) => {
// clean out any auth credentials
const urlInfo = getUrlInfo(connection)
let username
Expand Down Expand Up @@ -45,7 +45,7 @@ export const getCouchInfo = (connection?: string) => {
}
}

export const getUrlInfo = (url = env.COUCH_DB_URL) => {
export const getUrlInfo = (url: string | null = env.COUCH_DB_URL) => {
let cleanUrl, username, password, host
if (url) {
// Ensure the URL starts with a protocol
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require("../../../tests")
const getUrlInfo = require("../couch").getUrlInfo

import { getUrlInfo } from "../couch"

describe("pouch", () => {
describe("Couch DB URL parsing", () => {
Expand Down
30 changes: 17 additions & 13 deletions packages/backend-core/src/sql/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1172,20 +1172,22 @@ class InternalBuilder {
nulls = value.direction === SortOrder.ASCENDING ? "first" : "last"
}

const composite = `${aliased}.${key}`
let identifier

if (this.isAggregateField(key)) {
query = query.orderBy(key, direction, nulls)
identifier = this.rawQuotedIdentifier(key)
} else if (this.client === SqlClient.ORACLE) {
identifier = this.convertClobs(composite)
} else {
let composite = `${aliased}.${key}`
if (this.client === SqlClient.ORACLE) {
query = query.orderByRaw(`?? ?? nulls ??`, [
this.convertClobs(composite),
this.knex.raw(direction),
this.knex.raw(nulls as string),
])
} else {
query = query.orderBy(composite, direction, nulls)
}
identifier = this.rawQuotedIdentifier(composite)
}

query = query.orderByRaw(`?? ?? ${nulls ? "nulls ??" : ""}`, [
identifier,
this.knex.raw(direction),
...(nulls ? [this.knex.raw(nulls as string)] : []),
])
}
}

Expand Down Expand Up @@ -1344,14 +1346,16 @@ class InternalBuilder {

// add the correlation to the overall query
subQuery = subQuery.where(
correlatedTo,
this.rawQuotedIdentifier(correlatedTo),
"=",
this.rawQuotedIdentifier(correlatedFrom)
)

const standardWrap = (select: Knex.Raw): Knex.QueryBuilder => {
subQuery = subQuery
.select(relationshipFields)
.select(
relationshipFields.map(field => this.rawQuotedIdentifier(field))
)
.limit(getRelationshipLimit())
// @ts-ignore - the from alias syntax isn't in Knex typing
return knex.select(select).from({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const _ = require("lodash/fp")
const { structures } = require("../../../tests")
import { range } from "lodash/fp"
import { structures } from "../.."

jest.mock("../../../src/context")
jest.mock("../../../src/db")

const context = require("../../../src/context")
const db = require("../../../src/db")
import * as context from "../../../src/context"
import * as db from "../../../src/db"

const { getCreatorCount } = require("../../../src/users/users")
import { getCreatorCount } from "../../../src/users/users"

describe("Users", () => {
let getGlobalDBMock
let paginationMock
let getGlobalDBMock: jest.SpyInstance
let paginationMock: jest.SpyInstance

beforeEach(() => {
jest.resetAllMocks()
Expand All @@ -22,11 +22,10 @@ describe("Users", () => {
jest.spyOn(db, "getGlobalUserParams")
})

it("Retrieves the number of creators", async () => {
const getUsers = (offset, limit, creators = false) => {
const range = _.range(offset, limit)
it("retrieves the number of creators", async () => {
const getUsers = (offset: number, limit: number, creators = false) => {
const opts = creators ? { builder: { global: true } } : undefined
return range.map(() => structures.users.user(opts))
return range(offset, limit).map(() => structures.users.user(opts))
}
const page1Data = getUsers(0, 8)
const page2Data = getUsers(8, 12, true)
Expand Down
2 changes: 1 addition & 1 deletion packages/bbui/src/Icon/Icon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
export let size = "M"
export let hoverable = false
export let disabled = false
export let color: string
export let color: string = undefined
export let hoverColor = undefined
export let tooltip = undefined
export let tooltipPosition = TooltipPosition.Bottom
Expand Down
2 changes: 1 addition & 1 deletion packages/bbui/src/Label/Label.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
export let size = "M"
export let tooltip = ""
export let muted
export let muted = undefined
</script>

<TooltipWrapper {tooltip} {size}>
Expand Down
1 change: 1 addition & 0 deletions packages/bbui/src/helpers.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
declare module "./helpers" {
export const cloneDeep: <T>(obj: T) => T
export const copyToClipboard: (value: any) => Promise<void>
}
2 changes: 1 addition & 1 deletion packages/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"dayjs": "^1.10.8",
"downloadjs": "1.4.7",
"fast-json-patch": "^3.1.1",
"json-format-highlight": "^1.0.4",
"lodash": "4.17.21",
"posthog-js": "^1.118.0",
"remixicon": "2.5.0",
Expand All @@ -94,6 +93,7 @@
"@sveltejs/vite-plugin-svelte": "1.4.0",
"@testing-library/jest-dom": "6.4.2",
"@testing-library/svelte": "^4.1.0",
"@types/sanitize-html": "^2.13.0",
"@types/shortid": "^2.2.0",
"babel-jest": "^29.6.2",
"identity-obj-proxy": "^3.0.0",
Expand Down
57 changes: 36 additions & 21 deletions packages/builder/src/components/common/CodeEditor/CodeEditor.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script>
<script lang="ts">
import { Label } from "@budibase/bbui"
import { onMount, createEventDispatcher, onDestroy } from "svelte"
import { FIND_ANY_HBS_REGEX } from "@budibase/string-templates"
Expand All @@ -12,7 +12,6 @@
completionStatus,
} from "@codemirror/autocomplete"
import {
EditorView,
lineNumbers,
keymap,
highlightSpecialChars,
Expand All @@ -25,6 +24,7 @@
MatchDecorator,
ViewPlugin,
Decoration,
EditorView,
} from "@codemirror/view"
import {
bracketMatching,
Expand All @@ -44,12 +44,14 @@
import { javascript } from "@codemirror/lang-javascript"
import { EditorModes } from "./"
import { themeStore } from "@/stores/portal"
export let label
export let completions = []
export let mode = EditorModes.Handlebars
export let value = ""
export let placeholder = null
import type { EditorMode } from "@budibase/types"
export let label: string | undefined = undefined
// TODO: work out what best type fits this
export let completions: any[] = []
export let mode: EditorMode = EditorModes.Handlebars
export let value: string | null = ""
export let placeholder: string | null = null
export let autocompleteEnabled = true
export let autofocus = false
export let jsBindingWrapping = true
Expand All @@ -58,8 +60,8 @@
const dispatch = createEventDispatcher()
let textarea
let editor
let textarea: HTMLDivElement
let editor: EditorView
let mounted = false
let isEditorInitialised = false
let queuedRefresh = false
Expand Down Expand Up @@ -100,15 +102,22 @@
/**
* Will refresh the editor contents only after
* it has been fully initialised
* @param value {string} the editor value
*/
const refresh = (value, initialised, mounted) => {
const refresh = (
value: string | null,
initialised?: boolean,
mounted?: boolean
) => {
if (!initialised || !mounted) {
queuedRefresh = true
return
}
if (editor.state.doc.toString() !== value || queuedRefresh) {
if (
editor &&
value &&
(editor.state.doc.toString() !== value || queuedRefresh)
) {
editor.dispatch({
changes: { from: 0, to: editor.state.doc.length, insert: value },
})
Expand All @@ -120,12 +129,17 @@
export const getCaretPosition = () => {
const selection_range = editor.state.selection.ranges[0]
return {
start: selection_range.from,
end: selection_range.to,
start: selection_range?.from,
end: selection_range?.to,
}
}
export const insertAtPos = opts => {
export const insertAtPos = (opts: {
start: number
end?: number
value: string
cursor: { anchor: number }
}) => {
// Updating the value inside.
// Retain focus
editor.dispatch({
Expand Down Expand Up @@ -192,15 +206,15 @@
const indentWithTabCustom = {
key: "Tab",
run: view => {
run: (view: EditorView) => {
if (completionStatus(view.state) === "active") {
acceptCompletion(view)
return true
}
indentMore(view)
return true
},
shift: view => {
shift: (view: EditorView) => {
indentLess(view)
return true
},
Expand Down Expand Up @@ -232,7 +246,8 @@
// None of this is reactive, but it never has been, so we just assume most
// config flags aren't changed at runtime
const buildExtensions = base => {
// TODO: work out type for base
const buildExtensions = (base: any[]) => {
let complete = [...base]
if (autocompleteEnabled) {
Expand All @@ -242,7 +257,7 @@
closeOnBlur: true,
icons: false,
optionClass: completion =>
completion.simple
"simple" in completion && completion.simple
? "autocomplete-option-simple"
: "autocomplete-option",
})
Expand Down Expand Up @@ -347,7 +362,7 @@

{#if label}
<div>
<Label small>{label}</Label>
<Label size="S">{label}</Label>
</div>
{/if}

Expand Down
Loading

0 comments on commit 16222f0

Please sign in to comment.