Merge branch 'develop' of github.com:Budibase/budibase into feature/test-image

This commit is contained in:
mike12345567 2023-01-20 19:55:11 +00:00
commit 0f33fd8d48
267 changed files with 5896 additions and 4690 deletions

View File

@ -6,6 +6,8 @@ labels: bug
assignees: '' assignees: ''
--- ---
**Checklist**
- [ ] I have searched budibase discussions and github issues to check if my issue already exists
**Hosting** **Hosting**
<!-- Delete as appropriate --> <!-- Delete as appropriate -->

View File

@ -1,5 +1,5 @@
{ {
"version": "2.2.12-alpha.6", "version": "2.2.12-alpha.32",
"npmClient": "yarn", "npmClient": "yarn",
"packages": [ "packages": [
"packages/*" "packages/*"

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/backend-core", "name": "@budibase/backend-core",
"version": "2.2.12-alpha.6", "version": "2.2.12-alpha.32",
"description": "Budibase backend core libraries used in server and worker", "description": "Budibase backend core libraries used in server and worker",
"main": "dist/src/index.js", "main": "dist/src/index.js",
"types": "dist/src/index.d.ts", "types": "dist/src/index.d.ts",
@ -23,7 +23,7 @@
}, },
"dependencies": { "dependencies": {
"@budibase/nano": "10.1.1", "@budibase/nano": "10.1.1",
"@budibase/types": "2.2.12-alpha.6", "@budibase/types": "2.2.12-alpha.32",
"@shopify/jest-koa-mocks": "5.0.1", "@shopify/jest-koa-mocks": "5.0.1",
"@techpass/passport-openidconnect": "0.3.2", "@techpass/passport-openidconnect": "0.3.2",
"aws-cloudfront-sign": "2.2.0", "aws-cloudfront-sign": "2.2.0",
@ -31,6 +31,7 @@
"bcrypt": "5.0.1", "bcrypt": "5.0.1",
"bcryptjs": "2.4.3", "bcryptjs": "2.4.3",
"bull": "4.10.1", "bull": "4.10.1",
"correlation-id": "4.0.0",
"dotenv": "16.0.1", "dotenv": "16.0.1",
"emitter-listener": "1.1.2", "emitter-listener": "1.1.2",
"ioredis": "4.28.0", "ioredis": "4.28.0",
@ -63,15 +64,17 @@
"@types/ioredis": "4.28.0", "@types/ioredis": "4.28.0",
"@types/jest": "27.5.1", "@types/jest": "27.5.1",
"@types/koa": "2.13.4", "@types/koa": "2.13.4",
"@types/koa-pino-logger": "3.0.0",
"@types/lodash": "4.14.180", "@types/lodash": "4.14.180",
"@types/node": "14.18.20", "@types/node": "14.18.20",
"@types/node-fetch": "2.6.1", "@types/node-fetch": "2.6.1",
"@types/pino-http": "5.8.1",
"@types/pouchdb": "6.4.0", "@types/pouchdb": "6.4.0",
"@types/redlock": "4.0.3", "@types/redlock": "4.0.3",
"@types/semver": "7.3.7", "@types/semver": "7.3.7",
"@types/tar-fs": "2.0.1", "@types/tar-fs": "2.0.1",
"@types/uuid": "8.3.4", "@types/uuid": "8.3.4",
"chance": "1.1.3", "chance": "1.1.8",
"ioredis-mock": "5.8.0", "ioredis-mock": "5.8.0",
"jest": "28.1.1", "jest": "28.1.1",
"koa": "2.13.4", "koa": "2.13.4",

View File

@ -1,4 +1,5 @@
import fetch from "node-fetch" import fetch from "node-fetch"
import * as logging from "../logging"
export default class API { export default class API {
host: string host: string
@ -22,6 +23,9 @@ export default class API {
let json = options.headers["Content-Type"] === "application/json" let json = options.headers["Content-Type"] === "application/json"
// add x-budibase-correlation-id header
logging.correlation.setHeader(options.headers)
const requestOptions = { const requestOptions = {
method: method, method: method,
body: json ? JSON.stringify(options.body) : options.body, body: json ? JSON.stringify(options.body) : options.body,

View File

@ -22,6 +22,7 @@ export enum Header {
TENANT_ID = "x-budibase-tenant-id", TENANT_ID = "x-budibase-tenant-id",
TOKEN = "x-budibase-token", TOKEN = "x-budibase-token",
CSRF_TOKEN = "x-csrf-token", CSRF_TOKEN = "x-csrf-token",
CORRELATION_ID = "x-budibase-correlation-id",
} }
export enum GlobalRole { export enum GlobalRole {

View File

@ -23,7 +23,7 @@ export default class LoggingProcessor implements EventProcessor {
return return
} }
let timestampString = getTimestampString(timestamp) let timestampString = getTimestampString(timestamp)
let message = `[audit] [tenant=${identity.tenantId}] [identityType=${identity.type}] [identity=${identity.id}] ${timestampString} ${event} ` let message = `[audit] [identityType=${identity.type}] ${timestampString} ${event} `
if (env.isDev()) { if (env.isDev()) {
message = message + `[debug: [properties=${JSON.stringify(properties)}] ]` message = message + `[debug: [properties=${JSON.stringify(properties)}] ]`
} }

View File

@ -3,7 +3,6 @@ import {
Event, Event,
RowsImportedEvent, RowsImportedEvent,
RowsCreatedEvent, RowsCreatedEvent,
RowImportFormat,
Table, Table,
} from "@budibase/types" } from "@budibase/types"
@ -16,14 +15,9 @@ const created = async (count: number, timestamp?: string | number) => {
await publishEvent(Event.ROWS_CREATED, properties, timestamp) await publishEvent(Event.ROWS_CREATED, properties, timestamp)
} }
const imported = async ( const imported = async (table: Table, count: number) => {
table: Table,
format: RowImportFormat,
count: number
) => {
const properties: RowsImportedEvent = { const properties: RowsImportedEvent = {
tableId: table._id as string, tableId: table._id as string,
format,
count, count,
} }
await publishEvent(Event.ROWS_IMPORTED, properties) await publishEvent(Event.ROWS_IMPORTED, properties)

View File

@ -2,7 +2,6 @@ import { publishEvent } from "../events"
import { import {
Event, Event,
TableExportFormat, TableExportFormat,
TableImportFormat,
Table, Table,
TableCreatedEvent, TableCreatedEvent,
TableUpdatedEvent, TableUpdatedEvent,
@ -40,10 +39,9 @@ async function exported(table: Table, format: TableExportFormat) {
await publishEvent(Event.TABLE_EXPORTED, properties) await publishEvent(Event.TABLE_EXPORTED, properties)
} }
async function imported(table: Table, format: TableImportFormat) { async function imported(table: Table) {
const properties: TableImportedEvent = { const properties: TableImportedEvent = {
tableId: table._id as string, tableId: table._id as string,
format,
} }
await publishEvent(Event.TABLE_IMPORTED, properties) await publishEvent(Event.TABLE_IMPORTED, properties)
} }

View File

@ -1,4 +1,8 @@
import { Header } from "./constants"
import env from "./environment" import env from "./environment"
const correlator = require("correlation-id")
import { Options } from "pino-http"
import { IncomingMessage } from "http"
const NonErrors = ["AccountError"] const NonErrors = ["AccountError"]
@ -31,14 +35,26 @@ export function logWarn(message: string) {
console.warn(`bb-warn: ${message}`) console.warn(`bb-warn: ${message}`)
} }
export function pinoSettings() { export function pinoSettings(): Options {
return { return {
prettyPrint: { prettyPrint: {
levelFirst: true, levelFirst: true,
}, },
genReqId: correlator.getId,
level: env.LOG_LEVEL || "error", level: env.LOG_LEVEL || "error",
autoLogging: { autoLogging: {
ignore: (req: { url: string }) => req.url.includes("/health"), ignore: (req: IncomingMessage) => !!req.url?.includes("/health"),
}, },
} }
} }
const setCorrelationHeader = (headers: any) => {
const correlationId = correlator.getId()
if (correlationId) {
headers[Header.CORRELATION_ID] = correlationId
}
}
export const correlation = {
setHeader: setCorrelationHeader,
}

View File

@ -15,4 +15,5 @@ export { default as csrf } from "./csrf"
export { default as adminOnly } from "./adminOnly" export { default as adminOnly } from "./adminOnly"
export { default as builderOrAdmin } from "./builderOrAdmin" export { default as builderOrAdmin } from "./builderOrAdmin"
export { default as builderOnly } from "./builderOnly" export { default as builderOnly } from "./builderOnly"
export { default as logging } from "./logging"
export * as joiValidator from "./joi-validator" export * as joiValidator from "./joi-validator"

View File

@ -0,0 +1,88 @@
const correlator = require("correlation-id")
import { Header } from "../constants"
import { v4 as uuid } from "uuid"
import * as context from "../context"
const debug = console.warn
const trace = console.trace
const log = console.log
const info = console.info
const warn = console.warn
const error = console.error
const getTenantId = () => {
let tenantId
try {
tenantId = context.getTenantId()
} catch (e: any) {
// do nothing
}
return tenantId
}
const getAppId = () => {
let appId
try {
appId = context.getAppId()
} catch (e) {
// do nothing
}
return appId
}
const getIdentityId = () => {
let identityId
try {
const identity = context.getIdentity()
identityId = identity?._id
} catch (e) {
// do nothing
}
return identityId
}
const print = (fn: any, data: any[]) => {
let message = ""
const correlationId = correlator.getId()
if (correlationId) {
message = message + `[correlationId=${correlator.getId()}]`
}
const tenantId = getTenantId()
if (tenantId) {
message = message + ` [tenantId=${tenantId}]`
}
const appId = getAppId()
if (appId) {
message = message + ` [appId=${appId}]`
}
const identityId = getIdentityId()
if (identityId) {
message = message + ` [identityId=${identityId}]`
}
fn(message, data)
}
const logging = (ctx: any, next: any) => {
// use the provided correlation id header if present
let correlationId = ctx.headers[Header.CORRELATION_ID]
if (!correlationId) {
correlationId = uuid()
}
return correlator.withId(correlationId, () => {
console.debug = data => print(debug, data)
console.trace = data => print(trace, data)
console.log = data => print(log, data)
console.info = data => print(info, data)
console.warn = data => print(warn, data)
console.error = data => print(error, data)
return next()
})
}
export default logging

View File

@ -1,7 +1,8 @@
import { structures } from "../../../tests" import { structures } from "../../../tests"
import * as utils from "../../utils" import * as utils from "../../utils"
import * as events from "../../events" import * as events from "../../events"
import { DEFAULT_TENANT_ID } from "../../constants" import * as db from "../../db"
import { DEFAULT_TENANT_ID, Header } from "../../constants"
import { doInTenant } from "../../context" import { doInTenant } from "../../context"
describe("utils", () => { describe("utils", () => {
@ -14,4 +15,95 @@ describe("utils", () => {
}) })
}) })
}) })
describe("getAppIdFromCtx", () => {
it("gets appId from header", async () => {
const ctx = structures.koa.newContext()
const expected = db.generateAppID()
ctx.request.headers = {
[Header.APP_ID]: expected,
}
const actual = await utils.getAppIdFromCtx(ctx)
expect(actual).toBe(expected)
})
it("gets appId from body", async () => {
const ctx = structures.koa.newContext()
const expected = db.generateAppID()
ctx.request.body = {
appId: expected,
}
const actual = await utils.getAppIdFromCtx(ctx)
expect(actual).toBe(expected)
})
it("gets appId from path", async () => {
const ctx = structures.koa.newContext()
const expected = db.generateAppID()
ctx.path = `/apps/${expected}`
const actual = await utils.getAppIdFromCtx(ctx)
expect(actual).toBe(expected)
})
it("gets appId from url", async () => {
const ctx = structures.koa.newContext()
const expected = db.generateAppID()
const app = structures.apps.app(expected)
// set custom url
const appUrl = "custom-url"
app.url = `/${appUrl}`
ctx.path = `/app/${appUrl}`
// save the app
const database = db.getDB(expected)
await database.put(app)
const actual = await utils.getAppIdFromCtx(ctx)
expect(actual).toBe(expected)
})
it("doesn't get appId from url when previewing", async () => {
const ctx = structures.koa.newContext()
const appId = db.generateAppID()
const app = structures.apps.app(appId)
// set custom url
const appUrl = "preview"
app.url = `/${appUrl}`
ctx.path = `/app/${appUrl}`
// save the app
const database = db.getDB(appId)
await database.put(app)
const actual = await utils.getAppIdFromCtx(ctx)
expect(actual).toBe(undefined)
})
it("gets appId from referer", async () => {
const ctx = structures.koa.newContext()
const expected = db.generateAppID()
ctx.request.headers = {
referer: `http://test.com/builder/app/${expected}/design/screen_123/screens`,
}
const actual = await utils.getAppIdFromCtx(ctx)
expect(actual).toBe(expected)
})
it("doesn't get appId from referer when not builder", async () => {
const ctx = structures.koa.newContext()
const appId = db.generateAppID()
ctx.request.headers = {
referer: `http://test.com/foo/app/${appId}/bar`,
}
const actual = await utils.getAppIdFromCtx(ctx)
expect(actual).toBe(undefined)
})
})
}) })

View File

