From e6a81f2106903330058a644c21b191904fdac359 Mon Sep 17 00:00:00 2001 From: melohagan <101575380+melohagan@users.noreply.github.com> Date: Mon, 19 Dec 2022 08:23:24 +0000 Subject: [PATCH] External datasource ordering (#9048) * Sort external datasources * lint * Refactor --- .../modals/CreateDatasourceModal.svelte | 28 +++++++++++++++++-- .../builder/src/constants/backend/index.js | 9 ++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte index 8155fce70c..a07829eb58 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte @@ -11,7 +11,7 @@ import { onMount } from "svelte" import ICONS from "../icons" import { API } from "api" - import { IntegrationTypes } from "constants/backend" + import { IntegrationTypes, DatasourceTypes } from "constants/backend" import CreateTableModal from "components/backend/TableNavigator/modals/CreateTableModal.svelte" import DatasourceConfigModal from "components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte" import GoogleDatasourceConfigModal from "components/backend/DatasourceNavigator/modals/GoogleDatasourceConfigModal.svelte" @@ -31,6 +31,7 @@ $: customIntegrations = Object.entries(integrations).filter( entry => entry[1].custom ) + $: sortedIntegrations = sortIntegrations(integrations) checkShowImport() @@ -99,6 +100,29 @@ } integrations = newIntegrations } + + function sortIntegrations(integrations) { + let integrationsArray = Object.entries(integrations) + function getTypeOrder(schema) { + if (schema.type === DatasourceTypes.API) { + return 1 + } + if (schema.type === DatasourceTypes.RELATIONAL) { + return 2 + } + return schema.type?.charCodeAt(0) + } + + integrationsArray.sort((a, b) => { + let typeOrderA = getTypeOrder(a[1]) + let typeOrderB = getTypeOrder(b[1]) + if (typeOrderA === typeOrderB) { + return a[1].friendlyName?.localeCompare(b[1].friendlyName) + } + return typeOrderA < typeOrderB ? -1 : 1 + }) + return integrationsArray + } @@ -157,7 +181,7 @@ Connect to an external datasource
- {#each Object.entries(integrations).filter(([key, val]) => key !== IntegrationTypes.INTERNAL && !val.custom) as [integrationType, schema]} + {#each sortedIntegrations.filter(([key, val]) => key !== IntegrationTypes.INTERNAL && !val.custom) as [integrationType, schema]} selectIntegration(evt.detail)} {schema} diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js index 35e250d459..40e6e753a8 100644 --- a/packages/builder/src/constants/backend/index.js +++ b/packages/builder/src/constants/backend/index.js @@ -261,3 +261,12 @@ export const BannedSearchTypes = [ "json", "jsonarray", ] + +export const DatasourceTypes = { + RELATIONAL: "Relational", + NON_RELATIONAL: "Non-relational", + SPREADSHEET: "Spreadsheet", + OBJECT_STORE: "Object store", + GRAPH: "Graph", + API: "API", +}