Skip to content

Commit

Permalink
fix: random warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
MiniDigger committed Jul 25, 2024
1 parent af7ff65 commit 322a8f3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/design/Spinner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const circleRadius = computed(() => (props.diameter - props.stroke) / 2);
const circleCircumference = computed(() => 2 * Math.PI * circleRadius.value);
watch(
props,
() => props,
() => {
attachSvgStyle();
attachCircleStyle();
Expand Down
22 changes: 10 additions & 12 deletions frontend/src/components/modals/NewPageModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ const updateProjectPagesCallback = inject<(pages: HangarProjectPage[]) => void>(
const modal = ref<any | null>(null); // Filled by vue
const pageRoots = computed(() => [{ value: -1, text: "<none>" }, ...flatDeep(props.pages, "")]);
const name = ref("");
const parent = ref<number>();
const loading = ref<boolean>(false);
const body = computed(() => ({
const body = reactive({
projectId: props.projectId,
name: name.value,
parentId: parent.value === -1 ? undefined : parent.value,
}));
name: "",
parentId: undefined as number | undefined,
});
const rules = [
required(),
maxLength()(useBackendData.validations.project.pageName.max!),
Expand All @@ -49,12 +47,12 @@ async function createPage() {
loading.value = true;
if (!(await v.value.$validate())) return;
const slug = await useInternalApi<string>(`pages/create/${props.projectId}`, "post", {
name: name.value,
parentId: parent.value === -1 ? null : parent.value,
name: body.name,
parentId: body.parentId === -1 ? null : body.parentId,
});
name.value = "";
parent.value = undefined;
body.name = "";
body.parentId = undefined;
if (updateProjectPagesCallback) {
updateProjectPagesCallback(await useInternalApi<HangarProjectPage[]>(`pages/list/${props.projectId}`, "get"));
Expand All @@ -74,14 +72,14 @@ async function createPage() {
<Modal ref="modal" :title="i18n.t('page.new.title')" window-classes="w-120">
<div class="flex flex-col">
<InputText
v-model.trim="name"
v-model.trim="body.name"
:label="i18n.t('page.new.name')"
counter
:maxlength="useBackendData.validations.project.pageName.max"
:minlength="useBackendData.validations.project.pageName.min"
:rules="rules"
/>
<InputSelect v-model="parent" :values="pageRoots" :label="i18n.t('page.new.parent')" class="pt-2 pb-1" />
<InputSelect v-model="body.parentId" :values="pageRoots" :label="i18n.t('page.new.parent')" class="pt-2 pb-1" />
</div>
<div>
<Button class="mt-3" :disabled="loading" @click="createPage">{{ i18n.t("general.create") }}</Button>
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/composables/useErrorHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ import type { AxiosError } from "axios";
import { isAxiosError } from "axios";
import type { Composer } from "vue-i18n";
import type { HangarApiException, HangarValidationException, MultiHangarApiException } from "~/types/backend";
import { tryUseNuxtApp } from "#app/nuxt";

export function handleRequestError(err: AxiosError | unknown, msg: string | undefined = undefined, alwaysShowErrorPage = false) {
const i18n = useNuxtApp().$i18n;
const i18n = tryUseNuxtApp()?.$i18n;
if (!i18n) {
console.error("didnt find i18n!");
_handleRequestError(err, i18n);
return;
}
if (import.meta.env.SSR || alwaysShowErrorPage) {
_handleRequestError(err, i18n);
}
Expand Down Expand Up @@ -55,7 +61,7 @@ export function handleRequestError(err: AxiosError | unknown, msg: string | unde
}
}

function _handleRequestError(err: AxiosError | unknown, i18n: Composer) {
function _handleRequestError(err: AxiosError | unknown, i18n?: Composer) {
const transformed = transformAxiosError(err);
if (!isAxiosError(err)) {
// everything should be an AxiosError
Expand All @@ -69,7 +75,7 @@ function _handleRequestError(err: AxiosError | unknown, i18n: Composer) {
"isMultiException" in err.response.data ? (err.response.data as MultiHangarApiException).exceptions?.[0] : (err.response.data as HangarApiException);
createError({
statusCode: data?.httpError.statusCode,
statusMessage: data?.message ? (i18n.te(data.message) ? i18n.t(data.message) : data.message) : undefined,
statusMessage: data?.message ? (i18n?.te(data.message) ? i18n.t(data.message) : data.message) : undefined,
});
} else if ("isHangarValidationException" in err.response.data) {
const data = err.response.data as HangarValidationException;
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/composables/useValidationHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type ErrorObject, useVuelidate, type ValidationRule } from "@vuelidate/core";
import type { ComputedRef, Ref } from "vue";
import type { Ref } from "vue";
import * as validators from "@vuelidate/validators";
import { createI18nMessage, helpers, type ValidatorWrapper } from "@vuelidate/validators";
import { difference, isEmpty, uniq } from "lodash-es";
Expand Down Expand Up @@ -98,12 +98,12 @@ export const noDuplicated = withOverrideMessage((elements: any[] | (() => any[])
})
);

export const validPageName = withOverrideMessage((body: ComputedRef<{ projectId: number; parentId?: number; name: string }>) =>
export const validPageName = withOverrideMessage((body: { projectId: number; parentId?: number; name: string }) =>
helpers.withParams(
{ body, type: "validPageName" },
helpers.withAsync(async () => {
try {
await useInternalApi("pages/checkName", "get", body.value);
await useInternalApi("pages/checkName", "get", body);
return { $valid: true };
} catch (e: AxiosError | any) {
if (e?.response?.data?.detail) {
Expand Down

0 comments on commit 322a8f3

Please sign in to comment.