Skip to content

Commit

Permalink
fix preferences view
Browse files Browse the repository at this point in the history
  • Loading branch information
Anchel123 committed Jan 15, 2025
1 parent 99d06e2 commit 42ab14d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/api/graph/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class Graph {
return new Graph(graphName || "", [], [], { nodes: [], links: [] }, new Map<string, Category>(), new Map<string, Category>(), new Map<number, Node>(), new Map<number, Link>(), colors)
}

public static create(id: string, results: any, colors?: string[]): Graph {
public static create(id: string, results: { data: Data, metadata: any[] }, colors?: string[]): Graph {
const graph = Graph.empty(undefined, colors)
graph.extend(results)
graph.id = id
Expand Down
10 changes: 6 additions & 4 deletions app/graph/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export default function View({ graph, setGraph, selectedValue }: {

const handlePreferencesChange = (colors?: string[]) => {
setGraph(Graph.create(graph.Id, { data: graph.Data, metadata: graph.Metadata }, colors || colorsArr))
if (colors) return
if (colors) {
localStorage.removeItem(graph.Id)
}
localStorage.setItem(graph.Id, JSON.stringify(colorsArr));
}

Expand All @@ -40,9 +42,9 @@ export default function View({ graph, setGraph, selectedValue }: {
className="w-[30%] h-[50%]"
title="Preferences"
>
<div className="h-full flex flex-col gap-8">
<div className="h-full flex flex-col gap-8 overflow-hidden">
<p className="text-xl">Legends</p>
<ul className="flex flex-col gap-4 overflow-auto">
<ul className="flex flex-col gap-4 p-2 overflow-auto">
{
colorsArr.map((c, i) => (
<li onMouseEnter={() => setHover(c)} onMouseLeave={(() => setHover(""))} key={c} className={cn(`flex gap-8 items-center`)}>
Expand Down Expand Up @@ -154,7 +156,7 @@ export default function View({ graph, setGraph, selectedValue }: {
<RotateCcw />
</Button>
<Button
disabled={graph.Colors.filter((c, i) => c === colorsArr[i]).length === colorsArr.length && DEFAULT_COLORS.length === colorsArr.length}
disabled={graph.Colors.every((c) => colorsArr.some(color => color === c)) && graph.Colors.length === colorsArr.length}
variant="Primary"
label="Apply"
onClick={() => handlePreferencesChange()}
Expand Down
2 changes: 1 addition & 1 deletion app/schema/SchemaView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export default function SchemaView({ schema, fetchCount, session }: Props) {
}}
onDeleteElement={handleDeleteElement}
chartRef={chartRef}
addDisabled={session?.user.role === "Read-Only"}
addDisabled={session?.user.role === "Read-Only" || !schema.Id}
/>
{
isCollapsed &&
Expand Down

0 comments on commit 42ab14d

Please sign in to comment.