1
0
Fork 0
mirror of synced 2024-06-29 11:31:06 +12:00

Add _id field

This commit is contained in:
Rory Powell 2021-12-11 10:40:57 +00:00
parent e8755b6854
commit 4b1fb01eb4
5 changed files with 20 additions and 19 deletions

View file

@ -2,6 +2,7 @@
import { Table, Modal, Layout, ActionButton } from "@budibase/bbui"
import AuthTypeRenderer from "./AuthTypeRenderer.svelte"
import RestAuthenticationModal from "./RestAuthenticationModal.svelte"
import { uuid } from "builderStore/uuid"
export let configs = []
@ -20,24 +21,22 @@
const onConfirm = config => {
if (currentConfig) {
// TODO: Update with _id
configs = configs.map(c => {
// replace the current config with the new one
if (c.name === currentConfig.name) {
if (c._id === currentConfig._id) {
return config
}
return c
})
} else {
configs.push(config)
configs = [...configs]
config._id = uuid()
configs = [...configs, config]
}
}
const onDelete = () => {
// TODO: Update with _id
configs = configs.filter(c => {
return c.name !== currentConfig.name
return c._id !== currentConfig._id
})
}
</script>

View file

@ -156,7 +156,6 @@
confirmText={currentConfig ? "Update" : "Add"}
disabled={hasErrors || !hasChanged}
cancelText={"Cancel"}
warning={true}
size="M"
showSecondaryButton={!!currentConfig}
secondaryButtonText={"Delete"}

View file

@ -1,15 +1,15 @@
export const AUTH_TYPES = {
BEARER: "bearer",
BASIC: "basic",
BEARER: "bearer",
}
export const AUTH_TYPE_LABELS = [
{
label: "Bearer Token",
value: AUTH_TYPES.BEARER,
},
{
label: "Basic Auth",
value: AUTH_TYPES.BASIC,
},
{
label: "Bearer Token",
value: AUTH_TYPES.BEARER,
},
]

View file

@ -19,6 +19,7 @@ enum AuthType {
}
interface AuthConfig {
_id: string
name: string
type: AuthType
config: BasicAuthConfig | BearerAuthConfig
@ -170,12 +171,12 @@ module RestModule {
}
}
processAuth(authConfigName: string) {
if (!this.config.authConfigs || !authConfigName) {
processAuth(authConfigId: string) {
if (!this.config.authConfigs || !authConfigId) {
return
}
const authConfig = this.config.authConfigs.filter(
authConfig => authConfig.name === authConfigName
c => c._id === authConfigId
)[0]
let config
switch (authConfig.type) {
@ -198,14 +199,14 @@ module RestModule {
headers = {},
json = {},
method = "GET",
authConfigName = "",
authConfigId = "",
}) {
this.headers = {
...this.config.defaultHeaders,
...headers,
}
this.processAuth(authConfigName)
this.processAuth(authConfigId)
const input: any = { method, headers: this.headers }
if (json && typeof json === "object" && Object.keys(json).length > 0) {

View file

@ -107,6 +107,7 @@ describe("REST Integration", () => {
describe("authentication", () => {
const basicAuth = {
_id: "c59c14bd1898a43baa08da68959b24686",
name: "basic-1",
type : AuthType.BASIC,
config : {
@ -116,6 +117,7 @@ describe("REST Integration", () => {
}
const bearerAuth = {
_id: "0d91d732f34e4befabeff50b392a8ff3",
name: "bearer-1",
type : AuthType.BEARER,
config : {
@ -132,7 +134,7 @@ describe("REST Integration", () => {
it("adds basic auth", async () => {
const query = {
authConfigName: "basic-1"
authConfigId: "c59c14bd1898a43baa08da68959b24686"
}
await config.integration.read(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
@ -145,7 +147,7 @@ describe("REST Integration", () => {
it("adds bearer auth", async () => {
const query = {
authConfigName: "bearer-1"
authConfigId: "0d91d732f34e4befabeff50b392a8ff3"
}
await config.integration.read(query)
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {