Skip to content

Commit

Permalink
clean up diff
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Kusumgar committed Dec 18, 2024
1 parent 4c7926d commit ef39bce
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 53 deletions.
4 changes: 2 additions & 2 deletions app/server/src/controllers/configController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const configDefaults = (appType: string) => {
};

export class ConfigController {
static readAppConfigFile = (
static _readAppConfigFile = (
appName: string,
appsPath: string,
_baseUrl: string,
Expand Down Expand Up @@ -54,7 +54,7 @@ export class ConfigController {
configReader, appsPath, defaultCodeReader, appHelpReader, baseUrl
} = req.app.locals as AppLocals;

const config = this.readAppConfigFile(
const config = this._readAppConfigFile(
appName,
appsPath,
baseUrl,
Expand Down
27 changes: 11 additions & 16 deletions app/static/src/components/WodinSession.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { localStorageManager } from "../localStorageManager";
import { AppStateGetter } from "../store/appState/getters";
import { SessionMetadata } from "../types/responseTypes";
import { SessionsMutation } from "../store/sessions/mutations";
import { STATIC_BUILD } from "@/parseEnv";
export default defineComponent({
name: "WodinSession",
Expand All @@ -32,9 +31,7 @@ export default defineComponent({
const store = useStore();
const initialised = ref(false);
const appInitialised = computed(() => STATIC_BUILD ?
!!store.state.config :
!!store.state.config && !!store.state.sessions.sessionsMetadata);
const appInitialised = computed(() => !!store.state.config && !!store.state.sessions.sessionsMetadata);
// These props won't change as provided by server
// eslint-disable-next-line vue/no-setup-props-destructure
Expand All @@ -58,18 +55,16 @@ export default defineComponent({
});
watch(appInitialised, () => {
if (!STATIC_BUILD) {
// Child component will either be SessionsPage or WodinApp depending on route - both will need the latest
// session id so delay rendering these until this has been committed
const baseUrlPath = store.getters[AppStateGetter.baseUrlPath];
const sessions = localStorageManager.getSessionIds(store.state.appName, baseUrlPath);
const sessionId = sessions.length ? sessions[0] : null;
// check latest session id is actually available from the back end
const sessionAvailable =
sessionId && !!store.state.sessions.sessionsMetadata.find((s: SessionMetadata) => s.id === sessionId);
if (sessionAvailable) {
store.commit(`sessions/${SessionsMutation.SetLatestSessionId}`, sessionId);
}
// Child component will either be SessionsPage or WodinApp depending on route - both will need the latest
// session id so delay rendering these until this has been committed
const baseUrlPath = store.getters[AppStateGetter.baseUrlPath];
const sessions = localStorageManager.getSessionIds(store.state.appName, baseUrlPath);
const sessionId = sessions.length ? sessions[0] : null;
// check latest session id is actually available from the back end
const sessionAvailable =
sessionId && !!store.state.sessions.sessionsMetadata.find((s: SessionMetadata) => s.id === sessionId);
if (sessionAvailable) {
store.commit(`sessions/${SessionsMutation.SetLatestSessionId}`, sessionId);
}
initialised.value = true;
});
Expand Down
8 changes: 6 additions & 2 deletions app/static/src/components/WodinTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@
<script lang="ts">
import { defineComponent, ref, PropType } from "vue";
interface Props {
tabNames: string[];
}
export default defineComponent({
name: "WodinTabs",
props: {
tabNames: { type: Array as PropType<readonly string[]>, required: true }
tabNames: { type: Array as PropType<string[]>, required: true }
},
emits: ["tabSelected"],
setup(props, { emit }) {
setup(props: Props, { emit }) {
// eslint-disable-next-line vue/no-setup-props-destructure
const selectedTabName = ref(props.tabNames[0]);
Expand Down
2 changes: 1 addition & 1 deletion app/static/src/components/code/CodeEditor.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div>
<button
v-if="defaultCodeExists && !readOnly"
v-if="defaultCodeExists"
class="btn btn-primary btn-sm mb-2"
id="reset-btn"
v-help="'resetCode'"
Expand Down
29 changes: 12 additions & 17 deletions app/static/src/components/code/CodeTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@
<div v-if="appIsConfigured" class="code-tab">
<generic-help title="Write odin code" :markdown="codeHelp"></generic-help>
<code-editor />
<div v-if="!readOnly">
<button class="btn btn-primary mt-2" id="compile-btn" :disabled="!codeIsValid" @click="compile">Compile</button>
<div class="mt-2" id="code-status" :class="codeValidating ? 'code-validating-text' : ''">
<vue-feather
class="inline-icon me-1"
:class="iconClass"
:type="validIcon"
:size="20"
:stroke-width="4"
></vue-feather>
{{ validMsg }}
</div>
<error-info :error="error"></error-info>
<button class="btn btn-primary mt-2" id="compile-btn" :disabled="!codeIsValid" @click="compile">Compile</button>
<div class="mt-2" id="code-status" :class="codeValidating ? 'code-validating-text' : ''">
<vue-feather
class="inline-icon me-1"
:class="iconClass"
:type="validIcon"
:size="20"
:stroke-width="4"
></vue-feather>
{{ validMsg }}
</div>
<error-info :error="error"></error-info>
<div class="mt-3">
<graph-configs-collapsible></graph-configs-collapsible>
</div>
Expand All @@ -33,7 +31,6 @@ import userMessages from "../../userMessages";
import ErrorInfo from "../ErrorInfo.vue";
import GenericHelp from "../help/GenericHelp.vue";
import GraphConfigsCollapsible from "../graphConfig/GraphConfigsCollapsible.vue";
import { AppConfig } from "@/types/responseTypes";
export default defineComponent({
name: "CodeTab",
Expand All @@ -47,7 +44,6 @@ export default defineComponent({
},
setup() {
const store = useStore();
const readOnly = computed(() => (store.state.config as AppConfig).readOnlyCode);
const codeIsValid = computed(() => store.state.model.odinModelResponse?.valid);
const codeValidating = computed(() => store.state.code.loading);
const error = computed(() => store.state.model.odinModelCodeError);
Expand All @@ -70,8 +66,7 @@ export default defineComponent({
error,
codeHelp,
codeValidating,
loadingMessage,
readOnly
loadingMessage
};
}
});
Expand Down
6 changes: 2 additions & 4 deletions app/static/src/components/header/AppHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<a class="navbar-brand pl-2" :href="baseUrl">{{ courseTitle }}</a>
<span class="nav-item navbar-app">{{ appTitle }}</span>
</span>
<span v-if="!STATIC_BUILD" class="nav-item dropdown">
<span class="nav-item dropdown">
<a
id="sessions-menu"
class="nav-link dropdown-toggle"
Expand Down Expand Up @@ -57,7 +57,6 @@ import EditSessionLabel from "../sessions/EditSessionLabel.vue";
import VersionMenu from "./VersionMenu.vue";
import { LanguageSwitcher } from "../../../translationPackage";
import { Language } from "../../types/languageTypes";
import { STATIC_BUILD } from "@/parseEnv";
type LanguagesKeys = Record<Language, string>;
Expand Down Expand Up @@ -107,8 +106,7 @@ export default defineComponent({
sessionLabel,
sessionMenuHeader,
sessionPersisted,
languagesKeys,
STATIC_BUILD
languagesKeys
};
}
});
Expand Down
10 changes: 2 additions & 8 deletions app/static/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,8 @@ export function initialiseRouter(
return createRouter({
history: createWebHistory(routeBase),
routes: [
{
path: "/",
component: appComponent
},
{
path: "/sessions",
component: SessionsPage
}
{ path: "/", component: appComponent },
{ path: "/sessions", component: SessionsPage }
]
});
}
6 changes: 3 additions & 3 deletions app/static/tests/unit/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe("router", () => {
});

it("can initialise router", () => {
const router = initialiseRouter(WodinSession as any, "day1", "http://localhost:3000", "apps");
const router = initialiseRouter(WodinSession, "day1", "http://localhost:3000", "apps");
expect(router).toBe(mockRouter);
expect(mockCreateWebHistory).toHaveBeenCalledTimes(1);
expect(mockCreateWebHistory).toHaveBeenCalledWith("/apps/day1");
Expand All @@ -75,7 +75,7 @@ describe("router", () => {

it("initialiseRouter removes session id from current url", () => {
window.location.href = "http://localhost:3000/apps/day1/?sessionId=9876";
const router = initialiseRouter(WodinSession as any, "day1", "http://localhost:3000", "apps");
const router = initialiseRouter(WodinSession, "day1", "http://localhost:3000", "apps");
expect(router).toBe(mockRouter);

expect(mockPushState).toHaveBeenCalledTimes(1);
Expand All @@ -85,7 +85,7 @@ describe("router", () => {
});

it("include baseUrl path in routeBase", () => {
const router = initialiseRouter(WodinSession as any, "day1", "http://localhost:3000/test", "apps");
const router = initialiseRouter(WodinSession, "day1", "http://localhost:3000/test", "apps");
expect(router).toBe(mockRouter);
expect(mockCreateWebHistory).toHaveBeenCalledTimes(1);
expect(mockCreateWebHistory).toHaveBeenCalledWith("/test/apps/day1");
Expand Down

0 comments on commit ef39bce

Please sign in to comment.