Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/#74 unused event types #218

Merged
merged 4 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/shared/lib/use-events/normalize-unknown-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { ServerEvent, NormalizedEvent } from "../../types";
export const normalizeUnknownEvent = (event: ServerEvent<unknown>): NormalizedEvent<unknown> => ({
id: event.uuid,
type: 'unknown',
labels: [event.type],
labels: [String(event.type)],
origin: null,
serverName: "",
date: event.timestamp ? new Date(event.timestamp * 1000) : null,
Expand Down
12 changes: 10 additions & 2 deletions src/shared/stores/events/events-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {PAGE_TYPES} from "../../constants";
import {useSettings} from "../../lib/use-settings";
import type {EventId, EventType, ServerEvent, TEventsGroup, TProjects} from '../../types';
import {EVENT_TYPES} from "../../types";
import {useSettingsStore} from "../settings";
import {
getStoredLockedIds,
setStoredCachedIds,
Expand Down Expand Up @@ -84,13 +85,20 @@ export const useEventsStore = defineStore("eventsStore", {
},
// events
initializeEvents (events: ServerEvent<unknown>[]): void {
this.events = events.slice(0, MAX_EVENTS_COUNT);
const { availableEvents } = useSettingsStore();

this.events = events
.filter((el) => availableEvents.includes(el.type as EventType))
.slice(0, MAX_EVENTS_COUNT);

this.syncCachedWithActive(events.map(({ uuid }) => uuid));
this.initActiveProjectKey();
},
addList(events: ServerEvent<unknown>[]): void {
events.forEach((event) => {
const { availableEvents } = useSettingsStore();
events
.filter((el) => availableEvents.includes(el.type as EventType))
.forEach((event) => {
const isExistedEvent: boolean = this.events.some((el): boolean => el.uuid === event.uuid);
if (!isExistedEvent) {
this.events.unshift(event)
Expand Down
6 changes: 5 additions & 1 deletion src/shared/stores/settings/settings-store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {defineStore} from "pinia";
import {REST_API_URL} from "../../lib/io/constants";
import type { TSettings } from "../../types";
import {EVENT_TYPES, type EventType, type TSettings} from "../../types";
import {THEME_MODES} from "./constants";
import {
getStoredEventsCountVisibility,
Expand All @@ -23,6 +23,7 @@ export const useSettingsStore = defineStore("settingsStore", {
themeType: getStoredActiveTheme(),
isFixedHeader: getStoredFixedHeader(),
isVisibleEventCounts: getStoredEventsCountVisibility(),
availableEvents: [] as EventType[],
}),
actions: {
async fetchSettings() {
Expand All @@ -44,6 +45,9 @@ export const useSettingsStore = defineStore("settingsStore", {
this.authLogicUrl = settings.auth.login_url;
}

// TODO: meed to move to the events store
this.availableEvents = settings?.client?.events ?? Object.values(EVENT_TYPES);

this.isFetched = true

return settings
Expand Down
2 changes: 1 addition & 1 deletion src/shared/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type EventType = OneOfValues<typeof EVENT_TYPES>;

export interface ServerEvent<T> {
uuid: EventId,
type: EventType | string,
type: EventType | unknown,
payload: T,
project: string | null,
timestamp: number // unavailable for some ray dump events
Expand Down
5 changes: 5 additions & 0 deletions src/shared/types/settings.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {type EventType} from "./events";

export type TProfile = {
username: string,
email: string,
Expand All @@ -10,6 +12,9 @@ export type TSettings = {
login_url: string,
},
version: string,
client: {
events: EventType[],
}
}


Expand Down
8 changes: 6 additions & 2 deletions src/widgets/ui/layout-sidebar/layout-sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const logout = () => {

const path = computed(() => useRoute().path);

const { apiVersion } = storeToRefs(useSettingsStore());
const { apiVersion, availableEvents } = storeToRefs(useSettingsStore());

const clientVersion = ref(
!version || version === "0.0.1" ? "@dev" : `v${version}`,
Expand All @@ -122,6 +122,10 @@ const setProject = (projectKey: string) => {
isVisibleProjects.value = false;
};

const filteredNavOrder = computed(() =>
EVENTS_NAV_ORDER.filter((type) => availableEvents.value.includes(type)),
);

const makeShortTitle = (title: string) => (title || "").substring(0, 2);
const generateRadialGradient = (input: string) =>
`linear-gradient(to right, ${textToColors(input || "").join(", ")})`;
Expand Down Expand Up @@ -170,7 +174,7 @@ const generateRadialGradient = (input: string) =>
</NuxtLink>
</template>

<template v-for="type in EVENTS_NAV_ORDER" :key="type">
<template v-for="type in filteredNavOrder" :key="type">
<NuxtLink
:to="EVENTS_LINKS_MAP[type].path"
:title="EVENTS_LINKS_MAP[type].title"
Expand Down
Loading