Skip to content

Commit

Permalink
extract STATIC_BUILD from app vue files
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Kusumgar committed Dec 3, 2024
1 parent 16e61ec commit 4a62a0b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/static/src/components/WodinTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { defineComponent, ref, PropType } from "vue";
export default defineComponent({
name: "WodinTabs",
props: {
tabNames: { type: Array as PropType<string[]>, required: true },
tabNames: { type: Array as PropType<readonly string[]>, required: true },
initSelectedTab: { type: String }
},
emits: ["tabSelected"],
Expand Down
12 changes: 8 additions & 4 deletions app/static/src/components/basic/BasicApp.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<wodin-app>
<template v-slot:left>
<wodin-tabs id="left-tabs" :tabNames="['Code', 'Options']" :init-selected-tab="STATIC_BUILD ? 'Options' : undefined">
<wodin-tabs id="left-tabs" :tabNames="leftTabNames" :init-selected-tab="initSelectedTab">
<template v-slot:Code>
<code-tab></code-tab>
</template>
Expand Down Expand Up @@ -30,7 +30,7 @@
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { defineComponent, PropType } from "vue";
import { useStore } from "vuex";
import WodinApp from "../WodinApp.vue";
import WodinTabs from "../WodinTabs.vue";
Expand All @@ -43,7 +43,8 @@ import { AppStateMutation } from "../../store/appState/mutations";
import { VisualisationTab } from "../../store/appState/state";
import HelpTab from "../help/HelpTab.vue";
import includeConfiguredTabs from "../mixins/includeConfiguredTabs";
import { STATIC_BUILD } from "@/parseEnv";
const leftTabNames = ['Code', 'Options'] as const;
export default defineComponent({
name: "BasicApp",
Expand All @@ -57,6 +58,9 @@ export default defineComponent({
WodinApp,
WodinTabs
},
props: {
initSelectedTab: { type: String as PropType<typeof leftTabNames[number]>, required: false }
},
setup() {
const store = useStore();
const rightTabSelected = (tab: string) => {
Expand All @@ -72,7 +76,7 @@ export default defineComponent({
helpTabName,
multiSensitivityTabName,
rightTabNames,
STATIC_BUILD
leftTabNames
};
}
});
Expand Down
12 changes: 8 additions & 4 deletions app/static/src/components/fit/FitApp.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<wodin-app>
<template v-slot:left>
<wodin-tabs id="left-tabs" :tabNames="['Data', 'Code', 'Options']" :init-selected-tab="STATIC_BUILD ? 'Options' : undefined">
<wodin-tabs id="left-tabs" :tabNames="['Data', 'Code', 'Options']" :init-selected-tab="initSelectedTab">
<template v-slot:Data>
<data-tab></data-tab>
</template>
Expand Down Expand Up @@ -36,7 +36,7 @@
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { defineComponent, PropType } from "vue";
import { useStore } from "vuex";
import MultiSensitivityTab from "@/components/multiSensitivity/MultiSensitivityTab.vue";
import WodinApp from "../WodinApp.vue";
Expand All @@ -51,7 +51,8 @@ import SensitivityTab from "../sensitivity/SensitivityTab.vue";
import { VisualisationTab } from "../../store/appState/state";
import { AppStateMutation } from "../../store/appState/mutations";
import includeConfiguredTabs from "../mixins/includeConfiguredTabs";
import { STATIC_BUILD } from "@/parseEnv";
const leftTabNames = ['Data', 'Code', 'Options'] as const;
export default defineComponent({
name: "FitApp",
Expand All @@ -67,6 +68,9 @@ export default defineComponent({
WodinApp,
WodinTabs
},
props: {
initSelectedTab: { type: String as PropType<typeof leftTabNames[number]>, required: false }
},
setup() {
const store = useStore();
Expand All @@ -83,7 +87,7 @@ export default defineComponent({
helpTabName,
rightTabNames,
rightTabSelected,
STATIC_BUILD
leftTabNames
};
}
});
Expand Down
12 changes: 8 additions & 4 deletions app/static/src/components/stochastic/StochasticApp.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<wodin-app>
<template v-slot:left>
<wodin-tabs id="left-tabs" :tabNames="['Code', 'Options']" :init-selected-tab="STATIC_BUILD ? 'Options' : undefined">
<wodin-tabs id="left-tabs" :tabNames="leftTabNames" :init-selected-tab="initSelectedTab">
<template v-slot:Code>
<code-tab></code-tab>
</template>
Expand Down Expand Up @@ -30,7 +30,7 @@
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { defineComponent, PropType } from "vue";
import { useStore } from "vuex";
import MultiSensitivityTab from "@/components/multiSensitivity/MultiSensitivityTab.vue";
import { VisualisationTab } from "../../store/appState/state";
Expand All @@ -43,7 +43,8 @@ import OptionsTab from "../options/OptionsTab.vue";
import SensitivityTab from "../sensitivity/SensitivityTab.vue";
import includeConfiguredTabs from "../mixins/includeConfiguredTabs";
import HelpTab from "../help/HelpTab.vue";
import { STATIC_BUILD } from "@/parseEnv";
const leftTabNames = ['Code', 'Options'] as const;
export default defineComponent({
name: "StochasticApp",
Expand All @@ -57,6 +58,9 @@ export default defineComponent({
WodinApp,
WodinTabs
},
props: {
initSelectedTab: { type: String as PropType<typeof leftTabNames[number]>, required: false }
},
setup() {
const store = useStore();
const rightTabSelected = (tab: string) => {
Expand All @@ -71,7 +75,7 @@ export default defineComponent({
helpTabName,
rightTabNames,
rightTabSelected,
STATIC_BUILD
leftTabNames
};
}
});
Expand Down
29 changes: 19 additions & 10 deletions app/static/src/router.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { createRouter, createWebHistory, RouteComponent, Router } from "vue-router";
import { createRouter, createWebHistory, Router, RouteRecordRaw } from "vue-router";
import SessionsPage from "./components/sessions/SessionsPage.vue";
import { STATIC_BUILD } from "./parseEnv";
import type BasicApp from "./components/basic/BasicApp.vue";
import type FitApp from "./components/fit/FitApp.vue";
import type StochasticApp from "./components/stochastic/StochasticApp.vue";

export function initialiseRouter(
appComponent: RouteComponent,
appComponent: typeof BasicApp | typeof FitApp | typeof StochasticApp,
appName: string,
baseUrl: string,
appsPath: string
Expand All @@ -23,15 +26,21 @@ export function initialiseRouter(
}
const routeBase = `${basePath}/${appsPath}/${appName}`;

const appRoute: RouteRecordRaw = {
path: "/",
component: appComponent,
props: {
initSelectedTab: STATIC_BUILD ? "Options" : undefined
} as Parameters<NonNullable<(typeof appComponent)["setup"]>>["0"]
};

const sessionsRoute: RouteRecordRaw = {
path: "/sessions",
component: SessionsPage
};

return createRouter({
history: createWebHistory(routeBase),
routes: STATIC_BUILD ?
[
{ path: "/", component: appComponent },
] :
[
{ path: "/", component: appComponent },
{ path: "/sessions", component: SessionsPage }
]
routes: STATIC_BUILD ? [ appRoute ] : [ appRoute, sessionsRoute ]
});
}

0 comments on commit 4a62a0b

Please sign in to comment.