From a259c0a8ee43c96ca512e20b6bcc854457fafcef Mon Sep 17 00:00:00 2001 From: guerler Date: Wed, 6 Nov 2024 09:06:08 +0300 Subject: [PATCH] Convert components to typescript --- public/galaxy-charts.xml | 15 +++ src/components/ApiStatus.vue | 4 +- src/components/GalaxyCharts.vue | 78 ++++++------- src/components/InputConditional.vue | 89 +++++++++------ src/components/InputData.vue | 43 ++++--- src/components/InputDataColumn.vue | 43 +++---- src/components/InputForm.vue | 69 +++++++---- src/components/InputRepeats.vue | 49 ++++---- src/components/SidePanel.vue | 107 +++++++----------- src/main.js | 2 +- src/types.ts | 1 + .../{parseIncoming.js => parseIncoming.ts} | 34 +++++- src/utilities/toBoolean.ts | 4 +- 13 files changed, 295 insertions(+), 243 deletions(-) create mode 100644 src/types.ts rename src/utilities/{parseIncoming.js => parseIncoming.ts} (51%) diff --git a/public/galaxy-charts.xml b/public/galaxy-charts.xml index aa27f62..ca4da87 100644 --- a/public/galaxy-charts.xml +++ b/public/galaxy-charts.xml @@ -21,6 +21,21 @@ spec_type + + + My Data ColumnHelp + my_data_column_name + data_column + + + + My Float Help + my_float_name + float + 1 + 0 + 100 + setting_text diff --git a/src/components/ApiStatus.vue b/src/components/ApiStatus.vue index 788d91e..54a12ed 100644 --- a/src/components/ApiStatus.vue +++ b/src/components/ApiStatus.vue @@ -1,10 +1,10 @@ - diff --git a/src/components/InputConditional.vue b/src/components/InputConditional.vue index bd7cd4d..f39681c 100644 --- a/src/components/InputConditional.vue +++ b/src/components/InputConditional.vue @@ -1,77 +1,98 @@ - diff --git a/src/components/InputDataColumn.vue b/src/components/InputDataColumn.vue index bc31fbf..f48ea91 100644 --- a/src/components/InputDataColumn.vue +++ b/src/components/InputDataColumn.vue @@ -1,33 +1,23 @@ - diff --git a/src/main.js b/src/main.js index fe17090..130cd45 100644 --- a/src/main.js +++ b/src/main.js @@ -4,7 +4,7 @@ import App from "./App.vue"; const config = { credentials: process.env.credentials, dataset_url: null, - dataset_id: "unavailable", + dataset_id: "12e4b4feedfe9f3f", settings: { setting_text: "My Test Setting", setting_boolean: true, diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..a9b50c5 --- /dev/null +++ b/src/types.ts @@ -0,0 +1 @@ +type InputValueType = boolean | string | number | null | undefined; \ No newline at end of file diff --git a/src/utilities/parseIncoming.js b/src/utilities/parseIncoming.ts similarity index 51% rename from src/utilities/parseIncoming.js rename to src/utilities/parseIncoming.ts index 5ba17eb..afa2337 100644 --- a/src/utilities/parseIncoming.js +++ b/src/utilities/parseIncoming.ts @@ -1,21 +1,43 @@ -export function parseIncoming(config) { - // access attached data +interface Config { + root?: string; + title?: string; + visualization_config?: { + chart_dict?: { + groups?: any; + settings?: any; + }; + [key: string]: any; + }; + [key: string]: any; +} + +interface ParsedIncoming { + root: string; + visualizationConfig: Config; + visualizationId?: string; + visualizationPlugin?: any; + visualizationTitle: string; +} + +export function parseIncoming(config: Config): ParsedIncoming { + // Access attached data const element = document.getElementById("app"); - const incoming = JSON.parse(element.getAttribute("data-incoming")) || {}; + const incoming = JSON.parse(element?.getAttribute("data-incoming") || "{}") || {}; - // parse incoming data + // Parse incoming data const root = incoming.root || config?.root || "/"; const visualizationId = incoming.visualization_id; const visualizationPlugin = incoming.visualization_plugin; const visualizationTitle = incoming.visualization_title || config?.title || "Unnamed Visualization"; - // parse chart dict + // Parse chart dict let visualizationConfig = incoming.visualization_config || config; if (incoming.visualization_config?.chart_dict) { const chartDict = incoming.visualization_config.chart_dict; visualizationConfig.groups = chartDict.groups; visualizationConfig.settings = chartDict.settings; - delete visualizationConfig["chartDict"]; + delete visualizationConfig["chart_dict"]; } + return { root, visualizationConfig, visualizationId, visualizationPlugin, visualizationTitle }; } diff --git a/src/utilities/toBoolean.ts b/src/utilities/toBoolean.ts index 8d1c14d..868d68f 100644 --- a/src/utilities/toBoolean.ts +++ b/src/utilities/toBoolean.ts @@ -1,3 +1,5 @@ -export function toBoolean(value: string | boolean | undefined) { +import { type InputValueType } from "@/types"; + +export function toBoolean(value: InputValueType) { return String(value).toLowerCase() === "true"; }