remove undefineds from integrations to satisfy response type
This commit is contained in:
parent
0146b1c389
commit
ba834a8cfc
|
@ -1,34 +1,27 @@
|
|||
import { writable, type Writable } from "svelte/store"
|
||||
import { API } from "api"
|
||||
import { Integration, SourceName } from "@budibase/types"
|
||||
import { Integration } from "@budibase/types"
|
||||
|
||||
type IntegrationsState = Record<SourceName, Integration | undefined>
|
||||
type IntegrationsState = Record<string, Integration>
|
||||
|
||||
const INITIAL_STATE: IntegrationsState = {
|
||||
[SourceName.POSTGRES]: undefined,
|
||||
[SourceName.DYNAMODB]: undefined,
|
||||
[SourceName.MONGODB]: undefined,
|
||||
[SourceName.ELASTICSEARCH]: undefined,
|
||||
[SourceName.COUCHDB]: undefined,
|
||||
[SourceName.SQL_SERVER]: undefined,
|
||||
[SourceName.S3]: undefined,
|
||||
[SourceName.AIRTABLE]: undefined,
|
||||
[SourceName.MYSQL]: undefined,
|
||||
[SourceName.ARANGODB]: undefined,
|
||||
[SourceName.REST]: undefined,
|
||||
[SourceName.FIRESTORE]: undefined,
|
||||
[SourceName.GOOGLE_SHEETS]: undefined,
|
||||
[SourceName.REDIS]: undefined,
|
||||
[SourceName.SNOWFLAKE]: undefined,
|
||||
[SourceName.ORACLE]: undefined,
|
||||
[SourceName.BUDIBASE]: undefined,
|
||||
}
|
||||
const INITIAL_STATE: IntegrationsState = {}
|
||||
|
||||
const createIntegrationsStore = () => {
|
||||
const store: Writable<IntegrationsState> = writable(INITIAL_STATE)
|
||||
|
||||
const init = async () => {
|
||||
const integrations = await API.getIntegrations()
|
||||
const response = await API.getIntegrations()
|
||||
|
||||
// Filter out undefineds
|
||||
const integrations = Object.entries(response).reduce(
|
||||
(acc, [key, value]) => {
|
||||
if (value) {
|
||||
acc[key] = value
|
||||
}
|
||||
return acc
|
||||
},
|
||||
{} as IntegrationsState
|
||||
)
|
||||
store.set(integrations)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue