Skip to content

Commit b478a85

Browse files
mfisher87nakul-py
andcommitted
Simplify call to useColorMapList effect
Co-authored-by: Nakul Verma <[email protected]>
1 parent c1fbede commit b478a85

File tree

3 files changed

+6
-21
lines changed

3 files changed

+6
-21
lines changed

packages/base/src/dialogs/symbology/colorRampUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const getColorMapList = (): IColorMap[] => {
9191
/**
9292
* Hook that loads and sets color maps.
9393
*/
94-
export const useColorMapList = (setColorMaps: (maps: IColorMap[]) => void) => {
94+
export const useColorMapList = (setColorMaps: React.Dispatch<React.SetStateAction<IColorMap[]>>) => {
9595
useEffect(() => {
9696
setColorMaps(getColorMapList());
9797
}, [setColorMaps]);

packages/base/src/dialogs/symbology/components/color_ramp/CanvasSelectComponent.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
import { Button } from '@jupyterlab/ui-components';
22
import React, { useEffect, useRef, useState } from 'react';
33

4-
import {
5-
useColorMapList,
6-
COLOR_RAMP_DEFINITIONS,
7-
ColorRampName,
8-
} from '@/src/dialogs/symbology/colorRampUtils';
4+
import { useColorMapList } from '@/src/dialogs/symbology/colorRampUtils';
95
import ColorRampEntry from './ColorRampEntry';
10-
11-
export interface IColorMap {
12-
name: string;
13-
colors: string[];
14-
type?: string;
15-
}
6+
import { IColorMap } from '@/src/types';
167

178
interface ICanvasSelectComponentProps {
189
selectedRamp: string;
@@ -27,13 +18,7 @@ const CanvasSelectComponent: React.FC<ICanvasSelectComponentProps> = ({
2718
const [isOpen, setIsOpen] = useState(false);
2819
const [colorMaps, setColorMaps] = useState<IColorMap[]>([]);
2920

30-
useColorMapList((maps: IColorMap[]) => {
31-
const withTypes = maps.map(m => {
32-
const def = COLOR_RAMP_DEFINITIONS[m.name as ColorRampName];
33-
return { ...m, type: def?.type ?? 'Unknown' };
34-
});
35-
setColorMaps(withTypes);
36-
});
21+
useColorMapList(setColorMaps);
3722

3823
useEffect(() => {
3924
if (colorMaps.length > 0) {

packages/base/src/dialogs/symbology/components/color_ramp/ColorRampEntry.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useEffect } from 'react';
22

3-
import { IColorMap } from './CanvasSelectComponent';
3+
import { IColorMap } from '@/src/types';
44

55
interface IColorRampEntryProps {
66
index: number;
@@ -47,7 +47,7 @@ const ColorRampEntry: React.FC<IColorRampEntryProps> = ({
4747
<span
4848
style={{ color: 'var(--jp-ui-font-color2)', fontStyle: 'italic' }}
4949
>
50-
({colorMap.type})
50+
({colorMap.definition.type})
5151
</span>
5252
</span>
5353
<canvas

0 commit comments

Comments
 (0)