-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15198 from Budibase/chore/datasource-store-typing
Typing datasource and sorted integration stores
- Loading branch information
Showing
9 changed files
with
139 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { integrations } from "./integrations" | ||
import { derived } from "svelte/store" | ||
|
||
import { DatasourceTypes } from "constants/backend" | ||
import { UIIntegration, Integration } from "@budibase/types" | ||
|
||
const getIntegrationOrder = (type: string | undefined) => { | ||
// if type is not known, sort to end | ||
if (!type) { | ||
return Number.MAX_SAFE_INTEGER | ||
} | ||
if (type === DatasourceTypes.API) return 1 | ||
if (type === DatasourceTypes.RELATIONAL) return 2 | ||
if (type === DatasourceTypes.NON_RELATIONAL) return 3 | ||
|
||
// Sort all others arbitrarily by the first character of their name. | ||
// Character codes can technically be as low as 0, so make sure the number is at least 4 | ||
return type.charCodeAt(0) + 4 | ||
} | ||
|
||
export const createSortedIntegrationsStore = () => { | ||
return derived<typeof integrations, UIIntegration[]>( | ||
integrations, | ||
$integrations => { | ||
const entries: [string, Integration][] = Object.entries($integrations) | ||
const integrationsAsArray = entries.map(([name, integration]) => ({ | ||
name, | ||
...integration, | ||
})) | ||
|
||
return integrationsAsArray.sort((integrationA, integrationB) => { | ||
const integrationASortOrder = getIntegrationOrder(integrationA.type) | ||
const integrationBSortOrder = getIntegrationOrder(integrationB.type) | ||
if (integrationASortOrder === integrationBSortOrder) { | ||
return integrationA.friendlyName.localeCompare( | ||
integrationB.friendlyName | ||
) | ||
} | ||
|
||
return integrationASortOrder < integrationBSortOrder ? -1 : 1 | ||
}) | ||
} | ||
) | ||
} | ||
|
||
export const sortedIntegrations = createSortedIntegrationsStore() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ export * from "./sdk" | |
export * from "./api" | ||
export * from "./core" | ||
export * from "./shared" | ||
export * from "./ui" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./stores" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./integration" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Integration } from "@budibase/types" | ||
|
||
export interface UIIntegration extends Integration { | ||
name: string | ||
} |