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

feat: preference #2458

Merged
merged 7 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
19 changes: 15 additions & 4 deletions src/components/Configs/Changes/ConfigChangeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useState } from "react";
import ConfigLink from "../ConfigLink/ConfigLink";
import MRTConfigListTagsCell from "../ConfigList/Cells/MRTConfigListTagsCell";
import { ConfigDetailChangeModal } from "./ConfigDetailsChanges/ConfigDetailsChanges";
import { DateTimePreferenceOptions } from "@flanksource-ui/store/preference.state";

export const paramsToReset = {
configChanges: ["pageIndex", "pageSize"]
Expand All @@ -29,7 +30,12 @@ export function ConfigChangeDateCell({
<Age from={dateString} />
{(count || 1) > 1 && (
<span className="inline-block pl-1 text-gray-500">
(x{count} over <Age from={firstObserved} />)
(x{count} over{" "}
<Age
dateTimePreferenceOverride={DateTimePreferenceOptions.Short}
from={firstObserved}
/>
)
</span>
)}
</div>
Expand All @@ -45,18 +51,23 @@ const configChangesColumn: MRT_ColumnDef<ConfigChange>[] = [
meta: {
cellClassName: "text-ellipsis overflow-hidden"
},
maxSize: 70,
maxSize: 160,
Cell: ({ cell, row, column }) => {
const dateString = row?.getValue<string>(column.id);
const firstObserved = row?.original.first_observed;
const count = row.original.count;

return (
<div className="text-xs">
<Age from={dateString} />
<Age from={dateString} suffix={true} />
{(count || 1) > 1 && (
<span className="inline-block pl-1 text-gray-500">
(x{count} over <Age from={firstObserved} />)
(x{count} over{" "}
<Age
dateTimePreferenceOverride={DateTimePreferenceOptions.Short}
from={firstObserved}
/>
)
</span>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ export function ConfigTypesDropdown({
}
);

console.log(field.value);

return (
<MultiSelectDropdown
isLoading={isLoading}
Expand Down
8 changes: 7 additions & 1 deletion src/components/Notifications/NotificationSendHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useSearchParams } from "react-router-dom";
import NotificationDetailsModal from "./NotificationDetailsModal";
import NotificationResourceDisplay from "./NotificationResourceDisplay";
import { NotificationStatusCell } from "./NotificationsStatusCell";
import { DateTimePreferenceOptions } from "@flanksource-ui/store/preference.state";

const notificationSendHistoryColumns: MRT_ColumnDef<NotificationSendHistoryApiResponse>[] =
[
Expand All @@ -23,7 +24,12 @@ const notificationSendHistoryColumns: MRT_ColumnDef<NotificationSendHistoryApiRe
<Age from={dateString} />
{(count || 1) > 1 && (
<span className="inline-block pl-1 text-gray-500">
(x{count} over <Age from={firstObserved} />)
(x{count} over{" "}
<Age
dateTimePreferenceOverride={DateTimePreferenceOptions.Short}
from={firstObserved}
/>
)
</span>
)}
</div>
Expand Down
10 changes: 0 additions & 10 deletions src/components/Topology/TopologyPage/TopologyFilterBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import { ComponentLabelsDropdown } from "@flanksource-ui/components/Topology/Dro
import { ComponentTypesDropdown } from "@flanksource-ui/components/Topology/Dropdowns/ComponentTypesDropdown";
import { allOption } from "@flanksource-ui/pages/TopologyPage";
import { useMemo } from "react";
import TopologyPopOver from "../TopologyPopover";
import { TopologySort } from "../TopologyPopover/topologySort";

type TopologyFilterBarProps = {
data?: GetTopologyApiResponse;
topologyCardSize: string;
setTopologyCardSize: (size: string) => void;
sortLabels: {
id: number;
value: string;
Expand All @@ -24,8 +21,6 @@ type TopologyFilterBarProps = {

export default function TopologyFilterBar({
data,
topologyCardSize,
setTopologyCardSize,
sortLabels
}: TopologyFilterBarProps) {
// todo: add team and inspect the shape of the data
Expand Down Expand Up @@ -129,11 +124,6 @@ export default function TopologyFilterBar({
<TopologySort sortLabels={sortLabels} />
</div>
</div>

<TopologyPopOver
size={topologyCardSize}
setSize={setTopologyCardSize}
/>
</div>
</FormikFilterForm>
);
Expand Down
30 changes: 0 additions & 30 deletions src/components/Topology/TopologyPopover/index.tsx

This file was deleted.

152 changes: 0 additions & 152 deletions src/components/Topology/TopologyPopover/topologyPreference.tsx

This file was deleted.

15 changes: 4 additions & 11 deletions src/pages/TopologyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import TopologySidebar from "@flanksource-ui/components/Topology/Sidebar/Topolog
import { TopologyBreadcrumbs } from "@flanksource-ui/components/Topology/TopologyBreadcrumbs";
import { TopologyCard } from "@flanksource-ui/components/Topology/TopologyCard";
import TopologyFilterBar from "@flanksource-ui/components/Topology/TopologyPage/TopologyFilterBar";
import { getCardWidth } from "@flanksource-ui/components/Topology/TopologyPopover/topologyPreference";
import { Head } from "@flanksource-ui/ui/Head";
import { SearchLayout } from "@flanksource-ui/ui/Layout/SearchLayout";
import CardsSkeletonLoader from "@flanksource-ui/ui/SkeletonLoader/CardsSkeletonLoader";
import { refreshButtonClickedTrigger } from "@flanksource-ui/ui/SlidingSideBar/SlidingSideBar";
import { useQuery } from "@tanstack/react-query";
import { useAtom } from "jotai";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useCallback, useEffect, useMemo, useRef } from "react";
import { useParams, useSearchParams } from "react-router-dom";
import LoadingBar, { LoadingBarRef } from "react-top-loading-bar";
import {
getSortLabels,
getSortedTopology
} from "../components/Topology/TopologyPopover/topologySort";
import { cardPreferenceAtom } from "@flanksource-ui/store/preference.state";

export const allOption = {
All: {
Expand Down Expand Up @@ -72,9 +72,7 @@ export function TopologyPage() {
sortOrder: "desc"
});

const [topologyCardSize, setTopologyCardSize] = useState(() =>
getCardWidth()
);
const [topologyCardSize] = useAtom(cardPreferenceAtom);

const selectedLabel = searchParams.get("labels") ?? "All";
const team = searchParams.get("team") ?? "All";
Expand Down Expand Up @@ -220,12 +218,7 @@ export function TopologyPage() {
>
<div className="flex h-full flex-row overflow-y-auto py-2">
<div className="flex h-full flex-1 flex-col overflow-y-auto">
<TopologyFilterBar
data={data}
setTopologyCardSize={setTopologyCardSize}
topologyCardSize={topologyCardSize}
sortLabels={sortLabels ?? []}
/>
<TopologyFilterBar data={data} sortLabels={sortLabels ?? []} />
{isLoading && !topology?.length ? (
<CardsSkeletonLoader />
) : (
Expand Down
36 changes: 36 additions & 0 deletions src/store/preference.state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { atomWithStorage } from "jotai/utils";

export enum DateTimePreferenceOptions {
Short = "short", // 1h
Medium = "medium", // '10:30', Mon 10:30, Jan 1 10:30, Jan 2 2025 10:30
Full = "long", // Jan 1 10:30:01.999
Timestamp = "timestamp" // 2025-01-01 10:30:01.999
}

export const datetimePreferenceAtom =
atomWithStorage<DateTimePreferenceOptions>(
"datetime_preference",
DateTimePreferenceOptions.Timestamp,
undefined,
{
getOnInit: true
}
);

export const displayTimezonePreferenceAtom = atomWithStorage<string>(
"display_timezone_preference",
"Browser",
undefined,
{
getOnInit: true
}
);

export const cardPreferenceAtom = atomWithStorage<string>(
"topology_card_width",
"554px",
undefined,
{
getOnInit: true
}
);
Loading
Loading