@ -25,13 +25,16 @@ const jwt = require("jsonwebtoken")
const APP_PREFIX = DocumentType.APP + SEPARATOR const APP_PREFIX = DocumentType.APP + SEPARATOR
const PROD_APP_PREFIX = "/app/" const PROD_APP_PREFIX = "/app/"
const BUILDER_PREVIEW_PATH = "/app/preview"
const BUILDER_REFERER_PREFIX = "/builder/app/"
function confirmAppId(possibleAppId: string | undefined) { function confirmAppId(possibleAppId: string | undefined) {
return possibleAppId && possibleAppId.startsWith(APP_PREFIX) return possibleAppId && possibleAppId.startsWith(APP_PREFIX)
? possibleAppId ? possibleAppId
: undefined : undefined
} }
async function resolveAppUrl(ctx: Ctx) { export async function resolveAppUrl(ctx: Ctx) {
const appUrl = ctx.path.split("/")[2] const appUrl = ctx.path.split("/")[2]
let possibleAppUrl = `/${appUrl.toLowerCase()}` let possibleAppUrl = `/${appUrl.toLowerCase()}`
@ -75,7 +78,7 @@ export function isServingApp(ctx: Ctx) {
*/ */
export async function getAppIdFromCtx(ctx: Ctx) { export async function getAppIdFromCtx(ctx: Ctx) {
// look in headers // look in headers
const options = [ctx.headers[Header.APP_ID]] const options = [ctx.request.headers[Header.APP_ID]]
let appId let appId
for (let option of options) { for (let option of options) {
appId = confirmAppId(option as string) appId = confirmAppId(option as string)
@ -95,15 +98,23 @@ export async function getAppIdFromCtx(ctx: Ctx) {
appId = confirmAppId(pathId) appId = confirmAppId(pathId)
} }
// look in the referer // lookup using custom url - prod apps only
const refererId = parseAppIdFromUrl(ctx.request.headers.referer) // filter out the builder preview path which collides with the prod app path
if (!appId && refererId) { // to ensure we don't load all apps excessively
appId = confirmAppId(refererId) const isBuilderPreview = ctx.path.startsWith(BUILDER_PREVIEW_PATH)
const isViewingProdApp =
ctx.path.startsWith(PROD_APP_PREFIX) && !isBuilderPreview
if (!appId && isViewingProdApp) {
appId = confirmAppId(await resolveAppUrl(ctx))
} }
// look in the url - prod app // look in the referer - builder only
if (!appId && ctx.path.startsWith(PROD_APP_PREFIX)) { // make sure this is performed after prod app url resolution, in case the
appId = confirmAppId(await resolveAppUrl(ctx)) // referer header is present from a builder redirect
const referer = ctx.request.headers.referer
if (!appId && referer?.includes(BUILDER_REFERER_PREFIX)) {
const refererId = parseAppIdFromUrl(ctx.request.headers.referer)
appId = confirmAppId(refererId)
} }
return appId return appId

View File

@ -0,0 +1,21 @@
import { generator } from "."
import { App } from "@budibase/types"
import { DEFAULT_TENANT_ID, DocumentType } from "../../../src/constants"
export function app(id: string): App {
return {
_id: DocumentType.APP_METADATA,
appId: id,
type: "",
version: "0.0.1",
componentLibraries: [],
name: generator.name(),
url: `/custom-url`,
instance: {
_id: id,
},
tenantId: DEFAULT_TENANT_ID,
status: "",
template: undefined,
}
}

View File

@ -3,7 +3,8 @@ export * from "./common"
import Chance from "chance" import Chance from "chance"
export const generator = new Chance() export const generator = new Chance()
export * as koa from "./koa"
export * as accounts from "./accounts" export * as accounts from "./accounts"
export * as apps from "./apps"
export * as koa from "./koa"
export * as licenses from "./licenses" export * as licenses from "./licenses"
export * as plugins from "./plugins" export * as plugins from "./plugins"

View File

@ -5,9 +5,11 @@ export const newContext = (): BBContext => {
const ctx = createMockContext() const ctx = createMockContext()
return { return {
...ctx, ...ctx,
path: "/",
cookies: createMockCookies(), cookies: createMockCookies(),
request: { request: {
...ctx.request, ...ctx.request,
headers: {},
body: {}, body: {},
}, },
} }

View File

@ -12,6 +12,7 @@
"declaration": true, "declaration": true,
"types": [ "node", "jest" ], "types": [ "node", "jest" ],
"outDir": "dist", "outDir": "dist",
"skipLibCheck": true
}, },
"include": [ "include": [
"**/*.js", "**/*.js",

View File

@ -1,7 +1,7 @@
{ {
"name": "@budibase/bbui", "name": "@budibase/bbui",
"description": "A UI solution used in the different Budibase projects.", "description": "A UI solution used in the different Budibase projects.",
"version": "2.2.12-alpha.6", "version": "2.2.12-alpha.32",
"license": "MPL-2.0", "license": "MPL-2.0",
"svelte": "src/index.js", "svelte": "src/index.js",
"module": "dist/bbui.es.js", "module": "dist/bbui.es.js",
@ -38,7 +38,7 @@
], ],
"dependencies": { "dependencies": {
"@adobe/spectrum-css-workflow-icons": "1.2.1", "@adobe/spectrum-css-workflow-icons": "1.2.1",
"@budibase/string-templates": "2.2.12-alpha.6", "@budibase/string-templates": "2.2.12-alpha.32",
"@spectrum-css/actionbutton": "1.0.1", "@spectrum-css/actionbutton": "1.0.1",
"@spectrum-css/actiongroup": "1.0.1", "@spectrum-css/actiongroup": "1.0.1",
"@spectrum-css/avatar": "3.0.2", "@spectrum-css/avatar": "3.0.2",

View File

@ -1,11 +1,11 @@
const ignoredClasses = [".flatpickr-calendar", ".modal-container"] const ignoredClasses = [".flatpickr-calendar"]
let clickHandlers = [] let clickHandlers = []
/** /**
* Handle a body click event * Handle a body click event
*/ */
const handleClick = event => { const handleClick = event => {
// Ignore click if needed // Ignore click if this is an ignored class
for (let className of ignoredClasses) { for (let className of ignoredClasses) {
if (event.target.closest(className)) { if (event.target.closest(className)) {
return return
@ -14,9 +14,18 @@ const handleClick = event => {
// Process handlers // Process handlers
clickHandlers.forEach(handler => { clickHandlers.forEach(handler => {
if (!handler.element.contains(event.target)) { if (handler.element.contains(event.target)) {
handler.callback?.(event) return
} }
// Ignore clicks for modals, unless the handler is registered from a modal
const sourceInModal = handler.element.closest(".spectrum-Modal") != null
const clickInModal = event.target.closest(".spectrum-Modal") != null
if (clickInModal && !sourceInModal) {
return
}
handler.callback?.(event)
}) })
} }
document.documentElement.addEventListener("click", handleClick, true) document.documentElement.addEventListener("click", handleClick, true)

View File

@ -1,75 +1,68 @@
export default function positionDropdown(element, { anchor, align, maxWidth }) { export default function positionDropdown(
let positionSide = "top" element,
let maxHeight = 0 { anchor, align, maxWidth, useAnchorWidth }
let dimensions = getDimensions(anchor) ) {
const update = () => {
const anchorBounds = anchor.getBoundingClientRect()
const elementBounds = element.getBoundingClientRect()
let styles = {
maxHeight: null,
minWidth: null,
maxWidth,
left: null,
top: null,
}
function getDimensions() { // Determine vertical styles
const { if (window.innerHeight - anchorBounds.bottom < 100) {
bottom, styles.top = anchorBounds.top - elementBounds.height - 5
top: spaceAbove,
left,
width,
} = anchor.getBoundingClientRect()
const spaceBelow = window.innerHeight - bottom
const containerRect = element.getBoundingClientRect()
let y
if (spaceAbove > spaceBelow) {
positionSide = "bottom"
maxHeight = spaceAbove - 20
y = window.innerHeight - spaceAbove + 5
} else { } else {
positionSide = "top" styles.top = anchorBounds.bottom + 5
y = bottom + 5 styles.maxHeight = window.innerHeight - anchorBounds.bottom - 20
maxHeight = spaceBelow - 20
} }
return { // Determine horizontal styles
[positionSide]: y, if (!maxWidth && useAnchorWidth) {
left, styles.maxWidth = anchorBounds.width
width,
containerWidth: containerRect.width,
} }
if (useAnchorWidth) {
styles.minWidth = anchorBounds.width
}
if (align === "right") {
styles.left = anchorBounds.left + anchorBounds.width - elementBounds.width
} else if (align === "right-side") {
styles.left = anchorBounds.left + anchorBounds.width
} else {
styles.left = anchorBounds.left
}
// Apply styles
Object.entries(styles).forEach(([style, value]) => {
if (value) {
element.style[style] = `${value.toFixed(0)}px`
} else {
element.style[style] = null
}
})
} }
function calcLeftPosition() { // Apply initial styles which don't need to change
let left
if (align == "right") {
left = dimensions.left + dimensions.width - dimensions.containerWidth
} else if (align == "right-side") {
left = dimensions.left + dimensions.width
} else {
left = dimensions.left
}
return left
}
element.style.position = "absolute" element.style.position = "absolute"
element.style.zIndex = "9999" element.style.zIndex = "9999"
if (maxWidth) {
element.style.maxWidth = `${maxWidth}px`
}
element.style.minWidth = `${dimensions.width}px`
element.style.maxHeight = `${maxHeight.toFixed(0)}px`
element.style.transformOrigin = `center ${positionSide}`
element.style[positionSide] = `${dimensions[positionSide]}px`
element.style.left = `${calcLeftPosition(dimensions).toFixed(0)}px`
// Observe both anchor and element and resize the popover as appropriate
const resizeObserver = new ResizeObserver(entries => { const resizeObserver = new ResizeObserver(entries => {
entries.forEach(() => { entries.forEach(update)
dimensions = getDimensions()
element.style[positionSide] = `${dimensions[positionSide]}px`
element.style.left = `${calcLeftPosition(dimensions).toFixed(0)}px`
})
}) })
resizeObserver.observe(anchor) resizeObserver.observe(anchor)
resizeObserver.observe(element) resizeObserver.observe(element)
document.addEventListener("scroll", update, true)
return { return {
destroy() { destroy() {
resizeObserver.disconnect() resizeObserver.disconnect()
document.removeEventListener("scroll", update, true)
}, },
} }
} }

View File

@ -58,5 +58,6 @@
overflow: hidden; overflow: hidden;
user-select: none; user-select: none;
text-transform: uppercase; text-transform: uppercase;
flex-shrink: 0;
} }
</style> </style>

View File

@ -14,7 +14,7 @@
export let active = false export let active = false
export let tooltip = undefined export let tooltip = undefined
export let dataCy export let dataCy
export let newStyles = false export let newStyles = true
let showTooltip = false let showTooltip = false
</script> </script>
@ -28,6 +28,7 @@
class:spectrum-Button--quiet={quiet} class:spectrum-Button--quiet={quiet}
class:new-styles={newStyles} class:new-styles={newStyles}
class:active class:active
class:disabled
class="spectrum-Button spectrum-Button--size{size.toUpperCase()}" class="spectrum-Button spectrum-Button--size{size.toUpperCase()}"
{disabled} {disabled}
data-cy={dataCy} data-cy={dataCy}
@ -108,7 +109,10 @@
border-color: transparent; border-color: transparent;
color: var(--spectrum-global-color-gray-900); color: var(--spectrum-global-color-gray-900);
} }
.spectrum-Button--secondary.new-styles:hover { .spectrum-Button--secondary.new-styles:not(.disabled):hover {
background: var(--spectrum-global-color-gray-300); background: var(--spectrum-global-color-gray-300);
} }
.spectrum-Button--secondary.new-styles.disabled {
color: var(--spectrum-global-color-gray-500);
}
</style> </style>

View File

@ -34,7 +34,6 @@
display: none; display: none;
} }
.main { .main {
font-family: var(--font-sans);
padding: var(--spacing-xl); padding: var(--spacing-xl);
} }
.main :global(textarea) { .main :global(textarea) {

View File

@ -264,7 +264,7 @@
max-height: 100%; max-height: 100%;
} }
:global(.flatpickr-calendar) { :global(.flatpickr-calendar) {
font-family: "Source Sans Pro", sans-serif; font-family: var(--font-sans);
} }
.is-disabled { .is-disabled {
pointer-events: none !important; pointer-events: none !important;

View File

@ -2,12 +2,12 @@
import "@spectrum-css/picker/dist/index-vars.css" import "@spectrum-css/picker/dist/index-vars.css"
import "@spectrum-css/popover/dist/index-vars.css" import "@spectrum-css/popover/dist/index-vars.css"
import "@spectrum-css/menu/dist/index-vars.css" import "@spectrum-css/menu/dist/index-vars.css"
import { fly } from "svelte/transition"
import { createEventDispatcher } from "svelte" import { createEventDispatcher } from "svelte"
import clickOutside from "../../Actions/click_outside" import clickOutside from "../../Actions/click_outside"
import Search from "./Search.svelte" import Search from "./Search.svelte"
import Icon from "../../Icon/Icon.svelte" import Icon from "../../Icon/Icon.svelte"
import StatusLight from "../../StatusLight/StatusLight.svelte" import StatusLight from "../../StatusLight/StatusLight.svelte"
import Popover from "../../Popover/Popover.svelte"
export let id = null export let id = null
export let disabled = false export let disabled = false
@ -33,7 +33,10 @@
export let sort = false export let sort = false
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let searchTerm = null let searchTerm = null
let button
let popover
$: sortedOptions = getSortedOptions(options, getOptionLabel, sort) $: sortedOptions = getSortedOptions(options, getOptionLabel, sort)
$: filteredOptions = getFilteredOptions( $: filteredOptions = getFilteredOptions(
@ -42,7 +45,9 @@
getOptionLabel getOptionLabel
) )
const onClick = () => { const onClick = e => {
e.preventDefault()
e.stopPropagation()
dispatch("click") dispatch("click")
if (readonly) { if (readonly) {
return return
@ -76,77 +81,119 @@
} }
</script> </script>
<div use:clickOutside={() => (open = false)}> <button
<button {id}
{id} class="spectrum-Picker spectrum-Picker--sizeM"
class="spectrum-Picker spectrum-Picker--sizeM" class:spectrum-Picker--quiet={quiet}
class:spectrum-Picker--quiet={quiet} {disabled}
{disabled} class:is-invalid={!!error}
class:is-invalid={!!error} class:is-open={open}
class:is-open={open} aria-haspopup="listbox"
aria-haspopup="listbox" on:click={onClick}
on:click={onClick} bind:this={button}
> >
{#if fieldIcon} {#if fieldIcon}
<span class="option-extra"> <span class="option-extra icon">
<Icon name={fieldIcon} /> <Icon size="S" name={fieldIcon} />
</span>
{/if}
{#if fieldColour}
<span class="option-extra">
<StatusLight square color={fieldColour} />
</span>
{/if}
<span
class="spectrum-Picker-label"
class:is-placeholder={isPlaceholder}
class:auto-width={autoWidth}
>
{fieldText}
</span> </span>
{#if error} {/if}
<svg {#if fieldColour}
class="spectrum-Icon spectrum-Icon--sizeM spectrum-Picker-validationIcon" <span class="option-extra">
focusable="false" <StatusLight square color={fieldColour} />
aria-hidden="true" </span>
aria-label="Folder" {/if}
> <span
<use xlink:href="#spectrum-icon-18-Alert" /> class="spectrum-Picker-label"
</svg> class:is-placeholder={isPlaceholder}
{/if} class:auto-width={autoWidth}
>
{fieldText}
</span>
{#if error}
<svg <svg
class="spectrum-Icon spectrum-UIIcon-ChevronDown100 spectrum-Picker-menuIcon" class="spectrum-Icon spectrum-Icon--sizeM spectrum-Picker-validationIcon"
focusable="false" focusable="false"
aria-hidden="true" aria-hidden="true"
aria-label="Folder"
> >
<use xlink:href="#spectrum-css-icon-Chevron100" /> <use xlink:href="#spectrum-icon-18-Alert" />
</svg> </svg>
</button> {/if}
{#if open} <svg
<div class="spectrum-Icon spectrum-UIIcon-ChevronDown100 spectrum-Picker-menuIcon"
transition:fly|local={{ y: -20, duration: 200 }} focusable="false"
class="spectrum-Popover spectrum-Popover--bottom spectrum-Picker-popover is-open" aria-hidden="true"
class:auto-width={autoWidth} >
> <use xlink:href="#spectrum-css-icon-Chevron100" />
{#if autocomplete} </svg>
<Search </button>
value={searchTerm}
on:change={event => (searchTerm = event.detail)} <Popover
{disabled} anchor={button}
placeholder="Search" align="left"
/> bind:this={popover}
{open}
on:close={() => (open = false)}
useAnchorWidth={!autoWidth}
maxWidth={autoWidth ? 400 : null}
>
<div
class="popover-content"
class:auto-width={autoWidth}
use:clickOutside={() => (open = false)}
>
{#if autocomplete}
<Search
value={searchTerm}
on:change={event => (searchTerm = event.detail)}
{disabled}
placeholder="Search"
/>
{/if}
<ul class="spectrum-Menu" role="listbox">
{#if placeholderOption}
<li
class="spectrum-Menu-item placeholder"
class:is-selected={isPlaceholder}
role="option"
aria-selected="true"
tabindex="0"
on:click={() => onSelectOption(null)}
>
<span class="spectrum-Menu-itemLabel">{placeholderOption}</span>
<svg
class="spectrum-Icon spectrum-UIIcon-Checkmark100 spectrum-Menu-checkmark spectrum-Menu-itemIcon"
focusable="false"
aria-hidden="true"
>
<use xlink:href="#spectrum-css-icon-Checkmark100" />
</svg>
</li>
{/if} {/if}
<ul class="spectrum-Menu" role="listbox"> {#if filteredOptions.length}
{#if placeholderOption} {#each filteredOptions as option, idx}
<li <li
class="spectrum-Menu-item placeholder" class="spectrum-Menu-item"
class:is-selected={isPlaceholder} class:is-selected={isOptionSelected(getOptionValue(option, idx))}
role="option" role="option"
aria-selected="true" aria-selected="true"
tabindex="0" tabindex="0"
on:click={() => onSelectOption(null)} on:click={() => onSelectOption(getOptionValue(option, idx))}
class:is-disabled={!isOptionEnabled(option)}
> >
<span class="spectrum-Menu-itemLabel">{placeholderOption}</span> {#if getOptionIcon(option, idx)}
<span class="option-extra icon">
<Icon size="S" name={getOptionIcon(option, idx)} />
</span>
{/if}
{#if getOptionColour(option, idx)}
<span class="option-extra">
<StatusLight square color={getOptionColour(option, idx)} />
</span>
{/if}
<span class="spectrum-Menu-itemLabel">
{getOptionLabel(option, idx)}
</span>
<svg <svg
class="spectrum-Icon spectrum-UIIcon-Checkmark100 spectrum-Menu-checkmark spectrum-Menu-itemIcon" class="spectrum-Icon spectrum-UIIcon-Checkmark100 spectrum-Menu-checkmark spectrum-Menu-itemIcon"
focusable="false" focusable="false"
@ -155,61 +202,13 @@
<use xlink:href="#spectrum-css-icon-Checkmark100" /> <use xlink:href="#spectrum-css-icon-Checkmark100" />
</svg> </svg>
</li> </li>
{/if} {/each}
{#if filteredOptions.length} {/if}
{#each filteredOptions as option, idx} </ul>
<li </div>
class="spectrum-Menu-item" </Popover>
class:is-selected={isOptionSelected(getOptionValue(option, idx))}
role="option"
aria-selected="true"
tabindex="0"
on:click={() => onSelectOption(getOptionValue(option, idx))}
class:is-disabled={!isOptionEnabled(option)}
>
{#if getOptionIcon(option, idx)}
<span class="option-extra">
<Icon name={getOptionIcon(option, idx)} />
</span>
{/if}
{#if getOptionColour(option, idx)}
<span class="option-extra">
<StatusLight square color={getOptionColour(option, idx)} />
</span>
{/if}
<span class="spectrum-Menu-itemLabel">
{getOptionLabel(option, idx)}
</span>
<svg
class="spectrum-Icon spectrum-UIIcon-Checkmark100 spectrum-Menu-checkmark spectrum-Menu-itemIcon"
focusable="false"
aria-hidden="true"
>
<use xlink:href="#spectrum-css-icon-Checkmark100" />
</svg>
</li>
{/each}
{/if}
</ul>
</div>
{/if}
</div>
<style> <style>
.spectrum-Popover {
max-height: 240px;
z-index: 999;
top: 100%;
}
.spectrum-Popover:not(.auto-width) {
width: 100%;
}
.spectrum-Popover.auto-width :global(.spectrum-Menu-itemLabel) {
max-width: 400px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.spectrum-Picker { .spectrum-Picker {
width: 100%; width: 100%;
box-shadow: none; box-shadow: none;
@ -229,9 +228,6 @@
.spectrum-Picker-label.auto-width.is-placeholder { .spectrum-Picker-label.auto-width.is-placeholder {
padding-right: 2px; padding-right: 2px;
} }
.auto-width .spectrum-Menu-item {
padding-right: var(--spacing-xl);
}
/* Icon and colour alignment */ /* Icon and colour alignment */
.spectrum-Menu-checkmark { .spectrum-Menu-checkmark {
@ -241,27 +237,48 @@
.option-extra { .option-extra {
padding-right: 8px; padding-right: 8px;
} }
.option-extra.icon {
margin: 0 -1px;
}
.spectrum-Popover :global(.spectrum-Search) { /* Popover */
.popover-content {
display: contents;
}
.popover-content.auto-width .spectrum-Menu-itemLabel {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.popover-content:not(.auto-width) .spectrum-Menu-itemLabel {
width: 0;
flex: 1 1 auto;
}
.popover-content.auto-width .spectrum-Menu-item {
padding-right: var(--spacing-xl);
}
.spectrum-Menu-item.is-disabled {
pointer-events: none;
}
/* Search styles inside popover */
.popover-content :global(.spectrum-Search) {
margin-top: -1px; margin-top: -1px;
margin-left: -1px; margin-left: -1px;
width: calc(100% + 2px); width: calc(100% + 2px);
} }
.spectrum-Popover :global(.spectrum-Search input) { .popover-content :global(.spectrum-Search input) {
height: auto; height: auto;
border-bottom-left-radius: 0; border-bottom-left-radius: 0;
border-bottom-right-radius: 0; border-bottom-right-radius: 0;
padding-top: var(--spectrum-global-dimension-size-100); padding-top: var(--spectrum-global-dimension-size-100);
padding-bottom: var(--spectrum-global-dimension-size-100); padding-bottom: var(--spectrum-global-dimension-size-100);
} }
.spectrum-Popover :global(.spectrum-Search .spectrum-ClearButton) { .popover-content :global(.spectrum-Search .spectrum-ClearButton) {
right: 1px; right: 1px;
top: 2px; top: 2px;
} }
.spectrum-Popover :global(.spectrum-Search .spectrum-Textfield-icon) { .popover-content :global(.spectrum-Search .spectrum-Textfield-icon) {
top: 9px; top: 9px;
} }
.spectrum-Menu-item.is-disabled {
pointer-events: none;
}
</style> </style>

View File

@ -112,8 +112,4 @@
.spectrum-Textfield { .spectrum-Textfield {
width: 100%; width: 100%;
} }
input:disabled {
color: var(--spectrum-global-color-gray-600) !important;
-webkit-text-fill-color: var(--spectrum-global-color-gray-600) !important;
}
</style> </style>

View File

@ -19,6 +19,7 @@
.icon { .icon {
width: 28px; width: 28px;
height: 28px; height: 28px;
flex: 0 0 28px;
display: grid; display: grid;
place-items: center; place-items: center;
border-radius: 50%; border-radius: 50%;
@ -34,6 +35,7 @@
.icon.size--S { .icon.size--S {
width: 22px; width: 22px;
height: 22px; height: 22px;
flex: 0 0 22px;
} }
.icon.size--S :global(.spectrum-Icon) { .icon.size--S :global(.spectrum-Icon) {
width: 16px; width: 16px;
@ -46,6 +48,7 @@
.icon.size--L { .icon.size--L {
width: 40px; width: 40px;
height: 40px; height: 40px;
flex: 0 0 40px;
} }
.icon.size--L :global(.spectrum-Icon) { .icon.size--L :global(.spectrum-Icon) {
width: 28px; width: 28px;

View File

@ -56,5 +56,6 @@
--spectrum-semantic-positive-icon-color: #2d9d78; --spectrum-semantic-positive-icon-color: #2d9d78;
--spectrum-semantic-negative-icon-color: #e34850; --spectrum-semantic-negative-icon-color: #e34850;
min-width: 100px; min-width: 100px;
margin: 0;
} }
</style> </style>

View File

@ -21,6 +21,7 @@
label { label {
padding: 0; padding: 0;
white-space: nowrap; white-space: nowrap;
color: var(--spectrum-global-color-gray-600);
} }
.muted { .muted {

View File

@ -1,32 +1,95 @@
<script> <script>
import { setContext } from "svelte"
import clickOutside from "../Actions/click_outside"
export let wide = false export let wide = false
export let maxWidth = "80ch" export let narrow = false
export let noPadding = false export let noPadding = false
let sidePanelVisble = false
setContext("side-panel", {
open: () => (sidePanelVisble = true),
close: () => (sidePanelVisble = false),
})
</script> </script>
<div style="--max-width: {maxWidth}" class:wide class:noPadding> <div class="page">
<slot /> <div class="main">
<div class="content" class:wide class:noPadding class:narrow>
<slot />
</div>
</div>
<div
id="side-panel"
class:visible={sidePanelVisble}
use:clickOutside={() => {
sidePanelVisble = false
}}
>
<slot name="side-panel" />
</div>
</div> </div>
<style> <style>
div { .page {
position: relative;
}
.page,
.main {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: stretch;
flex: 1 1 auto;
overflow-x: hidden;
}
.main {
overflow: auto;
}
.content {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: flex-start; justify-content: flex-start;
align-items: stretch; align-items: stretch;
max-width: var(--max-width); max-width: 1080px;
margin: 0 auto; margin: 0 auto;
padding: calc(var(--spacing-xl) * 2); flex: 1 1 auto;
min-height: calc(100% - var(--spacing-xl) * 4); padding: 50px;
z-index: 1;
} }
.content.wide {
.wide {
max-width: none; max-width: none;
margin: 0; }
.content.narrow {
max-width: 840px;
}
#side-panel {
position: absolute;
right: 0;
top: 0;
padding: 24px;
background: var(--background);
border-left: var(--border-light);
width: 320px;
max-width: calc(100vw - 48px - 48px);
overflow: auto;
overflow-x: hidden;
transform: translateX(100%);
transition: transform 130ms ease-out;
height: calc(100% - 48px);
z-index: 2;
}
#side-panel.visible {
transform: translateX(0);
} }
.noPadding { @media (max-width: 640px) {
padding: 0px; .content {
margin: 0px; padding: 24px;
max-width: calc(100vw - 48px) !important;
width: calc(100vw - 48px) !important;
overflow: auto;
}
} }
</style> </style>

View File

@ -30,9 +30,11 @@
<Label>{subtitle}</Label> <Label>{subtitle}</Label>
{/if} {/if}
</div> </div>
<div class="right"> {#if $$slots.default}
<slot /> <div class="right">
</div> <slot />
</div>
{/if}
</div> </div>
<style> <style>
@ -45,6 +47,7 @@
justify-content: space-between; justify-content: space-between;
border: 1px solid var(--spectrum-global-color-gray-300); border: 1px solid var(--spectrum-global-color-gray-300);
transition: background 130ms ease-out; transition: background 130ms ease-out;
gap: var(--spacing-m);
} }
.list-item:not(:first-child) { .list-item:not(:first-child) {
border-top: none; border-top: none;

View File

@ -26,7 +26,6 @@
padding: 40px; padding: 40px;
background-color: var(--purple); background-color: var(--purple);
color: white; color: white;
font-family: var(--font-sans);
font-weight: bold; font-weight: bold;
text-align: center; text-align: center;
user-select: none; user-select: none;

View File

@ -19,7 +19,6 @@
<style> <style>
p, span { p, span {
font-family: var(--font-sans);
font-size: var(--font-size-s); font-size: var(--font-size-s);
} }

View File

@ -104,7 +104,7 @@
{/if} {/if}
{#if showCancelButton} {#if showCancelButton}
<Button group secondary newStyles on:click={close}> <Button group secondary on:click={close}>
{cancelText} {cancelText}
</Button> </Button>
{/if} {/if}
@ -151,7 +151,8 @@
overflow: visible; overflow: visible;
} }
.spectrum-Dialog-heading { .spectrum-Dialog-heading {
font-family: var(--font-sans); font-family: var(--font-accent);
font-weight: 600;
} }
.spectrum-Dialog-heading.noDivider { .spectrum-Dialog-heading.noDivider {
margin-bottom: 12px; margin-bottom: 12px;

View File

@ -42,7 +42,6 @@
<style> <style>
p { p {
margin: 0; margin: 0;
font-family: var(--font-sans);
font-size: var(--font-size-s); font-size: var(--font-size-s);
} }
p.error { p.error {

View File

@ -4,6 +4,9 @@
import { createEventDispatcher } from "svelte" import { createEventDispatcher } from "svelte"
import positionDropdown from "../Actions/position_dropdown" import positionDropdown from "../Actions/position_dropdown"
import clickOutside from "../Actions/click_outside" import clickOutside from "../Actions/click_outside"
import { fly } from "svelte/transition"
import { getContext } from "svelte"
import Context from "../context"
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@ -12,9 +15,10 @@
export let portalTarget export let portalTarget
export let dataCy export let dataCy
export let maxWidth export let maxWidth
export let direction = "bottom" export let direction = "bottom"
export let showTip = false export let showTip = false
export let open = false
export let useAnchorWidth = false
let tipSvg = let tipSvg =
'<svg xmlns="http://www.w3.org/svg/2000" width="23" height="12" class="spectrum-Popover-tip" > <path class="spectrum-Popover-tip-triangle" d="M 0.7071067811865476 0 L 11.414213562373096 10.707106781186548 L 22.121320343559645 0" /> </svg>' '<svg xmlns="http://www.w3.org/svg/2000" width="23" height="12" class="spectrum-Popover-tip" > <path class="spectrum-Popover-tip-triangle" d="M 0.7071067811865476 0 L 11.414213562373096 10.707106781186548 L 22.121320343559645 0" /> </svg>'
@ -22,6 +26,7 @@
$: tooltipClasses = showTip $: tooltipClasses = showTip
? `spectrum-Popover--withTip spectrum-Popover--${direction}` ? `spectrum-Popover--withTip spectrum-Popover--${direction}`
: "" : ""
$: target = portalTarget || getContext(Context.PopoverRoot) || ".spectrum"
export const show = () => { export const show = () => {
dispatch("open") dispatch("open")
@ -35,13 +40,22 @@
const handleOutsideClick = e => { const handleOutsideClick = e => {
if (open) { if (open) {
e.stopPropagation() // Stop propagation if the source is the anchor
let node = e.target
let fromAnchor = false
while (!fromAnchor && node && node.parentNode) {
fromAnchor = node === anchor
node = node.parentNode
}
if (fromAnchor) {
e.stopPropagation()
}
// Hide the popover
hide() hide()
} }
} }
let open = null
function handleEscape(e) { function handleEscape(e) {
if (open && e.key === "Escape") { if (open && e.key === "Escape") {
hide() hide()
@ -50,15 +64,16 @@
</script> </script>
{#if open} {#if open}
<Portal target={portalTarget}> <Portal {target}>
<div <div
tabindex="0" tabindex="0"
use:positionDropdown={{ anchor, align, maxWidth }} use:positionDropdown={{ anchor, align, maxWidth, useAnchorWidth }}
use:clickOutside={handleOutsideClick} use:clickOutside={handleOutsideClick}
on:keydown={handleEscape} on:keydown={handleEscape}
class={"spectrum-Popover is-open " + (tooltipClasses || "")} class={"spectrum-Popover is-open " + (tooltipClasses || "")}
role="presentation" role="presentation"
data-cy={dataCy} data-cy={dataCy}
transition:fly|local={{ y: -20, duration: 200 }}
> >
{#if showTip} {#if showTip}
{@html tipSvg} {@html tipSvg}

View File

@ -29,7 +29,6 @@
font-size: var(--font-size-m); font-size: var(--font-size-m);
margin: 0 0 var(--spacing-l) 0; margin: 0 0 var(--spacing-l) 0;
font-weight: 600; font-weight: 600;
font-family: var(--font-sans);
} }
.input-group-column { .input-group-column {

View File

@ -1,8 +1,11 @@
<script> <script>
export let value export let value
export let schema
</script> </script>
<div>{typeof value === "object" ? JSON.stringify(value) : value}</div> <div class:capitalise={schema?.capitalise}>
{typeof value === "object" ? JSON.stringify(value) : value}
</div>
<style> <style>
div { div {
@ -10,5 +13,10 @@
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
max-width: var(--max-cell-width); max-width: var(--max-cell-width);
width: 0;
flex: 1 1 auto;
}
div.capitalise {
text-transform: capitalize;
} }
</style> </style>

View File

@ -21,6 +21,8 @@
* template: a HBS or JS binding to use as the value * template: a HBS or JS binding to use as the value
* background: the background color * background: the background color
* color: the text color * color: the text color
* borderLeft: show a left border
* borderRight: show a right border
*/ */
export let data = [] export let data = []
export let schema = {} export let schema = {}
@ -31,6 +33,7 @@
export let allowSelectRows export let allowSelectRows
export let allowEditRows = true export let allowEditRows = true
export let allowEditColumns = true export let allowEditColumns = true
export let allowClickRows = true
export let selectedRows = [] export let selectedRows = []
export let customRenderers = [] export let customRenderers = []
export let disableSorting = false export let disableSorting = false
@ -270,6 +273,17 @@
if (schema[field].align === "Right") { if (schema[field].align === "Right") {
styles[field] += "justify-content: flex-end; text-align: right;" styles[field] += "justify-content: flex-end; text-align: right;"
} }
if (schema[field].borderLeft) {
styles[field] +=
"border-left: 1px solid var(--spectrum-global-color-gray-200);"
}
if (schema[field].borderLeft) {
styles[field] +=
"border-right: 1px solid var(--spectrum-global-color-gray-200);"
}
if (schema[field].minWidth) {
styles[field] += `min-width: ${schema[field].minWidth};`
}
}) })
return styles return styles
} }
@ -290,7 +304,11 @@
</slot> </slot>
</div> </div>
{:else} {:else}
<div class="spectrum-Table" style={`${heightStyle}${gridStyle}`}> <div
class="spectrum-Table"
class:no-scroll={!rowCount}
style={`${heightStyle}${gridStyle}`}
>
{#if fields.length} {#if fields.length}
<div class="spectrum-Table-head"> <div class="spectrum-Table-head">
{#if showEditColumn} {#if showEditColumn}
@ -356,7 +374,7 @@
{/if} {/if}
{#if sortedRows?.length} {#if sortedRows?.length}
{#each sortedRows as row, idx} {#each sortedRows as row, idx}
<div class="spectrum-Table-row"> <div class="spectrum-Table-row" class:clickable={allowClickRows}>
{#if showEditColumn} {#if showEditColumn}
<div <div
class:noBorderCheckbox={!showHeaderBorder} class:noBorderCheckbox={!showHeaderBorder}
@ -433,10 +451,10 @@
/* Wrapper */ /* Wrapper */
.wrapper { .wrapper {
position: relative; position: relative;
z-index: 0;
--table-bg: var(--spectrum-global-color-gray-50); --table-bg: var(--spectrum-global-color-gray-50);
--table-border: 1px solid var(--spectrum-alias-border-color-mid); --table-border: 1px solid var(--spectrum-alias-border-color-mid);
--cell-padding: var(--spectrum-global-dimension-size-250); --cell-padding: var(--spectrum-global-dimension-size-250);
overflow: auto;
} }
.wrapper--quiet { .wrapper--quiet {
--table-bg: var(--spectrum-alias-background-color-transparent); --table-bg: var(--spectrum-alias-background-color-transparent);
@ -460,6 +478,9 @@
display: grid; display: grid;
overflow: auto; overflow: auto;
} }
.spectrum-Table.no-scroll {
overflow: visible;
}
/* Header */ /* Header */
.spectrum-Table-head { .spectrum-Table-head {
@ -546,12 +567,13 @@
/* Table rows */ /* Table rows */
.spectrum-Table-row { .spectrum-Table-row {
display: contents; display: contents;
cursor: auto;
} }
.spectrum-Table-row:hover .spectrum-Table-cell { .spectrum-Table-row.clickable {
/*background-color: var(--hover-bg) !important;*/ cursor: pointer;
} }
.spectrum-Table-row:hover .spectrum-Table-cell:after { .spectrum-Table-row.clickable:hover .spectrum-Table-cell {
background-color: var(--spectrum-alias-highlight-hover); background-color: var(--spectrum-global-color-gray-100);
} }
.wrapper--quiet .spectrum-Table-row { .wrapper--quiet .spectrum-Table-row {
border-left: none; border-left: none;
@ -584,24 +606,13 @@
border-bottom: 1px solid var(--spectrum-alias-border-color-mid); border-bottom: 1px solid var(--spectrum-alias-border-color-mid);
background-color: var(--table-bg); background-color: var(--table-bg);
z-index: auto; z-index: auto;
transition: background-color 130ms ease-out;
} }
.spectrum-Table-cell--edit { .spectrum-Table-cell--edit {
position: sticky; position: sticky;
left: 0; left: 0;
z-index: 2; z-index: 2;
} }
.spectrum-Table-cell:after {
content: "";
position: absolute;
width: 100%;
height: 100%;
background-color: transparent;
top: 0;
left: 0;
pointer-events: none;
transition: background-color
var(--spectrum-global-animation-duration-100, 0.13s) ease-in-out;
}
/* Placeholder */ /* Placeholder */
.placeholder { .placeholder {

View File

@ -82,7 +82,8 @@
.spectrum-Tabs-item { .spectrum-Tabs-item {
color: var(--spectrum-global-color-gray-600); color: var(--spectrum-global-color-gray-600);
} }
.spectrum-Tabs-item.is-selected { .spectrum-Tabs-item.is-selected,
.spectrum-Tabs-item:hover {
color: var(--spectrum-global-color-gray-900); color: var(--spectrum-global-color-gray-900);
} }
</style> </style>

View File

@ -37,7 +37,7 @@
<style> <style>
.spectrum-Tags-item { .spectrum-Tags-item {
margin-top: 0;
margin-bottom: 0; margin-bottom: 0;
margin-top: 0;
} }
</style> </style>

View File

@ -5,3 +5,13 @@
<div class="spectrum-Tags" role="list" aria-label="list"> <div class="spectrum-Tags" role="list" aria-label="list">
<slot /> <slot />
</div> </div>
<style>
.spectrum-Tags {
margin-top: -8px;
margin-left: -4px;
}
.spectrum-Tags :global(.spectrum-Tags-item) {
margin: 8px 0 0 4px !important;
}
</style>

View File

@ -15,3 +15,9 @@
> >
<slot /> <slot />
</h1> </h1>
<style>
h1 {
font-family: var(--font-accent);
}
</style>

View File

@ -40,12 +40,14 @@
--rounded-medium: 8px; --rounded-medium: 8px;
--rounded-large: 16px; --rounded-large: 16px;
--font-sans: Source Sans Pro, -apple-system, BlinkMacSystemFont, Segoe UI, "Inter", --font-sans: "Source Sans Pro", -apple-system, BlinkMacSystemFont, Segoe UI, "Inter",
"Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Helvetica Neue", Arial, "Noto Sans", sans-serif;
"Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; --font-accent: "Source Sans Pro", -apple-system, BlinkMacSystemFont, Segoe UI, "Inter",
"Helvetica Neue", Arial, "Noto Sans", sans-serif;
--font-serif: "Georgia", Cambria, Times New Roman, Times, serif; --font-serif: "Georgia", Cambria, Times New Roman, Times, serif;
--font-mono: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", --font-mono: Menlo, Monaco, Consolas, "Liberation Mono", "Courier New",
monospace; monospace;
--spectrum-alias-body-text-font-family: var(--font-sans);
font-size: 16px; font-size: 16px;
--font-size-xs: 0.75rem; --font-size-xs: 0.75rem;
@ -89,6 +91,8 @@
--border-light-2: 2px var(--grey-3) solid; --border-light-2: 2px var(--grey-3) solid;
--border-blue: 2px var(--blue) solid; --border-blue: 2px var(--blue) solid;
--border-transparent: 2px transparent solid; --border-transparent: 2px transparent solid;
--spectrum-alias-text-color-disabled: var(--spectrum-global-color-gray-600);
} }
a { a {

View File

@ -1,3 +1,4 @@
export default { export default {
Modal: "bbui-modal", Modal: "bbui-modal",
PopoverRoot: "bbui-popover-root",
} }

View File

@ -3,7 +3,7 @@
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 48 48" style="enable-background:new 0 0 48 48;" xml:space="preserve"> viewBox="0 0 48 48" style="enable-background:new 0 0 48 48;" xml:space="preserve">
<style type="text/css"> <style type="text/css">
.st0{fill:#393C44;} .st0{fill:#000000;}
.st1{fill:#FFFFFF;} .st1{fill:#FFFFFF;}
.st2{fill:#4285F4;} .st2{fill:#4285F4;}
</style> </style>

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@ -11,9 +11,5 @@
"WORKER_PORT": "4200", "WORKER_PORT": "4200",
"JWT_SECRET": "test", "JWT_SECRET": "test",
"HOST_IP": "" "HOST_IP": ""
},
"retries": {
"runMode": 1,
"openMode": 0
} }
} }

View File

@ -2,7 +2,7 @@ import filterTests from "../../support/filterTests"
// const interact = require("../support/interact") // const interact = require("../support/interact")
filterTests(["smoke", "all"], () => { filterTests(["smoke", "all"], () => {
context("Auth Configuration", () => { xcontext("Auth Configuration", () => {
before(() => { before(() => {
cy.login() cy.login()
}) })
@ -21,7 +21,7 @@ filterTests(["smoke", "all"], () => {
cy.get("[data-cy=oidc-active]").should('not.be.checked') cy.get("[data-cy=oidc-active]").should('not.be.checked')
cy.intercept("POST", "/api/global/configs").as("updateAuth") cy.intercept("POST", "/api/global/configs").as("updateAuth")
cy.get("button[data-cy=oidc-save]").contains("Save").click({force: true}) cy.get("button[data-cy=oidc-save]").contains("Save").click({ force: true })
cy.wait("@updateAuth") cy.wait("@updateAuth")
cy.get("@updateAuth").its("response.statusCode").should("eq", 200) cy.get("@updateAuth").its("response.statusCode").should("eq", 200)
@ -45,7 +45,7 @@ filterTests(["smoke", "all"], () => {
cy.get("button[data-cy=oidc-save]").should("not.be.disabled"); cy.get("button[data-cy=oidc-save]").should("not.be.disabled");
cy.intercept("POST", "/api/global/configs").as("updateAuth") cy.intercept("POST", "/api/global/configs").as("updateAuth")
cy.get("button[data-cy=oidc-save]").contains("Save").click({force: true}) cy.get("button[data-cy=oidc-save]").contains("Save").click({ force: true })
cy.wait("@updateAuth") cy.wait("@updateAuth")
cy.get("@updateAuth").its("response.statusCode").should("eq", 200) cy.get("@updateAuth").its("response.statusCode").should("eq", 200)
@ -85,11 +85,11 @@ filterTests(["smoke", "all"], () => {
cy.get(".auth-form input.spectrum-Textfield-input").type("Another ") cy.get(".auth-form input.spectrum-Textfield-input").type("Another ")
cy.get(".spectrum-Tags").find(".spectrum-Tags-item").its("length").should("eq", 6) cy.get(".spectrum-Tags").find(".spectrum-Tags-item").its("length").should("eq", 6)
cy.get(".spectrum-Tags-item").contains("Another") cy.get(".spectrum-Tags-item").contains("Another")
cy.get("button[data-cy=oidc-save]").should("not.be.disabled"); cy.get("button[data-cy=oidc-save]").should("not.be.disabled");
cy.intercept("POST", "/api/global/configs").as("updateAuth") cy.intercept("POST", "/api/global/configs").as("updateAuth")
cy.get("button[data-cy=oidc-save]").contains("Save").click({force: true}) cy.get("button[data-cy=oidc-save]").contains("Save").click({ force: true })
cy.wait("@updateAuth") cy.wait("@updateAuth")
cy.get("@updateAuth").its("response.statusCode").should("eq", 200) cy.get("@updateAuth").its("response.statusCode").should("eq", 200)
@ -123,7 +123,7 @@ filterTests(["smoke", "all"], () => {
cy.get("button[data-cy=oidc-save]").should("not.be.disabled"); cy.get("button[data-cy=oidc-save]").should("not.be.disabled");
cy.intercept("POST", "/api/global/configs").as("updateAuth") cy.intercept("POST", "/api/global/configs").as("updateAuth")
cy.get("button[data-cy=oidc-save]").contains("Save").click({force: true}) cy.get("button[data-cy=oidc-save]").contains("Save").click({ force: true })
cy.wait("@updateAuth") cy.wait("@updateAuth")
cy.get("@updateAuth").its("response.statusCode").should("eq", 200) cy.get("@updateAuth").its("response.statusCode").should("eq", 200)
@ -144,7 +144,7 @@ filterTests(["smoke", "all"], () => {
cy.get("div.content").scrollTo("bottom") cy.get("div.content").scrollTo("bottom")
cy.get("[data-cy=restore-oidc-default-scopes]").click({force: true}) cy.get("[data-cy=restore-oidc-default-scopes]").click({ force: true })
cy.get(".spectrum-Tags").find(".spectrum-Tags-item").its("length").should("eq", 4) cy.get(".spectrum-Tags").find(".spectrum-Tags-item").its("length").should("eq", 4)

View File

@ -3,107 +3,112 @@ const interact = require('../../support/interact')
filterTests(["smoke", "all"], () => { filterTests(["smoke", "all"], () => {
context("User Settings Menu", () => { context("User Settings Menu", () => {
before(() => { before(() => {
cy.login() cy.login()
}) })
it("should update user information via user settings menu", () => { it("should update user information via user settings menu", () => {
const fname = "test" const fname = "test"
const lname = "user" const lname = "user"
cy.visit(`${Cypress.config().baseUrl}/builder`) cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.updateUserInformation(fname, lname) cy.updateUserInformation(fname, lname)
// Go to user info and confirm name update // Go to user info and confirm name update
cy.contains("Users").click() cy.contains("Users").click()
cy.contains("test@test.com").click() cy.contains("test@test.com").click()
cy.get(interact.FIELD, { timeout: 1000 }).eq(1).within(() => { cy.get(interact.FIELD, { timeout: 1000 }).eq(1).within(() => {
cy.get(interact.SPECTRUM_TEXTFIELD_INPUT).should('have.value', fname) cy.get(interact.SPECTRUM_TEXTFIELD_INPUT).should('have.value', fname)
}) })
cy.get(interact.FIELD).eq(2).within(() => { cy.get(interact.FIELD).eq(2).within(() => {
cy.get(interact.SPECTRUM_TEXTFIELD_INPUT).should('have.value', lname) cy.get(interact.SPECTRUM_TEXTFIELD_INPUT).should('have.value', lname)
}) })
}) })
it("should allow copying of the users API key", () => { xit("should allow copying of the users API key", () => {
cy.get(".user-dropdown .avatar > .icon", { timeout: 2000 }).click({ force: true }) cy.get(".user-dropdown .avatar > .icon", { timeout: 2000 }).click({ force: true })
cy.get(interact.SPECTRUM_MENU_ITEM).contains("View API key").click({ force: true }) cy.get(interact.SPECTRUM_MENU_ITEM).contains("View API key").click({ force: true })
cy.get(interact.SPECTRUM_DIALOG_CONTENT).within(() => { cy.get(interact.SPECTRUM_DIALOG_CONTENT).within(() => {
cy.get(interact.SPECTRUM_ICON).click({force: true}) cy.get(interact.SPECTRUM_ICON).click({ force: true })
}) })
// There may be timing issues with this on the smoke build // There may be timing issues with this on the smoke build
cy.wait(500) cy.wait(500)
cy.get(".spectrum-Toast-content") cy.get(".spectrum-Toast-content")
.contains("URL copied to clipboard") .contains("URL copied to clipboard")
.should("be.visible") .should("be.visible")
}) })
it("should allow API key regeneration", () => { it("should allow API key regeneration", () => {
// Get initial API key value cy.get(".user-dropdown .icon", { timeout: 2000 }).click({ force: true })
cy.get(interact.SPECTRUM_DIALOG_CONTENT) cy.get(interact.SPECTRUM_MENU_ITEM).contains("View API key").click({ force: true })
cy.get(interact.SPECTRUM_DIALOG_CONTENT).within(() => {
cy.get(interact.SPECTRUM_ICON).click({ force: true })
})
// Get initial API key value
cy.get(interact.SPECTRUM_DIALOG_CONTENT)
.find(interact.SPECTRUM_TEXTFIELD_INPUT).invoke('val').as('keyOne') .find(interact.SPECTRUM_TEXTFIELD_INPUT).invoke('val').as('keyOne')
// Click re-generate key button // Click re-generate key button
cy.get("button").contains("Re-generate key").click({ force: true }) cy.get("button").contains("Regenerate key").click({ force: true })
// Verify API key was changed // Verify API key was changed
cy.get(interact.SPECTRUM_DIALOG_CONTENT).within(() => { cy.get(interact.SPECTRUM_DIALOG_CONTENT).within(() => {
cy.get('@keyOne').then((keyOne) => { cy.get('@keyOne').then((keyOne) => {
cy.get(interact.SPECTRUM_TEXTFIELD_INPUT).invoke('val').should('not.eq', keyOne) cy.get(interact.SPECTRUM_TEXTFIELD_INPUT).invoke('val').should('not.eq', keyOne)
})
}) })
cy.closeModal() })
cy.closeModal()
}) })
it("should update password", () => { it("should update password", () => {
// Access Update password modal // Access Update password modal
cy.get(".user-dropdown .avatar > .icon", { timeout: 2000 }).click({ force: true }) cy.get(".user-dropdown .icon", { timeout: 2000 }).click({ force: true })
cy.get(interact.SPECTRUM_MENU_ITEM).contains("Update password").click({ force: true }) cy.get(interact.SPECTRUM_MENU_ITEM).contains("Update password").click({ force: true })
// Enter new password and update // Enter new password and update
cy.get(interact.SPECTRUM_DIALOG_GRID).within(() => { cy.get(interact.SPECTRUM_DIALOG_GRID).within(() => {
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
// password set to 'newpwd' // password set to 'newpwd'
cy.get(interact.SPECTRUM_TEXTFIELD_INPUT).eq(i).type("newpwd") cy.get(interact.SPECTRUM_TEXTFIELD_INPUT).eq(i).type("newpwd")
} }
cy.get("button").contains("Update password").click({ force: true }) cy.get("button").contains("Update password").click({ force: true })
}) })
// Logout & in with new password // Logout & in with new password
//cy.logOut() //cy.logOut()
cy.login("test@test.com", "newpwd") cy.login("test@test.com", "newpwd")
}) })
it("should open and close developer mode", () => { xit("should open and close developer mode", () => {
cy.get(".user-dropdown .avatar > .icon", { timeout: 2000 }).click({ force: true }) cy.get(".user-dropdown .icon", { timeout: 2000 }).click({ force: true })
// Close developer mode & verify
cy.get(interact.SPECTRUM_MENU_ITEM).contains("Close developer mode").click({ force: true })
cy.get(interact.SPECTRUM_SIDENAV).should('not.exist') // No config sections
cy.get(interact.CREATE_APP_BUTTON).should('not.exist') // No create app button
cy.get(".app").should('not.exist') // At least one app should be available
// Open developer mode & verify // Close developer mode & verify
cy.get(".avatar > .icon").click({ force: true }) cy.get(interact.SPECTRUM_MENU_ITEM).contains("Close developer mode").click({ force: true })
cy.get(interact.SPECTRUM_MENU_ITEM).contains("Open developer mode").click({ force: true }) cy.get(interact.SPECTRUM_SIDENAV).should('not.exist') // No config sections
cy.get(interact.SPECTRUM_SIDENAV).should('exist') // config sections available cy.get(interact.CREATE_APP_BUTTON).should('not.exist') // No create app button
cy.get(interact.CREATE_APP_BUTTON).should('exist') // create app button available cy.get(".app").should('not.exist') // At least one app should be available
// Open developer mode & verify
cy.get(".avatar > .icon").click({ force: true })
cy.get(interact.SPECTRUM_MENU_ITEM).contains("Open developer mode").click({ force: true })
cy.get(".app-table").should('exist') // config sections available
cy.get(interact.CREATE_APP_BUTTON).should('exist') // create app button available
}) })
after(() => { after(() => {
// Change password back to original value // Change password back to original value
cy.get(".user-dropdown .avatar > .icon", { timeout: 2000 }).click({ force: true }) cy.get(".user-dropdown .icon", { timeout: 2000 }).click({ force: true })
cy.get(interact.SPECTRUM_MENU_ITEM).contains("Update password").click({ force: true }) cy.get(interact.SPECTRUM_MENU_ITEM).contains("Update password").click({ force: true })
cy.get(interact.SPECTRUM_DIALOG_GRID).within(() => { cy.get(interact.SPECTRUM_DIALOG_GRID).within(() => {
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
cy.get(interact.SPECTRUM_TEXTFIELD_INPUT).eq(i).type("test") cy.get(interact.SPECTRUM_TEXTFIELD_INPUT).eq(i).type("test")
} }
cy.get("button").contains("Update password").click({ force: true }) cy.get("button").contains("Update password").click({ force: true })
})
// Remove users name
cy.updateUserInformation()
}) })
// Remove users name
cy.updateUserInformation()
})
}) })
}) })

View File

@ -2,7 +2,7 @@ import filterTests from "../support/filterTests"
import clientPackage from "@budibase/client/package.json" import clientPackage from "@budibase/client/package.json"
filterTests(["all"], () => { filterTests(["all"], () => {
context("Application Overview screen", () => { xcontext("Application Overview screen", () => {
before(() => { before(() => {
cy.login() cy.login()
cy.deleteAllApps() cy.deleteAllApps()

View File

@ -14,15 +14,15 @@ filterTests(['smoke', 'all'], () => {
cy.visit(`${Cypress.config().baseUrl}/builder/portal/apps/create`, { timeout: 5000 }) //added /portal/apps/create cy.visit(`${Cypress.config().baseUrl}/builder/portal/apps/create`, { timeout: 5000 }) //added /portal/apps/create
cy.wait(1000) cy.wait(1000)
cy.get(interact.CREATE_APP_BUTTON, { timeout: 10000 }).contains('Start from scratch').should("exist") cy.get(interact.CREATE_APP_BUTTON, { timeout: 10000 }).contains('Start from scratch').should("exist")
cy.get(interact.TEMPLATE_CATEGORY_FILTER).should("exist") cy.get(interact.TEMPLATE_CATEGORY_FILTER).should("exist")
cy.get(interact.TEMPLATE_CATEGORY).should("exist") cy.get(interact.TEMPLATE_CATEGORY).should("exist")
cy.get(interact.APP_TABLE).should("not.exist") cy.get(interact.APP_TABLE).should("not.exist")
}) })
} }
it("should provide filterable templates", () => { xit("should provide filterable templates", () => {
cy.visit(`${Cypress.config().baseUrl}/builder`, { timeout: 5000 }) cy.visit(`${Cypress.config().baseUrl}/builder`, { timeout: 5000 })
cy.wait(500) cy.wait(500)
@ -30,16 +30,16 @@ filterTests(['smoke', 'all'], () => {
.its("body") .its("body")
.then(val => { .then(val => {
if (val.length > 0) { if (val.length > 0) {
cy.get(interact.SPECTRUM_BUTTON).contains("Templates").click({force: true}) cy.get(interact.SPECTRUM_BUTTON).contains("View Templates").click({ force: true })
} }
}) })
cy.get(interact.TEMPLATE_CATEGORY_FILTER).should("exist") cy.get(interact.TEMPLATE_CATEGORY_FILTER).should("exist")
cy.get(interact.TEMPLATE_CATEGORY).should("exist") cy.get(interact.TEMPLATE_CATEGORY).should("exist")
cy.get(interact.TEMPLATE_CATEGORY_ACTIONGROUP).its('length').should('be.gt', 1) cy.get(interact.TEMPLATE_CATEGORY_ACTIONGROUP).its('length').should('be.gt', 1)
cy.get(interact.TEMPLATE_CATEGORY_FILTER_ACTIONBUTTON).its('length').should('be.gt', 2) cy.get(interact.TEMPLATE_CATEGORY_FILTER_ACTIONBUTTON).its('length').should('be.gt', 2)
cy.get(interact.TEMPLATE_CATEGORY_FILTER_ACTIONBUTTON).eq(1).click() cy.get(interact.TEMPLATE_CATEGORY_FILTER_ACTIONBUTTON).eq(1).click()
cy.get(interact.TEMPLATE_CATEGORY_ACTIONGROUP).should('have.length', 1) cy.get(interact.TEMPLATE_CATEGORY_ACTIONGROUP).should('have.length', 1)
@ -104,14 +104,14 @@ filterTests(['smoke', 'all'], () => {
cy.visit(`${Cypress.config().baseUrl}/builder`, { timeout: 5000 }) cy.visit(`${Cypress.config().baseUrl}/builder`, { timeout: 5000 })
cy.updateUserInformation("Ted", "Userman") cy.updateUserInformation("Ted", "Userman")
cy.createApp("", false) cy.createApp("", false)
cy.applicationInAppTable("Teds app") cy.applicationInAppTable("Teds app")
cy.deleteApp("Teds app") cy.deleteApp("Teds app")
// Accomodate names that end in 'S' // Accomodate names that end in 'S'
cy.updateUserInformation("Chris", "Userman") cy.updateUserInformation("Chris", "Userman")
cy.createApp("", false) cy.createApp("", false)
cy.applicationInAppTable("Chris app") cy.applicationInAppTable("Chris app")
cy.deleteApp("Chris app") cy.deleteApp("Chris app")
@ -123,35 +123,49 @@ filterTests(['smoke', 'all'], () => {
const exportedApp = 'cypress/fixtures/exported-app.txt' const exportedApp = 'cypress/fixtures/exported-app.txt'
cy.importApp(exportedApp, "") cy.importApp(exportedApp, "")
cy.visit(`${Cypress.config().baseUrl}/builder`, { timeout: 2000 }) cy.visit(`${Cypress.config().baseUrl}/builder`, { timeout: 2000 })
cy.applicationInAppTable("My app") cy.applicationInAppTable("My app")
cy.get(".app-table .name").eq(0).click()
cy.get(".appTable .name").eq(0).click() cy.closeModal()
cy.get(`[aria-label="ShowMenu"]`).click()
cy.deleteApp("My app") cy.get(".spectrum-Menu").within(() => {
cy.contains("Overview").click()
})
cy.get(".app-overview-actions-icon").within(() => {
cy.get(".spectrum-Icon").click({ force: true })
})
cy.get(".spectrum-Menu").contains("Delete").click({ force: true })
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get("input").type("My app")
})
cy.get(".spectrum-Button--warning").click()
}) })
it("should create an application from an export, using the users first name as the default app name", () => { it("should create an application from an export, using the users first name as the default app name", () => {
const exportedApp = 'cypress/fixtures/exported-app.txt' const exportedApp = 'cypress/fixtures/exported-app.txt'
cy.updateUserInformation("Ted", "Userman") cy.updateUserInformation("Ted", "Userman")
cy.importApp(exportedApp, "") cy.importApp(exportedApp, "")
cy.visit(`${Cypress.config().baseUrl}/builder`) cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.applicationInAppTable("Teds app") cy.applicationInAppTable("Teds app")
cy.get(".app-table .name").eq(0).click()
cy.get(".appTable .name").eq(0).click() cy.closeModal()
cy.get(`[aria-label="ShowMenu"]`).click()
cy.deleteApp("Teds app") cy.get(".spectrum-Menu").within(() => {
cy.contains("Overview").click()
})
cy.get(".app-overview-actions-icon").within(() => {
cy.get(".spectrum-Icon").click({ force: true })
})
cy.get(".spectrum-Menu").contains("Delete").click({ force: true })
cy.get(".spectrum-Dialog-grid").within(() => {
cy.get("input").type("Teds app")
})
cy.get(".spectrum-Button--warning").click()
cy.updateUserInformation("", "") cy.updateUserInformation("", "")
}) })
it("should generate the first application from a template", () => { xit("should generate the first application from a template", () => {
cy.visit(`${Cypress.config().baseUrl}/builder`) cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(500) cy.wait(500)
@ -172,28 +186,28 @@ filterTests(['smoke', 'all'], () => {
const card = cy.get('.template-card').eq(0).should("exist"); const card = cy.get('.template-card').eq(0).should("exist");
const cardOverlay = card.get('.template-thumbnail-action-overlay').should("exist") const cardOverlay = card.get('.template-thumbnail-action-overlay').should("exist")
cardOverlay.invoke("show") cardOverlay.invoke("show")
cardOverlay.get("button").contains("Use template").should("exist").click({force: true}) cardOverlay.get("button").contains("Use template").should("exist").click({ force: true })
}) })
// CMD Create app from theme card // CMD Create app from theme card
cy.get(".spectrum-Modal").should('be.visible') cy.get(".spectrum-Modal").should('be.visible')
const templateName = cy.get(".spectrum-Modal .template-thumbnail-text") const templateName = cy.get(".spectrum-Modal .template-thumbnail-text")
templateName.invoke('text') templateName.invoke('text')
.then(templateNameText => { .then(templateNameText => {
const templateNameParsed = "/"+templateNameText.toLowerCase().replace(/\s+/g, "-") const templateNameParsed = "/" + templateNameText.toLowerCase().replace(/\s+/g, "-")
cy.get(interact.SPECTRUM_MODAL_INPUT).eq(0).should("have.value", templateNameText) cy.get(interact.SPECTRUM_MODAL_INPUT).eq(0).should("have.value", templateNameText)
cy.get(interact.SPECTRUM_MODAL_INPUT).eq(1).should("have.value", templateNameParsed) cy.get(interact.SPECTRUM_MODAL_INPUT).eq(1).should("have.value", templateNameParsed)
cy.get(".spectrum-Modal .spectrum-ButtonGroup").contains("Create app").click() cy.get(".spectrum-Modal .spectrum-ButtonGroup").contains("Create app").click()
cy.wait(5000) cy.wait(5000)
cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(2000)
cy.applicationInAppTable(templateNameText) cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.deleteApp(templateNameText) cy.wait(2000)
});
cy.applicationInAppTable(templateNameText)
cy.deleteApp(templateNameText)
});
}) })
@ -217,5 +231,5 @@ filterTests(['smoke', 'all'], () => {
cy.deleteApp(secondAppName) cy.deleteApp(secondAppName)
}) })
}) })
}) })

View File

@ -2,7 +2,7 @@ import filterTests from "../support/filterTests"
const interact = require('../support/interact') const interact = require('../support/interact')
filterTests(["smoke", "all"], () => { filterTests(["smoke", "all"], () => {
context("Screen Tests", () => { xcontext("Screen Tests", () => {
before(() => { before(() => {
cy.login() cy.login()
cy.createTestApp() cy.createTestApp()
@ -25,7 +25,7 @@ filterTests(["smoke", "all"], () => {
it.skip("should delete all screens then create first screen via button", () => { it.skip("should delete all screens then create first screen via button", () => {
cy.deleteAllScreens() cy.deleteAllScreens()
cy.contains("Create first screen").click() cy.contains("Create first screen").click()
cy.get(interact.BODY, { timeout: 2000 }).should('contain', '/home') cy.get(interact.BODY, { timeout: 2000 }).should('contain', '/home')
}) })
@ -33,7 +33,7 @@ filterTests(["smoke", "all"], () => {
it("Should create and filter screens by access level", () => { it("Should create and filter screens by access level", () => {
const accessLevels = ["Basic", "Admin", "Public", "Power"] const accessLevels = ["Basic", "Admin", "Public", "Power"]
for (const access of accessLevels){ for (const access of accessLevels) {
// Create screen with specified access level // Create screen with specified access level
cy.createScreen(access, access) cy.createScreen(access, access)
// Filter by access level and confirm screen visible // Filter by access level and confirm screen visible
@ -46,9 +46,9 @@ filterTests(["smoke", "all"], () => {
// Filter by All screens - Confirm all screens visible // Filter by All screens - Confirm all screens visible
cy.filterScreensAccessLevel("All screens") cy.filterScreensAccessLevel("All screens")
cy.get(interact.BODY).should('contain', accessLevels[0]) cy.get(interact.BODY).should('contain', accessLevels[0])
.and('contain', accessLevels[1]) .and('contain', accessLevels[1])
.and('contain', accessLevels[2]) .and('contain', accessLevels[2])
.and('contain', accessLevels[3]) .and('contain', accessLevels[3])
}) })
}) })
}) })

View File

@ -13,9 +13,9 @@ filterTests(["smoke", "all"], () => {
const datasource = "REST" const datasource = "REST"
const restUrl = "https://api.openbrewerydb.org/breweries" const restUrl = "https://api.openbrewerydb.org/breweries"
cy.selectExternalDatasource(datasource) cy.selectExternalDatasource(datasource)
cy.createRestQuery("GET", restUrl, "/breweries") cy.createRestQuery("GET", restUrl, "breweries")
cy.reload() cy.reload()
cy.contains(".nav-item-content", "/breweries", { timeout: 20000 }).click() cy.contains(".nav-item-content", "breweries", { timeout: 20000 }).click()
cy.contains(interact.SPECTRUM_TABS_ITEM, "Transformer", { timeout: 5000 }).click({ force: true }) cy.contains(interact.SPECTRUM_TABS_ITEM, "Transformer", { timeout: 5000 }).click({ force: true })
// Get Transformer Function from file // Get Transformer Function from file
cy.readFile("cypress/support/queryLevelTransformerFunction.js").then( cy.readFile("cypress/support/queryLevelTransformerFunction.js").then(
@ -44,9 +44,9 @@ filterTests(["smoke", "all"], () => {
const datasource = "REST" const datasource = "REST"
const restUrl = "https://api.openbrewerydb.org/breweries" const restUrl = "https://api.openbrewerydb.org/breweries"
cy.selectExternalDatasource(datasource) cy.selectExternalDatasource(datasource)
cy.createRestQuery("GET", restUrl, "/breweries") cy.createRestQuery("GET", restUrl, "breweries")
cy.reload() cy.reload()
cy.contains(".nav-item-content", "/breweries", { timeout: 2000 }).click() cy.contains(".nav-item-content", "breweries", { timeout: 2000 }).click()
cy.contains(interact.SPECTRUM_TABS_ITEM, "Transformer", { timeout: 5000 }).click({ force: true }) cy.contains(interact.SPECTRUM_TABS_ITEM, "Transformer", { timeout: 5000 }).click({ force: true })
// Get Transformer Function with Data from file // Get Transformer Function with Data from file
cy.readFile( cy.readFile(
@ -75,9 +75,9 @@ filterTests(["smoke", "all"], () => {
const datasource = "REST" const datasource = "REST"
const restUrl = "https://api.openbrewerydb.org/breweries" const restUrl = "https://api.openbrewerydb.org/breweries"
cy.selectExternalDatasource(datasource) cy.selectExternalDatasource(datasource)
cy.createRestQuery("GET", restUrl, "/breweries") cy.createRestQuery("GET", restUrl, "breweries")
cy.reload() cy.reload()
cy.contains(".nav-item-content", "/breweries", { timeout: 2000 }).click() cy.contains(".nav-item-content", "breweries", { timeout: 10000 }).click()
cy.contains(interact.SPECTRUM_TABS_ITEM, "Transformer", { timeout: 5000 }).click({ force: true }) cy.contains(interact.SPECTRUM_TABS_ITEM, "Transformer", { timeout: 5000 }).click({ force: true })
// Clear the code box and add "test" // Clear the code box and add "test"
cy.get(interact.CODEMIRROR_TEXTAREA) cy.get(interact.CODEMIRROR_TEXTAREA)

View File

@ -101,7 +101,7 @@ Cypress.Commands.add("deleteUser", email => {
}) })
Cypress.Commands.add("updateUserInformation", (firstName, lastName) => { Cypress.Commands.add("updateUserInformation", (firstName, lastName) => {
cy.get(".user-dropdown .avatar > .icon", { timeout: 2000 }).click({ cy.get(".user-dropdown .icon", { timeout: 2000 }).click({
force: true, force: true,
}) })
@ -132,7 +132,7 @@ Cypress.Commands.add("updateUserInformation", (firstName, lastName) => {
.blur() .blur()
} }
cy.get(".confirm-wrap").within(() => { cy.get(".confirm-wrap").within(() => {
cy.get("button").contains("Update information").click({ force: true }) cy.get("button").contains("Save").click({ force: true })
}) })
cy.get(".spectrum-Dialog-grid").should("not.exist") cy.get(".spectrum-Dialog-grid").should("not.exist")
}) })
@ -222,9 +222,12 @@ Cypress.Commands.add("deleteApp", name => {
// Go to app overview // Go to app overview
const appIdParsed = appId.split("_").pop() const appIdParsed = appId.split("_").pop()
const actionEleId = `[data-cy=row_actions_${appIdParsed}]` const actionEleId = `[data-cy=row_actions_${appIdParsed}]`
cy.get(actionEleId).within(() => { cy.get(actionEleId).click()
cy.contains("Manage").click({ force: true }) cy.get(`[aria-label="ShowMenu"]`).click()
cy.get(".spectrum-Menu").within(() => {
cy.contains("Overview").click()
}) })
cy.wait(500) cy.wait(500)
// Unpublish first if needed // Unpublish first if needed
@ -400,7 +403,7 @@ Cypress.Commands.add("searchForApplication", appName => {
return return
} else { } else {
// Searches for the app // Searches for the app
cy.get(".filter").then(() => { cy.get(".spectrum-Search").then(() => {
cy.get(".spectrum-Textfield").within(() => { cy.get(".spectrum-Textfield").within(() => {
cy.get("input").eq(0).clear({ force: true }) cy.get("input").eq(0).clear({ force: true })
cy.get("input").eq(0).type(appName, { force: true }) cy.get("input").eq(0).type(appName, { force: true })
@ -413,7 +416,7 @@ Cypress.Commands.add("searchForApplication", appName => {
// Assumes there are no others // Assumes there are no others
Cypress.Commands.add("applicationInAppTable", appName => { Cypress.Commands.add("applicationInAppTable", appName => {
cy.visit(`${Cypress.config().baseUrl}/builder`, { timeout: 30000 }) cy.visit(`${Cypress.config().baseUrl}/builder`, { timeout: 30000 })
cy.get(".appTable", { timeout: 30000 }).within(() => { cy.get(".app-table", { timeout: 30000 }).within(() => {
cy.get(".title").contains(appName).should("exist") cy.get(".title").contains(appName).should("exist")
}) })
}) })

View File

@ -1,6 +1,6 @@
{ {
"name": "@budibase/builder", "name": "@budibase/builder",
"version": "2.2.12-alpha.6", "version": "2.2.12-alpha.32",
"license": "GPL-3.0", "license": "GPL-3.0",
"private": true, "private": true,
"scripts": { "scripts": {
@ -71,10 +71,10 @@
} }
}, },
"dependencies": { "dependencies": {
"@budibase/bbui": "2.2.12-alpha.6", "@budibase/bbui": "2.2.12-alpha.32",
"@budibase/client": "2.2.12-alpha.6", "@budibase/client": "2.2.12-alpha.32",
"@budibase/frontend-core": "2.2.12-alpha.6", "@budibase/frontend-core": "2.2.12-alpha.32",
"@budibase/string-templates": "2.2.12-alpha.6", "@budibase/string-templates": "2.2.12-alpha.32",
"@sentry/browser": "5.19.1", "@sentry/browser": "5.19.1",
"@spectrum-css/page": "^3.0.1", "@spectrum-css/page": "^3.0.1",
"@spectrum-css/vars": "^3.0.1", "@spectrum-css/vars": "^3.0.1",
@ -87,7 +87,7 @@
"shortid": "2.2.15", "shortid": "2.2.15",
"svelte-dnd-action": "^0.9.8", "svelte-dnd-action": "^0.9.8",
"svelte-loading-spinners": "^0.1.1", "svelte-loading-spinners": "^0.1.1",
"svelte-portal": "0.1.0", "svelte-portal": "1.0.0",
"uuid": "8.3.1", "uuid": "8.3.1",
"yup": "0.29.2" "yup": "0.29.2"
}, },

View File

@ -11,11 +11,8 @@
<div class="banner-container" /> <div class="banner-container" />
<BannerDisplay /> <BannerDisplay />
<NotificationDisplay /> <NotificationDisplay />
<LicensingOverlays /> <LicensingOverlays />
<Router {routes} config={{ queryHandler }} /> <Router {routes} config={{ queryHandler }} />
<div class="modal-container" /> <div class="modal-container" />
<HelpIcon /> <HelpIcon />

View File

@ -378,6 +378,7 @@ const getProviderContextBindings = (asset, dataProviders) => {
providerId, providerId,
// Table ID is used by JSON fields to know what table the field is in // Table ID is used by JSON fields to know what table the field is in
tableId: table?._id, tableId: table?._id,
component: component._component,
category: component._instanceName, category: component._instanceName,
icon: def.icon, icon: def.icon,
display: { display: {

View File

@ -25,7 +25,6 @@
export let loading = false export let loading = false
export let hideAutocolumns export let hideAutocolumns
export let rowCount export let rowCount
export let type
export let disableSorting = false export let disableSorting = false
export let customPlaceholder = false export let customPlaceholder = false

View File

@ -12,6 +12,10 @@
name: "JSON", name: "JSON",
key: "json", key: "json",
}, },
{
name: "JSON with Schema",
key: "jsonWithSchema",
},
] ]
export let view export let view
@ -24,7 +28,7 @@
viewName: view, viewName: view,
format: exportFormat, format: exportFormat,
}) })
download(data, `export.${exportFormat}`) download(data, `export.${exportFormat === "csv" ? "csv" : "json"}`)
} catch (error) { } catch (error) {
notifications.error(`Unable to export ${exportFormat.toUpperCase()} data`) notifications.error(`Unable to export ${exportFormat.toUpperCase()} data`)
} }

View File

@ -6,22 +6,22 @@
Body, Body,
Layout, Layout,
} from "@budibase/bbui" } from "@budibase/bbui"
import TableDataImport from "../../TableNavigator/TableDataImport.svelte" import TableDataImport from "../../TableNavigator/ExistingTableDataImport.svelte"
import { API } from "api" import { API } from "api"
import { createEventDispatcher } from "svelte" import { createEventDispatcher } from "svelte"
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
export let tableId export let tableId
let dataImport let rows = []
let allValid = false
$: valid = dataImport?.csvString != null && dataImport?.valid let displayColumn = null
async function importData() { async function importData() {
try { try {
await API.importTableData({ await API.importTableData({
tableId, tableId,
data: dataImport, rows,
}) })
notifications.success("Rows successfully imported") notifications.success("Rows successfully imported")
} catch (error) { } catch (error) {
@ -37,14 +37,14 @@
title="Import Data" title="Import Data"
confirmText="Import" confirmText="Import"
onConfirm={importData} onConfirm={importData}
disabled={!valid} disabled={!allValid}
> >
<Body size="S"> <Body size="S">
Import rows to an existing table from a CSV. Only columns from the CSV which Import rows to an existing table from a CSV or JSON file. Only columns from
exist in the table will be imported. the file which exist in the table will be imported.
</Body> </Body>
<Layout gap="XS" noPadding> <Layout gap="XS" noPadding>
<Label grey extraSmall>CSV to import</Label> <Label grey extraSmall>CSV or JSON file to import</Label>
<TableDataImport bind:dataImport bind:existingTableId={tableId} /> <TableDataImport {tableId} bind:rows bind:allValid bind:displayColumn />
</Layout> </Layout>
</ModalContent> </ModalContent>

View File

@ -10,7 +10,6 @@
} from "@budibase/bbui" } from "@budibase/bbui"
import { tables } from "stores/backend" import { tables } from "stores/backend"
import { Helpers } from "@budibase/bbui" import { Helpers } from "@budibase/bbui"
import { writable } from "svelte/store"
export let save export let save
export let datasource export let datasource
@ -18,41 +17,95 @@
export let fromRelationship = {} export let fromRelationship = {}
export let toRelationship = {} export let toRelationship = {}
export let close export let close
export let selectedFromTable
let originalFromName = fromRelationship.name, const colNotSet = "Please specify a column name"
originalToName = toRelationship.name const relationshipTypes = [
let fromTable, toTable, through, linkTable, tableOptions {
let isManyToMany, isManyToOne, relationshipTypes label: "One to Many",
let errors, valid value: RelationshipTypes.MANY_TO_ONE,
let currentTables = {} },
{
label: "Many to Many",
value: RelationshipTypes.MANY_TO_MANY,
},
]
if (fromRelationship && !fromRelationship.relationshipType) { let originalFromColumnName = toRelationship.name,
fromRelationship.relationshipType = RelationshipTypes.MANY_TO_ONE originalToColumnName = fromRelationship.name
} let originalFromTable = plusTables.find(
table => table._id === toRelationship?.tableId
)
let originalToTable = plusTables.find(
table => table._id === fromRelationship?.tableId
)
if (toRelationship && selectedFromTable) { let tableOptions
toRelationship.tableId = selectedFromTable._id let errors = {}
} let hasClickedSave = !!fromRelationship.relationshipType
let fromPrimary,
fromForeign,
fromTable,
toTable,
throughTable,
fromColumn,
toColumn
let fromId, toId, throughId, throughToKey, throughFromKey
let isManyToMany, isManyToOne, relationshipType
function inSchema(table, prop, ogName) { $: {
if (!table || !prop || prop === ogName) { if (!fromPrimary) {
return false fromPrimary = fromRelationship.foreignKey
fromForeign = toRelationship.foreignKey
}
if (!fromColumn && !errors.fromColumn) {
fromColumn = toRelationship.name
}
if (!toColumn && !errors.toColumn) {
toColumn = fromRelationship.name
}
if (!fromId) {
fromId = toRelationship.tableId
}
if (!toId) {
toId = fromRelationship.tableId
}
if (!throughId) {
throughId = fromRelationship.through
throughFromKey = fromRelationship.throughFrom
throughToKey = fromRelationship.throughTo
}
if (!relationshipType) {
relationshipType = fromRelationship.relationshipType
} }
const keys = Object.keys(table.schema).map(key => key.toLowerCase())
return keys.indexOf(prop.toLowerCase()) !== -1
} }
const touched = writable({}) $: tableOptions = plusTables.map(table => ({
label: table.name,
value: table._id,
}))
$: valid = getErrorCount(errors) === 0 || !hasClickedSave
function invalidThroughTable({ through, throughTo, throughFrom }) { $: isManyToMany = relationshipType === RelationshipTypes.MANY_TO_MANY
$: isManyToOne = relationshipType === RelationshipTypes.MANY_TO_ONE
$: fromTable = plusTables.find(table => table._id === fromId)
$: toTable = plusTables.find(table => table._id === toId)
$: throughTable = plusTables.find(table => table._id === throughId)
$: toRelationship.relationshipType = fromRelationship?.relationshipType
const getErrorCount = errors =>
Object.entries(errors)
.filter(entry => !!entry[1])
.map(entry => entry[0]).length
function invalidThroughTable() {
// need to know the foreign key columns to check error // need to know the foreign key columns to check error
if (!through || !throughTo || !throughFrom) { if (!throughId || !throughToKey || !throughFromKey) {
return false return false
} }
const throughTable = plusTables.find(tbl => tbl._id === through) const throughTbl = plusTables.find(tbl => tbl._id === throughId)
const otherColumns = Object.values(throughTable.schema).filter( const otherColumns = Object.values(throughTbl.schema).filter(
col => col.name !== throughFrom && col.name !== throughTo col => col.name !== throughFromKey && col.name !== throughToKey
) )
for (let col of otherColumns) { for (let col of otherColumns) {
if (col.constraints?.presence && !col.autocolumn) { if (col.constraints?.presence && !col.autocolumn) {
@ -62,142 +115,134 @@
return false return false
} }
function checkForErrors(fromRelate, toRelate) { function validate() {
const isMany = const isMany = relationshipType === RelationshipTypes.MANY_TO_MANY
fromRelate.relationshipType === RelationshipTypes.MANY_TO_MANY
const tableNotSet = "Please specify a table" const tableNotSet = "Please specify a table"
const foreignKeyNotSet = "Please pick a foreign key"
const errObj = {} const errObj = {}
if ($touched.from && !fromTable) { if (!relationshipType) {
errObj.from = tableNotSet errObj.relationshipType = "Please specify a relationship type"
} }
if ($touched.to && !toTable) { if (!fromTable) {
errObj.to = tableNotSet errObj.fromTable = tableNotSet
} }
if ($touched.through && isMany && !fromRelate.through) { if (!toTable) {
errObj.through = tableNotSet errObj.toTable = tableNotSet
} }
if ($touched.through && invalidThroughTable(fromRelate)) { if (isMany && !throughTable) {
errObj.through = errObj.throughTable = tableNotSet
"Ensure all columns in table are nullable or auto generated"
} }
if ($touched.foreign && !isMany && !fromRelate.fieldName) { if (isMany && !throughFromKey) {
errObj.foreign = "Please pick the foreign key" errObj.throughFromKey = foreignKeyNotSet
} }
const colNotSet = "Please specify a column name" if (isMany && !throughToKey) {
if ($touched.fromCol && !fromRelate.name) { errObj.throughToKey = foreignKeyNotSet
errObj.fromCol = colNotSet
} }
if ($touched.toCol && !toRelate.name) { if (invalidThroughTable()) {
errObj.toCol = colNotSet errObj.throughTable =
"Ensure non-key columns are nullable or auto-generated"
} }
if ($touched.primary && !fromPrimary) { if (!isMany && !fromForeign) {
errObj.primary = "Please pick the primary key" errObj.fromForeign = foreignKeyNotSet
} }
if (!fromColumn) {
errObj.fromColumn = colNotSet
}
if (!toColumn) {
errObj.toColumn = colNotSet
}
if (!isMany && !fromPrimary) {
errObj.fromPrimary = "Please pick the primary key"
}
// currently don't support relationships back onto the table itself, needs to relate out // currently don't support relationships back onto the table itself, needs to relate out
const tableError = "From/to/through tables must be different" const tableError = "From/to/through tables must be different"
if (fromTable && (fromTable === toTable || fromTable === through)) { if (fromTable && (fromTable === toTable || fromTable === throughTable)) {
errObj.from = tableError errObj.fromTable = tableError
} }
if (toTable && (toTable === fromTable || toTable === through)) { if (toTable && (toTable === fromTable || toTable === throughTable)) {
errObj.to = tableError errObj.toTable = tableError
} }
if (through && (through === fromTable || through === toTable)) { if (
errObj.through = tableError throughTable &&
(throughTable === fromTable || throughTable === toTable)
) {
errObj.throughTable = tableError
} }
const colError = "Column name cannot be an existing column" const colError = "Column name cannot be an existing column"
if (inSchema(fromTable, fromRelate.name, originalFromName)) { if (isColumnNameBeingUsed(toTable, fromColumn, originalFromColumnName)) {
errObj.fromCol = colError errObj.fromColumn = colError
} }
if (inSchema(toTable, toRelate.name, originalToName)) { if (isColumnNameBeingUsed(fromTable, toColumn, originalToColumnName)) {
errObj.toCol = colError errObj.toColumn = colError
} }
let fromType, toType let fromType, toType
if (fromPrimary && fromRelate.fieldName) { if (fromPrimary && fromForeign) {
fromType = fromTable?.schema[fromPrimary]?.type fromType = fromTable?.schema[fromPrimary]?.type
toType = toTable?.schema[fromRelate.fieldName]?.type toType = toTable?.schema[fromForeign]?.type
} }
if (fromType && toType && fromType !== toType) { if (fromType && toType && fromType !== toType) {
errObj.foreign = errObj.fromForeign =
"Column type of the foreign key must match the primary key" "Column type of the foreign key must match the primary key"
} }
errors = errObj errors = errObj
return getErrorCount(errors) === 0
} }
let fromPrimary function isColumnNameBeingUsed(table, columnName, originalName) {
$: { if (!table || !columnName || columnName === originalName) {
if (!fromPrimary && fromTable) { return false
fromPrimary = fromTable.primary[0]
}
}
$: isManyToMany =
fromRelationship?.relationshipType === RelationshipTypes.MANY_TO_MANY
$: isManyToOne =
fromRelationship?.relationshipType === RelationshipTypes.MANY_TO_ONE
$: tableOptions = plusTables.map(table => ({
label: table.name,
value: table._id,
}))
$: fromTable = plusTables.find(table => table._id === toRelationship?.tableId)
$: toTable = plusTables.find(table => table._id === fromRelationship?.tableId)
$: through = plusTables.find(table => table._id === fromRelationship?.through)
$: checkForErrors(fromRelationship, toRelationship)
$: valid =
Object.keys(errors).length === 0 && Object.keys($touched).length !== 0
$: linkTable = through || toTable
$: relationshipTypes = [
{
label: "Many",
value: RelationshipTypes.MANY_TO_MANY,
},
{
label: "One",
value: RelationshipTypes.MANY_TO_ONE,
},
]
$: updateRelationshipType(fromRelationship?.relationshipType)
$: tableChanged(fromTable, toTable)
function updateRelationshipType(fromType) {
if (fromType === RelationshipTypes.MANY_TO_MANY) {
toRelationship.relationshipType = RelationshipTypes.MANY_TO_MANY
} else {
toRelationship.relationshipType = RelationshipTypes.MANY_TO_ONE
} }
const keys = Object.keys(table.schema).map(key => key.toLowerCase())
return keys.indexOf(columnName.toLowerCase()) !== -1
} }
function buildRelationships() { function buildRelationships() {
// if any to many only need to check from
const manyToMany =
fromRelationship.relationshipType === RelationshipTypes.MANY_TO_MANY
// main is simply used to know this is the side the user configured it from
const id = Helpers.uuid() const id = Helpers.uuid()
if (!manyToMany) { //Map temporary variables
delete fromRelationship.through
delete toRelationship.through
}
let relateFrom = { let relateFrom = {
...fromRelationship, ...fromRelationship,
tableId: toId,
name: toColumn,
relationshipType,
fieldName: fromForeign,
through: throughId,
throughFrom: throughFromKey,
throughTo: throughToKey,
type: "link", type: "link",
main: true, main: true,
_id: id, _id: id,
} }
let relateTo = { let relateTo = (toRelationship = {
...toRelationship, ...toRelationship,
tableId: fromId,
name: fromColumn,
through: throughId,
type: "link", type: "link",
_id: id, _id: id,
})
// if any to many only need to check from
const manyToMany =
relateFrom.relationshipType === RelationshipTypes.MANY_TO_MANY
if (!manyToMany) {
delete relateFrom.through
delete relateTo.through
} }
// [0] is because we don't support composite keys for relationships right now // [0] is because we don't support composite keys for relationships right now
if (manyToMany) { if (manyToMany) {
relateFrom = { relateFrom = {
...relateFrom, ...relateFrom,
through: through._id, through: throughTable._id,
fieldName: toTable.primary[0], fieldName: toTable.primary[0],
} }
relateTo = { relateTo = {
...relateTo, ...relateTo,
through: through._id, through: throughTable._id,
fieldName: fromTable.primary[0], fieldName: fromTable.primary[0],
throughFrom: relateFrom.throughTo, throughFrom: relateFrom.throughTo,
throughTo: relateFrom.throughFrom, throughTo: relateFrom.throughFrom,
@ -226,9 +271,27 @@
toRelationship = relateTo toRelationship = relateTo
} }
// save the relationship on to the datasource function removeExistingRelationship() {
if (originalFromTable && originalFromColumnName) {
delete datasource.entities[originalFromTable.name].schema[
originalToColumnName
]
}
if (originalToTable && originalToColumnName) {
delete datasource.entities[originalToTable.name].schema[
originalFromColumnName
]
}
}
async function saveRelationship() { async function saveRelationship() {
hasClickedSave = true
if (!validate()) {
return false
}
buildRelationships() buildRelationships()
removeExistingRelationship()
// source of relationship // source of relationship
datasource.entities[fromTable.name].schema[fromRelationship.name] = datasource.entities[fromTable.name].schema[fromRelationship.name] =
fromRelationship fromRelationship
@ -236,43 +299,14 @@
datasource.entities[toTable.name].schema[toRelationship.name] = datasource.entities[toTable.name].schema[toRelationship.name] =
toRelationship toRelationship
// If relationship has been renamed
if (originalFromName !== fromRelationship.name) {
delete datasource.entities[fromTable.name].schema[originalFromName]
}
if (originalToName !== toRelationship.name) {
delete datasource.entities[toTable.name].schema[originalToName]
}
// store the original names so it won't cause an error
originalToName = toRelationship.name
originalFromName = fromRelationship.name
await save() await save()
} }
async function deleteRelationship() { async function deleteRelationship() {
delete datasource.entities[fromTable.name].schema[fromRelationship.name] removeExistingRelationship()
delete datasource.entities[toTable.name].schema[toRelationship.name]
await save() await save()
await tables.fetch() await tables.fetch()
close() close()
} }
function tableChanged(fromTbl, toTbl) {
if (
(currentTables?.from?._id === fromTbl?._id &&
currentTables?.to?._id === toTbl?._id) ||
originalFromName ||
originalToName
) {
return
}
fromRelationship.name = toTbl?.name || ""
errors.fromCol = ""
toRelationship.name = fromTbl?.name || ""
errors.toCol = ""
currentTables = { from: fromTbl, to: toTbl }
}
</script> </script>
<ModalContent <ModalContent
@ -284,7 +318,9 @@
<Select <Select
label="Relationship type" label="Relationship type"
options={relationshipTypes} options={relationshipTypes}
bind:value={fromRelationship.relationshipType} bind:value={relationshipType}
bind:error={errors.relationshipType}
on:change={() => (errors.relationshipType = null)}
/> />
<div class="headings"> <div class="headings">
<Detail>Tables</Detail> <Detail>Tables</Detail>
@ -292,60 +328,74 @@
<Select <Select
label="Select from table" label="Select from table"
options={tableOptions} options={tableOptions}
disabled={!!selectedFromTable} bind:value={fromId}
on:change={() => ($touched.from = true)} bind:error={errors.fromTable}
bind:error={errors.from} on:change={e => {
bind:value={toRelationship.tableId} fromColumn = tableOptions.find(opt => opt.value === e.detail)?.label || ""
errors.fromTable = null
errors.fromColumn = null
}}
/> />
{#if isManyToOne && fromTable} {#if isManyToOne && fromTable}
<Select <Select
label={`Primary Key (${fromTable?.name})`} label={`Primary Key (${fromTable.name})`}
options={Object.keys(fromTable?.schema)} options={Object.keys(fromTable.schema)}
on:change={() => ($touched.primary = true)}
bind:error={errors.primary}
bind:value={fromPrimary} bind:value={fromPrimary}
bind:error={errors.fromPrimary}
on:change={() => (errors.fromPrimary = null)}
/> />
{/if} {/if}
<Select <Select
label={"Select to table"} label={"Select to table"}
options={tableOptions} options={tableOptions}
on:change={() => ($touched.to = true)} bind:value={toId}
bind:error={errors.to} bind:error={errors.toTable}
bind:value={fromRelationship.tableId} on:change={e => {
toColumn = tableOptions.find(opt => opt.value === e.detail)?.label || ""
errors.toTable = null
errors.toColumn = null
}}
/> />
{#if isManyToMany} {#if isManyToMany}
<Select <Select
label={"Through"} label={"Through"}
options={tableOptions} options={tableOptions}
on:change={() => ($touched.through = true)} bind:value={throughId}
bind:error={errors.through} bind:error={errors.throughTable}
bind:value={fromRelationship.through}
/> />
{#if fromTable && toTable && through} {#if fromTable && toTable && throughTable}
<Select <Select
label={`Foreign Key (${fromTable?.name})`} label={`Foreign Key (${fromTable?.name})`}
options={Object.keys(through?.schema)} options={Object.keys(throughTable?.schema)}
on:change={() => ($touched.fromForeign = true)} bind:value={throughToKey}
bind:error={errors.fromForeign} bind:error={errors.throughToKey}
bind:value={fromRelationship.throughTo} on:change={e => {
if (throughFromKey === e.detail) {
throughFromKey = null
}
errors.throughToKey = null
}}
/> />
<Select <Select
label={`Foreign Key (${toTable?.name})`} label={`Foreign Key (${toTable?.name})`}
options={Object.keys(through?.schema)} options={Object.keys(throughTable?.schema)}
on:change={() => ($touched.toForeign = true)} bind:value={throughFromKey}
bind:error={errors.toForeign} bind:error={errors.throughFromKey}
bind:value={fromRelationship.throughFrom} on:change={e => {
if (throughToKey === e.detail) {
throughToKey = null
}
errors.throughFromKey = null
}}
/> />
{/if} {/if}
{:else if isManyToOne && toTable} {:else if isManyToOne && toTable}
<Select <Select
label={`Foreign Key (${toTable?.name})`} label={`Foreign Key (${toTable?.name})`}
options={Object.keys(toTable?.schema).filter( options={Object.keys(toTable?.schema)}
field => toTable?.primary.indexOf(field) === -1 bind:value={fromForeign}
)} bind:error={errors.fromForeign}
on:change={() => ($touched.foreign = true)} on:change={() => (errors.fromForeign = null)}
bind:error={errors.foreign}
bind:value={fromRelationship.fieldName}
/> />
{/if} {/if}
<div class="headings"> <div class="headings">
@ -356,19 +406,21 @@
provide a name for these columns. provide a name for these columns.
</Body> </Body>
<Input <Input
on:blur={() => ($touched.fromCol = true)}
bind:error={errors.fromCol}
label="From table column" label="From table column"
bind:value={fromRelationship.name} bind:value={fromColumn}
bind:error={errors.fromColumn}
on:change={e => {
errors.fromColumn = e.detail?.length > 0 ? null : colNotSet
}}
/> />
<Input <Input
on:blur={() => ($touched.toCol = true)}
bind:error={errors.toCol}
label="To table column" label="To table column"
bind:value={toRelationship.name} bind:value={toColumn}
bind:error={errors.toColumn}
on:change={e => (errors.toColumn = e.detail?.length > 0 ? null : colNotSet)}
/> />
<div slot="footer"> <div slot="footer">
{#if originalFromName != null} {#if originalFromColumnName != null}
<Button warning text on:click={deleteRelationship}>Delete</Button> <Button warning text on:click={deleteRelationship}>Delete</Button>
{/if} {/if}
</div> </div>

View File

@ -0,0 +1,251 @@
<script>
import { Select } from "@budibase/bbui"
import { FIELDS } from "constants/backend"
import { API } from "api"
import { parseFile } from "./utils"
let error = null
let fileName = null
let fileType = null
let loading = false
let validation = {}
let validateHash = ""
let schema = null
let invalidColumns = []
export let tableId = null
export let rows = []
export let allValid = false
const typeOptions = [
{
label: "Text",
value: FIELDS.STRING.type,
},
{
label: "Number",
value: FIELDS.NUMBER.type,
},
{
label: "Date",
value: FIELDS.DATETIME.type,
},
{
label: "Options",
value: FIELDS.OPTIONS.type,
},
{
label: "Multi-select",
value: FIELDS.ARRAY.type,
},
{
label: "Barcode/QR",
value: FIELDS.BARCODEQR.type,
},
{
label: "Long Form Text",
value: FIELDS.LONGFORM.type,
},
]
$: {
schema = fetchSchema(tableId)
}
async function fetchSchema(tableId) {
try {
const definition = await API.fetchTableDefinition(tableId)
schema = definition.schema
} catch (e) {
error = e
}
}
async function handleFile(e) {
loading = true
error = null
validation = {}
try {
const response = await parseFile(e)
rows = response.rows
fileName = response.fileName
fileType = response.fileType
} catch (e) {
loading = false
error = e
}
}
async function validate(rows) {
loading = true
error = null
validation = {}
allValid = false
try {
if (rows.length > 0) {
const response = await API.validateExistingTableImport({
rows,
tableId,
})
validation = response.schemaValidation
invalidColumns = response.invalidColumns
allValid = response.allValid
}
} catch (e) {
error = e.message
}
loading = false
}
$: {
// binding in consumer is causing double renders here
const newValidateHash = JSON.stringify(rows)
if (newValidateHash !== validateHash) {
validate(rows)
}
validateHash = newValidateHash
}
</script>
<div class="dropzone">
<input
disabled={!schema || loading}
id="file-upload"
accept="text/csv,application/json"
type="file"
on:change={handleFile}
/>
<label for="file-upload" class:uploaded={rows.length > 0}>
{#if loading}
loading...
{:else if error}
error: {error}
{:else if fileName}
{fileName}
{:else}
Upload
{/if}
</label>
</div>
{#if fileName && Object.keys(validation).length === 0}
<p>No valid fields, try another file</p>
{:else if rows.length > 0 && !error}
<div class="schema-fields">
{#each Object.keys(validation) as name}
<div class="field">
<span>{name}</span>
<Select
value={schema[name]?.type}
options={typeOptions}
placeholder={null}
getOptionLabel={option => option.label}
getOptionValue={option => option.value}
disabled
/>
<span
class={loading || validation[name]
? "fieldStatusSuccess"
: "fieldStatusFailure"}
>
{validation[name] ? "Success" : "Failure"}
</span>
</div>
{/each}
</div>
{#if invalidColumns.length > 0}
<p class="spectrum-FieldLabel spectrum-FieldLabel--sizeM">
The following columns are present in the data you wish to import, but do
not match the schema of this table and will be ignored.
</p>
<ul class="ignoredList">
{#each invalidColumns as column}
<li>{column}</li>
{/each}
</ul>
{/if}
{/if}
<style>
.dropzone {
text-align: center;
display: flex;
align-items: center;
flex-direction: column;
border-radius: 10px;
transition: all 0.3s;
}
input {
display: none;
}
label {
font-family: var(--font-sans);
cursor: pointer;
font-weight: 600;
box-sizing: border-box;
overflow: hidden;
border-radius: var(--border-radius-s);
color: var(--ink);
padding: var(--spacing-m) var(--spacing-l);
transition: all 0.2s ease 0s;
display: inline-flex;
text-rendering: optimizeLegibility;
min-width: auto;
outline: none;
font-feature-settings: "case" 1, "rlig" 1, "calt" 0;
-webkit-box-align: center;
user-select: none;
flex-shrink: 0;
align-items: center;
justify-content: center;
width: 100%;
background-color: var(--grey-2);
font-size: var(--font-size-xs);
line-height: normal;
border: var(--border-transparent);
}
.uploaded {
color: var(--blue);
}
.schema-fields {
margin-top: var(--spacing-xl);
}
.field {
display: grid;
grid-template-columns: 2fr 2fr 1fr auto;
margin-top: var(--spacing-m);
align-items: center;
grid-gap: var(--spacing-m);
font-size: var(--spectrum-global-dimension-font-size-75);
}
.fieldStatusSuccess {
color: var(--green);
justify-self: center;
font-weight: 600;
}
.fieldStatusFailure {
color: var(--red);
justify-self: center;
font-weight: 600;
}
.ignoredList {
margin: 0;
padding: 0;
list-style: none;
font-size: var(--spectrum-global-dimension-font-size-75);
}
</style>

View File

@ -1,107 +1,21 @@
<script> <script>
import { Select, InlineAlert, notifications } from "@budibase/bbui" import { Select } from "@budibase/bbui"
import { FIELDS } from "constants/backend" import { FIELDS } from "constants/backend"
import { API } from "api" import { API } from "api"
import { parseFile } from "./utils"
const BYTES_IN_MB = 1000000 let error = null
const FILE_SIZE_LIMIT = BYTES_IN_MB * 5 let fileName = null
let fileType = null
export let files = [] let loading = false
export let dataImport = { let validation = {}
valid: true, let validateHash = ""
schema: {},
}
export let existingTableId
let csvString = undefined export let rows = []
let primaryDisplay = undefined export let schema = {}
let schema = {} export let allValid = true
let fields = [] export let displayColumn = null
let hasValidated = false
$: valid =
!schema ||
(fields.every(column => schema[column].success) &&
(!hasValidated || Object.keys(schema).length > 0))
$: dataImport = {
valid,
schema: buildTableSchema(schema),
csvString,
primaryDisplay,
}
$: noFieldsError = existingTableId
? "No columns in CSV match existing table schema"
: "Could not find any columns to import"
function buildTableSchema(schema) {
const tableSchema = {}
for (let key in schema) {
const type = schema[key].type
if (type === "omit") continue
tableSchema[key] = {
name: key,
type,
constraints: FIELDS[type.toUpperCase()].constraints,
}
}
return tableSchema
}
async function validateCSV() {
try {
const parseResult = await API.validateTableCSV({
csvString,
schema: schema || {},
tableId: existingTableId,
})
schema = parseResult?.schema
fields = Object.keys(schema || {}).filter(
key => schema[key].type !== "omit"
)
// Check primary display is valid
if (!primaryDisplay || fields.indexOf(primaryDisplay) === -1) {
primaryDisplay = fields[0]
}
hasValidated = true
} catch (error) {
notifications.error("CSV Invalid, please try another CSV file")
}
}
async function handleFile(evt) {
const fileArray = Array.from(evt.target.files)
if (fileArray.some(file => file.size >= FILE_SIZE_LIMIT)) {
notifications.error(
`Files cannot exceed ${
FILE_SIZE_LIMIT / BYTES_IN_MB
}MB. Please try again with smaller files.`
)
return
}
// Read CSV as plain text to upload alongside schema
let reader = new FileReader()
reader.addEventListener("load", function (e) {
csvString = e.target.result
files = fileArray
validateCSV()
})
reader.readAsText(fileArray[0])
}
async function omitColumn(columnName) {
schema[columnName].type = "omit"
await validateCSV()
}
const handleTypeChange = column => evt => {
schema[column].type = evt.detail
validateCSV()
}
const typeOptions = [ const typeOptions = [
{ {
@ -133,54 +47,114 @@
value: FIELDS.LONGFORM.type, value: FIELDS.LONGFORM.type,
}, },
] ]
async function handleFile(e) {
loading = true
error = null
validation = {}
try {
const response = await parseFile(e)
rows = response.rows
schema = response.schema
fileName = response.fileName
fileType = response.fileType
} catch (e) {
loading = false
error = e
}
}
async function validate(rows, schema) {
loading = true
error = null
validation = {}
allValid = false
try {
if (rows.length > 0) {
const response = await API.validateNewTableImport({ rows, schema })
validation = response.schemaValidation
allValid = response.allValid
}
} catch (e) {
error = e.message
}
loading = false
}
$: {
// binding in consumer is causing double renders here
const newValidateHash = JSON.stringify(rows) + JSON.stringify(schema)
if (newValidateHash !== validateHash) {
validate(rows, schema)
}
validateHash = newValidateHash
}
</script> </script>
<div class="dropzone"> <div class="dropzone">
<input id="file-upload" accept=".csv" type="file" on:change={handleFile} /> <input
<label for="file-upload" class:uploaded={files[0]}> disabled={loading}
{#if files[0]}{files[0].name}{:else}Upload{/if} id="file-upload"
accept="text/csv,application/json"
type="file"
on:change={handleFile}
/>
<label for="file-upload" class:uploaded={rows.length > 0}>
{#if loading}
loading...
{:else if error}
error: {error}
{:else if fileName}
{fileName}
{:else}
Upload
{/if}
</label> </label>
</div> </div>
{#if fields.length} {#if rows.length > 0 && !error}
<div class="schema-fields"> <div class="schema-fields">
{#each fields as columnName} {#each Object.values(schema) as column}
<div class="field"> <div class="field">
<span>{columnName}</span> <span>{column.name}</span>
<Select <Select
bind:value={schema[columnName].type} bind:value={column.type}
on:change={handleTypeChange(columnName)} on:change={e => (column.type = e.detail)}
options={typeOptions} options={typeOptions}
placeholder={null} placeholder={null}
getOptionLabel={option => option.label} getOptionLabel={option => option.label}
getOptionValue={option => option.value} getOptionValue={option => option.value}
disabled={!!existingTableId} disabled={loading}
/> />
<span class="field-status" class:error={!schema[columnName].success}> <span
{schema[columnName].success ? "Success" : "Failure"} class={loading || validation[column.name]
? "fieldStatusSuccess"
: "fieldStatusFailure"}
>
{validation[column.name] ? "Success" : "Failure"}
</span> </span>
<i <i
class="omit-button ri-close-circle-fill" class={`omit-button ri-close-circle-fill ${
on:click={() => omitColumn(columnName)} loading ? "omit-button-disabled" : ""
}`}
on:click={() => {
delete schema[column.name]
schema = schema
}}
/> />
</div> </div>
{/each} {/each}
</div> </div>
{#if !existingTableId} <div class="display-column">
<div class="display-column"> <Select
<Select label="Display Column"
label="Display Column" bind:value={displayColumn}
bind:value={primaryDisplay} options={Object.keys(schema)}
options={fields} sort
sort
/>
</div>
{/if}
{:else if hasValidated}
<div>
<InlineAlert
header="Invalid CSV"
bind:message={noFieldsError}
type="error"
/> />
</div> </div>
{/if} {/if}
@ -195,30 +169,11 @@
transition: all 0.3s; transition: all 0.3s;
} }
.field-status { input {
color: var(--green);
justify-self: center;
font-weight: 600;
}
.error {
color: var(--red);
}
.uploaded {
color: var(--blue);
}
input[type="file"] {
display: none; display: none;
} }
.schema-fields {
margin-top: var(--spacing-xl);
}
label { label {
font-family: var(--font-sans);
cursor: pointer; cursor: pointer;
font-weight: 600; font-weight: 600;
box-sizing: border-box; box-sizing: border-box;
@ -244,11 +199,12 @@
border: var(--border-transparent); border: var(--border-transparent);
} }
.omit-button { .uploaded {
font-size: 1.2em; color: var(--blue);
color: var(--grey-7); }
cursor: pointer;
justify-self: flex-end; .schema-fields {
margin-top: var(--spacing-xl);
} }
.field { .field {
@ -260,6 +216,30 @@
font-size: var(--spectrum-global-dimension-font-size-75); font-size: var(--spectrum-global-dimension-font-size-75);
} }
.fieldStatusSuccess {
color: var(--green);
justify-self: center;
font-weight: 600;
}
.fieldStatusFailure {
color: var(--red);
justify-self: center;
font-weight: 600;
}
.omit-button {
font-size: 1.2em;
color: var(--grey-7);
cursor: pointer;
justify-self: flex-end;
}
.omit-button-disabled {
pointer-events: none;
opacity: 70%;
}
.display-column { .display-column {
margin-top: var(--spacing-xl); margin-top: var(--spacing-xl);
} }

View File

@ -29,18 +29,27 @@
: BUDIBASE_INTERNAL_DB_ID : BUDIBASE_INTERNAL_DB_ID
export let name export let name
let dataImport
let error = "" let error = ""
let autoColumns = getAutoColumnInformation() let autoColumns = getAutoColumnInformation()
let schema = {}
let rows = []
let allValid = true
let displayColumn = null
function addAutoColumns(tableName, schema) { function getAutoColumns() {
for (let [subtype, col] of Object.entries(autoColumns)) { const selectedAutoColumns = {}
if (!col.enabled) {
continue Object.entries(autoColumns).forEach(([subtype, column]) => {
if (column.enabled) {
selectedAutoColumns[column.name] = buildAutoColumn(
name,
column.name,
subtype
)
} }
schema[col.name] = buildAutoColumn(tableName, col.name, subtype) })
}
return schema return selectedAutoColumns
} }
function checkValid(evt) { function checkValid(evt) {
@ -55,15 +64,15 @@
async function saveTable() { async function saveTable() {
let newTable = { let newTable = {
name, name,
schema: addAutoColumns(name, dataImport.schema || {}), schema: { ...schema, ...getAutoColumns() },
dataImport, rows,
type: "internal", type: "internal",
sourceId: targetDatasourceId, sourceId: targetDatasourceId,
} }
// Only set primary display if defined // Only set primary display if defined
if (dataImport.primaryDisplay && dataImport.primaryDisplay.length) { if (displayColumn && displayColumn.length) {
newTable.primaryDisplay = dataImport.primaryDisplay newTable.primaryDisplay = displayColumn
} }
// Create table // Create table
@ -90,7 +99,7 @@
title="Create Table" title="Create Table"
confirmText="Create" confirmText="Create"
onConfirm={saveTable} onConfirm={saveTable}
disabled={error || !name || (dataImport && !dataImport.valid)} disabled={error || !name || (rows.length && !allValid)}
> >
<Input <Input
data-cy="table-name-input" data-cy="table-name-input"
@ -117,8 +126,10 @@
</div> </div>
<div> <div>
<Layout gap="XS" noPadding> <Layout gap="XS" noPadding>
<Label grey extraSmall>Create Table from CSV (Optional)</Label> <Label grey extraSmall
<TableDataImport bind:dataImport /> >Create a Table from a CSV or JSON file (Optional)</Label
>
<TableDataImport bind:rows bind:schema bind:allValid bind:displayColumn />
</Layout> </Layout>
</div> </div>
</ModalContent> </ModalContent>

View File

@ -0,0 +1,71 @@
import { API } from "api"
import { FIELDS } from "constants/backend"
const BYTES_IN_MB = 1000000
const FILE_SIZE_LIMIT = BYTES_IN_MB * 5
const getDefaultSchema = rows => {
const newSchema = {}
rows.forEach(row => {
Object.keys(row).forEach(column => {
newSchema[column] = {
name: column,
type: "string",
constraints: FIELDS["STRING"].constraints,
}
})
})
return newSchema
}
export const parseFile = e => {
return new Promise((resolve, reject) => {
const file = Array.from(e.target.files)[0]
if (file.size >= FILE_SIZE_LIMIT) {
reject("file too large")
return
}
let reader = new FileReader()
const resolveRows = (rows, schema = null) => {
resolve({
rows,
schema: schema ?? getDefaultSchema(rows),
fileName: file.name,
fileType: file.type,
})
}
reader.addEventListener("load", function (e) {
const fileData = e.target.result
if (file.type === "text/csv") {
API.csvToJson(fileData)
.then(rows => {
resolveRows(rows)
})
.catch(() => {
reject("can't convert csv to json")
})
} else if (file.type === "application/json") {
const parsedFileData = JSON.parse(fileData)
if (Array.isArray(parsedFileData)) {
resolveRows(parsedFileData)
} else if (typeof parsedFileData === "object") {
resolveRows(parsedFileData.rows, parsedFileData.schema)
} else {
reject("invalid json format")
}
} else {
reject("invalid file type")
}
})
reader.readAsText(file)
})
}

View File

@ -8,6 +8,7 @@
ProgressCircle, ProgressCircle,
Layout, Layout,
Body, Body,
Icon,
} from "@budibase/bbui" } from "@budibase/bbui"
import { auth, apps } from "stores/portal" import { auth, apps } from "stores/portal"
import { processStringSync } from "@budibase/string-templates" import { processStringSync } from "@budibase/string-templates"
@ -56,85 +57,77 @@
} }
</script> </script>
<div class="lock-status"> {#if lockedBy}
{#if lockedBy} <div class="lock-status">
<Button <Icon
quiet name="LockClosed"
secondary hoverable
icon="LockClosed"
size={buttonSize} size={buttonSize}
on:click={() => { on:click={e => {
e.stopPropagation()
appLockModal.show() appLockModal.show()
}} }}
> />
<span class="lock-status-text">
{lockedByHeading}
</span>
</Button>
{/if}
</div>
{#key app}
<div>
<Modal bind:this={appLockModal}>
<ModalContent
title={lockedByHeading}
dataCy={"app-lock-modal"}
showConfirmButton={false}
showCancelButton={false}
>
<Layout noPadding>
<Body size="S">
Apps are locked to prevent work from being lost from overlapping
changes between your team.
</Body>
{#if lockedByYou && getExpiryDuration(app) > 0}
<span class="lock-expiry-body">
{processStringSync(
"This lock will expire in {{ duration time 'millisecond' }} from now. This lock will expire in This lock will expire in ",
{
time: getExpiryDuration(app),
}
)}
</span>
{/if}
<div class="lock-modal-actions">
<ButtonGroup>
<Button
secondary
quiet={lockedBy && lockedByYou}
disabled={processing}
on:click={() => {
appLockModal.hide()
}}
>
<span class="cancel"
>{lockedBy && !lockedByYou ? "Done" : "Cancel"}</span
>
</Button>
{#if lockedByYou}
<Button
secondary
disabled={processing}
on:click={() => {
releaseLock()
appLockModal.hide()
}}
>
{#if processing}
<ProgressCircle overBackground={true} size="S" />
{:else}
<span class="unlock">Release Lock</span>
{/if}
</Button>
{/if}
</ButtonGroup>
</div>
</Layout>
</ModalContent>
</Modal>
</div> </div>
{/key} {/if}
<Modal bind:this={appLockModal}>
<ModalContent
title={lockedByHeading}
dataCy={"app-lock-modal"}
showConfirmButton={false}
showCancelButton={false}
>
<Layout noPadding>
<Body size="S">
Apps are locked to prevent work being lost from overlapping changes
between your team.
</Body>
{#if lockedByYou && getExpiryDuration(app) > 0}
<span class="lock-expiry-body">
{processStringSync(
"This lock will expire in {{ duration time 'millisecond' }} from now.",
{
time: getExpiryDuration(app),
}
)}
</span>
{/if}
<div class="lock-modal-actions">
<ButtonGroup>
<Button
secondary
quiet={lockedBy && lockedByYou}
disabled={processing}
on:click={() => {
appLockModal.hide()
}}
>
<span class="cancel"
>{lockedBy && !lockedByYou ? "Done" : "Cancel"}</span
>
</Button>
{#if lockedByYou}
<Button
cta
disabled={processing}
on:click={() => {
releaseLock()
appLockModal.hide()
}}
>
{#if processing}
<ProgressCircle overBackground={true} size="S" />
{:else}
<span class="unlock">Release Lock</span>
{/if}
</Button>
{/if}
</ButtonGroup>
</div>
</Layout>
</ModalContent>
</Modal>
<style> <style>
.lock-modal-actions { .lock-modal-actions {
@ -148,8 +141,4 @@
gap: var(--spacing-s); gap: var(--spacing-s);
max-width: 175px; max-width: 175px;
} }
.lock-status-text {
font-weight: 400;
color: var(--spectrum-global-color-gray-800);
}
</style> </style>

View File

@ -135,7 +135,7 @@
div :global(.CodeMirror) { div :global(.CodeMirror) {
height: var(--code-mirror-height); height: var(--code-mirror-height);
min-height: var(--code-mirror-height); min-height: var(--code-mirror-height);
font-family: monospace; font-family: var(--font-mono);
line-height: 1.3; line-height: 1.3;
border: var(--spectrum-alias-border-size-thin) solid; border: var(--spectrum-alias-border-size-thin) solid;
border-color: var(--spectrum-alias-border-color); border-color: var(--spectrum-alias-border-color);

View File

@ -1,64 +0,0 @@
<script>
import {
ActionMenu,
Checkbox,
MenuItem,
Heading,
ProgressCircle,
} from "@budibase/bbui"
import { admin } from "stores/portal"
import { goto } from "@roxi/routify"
import { onMount } from "svelte"
let width = window.innerWidth
$: side = width < 500 ? "right" : "left"
const resizeObserver = new ResizeObserver(entries => {
if (entries?.[0]) {
width = entries[0].contentRect?.width
}
})
onMount(() => {
const doc = document.documentElement
resizeObserver.observe(doc)
return () => {
resizeObserver.unobserve(doc)
}
})
</script>
<ActionMenu align={side}>
<div slot="control" class="icon">
<ProgressCircle size="S" value={$admin.onboardingProgress} />
</div>
<MenuItem disabled>
<header class="item">
<Heading size="XXS">Get Started Checklist</Heading>
<ProgressCircle size="S" value={$admin.onboardingProgress} />
</header>
</MenuItem>
{#each Object.keys($admin.checklist) as checklistItem, idx}
<MenuItem>
<div
class="item"
on:click={() => $goto($admin.checklist[checklistItem].link)}
>
<span>{idx + 1}. {$admin.checklist[checklistItem].label}</span>
<Checkbox value={$admin.checklist[checklistItem].checked} />
</div>
</MenuItem>
{/each}
</ActionMenu>
<style>
.item {
display: grid;
align-items: center;
grid-template-columns: 175px 20px;
}
.icon {
cursor: pointer;
}
</style>

View File

@ -1,47 +1,46 @@
<script> <script>
import { Icon } from "@budibase/bbui" import { Icon, Modal } from "@budibase/bbui"
import ChooseIconModal from "components/start/ChooseIconModal.svelte" import ChooseIconModal from "components/start/ChooseIconModal.svelte"
export let name export let name
export let size export let size = "M"
export let app export let app
export let color
export let autoSave = false
let iconModal let modal
</script> </script>
<div class="editable-icon"> <div class="editable-icon">
<div <div class="hover" on:click={modal.show}>
class="edit-hover" <Icon name="Edit" {size} color="var(--spectrum-global-color-gray-600)" />
on:click={() => {
iconModal.show()
}}
>
<Icon name={"Edit"} size={"L"} />
</div> </div>
<div class="app-icon"> <div class="normal">
<Icon {name} {size} /> <Icon {name} {size} {color} />
</div> </div>
</div> </div>
<ChooseIconModal {app} bind:this={iconModal} />
<Modal bind:this={modal}>
<ChooseIconModal {name} {color} {app} {autoSave} on:change />
</Modal>
<style> <style>
.editable-icon:hover .app-icon {
opacity: 0;
}
.editable-icon { .editable-icon {
position: relative; position: relative;
display: flex;
justify-content: flex-start;
} }
.editable-icon:hover .edit-hover { .normal {
opacity: 1; display: block;
} }
.edit-hover { .hover {
color: var(--spectrum-global-color-gray-600); display: none;
cursor: pointer; cursor: pointer;
z-index: 100; }
width: 100%; .editable-icon:hover .normal {
height: 100%; display: none;
position: absolute; }
opacity: 0; .editable-icon:hover .hover {
/* transition: opacity var(--spectrum-global-animation-duration-100) ease; */ display: block;
} }
</style> </style>

View File

@ -31,6 +31,7 @@
bottom: var(--spacing-m); bottom: var(--spacing-m);
right: var(--spacing-m); right: var(--spacing-m);
border-radius: 55%; border-radius: 55%;
z-index: 99999;
} }
.hidden { .hidden {
display: none; display: none;

View File

@ -2,6 +2,7 @@
import { Select } from "@budibase/bbui" import { Select } from "@budibase/bbui"
import { roles } from "stores/backend" import { roles } from "stores/backend"
import { Constants, RoleUtils } from "@budibase/frontend-core" import { Constants, RoleUtils } from "@budibase/frontend-core"
import { createEventDispatcher } from "svelte"
export let value export let value
export let error export let error
@ -9,26 +10,62 @@
export let autoWidth = false export let autoWidth = false
export let quiet = false export let quiet = false
export let allowPublic = true export let allowPublic = true
export let allowRemove = false
$: options = getOptions($roles, allowPublic) const dispatch = createEventDispatcher()
const RemoveID = "remove"
$: options = getOptions($roles, allowPublic, allowRemove)
const getOptions = (roles, allowPublic) => { const getOptions = (roles, allowPublic) => {
if (allowRemove) {
roles = [
...roles,
{
_id: RemoveID,
name: "Remove",
},
]
}
if (allowPublic) { if (allowPublic) {
return roles return roles
} }
return roles.filter(role => role._id !== Constants.Roles.PUBLIC) return roles.filter(role => role._id !== Constants.Roles.PUBLIC)
} }
const getColor = role => {
if (allowRemove && role._id === RemoveID) {
return null
}
return RoleUtils.getRoleColour(role._id)
}
const getIcon = role => {
if (allowRemove && role._id === RemoveID) {
return "Close"
}
return null
}
const onChange = e => {
if (allowRemove && e.detail === RemoveID) {
dispatch("remove")
} else {
dispatch("change", e.detail)
}
}
</script> </script>
<Select <Select
{autoWidth} {autoWidth}
{quiet} {quiet}
bind:value bind:value
on:change on:change={onChange}
{options} {options}
getOptionLabel={role => role.name} getOptionLabel={role => role.name}
getOptionValue={role => role._id} getOptionValue={role => role._id}
getOptionColour={role => RoleUtils.getRoleColour(role._id)} getOptionColour={getColor}
getOptionIcon={getIcon}
{placeholder} {placeholder}
{error} {error}
/> />

View File

@ -1,128 +1,110 @@
<script> <script>
import { import { Layout, Detail, Button, Modal } from "@budibase/bbui"
Layout,
Detail,
Heading,
Button,
Modal,
ActionGroup,
ActionButton,
} from "@budibase/bbui"
import TemplateCard from "components/common/TemplateCard.svelte" import TemplateCard from "components/common/TemplateCard.svelte"
import CreateAppModal from "components/start/CreateAppModal.svelte" import CreateAppModal from "components/start/CreateAppModal.svelte"
import { licensing } from "stores/portal" import { licensing } from "stores/portal"
import { Content, SideNav, SideNavItem } from "components/portal/page"
export let templates export let templates
let selectedTemplateCategory let selectedCategory
let creationModal let creationModal
let template let template
const groupTemplatesByCategory = (templates, categoryFilter) => { $: categories = getCategories(templates)
let grouped = templates.reduce((acc, template) => { $: filteredCategories = getFilteredCategories(categories, selectedCategory)
if (
typeof categoryFilter === "string" && const getCategories = templates => {
[categoryFilter].indexOf(template.category) < 0 let categories = {}
) { templates?.forEach(template => {
return acc if (!categories[template.category]) {
categories[template.category] = []
} }
categories[template.category].push(template)
acc[template.category] = !acc[template.category] })
? [] categories = Object.entries(categories).map(
: acc[template.category] ([category, categoryTemplates]) => {
acc[template.category].push(template) return {
name: category,
return acc templates: categoryTemplates,
}, {}) }
return grouped }
)
categories.sort((a, b) => {
return a.name < b.name ? -1 : 1
})
return categories
} }
$: filteredTemplates = groupTemplatesByCategory( const getFilteredCategories = (categories, selectedCategory) => {
templates, if (!selectedCategory) {
selectedTemplateCategory return categories
) }
return categories.filter(x => x.name === selectedCategory)
$: filteredTemplateCategories = filteredTemplates }
? Object.keys(filteredTemplates).sort()
: []
$: templateCategories = templates
? Object.keys(groupTemplatesByCategory(templates)).sort()
: []
const stopAppCreation = () => { const stopAppCreation = () => {
template = null template = null
} }
</script> </script>
<div class="template-header"> <Content>
<Layout noPadding gap="S"> <div slot="side-nav">
<Heading size="S">Templates</Heading> <SideNav>
<div class="template-category-filters spectrum-ActionGroup"> <SideNavItem
<ActionGroup> on:click={() => (selectedCategory = null)}
<ActionButton text="All"
selected={!selectedTemplateCategory} active={selectedCategory == null}
on:click={() => { />
selectedTemplateCategory = null {#each categories as category}
}} <SideNavItem
> on:click={() => (selectedCategory = category.name)}
All text={category.name}
</ActionButton> active={selectedCategory === category.name}
{#each templateCategories as templateCategoryKey} />
<ActionButton {/each}
dataCy={templateCategoryKey} </SideNav>
selected={templateCategoryKey == selectedTemplateCategory} </div>
on:click={() => { <div class="template-categories">
selectedTemplateCategory = templateCategoryKey <Layout gap="XL" noPadding>
}} {#each filteredCategories as category}
> <div class="template-category" data-cy={category.name}>
{templateCategoryKey} <Detail size="M">{category.name}</Detail>
</ActionButton> <div class="template-grid">
{/each} {#each category.templates as templateEntry}
</ActionGroup> <TemplateCard
</div> name={templateEntry.name}
</Layout> imageSrc={templateEntry.image}
</div> backgroundColour={templateEntry.background}
icon={templateEntry.icon}
<div class="template-categories">
<Layout gap="XL" noPadding>
{#each filteredTemplateCategories as templateCategoryKey}
<div class="template-category" data-cy={templateCategoryKey}>
<Detail size="M">{templateCategoryKey}</Detail>
<div class="template-grid">
{#each filteredTemplates[templateCategoryKey] as templateEntry}
<TemplateCard
name={templateEntry.name}
imageSrc={templateEntry.image}
backgroundColour={templateEntry.background}
icon={templateEntry.icon}
>
{#if !($licensing?.usageMetrics?.apps >= 100)}
<Button
cta
on:click={() => {
template = templateEntry
creationModal.show()
}}
>
Use template
</Button>
{/if}
<a
href={templateEntry.url}
target="_blank"
class="overlay-preview-link spectrum-Button spectrum-Button--sizeM spectrum-Button--secondary"
on:click|stopPropagation
> >
Details {#if !($licensing?.usageMetrics?.apps >= 100)}
</a> <Button
</TemplateCard> cta
{/each} on:click={() => {
template = templateEntry
creationModal.show()
}}
>
Use template
</Button>
{/if}
<a
href={templateEntry.url}
target="_blank"
class="overlay-preview-link spectrum-Button spectrum-Button--sizeM spectrum-Button--secondary"
on:click|stopPropagation
>
Details
</a>
</TemplateCard>
{/each}
</div>
</div> </div>
</div> {/each}
{/each} </Layout>
</Layout> </div>
</div> </Content>
<Modal <Modal
bind:this={creationModal} bind:this={creationModal}

View File

@ -469,7 +469,7 @@
} }
.binding__type { .binding__type {
font-family: monospace; font-family: var(--font-mono);
background-color: var(--spectrum-global-color-gray-200); background-color: var(--spectrum-global-color-gray-200);
border-radius: var(--border-radius-s); border-radius: var(--border-radius-s);
padding: 2px 4px; padding: 2px 4px;

View File

@ -12,7 +12,7 @@
dummy.select() dummy.select()
document.execCommand("copy") document.execCommand("copy")
document.body.removeChild(dummy) document.body.removeChild(dummy)
notifications.success(`URL copied to clipboard`) notifications.success(`Copied to clipboard`)
} }
</script> </script>

View File

@ -57,15 +57,13 @@
<Button cta on:click={publishModal.show}>Publish</Button> <Button cta on:click={publishModal.show}>Publish</Button>
<Modal bind:this={publishModal}> <Modal bind:this={publishModal}>
<ModalContent <ModalContent
title="Publish to Production" title="Publish to production"
confirmText="Publish" confirmText="Publish"
onConfirm={publishApp} onConfirm={publishApp}
dataCy={"deploy-app-modal"} dataCy={"deploy-app-modal"}
> >
<span The changes you have made will be published to the production version of the
>The changes you have made will be published to the production version of application.
the application.</span
>
</ModalContent> </ModalContent>
</Modal> </Modal>

View File

@ -179,7 +179,7 @@
</ConfirmDialog> </ConfirmDialog>
<div class="buttons"> <div class="buttons">
<Button on:click={previewApp} newStyles secondary>Preview</Button> <Button on:click={previewApp} secondary>Preview</Button>
<DeployModal onOk={completePublish} /> <DeployModal onOk={completePublish} />
</div> </div>

View File

@ -70,7 +70,10 @@
type: "provider", type: "provider",
})) }))
$: links = bindings $: links = bindings
// Get only link bindings
.filter(x => x.fieldSchema?.type === "link") .filter(x => x.fieldSchema?.type === "link")
// Filter out bindings provided by forms
.filter(x => !x.component?.endsWith("/form"))
.map(binding => { .map(binding => {
const { providerId, readableBinding, fieldSchema } = binding || {} const { providerId, readableBinding, fieldSchema } = binding || {}
const { name, tableId } = fieldSchema || {} const { name, tableId } = fieldSchema || {}

View File

@ -185,7 +185,7 @@
div :global(.CodeMirror) { div :global(.CodeMirror) {
height: var(--code-mirror-height) !important; height: var(--code-mirror-height) !important;
border-radius: var(--border-radius-s); border-radius: var(--border-radius-s);
font-family: monospace !important; font-family: var(--font-mono);
line-height: 1.3; line-height: 1.3;
} }
</style> </style>

View File

@ -1,106 +0,0 @@
<script>
import { Layout, Icon, ActionButton, InlineAlert } from "@budibase/bbui"
import StatusRenderer from "./StatusRenderer.svelte"
import DateTimeRenderer from "components/common/renderers/DateTimeRenderer.svelte"
import TestDisplay from "components/automation/AutomationBuilder/TestDisplay.svelte"
import { goto } from "@roxi/routify"
import { automationStore } from "builderStore"
export let history
export let appId
export let close
const STOPPED_ERROR = "stopped_error"
$: exists = $automationStore.automations?.find(
auto => auto._id === history?.automationId
)
</script>
{#if history}
<div class="body">
<div class="top">
<div class="controls">
<StatusRenderer value={history.status} />
<ActionButton noPadding size="S" icon="Close" quiet on:click={close} />
</div>
</div>
<Layout paddingY="XL" paddingX="XL" gap="S">
<div class="icon">
<Icon name="Clock" />
<DateTimeRenderer value={history.createdAt} />
</div>
<div class="icon">
<Icon name="JourneyVoyager" />
<div>{history.automationName}</div>
</div>
{#if history.status === STOPPED_ERROR}
<div class="cron-error">
<InlineAlert
type="error"
header="CRON automation disabled"
message="Fix the error and re-publish your app to re-activate."
/>
</div>
{/if}
<div>
{#if exists}
<ActionButton
icon="Edit"
fullWidth={false}
on:click={() =>
$goto(`../../../app/${appId}/automate/${history.automationId}`)}
>Edit automation</ActionButton
>
{/if}
</div>
</Layout>
<div class="bottom">
{#key history}
<TestDisplay testResults={history} width="100%" />
{/key}
</div>
</div>
{:else}
<div>No details found</div>
{/if}
<style>
.body {
right: 0;
background-color: var(--background);
border-left: var(--border-light);
width: 420px;
height: calc(100vh - 240px);
position: fixed;
overflow: auto;
}
.top {
padding: var(--spacing-m) 0 var(--spacing-m) 0;
border-bottom: var(--border-light);
}
.bottom {
border-top: var(--border-light);
padding-top: calc(var(--spacing-xl) * 2);
padding-bottom: calc(var(--spacing-xl) * 2);
}
.icon {
display: flex;
gap: var(--spacing-m);
}
.controls {
padding: 0 var(--spacing-l) 0 var(--spacing-l);
display: grid;
grid-template-columns: 1fr auto;
gap: var(--spacing-s);
}
.cron-error {
display: flex;
width: 100%;
justify-content: center;
}
</style>

View File

@ -1,39 +0,0 @@
<script>
import { Icon } from "@budibase/bbui"
export let value
$: isError = !value || value.toLowerCase() === "error"
$: isStoppedError = value?.toLowerCase() === "stopped_error"
$: isStopped = value?.toLowerCase() === "stopped" || isStoppedError
$: status = getStatus(isError, isStopped)
function getStatus(error, stopped) {
if (error) {
return { color: "var(--red)", message: "Error", icon: "Alert" }
} else if (stopped) {
return { color: "var(--yellow)", message: "Stopped", icon: "StopCircle" }
} else {
return {
color: "var(--green)",
message: "Success",
icon: "CheckmarkCircle",
}
}
}
</script>
<div class="cell">
<Icon color={status.color} name={status.icon} />
<div style={`color: ${status.color};`}>
{status.message}
</div>
</div>
<style>
.cell {
display: flex;
flex-direction: row;
gap: var(--spacing-m);
align-items: center;
}
</style>

View File

@ -0,0 +1,37 @@
<script>
import { Icon } from "@budibase/bbui"
export let url
export let text
</script>
<div>
<a href={url}>
{text}
</a>
<Icon name="ChevronRight" />
</div>
<style>
div {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
color: var(--spectrum-global-color-gray-700);
gap: var(--spacing-m);
font-size: 16px;
font-weight: 600;
}
div :global(.spectrum-Icon),
a {
color: inherit;
transition: color 130ms ease-out;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
a:hover {
color: var(--spectrum-global-color-gray-900);
}
</style>

View File

@ -0,0 +1,22 @@
<div>
<slot />
</div>
<style>
div {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
gap: var(--spacing-m);
}
div :global(> *:last-child .spectrum-Icon) {
display: none;
}
div :global(> *:last-child) {
color: var(--spectrum-global-color-gray-900);
flex: 1 1 auto;
width: 0;
}
</style>

View File

@ -0,0 +1,46 @@
<script>
export let narrow = false
export let showMobileNav = false
</script>
<div class="content">
<div class="side-nav" class:show-mobile={showMobileNav}>
<slot name="side-nav" />
</div>
<div class="main" class:narrow>
<slot />
</div>
</div>
<style>
.content {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: stretch;
gap: 40px;
}
.side-nav {
flex: 0 0 200px;
}
.main {
flex: 1 1 auto;
}
.main.narrow {
max-width: 600px;
}
@media (max-width: 640px) {
.content {
flex-direction: column;
}
.side-nav:not(.show-mobile) {
display: none;
}
.side-nav.show-mobile :global(.side-nav) {
border-bottom: var(--border-light);
margin: 0 -24px;
padding: 0 24px 32px 24px;
}
}
</style>

View File

@ -0,0 +1,52 @@
<script>
import { Heading } from "@budibase/bbui"
export let title
export let wrap = true
</script>
<div class="header" class:wrap>
<slot name="icon" />
<Heading size="L">{title}</Heading>
<div class="buttons">
<slot name="buttons" />
</div>
</div>
<style>
.header {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
gap: var(--spacing-xl);
}
.header.wrap {
flex-wrap: wrap;
}
.header :global(.spectrum-Heading) {
flex: 1 1 auto;
margin-top: -2px;
}
.header:not(.wrap) :global(.spectrum-Heading) {
overflow: hidden;
width: 0;
white-space: nowrap;
text-overflow: ellipsis;
}
.buttons {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
gap: var(--spacing-xl);
}
.buttons :global(> div) {
display: contents;
}
@media (max-width: 640px) {
.wrap .buttons {
margin-bottom: var(--spacing-m);
}
}
</style>

View File

@ -0,0 +1,26 @@
<script>
export let title
</script>
<div class="side-nav">
{#if title}
<div class="title">{title}</div>
{/if}
<slot />
</div>
<style>
.side-nav {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: stretch;
gap: 4px;
}
.title {
margin-left: var(--spacing-m);
font-size: 12px;
color: var(--spectrum-global-color-gray-700);
margin-bottom: var(--spacing-m);
}
</style>

View File

@ -0,0 +1,23 @@
<script>
export let text
export let url
export let active = false
</script>
<a on:click href={url} class:active>
{text}
</a>
<style>
a {
padding: var(--spacing-s) var(--spacing-m);
color: var(--spectrum-global-color-gray-900);
border-radius: 4px;
transition: background 130ms ease-out;
}
.active,
a:hover {
background-color: var(--spectrum-global-color-gray-200);
cursor: pointer;
}
</style>

View File

@ -0,0 +1,6 @@
export { default as Breadcrumb } from "./Breadcrumb.svelte"
export { default as Breadcrumbs } from "./Breadcrumbs.svelte"
export { default as Header } from "./Header.svelte"
export { default as Content } from "./Content.svelte"
export { default as SideNavItem } from "./SideNavItem.svelte"
export { default as SideNav } from "./SideNav.svelte"

View File

@ -1,5 +1,6 @@
<script> <script>
import { ModalContent, Body, notifications } from "@budibase/bbui" import { ModalContent } from "@budibase/bbui"
import { Body, notifications } from "@budibase/bbui"
import { auth } from "stores/portal" import { auth } from "stores/portal"
import { onMount } from "svelte" import { onMount } from "svelte"
import CopyInput from "components/common/inputs/CopyInput.svelte" import CopyInput from "components/common/inputs/CopyInput.svelte"
@ -27,15 +28,13 @@
</script> </script>
<ModalContent <ModalContent
title="Developer information" title="API Key"
showConfirmButton={false} showSecondaryButton
showSecondaryButton={true} secondaryButtonText="Regenerate key"
secondaryButtonText="Re-generate key"
secondaryAction={generateAPIKey} secondaryAction={generateAPIKey}
showCancelButton={false}
confirmText="Close"
> >
<Body size="S"> <Body size="S">Your API key for accessing the Budibase public API:</Body>
You can find information about your developer account here, such as the API <CopyInput bind:value={apiKey} />
key used to access the Budibase API.
</Body>
<CopyInput bind:value={apiKey} label="API key" />
</ModalContent> </ModalContent>

View File

@ -18,11 +18,7 @@
} }
</script> </script>
<ModalContent <ModalContent title="My profile" confirmText="Save" onConfirm={updateInfo}>
title="Update user information"
confirmText="Update information"
onConfirm={updateInfo}
>
<Body size="S"> <Body size="S">
Personalise the platform by adding your first name and last name. Personalise the platform by adding your first name and last name.
</Body> </Body>

View File

@ -0,0 +1,16 @@
<script>
import { ModalContent } from "@budibase/bbui"
import { Select } from "@budibase/bbui"
import { themeStore } from "builderStore"
import { Constants } from "@budibase/frontend-core"
</script>
<ModalContent title="Theme">
<Select
options={Constants.Themes}
bind:value={$themeStore.theme}
placeholder={null}
getOptionLabel={x => x.name}
getOptionValue={x => x.class}
/>
</ModalContent>

View File

@ -1,85 +1,126 @@
<script> <script>
import { Heading, Button, Icon } from "@budibase/bbui" import { Heading, Body, Button, Icon, notifications } from "@budibase/bbui"
import AppLockModal from "../common/AppLockModal.svelte" import AppLockModal from "../common/AppLockModal.svelte"
import { processStringSync } from "@budibase/string-templates" import { processStringSync } from "@budibase/string-templates"
import { goto } from "@roxi/routify"
export let app export let app
export let editApp
export let appOverview const handleDefaultClick = () => {
if (window.innerWidth < 640) {
goToOverview()
} else {
goToBuilder()
}
}
const goToBuilder = () => {
if (app.lockedOther) {
notifications.error(
`App locked by ${app.lockedBy.email}. Please allow lock to expire or have them unlock this app.`
)
return
}
$goto(`../../app/${app.devId}`)
}
const goToOverview = () => {
$goto(`../overview/${app.devId}`)
}
</script> </script>
<div class="title" data-cy={`${app.devId}`}> <div class="app-row" on:click={handleDefaultClick}>
<div> <div class="title" data-cy={`${app.devId}`}>
<div class="app-icon" style="color: {app.icon?.color || ''}"> <div class="app-icon">
<Icon size="XL" name={app.icon?.name || "Apps"} /> <Icon size="L" name={app.icon?.name || "Apps"} color={app.icon?.color} />
</div> </div>
<div class="name" data-cy="app-name-link" on:click={() => editApp(app)}> <div class="name" data-cy="app-name-link">
<Heading size="XS"> <Heading size="S">
{app.name} {app.name}
</Heading> </Heading>
</div> </div>
</div> </div>
</div>
<div class="desktop"> <div class="updated">
{#if app.updatedAt} {#if app.updatedAt}
{processStringSync("Updated {{ duration time 'millisecond' }} ago", { {processStringSync("Updated {{ duration time 'millisecond' }} ago", {
time: new Date().getTime() - new Date(app.updatedAt).getTime(), time: new Date().getTime() - new Date(app.updatedAt).getTime(),
})} })}
{:else}
Never updated
{/if}
</div>
<div class="desktop">
<span><AppLockModal {app} buttonSize="M" /></span>
</div>
<div class="desktop">
<div class="app-status">
{#if app.deployed}
<Icon name="Globe" disabled={false} />
Published
{:else} {:else}
<Icon name="GlobeStrike" disabled={true} /> Never updated
<span class="disabled"> Unpublished </span>
{/if} {/if}
</div> </div>
</div>
<div data-cy={`row_actions_${app.appId}`}> <div class="title app-status" class:deployed={app.deployed}>
<div class="app-row-actions"> <Icon size="L" name={app.deployed ? "GlobeCheck" : "GlobeStrike"} />
<Button size="S" secondary newStyles on:click={() => appOverview(app)}> <Body size="S">{app.deployed ? "Published" : "Unpublished"}</Body>
Manage </div>
</Button>
<Button <div class="app-row-actions" data-cy={`row_actions_${app.appId}`}>
size="S" <AppLockModal {app} buttonSize="M" />
primary <Button size="S" secondary on:click={goToOverview}>Manage</Button>
newStyles <Button size="S" primary disabled={app.lockedOther} on:click={goToBuilder}>
disabled={app.lockedOther}
on:click={() => editApp(app)}
>
Edit Edit
</Button> </Button>
</div> </div>
</div> </div>
<style> <style>
div.title, .app-row {
div.title > div { background: var(--background);
display: flex; padding: 24px 32px;
max-width: 100%; border-radius: 8px;
display: grid;
grid-template-columns: 35% 25% 15% auto;
align-items: center;
gap: var(--spacing-m);
transition: border 130ms ease-out;
border: 1px solid transparent;
} }
.app-row:hover {
cursor: pointer;
border-color: var(--spectrum-global-color-gray-300);
}
.updated {
color: var(--spectrum-global-color-gray-700);
}
.title,
.name {
flex: 1 1 auto;
}
.name {
width: 0;
}
.title,
.app-status {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
gap: 10px;
}
.title :global(.spectrum-Heading),
.title :global(.spectrum-Icon),
.title :global(.spectrum-Body) {
color: var(--spectrum-global-color-gray-900);
}
.app-status:not(.deployed) :global(.spectrum-Icon),
.app-status:not(.deployed) :global(.spectrum-Body) {
color: var(--spectrum-global-color-gray-600);
}
.app-row-actions { .app-row-actions {
grid-gap: var(--spacing-s); gap: var(--spacing-m);
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: flex-end; justify-content: flex-end;
align-items: center;
} }
.app-status {
display: grid;
grid-gap: var(--spacing-s);
grid-template-columns: 24px 100px;
}
.app-status span.disabled {
opacity: 0.3;
}
.name { .name {
text-decoration: none; text-decoration: none;
overflow: hidden; overflow: hidden;
@ -88,17 +129,30 @@
overflow: hidden; overflow: hidden;
white-space: nowrap; white-space: nowrap;
text-overflow: ellipsis; text-overflow: ellipsis;
margin-left: calc(1.5 * var(--spacing-xl));
}
.title :global(h1:hover) {
color: var(--spectrum-global-color-blue-600);
cursor: pointer;
transition: color 130ms ease;
} }
@media (max-width: 1000px) {
.app-row {
grid-template-columns: 45% 30% auto;
}
.updated {
display: none;
}
}
@media (max-width: 800px) {
.app-row {
grid-template-columns: 1fr auto;
}
.app-status {
display: none;
}
}
@media (max-width: 640px) { @media (max-width: 640px) {
.desktop { .app-row {
display: none !important; padding: 20px;
}
.app-row-actions {
display: none;
} }
} }
</style> </style>

View File

@ -1,18 +1,20 @@
<script> <script>
import { import {
ModalContent, ModalContent,
Modal,
Icon, Icon,
ColorPicker, ColorPicker,
Label, Label,
notifications, notifications,
} from "@budibase/bbui" } from "@budibase/bbui"
import { apps } from "stores/portal" import { apps } from "stores/portal"
import { createEventDispatcher } from "svelte"
export let app export let app
let modal export let name
$: selectedIcon = app?.icon?.name || "Apps" export let color
$: selectedColor = app?.icon?.color export let autoSave = false
const dispatch = createEventDispatcher()
let iconsList = [ let iconsList = [
"Apps", "Apps",
@ -40,30 +42,15 @@
"GraphBarHorizontal", "GraphBarHorizontal",
"Demographic", "Demographic",
] ]
export const show = () => {
modal.show()
}
export const hide = () => {
modal.hide()
}
const onCancel = () => {
selectedIcon = ""
selectedColor = ""
hide()
}
const changeColor = val => {
selectedColor = val
}
const save = async () => { const save = async () => {
if (!autoSave) {
dispatch("change", { color, name })
return
}
try { try {
await apps.update(app.instance._id, { await apps.update(app.instance._id, {
icon: { icon: { name, color },
name: selectedIcon,
color: selectedColor,
},
}) })
} catch (error) { } catch (error) {
notifications.error("Error updating app") notifications.error("Error updating app")
@ -71,41 +58,32 @@
} }
</script> </script>
<Modal bind:this={modal} on:hide={onCancel}> <ModalContent title="Edit Icon" confirmText="Save" onConfirm={save}>
<ModalContent <div class="scrollable-icons">
title={"Edit Icon"} <div class="title-spacing">
confirmText={"Save"} <Label>Select an icon</Label>
onConfirm={() => save()}
>
<div class="scrollable-icons">
<div class="title-spacing">
<Label>Select an icon</Label>
</div>
<div class="grid">
{#each iconsList as item}
<div
class="icon-item"
class:selected={item === selectedIcon}
on:click={() => (selectedIcon = item)}
>
<Icon name={item} />
</div>
{/each}
</div>
</div> </div>
<div class="color-selection"> <div class="grid">
<div> {#each iconsList as item}
<Label>Select a color</Label> <div
</div> class="icon-item"
<div class="color-selection-item"> class:selected={item === name}
<ColorPicker on:click={() => (name = item)}
bind:value={selectedColor} >
on:change={e => changeColor(e.detail)} <Icon name={item} />
/> </div>
</div> {/each}
</div> </div>
</ModalContent> </div>
</Modal> <div class="color-selection">
<div>
<Label>Select a color</Label>
</div>
<div class="color-selection-item">
<ColorPicker bind:value={color} on:change={e => (color = e.detail)} />
</div>
</div>
</ModalContent>
<style> <style>
.scrollable-icons { .scrollable-icons {

View File

@ -138,6 +138,7 @@
} }
$goto(`/builder/app/${createdApp.instance._id}`) $goto(`/builder/app/${createdApp.instance._id}`)
// apps.load()
} catch (error) { } catch (error) {
creating = false creating = false
console.error(error) console.error(error)

View File

@ -1,22 +1,29 @@
<script> <script>
import { writable, get as svelteGet } from "svelte/store" import { writable, get as svelteGet } from "svelte/store"
import { notifications, Input, ModalContent, Body } from "@budibase/bbui" import {
notifications,
Input,
ModalContent,
Layout,
Label,
} from "@budibase/bbui"
import { apps } from "stores/portal" import { apps } from "stores/portal"
import { onMount } from "svelte" import { onMount } from "svelte"
import { createValidationStore } from "helpers/validation/yup" import { createValidationStore } from "helpers/validation/yup"
import * as appValidation from "helpers/validation/yup/app" import * as appValidation from "helpers/validation/yup/app"
import EditableIcon from "../common/EditableIcon.svelte"
export let app export let app
const values = writable({ name: "", url: null }) const values = writable({
const validation = createValidationStore() name: app.name,
$: validation.check($values) url: app.url,
iconName: app.icon?.name,
onMount(async () => { iconColor: app.icon?.color,
$values.name = app.name
$values.url = app.url
setupValidation()
}) })
const validation = createValidationStore()
$: validation.check($values)
const setupValidation = async () => { const setupValidation = async () => {
const applications = svelteGet(apps) const applications = svelteGet(apps)
@ -28,14 +35,14 @@
async function updateApp() { async function updateApp() {
try { try {
// Update App await apps.update(app.instance._id, {
const body = { name: $values.name?.trim(),
name: $values.name.trim(), url: $values.url?.trim(),
} icon: {
if ($values.url) { name: $values.iconName,
body.url = $values.url.trim() color: $values.iconColor,
} },
await apps.update(app.instance._id, body) })
} catch (error) { } catch (error) {
console.error(error) console.error(error)
notifications.error("Error updating app") notifications.error("Error updating app")
@ -68,15 +75,22 @@
let resolvedUrl = resolveAppUrl(null, appName) let resolvedUrl = resolveAppUrl(null, appName)
tidyUrl(resolvedUrl) tidyUrl(resolvedUrl)
} }
const updateIcon = e => {
const { name, color } = e.detail
$values.iconColor = color
$values.iconName = name
}
onMount(setupValidation)
</script> </script>
<ModalContent <ModalContent
title={"Edit app"} title="Edit name and URL"
confirmText={"Save"} confirmText="Save"
onConfirm={updateApp} onConfirm={updateApp}
disabled={!$validation.valid} disabled={!$validation.valid}
> >
<Body size="S">Update the name of your app.</Body>
<Input <Input
bind:value={$values.name} bind:value={$values.name}
error={$validation.touched.name && $validation.errors.name} error={$validation.touched.name && $validation.errors.name}
@ -84,6 +98,16 @@
on:change={nameToUrl($values.name)} on:change={nameToUrl($values.name)}
label="Name" label="Name"
/> />
<Layout noPadding gap="XS">
<Label>Icon</Label>
<EditableIcon
{app}
size="XL"
name={$values.iconName}
color={$values.iconColor}
on:change={updateIcon}
/>
</Layout>
<Input <Input
bind:value={$values.url} bind:value={$values.url}
error={$validation.touched.url && $validation.errors.url} error={$validation.touched.url && $validation.errors.url}

View File

@ -39,15 +39,21 @@
{#if showWarning} {#if showWarning}
<Icon name="Alert" /> <Icon name="Alert" />
{/if} {/if}
<div class="heading header-item"> <Heading size="XS" weight="light">
<Heading size="XS" weight="light">{usage.name}</Heading> <span class="nowrap">
</div> {usage.name}
</span>
</Heading>
</div> </div>
{#if unlimited} <Body size="S">
<Body size="S">{usage.used} / Unlimited</Body> <span class="nowrap">
{:else} {#if unlimited}
<Body size="S">{usage.used} / {usage.total}</Body> {usage.used} / Unlimited
{/if} {:else}
{usage.used} / {usage.total}
{/if}
</span>
</Body>
</div> </div>
<div> <div>
{#if unlimited} {#if unlimited}
@ -89,13 +95,14 @@
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
align-items: flex-end;
margin-bottom: 12px; margin-bottom: 12px;
gap: var(--spacing-m);
} }
.header-container { .header-container {
display: flex; display: flex;
} }
.heading { .nowrap {
margin-top: 3px; white-space: nowrap;
margin-left: 5px;
} }
</style> </style>

View File

@ -47,7 +47,7 @@
<div class="header-actions"> <div class="header-actions">
{#if secondaryDefined} {#if secondaryDefined}
<div> <div>
<Button newStyles secondary on:click={secondaryAction} <Button secondary on:click={secondaryAction}
>{secondaryActionText}</Button >{secondaryActionText}</Button
> >
</div> </div>

View File

@ -23,7 +23,6 @@ body {
--grey-8: var(--spectrum-global-color-gray-800); --grey-8: var(--spectrum-global-color-gray-800);
--grey-9: var(--spectrum-global-color-gray-900); --grey-9: var(--spectrum-global-color-gray-900);
font-family: var(--font-sans);
color: var(--ink); color: var(--ink);
background-color: var(--background-alt); background-color: var(--background-alt);
} }

View File

@ -105,32 +105,34 @@
</MenuItem> </MenuItem>
<MenuItem <MenuItem
on:click={() => on:click={() =>
$goto(`../../portal/overview/${application}?tab=Access`)} $goto(`../../portal/overview/${application}/access`)}
> >
Access Access
</MenuItem> </MenuItem>
<MenuItem <MenuItem
on:click={() => on:click={() =>
$goto( $goto(`../../portal/overview/${application}/automation-history`)}
`../../portal/overview/${application}?tab=${encodeURIComponent(
"Automation History"
)}`
)}
> >
Automation history Automation history
</MenuItem> </MenuItem>
<MenuItem <MenuItem
on:click={() => on:click={() =>
$goto(`../../portal/overview/${application}?tab=Backups`)} $goto(`../../portal/overview/${application}/backups`)}
> >
Backups Backups
</MenuItem> </MenuItem>
<MenuItem <MenuItem
on:click={() => on:click={() =>
$goto(`../../portal/overview/${application}?tab=Settings`)} $goto(`../../portal/overview/${application}/name-and-url`)}
> >
Settings Name and URL
</MenuItem>
<MenuItem
on:click={() =>
$goto(`../../portal/overview/${application}/version`)}
>
Version
</MenuItem> </MenuItem>
</ActionMenu> </ActionMenu>
<Heading size="XS">{$store.name || "App"}</Heading> <Heading size="XS">{$store.name || "App"}</Heading>

View File

@ -176,7 +176,6 @@
const addComponent = async component => { const addComponent = async component => {
try { try {
await store.actions.components.create(component) await store.actions.components.create(component)
$goto("../")
} catch (error) { } catch (error) {
notifications.error(error || "Error creating component") notifications.error(error || "Error creating component")
} }
@ -263,6 +262,7 @@
orderMap[component.component]} orderMap[component.component]}
on:click={() => addComponent(component.component)} on:click={() => addComponent(component.component)}
on:mouseover={() => (selectedIndex = null)} on:mouseover={() => (selectedIndex = null)}
on:focus
> >
<Icon name={component.icon} /> <Icon name={component.icon} />
<Body size="XS">{component.name}</Body> <Body size="XS">{component.name}</Body>

View File

@ -20,6 +20,7 @@
class="container" class="container"
on:mouseover={() => (showTooltip = true)} on:mouseover={() => (showTooltip = true)}
on:mouseleave={() => (showTooltip = false)} on:mouseleave={() => (showTooltip = false)}
on:focus
style="--color: {color};" style="--color: {color};"
> >
<StatusLight square {color} /> <StatusLight square {color} />

Some files were not shown because too many files have changed in this diff Show More