Skip to content

Commit

Permalink
Attach config to incoming data attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Nov 7, 2024
1 parent 5bd9ef3 commit a3e249b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 79 deletions.
60 changes: 1 addition & 59 deletions docs/public/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { GalaxyCharts } from "galaxy-charts";
import Plugin from "./Plugin.vue";
defineProps<{
config: object;
credentials?: RequestCredentials;
xml: string;
}>();
</script>

<template>
<GalaxyCharts :config="config" :xml="xml">
<GalaxyCharts :credentials="credentials" :xml="xml">
<template #default="{ datasetId, datasetUrl, root, settings, specs, tracks }">
<Plugin
:dataset-id="datasetId"
Expand Down
8 changes: 3 additions & 5 deletions src/components/GalaxyCharts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useConfigStore } from "@/store/configStore";
import { InputElementType, InputValuesType, PluginConfigType } from "@/types";
const props = defineProps<{
config: PluginConfigType;
credentials?: RequestCredentials;
xml: string;
}>();
Expand All @@ -30,13 +30,11 @@ const trackInputs = ref<Array<InputElementType>>([]);
const trackValues = ref<Array<InputValuesType>>([]);
// Parse incoming visualization details
const { root, visualizationConfig, visualizationId, visualizationPlugin, visualizationTitle } = parseIncoming(
props.config,
);
const { root, visualizationConfig, visualizationId, visualizationPlugin, visualizationTitle } = parseIncoming();
// Store values in config store
const configStore = useConfigStore();
configStore.setCredentials(props.config.credentials || "include");
configStore.setCredentials(props.credentials || "include");
configStore.setRoot(root || "/");
// Collect plugin details and parse incoming settings
Expand Down
27 changes: 16 additions & 11 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import { createApp, h } from "vue";
import App from "./App.vue";

const config = {
credentials: process.env.credentials,
dataset_url: null,
dataset_id: "12e4b4feedfe9f3f",
settings: {
setting_text: "My Test Setting",
setting_boolean: true,
setting_conditional: {
case_false: "something else",
test_condition: "false",
const dataIncoming = {
visualization_config: {
dataset_url: null,
dataset_id: "12e4b4feedfe9f3f",
settings: {
setting_text: "My Test Setting",
setting_boolean: true,
setting_conditional: {
case_false: "something else",
test_condition: "false",
},
},
},
};

const xml = "galaxy-charts.xml";

// Attach config to the data-incoming attribute
const appElement = document.querySelector("#app");
appElement.setAttribute("data-incoming", JSON.stringify(dataIncoming));

createApp({
render: () => h(App, { config: config, xml: xml }),
render: () => h(App, { credentials: process.env.credentials, xml: xml }),
}).mount("#app");
4 changes: 2 additions & 2 deletions src/utilities/parseIncoming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface ParsedIncoming {
visualizationTitle: string;
}

export function parseIncoming(config: PluginConfigType): ParsedIncoming {
export function parseIncoming(): ParsedIncoming {
// Access attached data
const element = document.getElementById("app");
const incoming = JSON.parse(element?.getAttribute("data-incoming") || "{}") || {};
Expand All @@ -20,7 +20,7 @@ export function parseIncoming(config: PluginConfigType): ParsedIncoming {
const visualizationTitle = incoming.visualization_title || "Unnamed Visualization";

// Parse chart dict
let visualizationConfig = incoming.visualization_config || config;
let visualizationConfig = incoming.visualization_config;
if (incoming.visualization_config?.chart_dict) {
const chartDict = incoming.visualization_config.chart_dict;
visualizationConfig.groups = chartDict.groups;
Expand Down

0 comments on commit a3e249b

Please sign in to comment.