Skip to content

Commit

Permalink
refactor: Cleanup js mappings for ui components + utils (#530)
Browse files Browse the repository at this point in the history
* Removed "spectrum" verbiage from utils, keys, etc.
* Explicitly mapped all components in WidgetUtils
* Added some barrel files
* Fixed child wrapping (I think this is what fixed the ui.column layout
in the e2e tests)

resolves #425
  • Loading branch information
bmingles committed Jun 14, 2024
1 parent d9d1e5e commit bbce797
Show file tree
Hide file tree
Showing 51 changed files with 223 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {
ActionButton as DHCActionButton,
ActionButtonProps as DHCActionButtonProps,
} from '@deephaven/components';
import { useButtonProps } from './useButtonProps';
import { SerializedButtonEventProps } from '../SerializedPropTypes';
import { useButtonProps } from './hooks/useButtonProps';
import { SerializedButtonEventProps } from './model/SerializedPropTypes';

function ActionButton(
export function ActionButton(
props: SerializedButtonEventProps<DHCActionButtonProps>
): JSX.Element {
const buttonProps = useButtonProps(props);
Expand Down
4 changes: 2 additions & 2 deletions plugins/ui/src/js/src/elements/ActionGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import {
import {
SerializedSelectionProps,
useSelectionProps,
} from './spectrum/useSelectionProps';
} from './hooks/useSelectionProps';

export type SerializedActionGroupProps<T> = Omit<
DHActionGroupProps<T>,
'selectionMode' | 'onChange' | 'onSelectionChange'
> &
SerializedSelectionProps;

function ActionGroup<T>({
export function ActionGroup<T>({
selectionMode: selectionModeMaybeUppercase,
onChange: serializedOnChange,
onSelectionChange: serializedOnSelectionChange,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { SpectrumButton, SpectrumButtonProps } from '@deephaven/components';
import { useButtonProps } from './useButtonProps';
import { SerializedButtonEventProps } from '../SerializedPropTypes';
import { useButtonProps } from './hooks/useButtonProps';
import { SerializedButtonEventProps } from './model/SerializedPropTypes';

function Button(
export function Button(
props: SerializedButtonEventProps<SpectrumButtonProps>
): JSX.Element {
const buttonProps = useButtonProps(props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
FormProps as DHCFormProps,
} from '@deephaven/components';

function Form(
export function Form(
props: DHCFormProps & {
onSubmit?: (data: { [key: string]: FormDataEntryValue }) => void;
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/ui/src/js/src/elements/HTMLElementView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { HTMLElementNode, getHTMLTag } from './HTMLElementUtils';
import { ELEMENT_KEY } from './ElementUtils';
import { HTMLElementNode, getHTMLTag } from './utils/HTMLElementUtils';
import { ELEMENT_KEY } from './utils/ElementUtils';

export type HTMLElementViewProps = {
element: HTMLElementNode;
Expand Down
4 changes: 2 additions & 2 deletions plugins/ui/src/js/src/elements/IconElementView.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { Icon } from '@deephaven/components';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { getIcon, IconElementNode } from './IconElementUtils';
import { ELEMENT_KEY } from './ElementUtils';
import { getIcon, IconElementNode } from './utils/IconElementUtils';
import { ELEMENT_KEY } from './utils/ElementUtils';

export type IconElementViewProps = {
element: IconElementNode;
Expand Down
9 changes: 6 additions & 3 deletions plugins/ui/src/js/src/elements/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { isElementOfType } from '@deephaven/react-hooks';
import { getSettings, RootState } from '@deephaven/redux';
import { ListView as DHListView } from '@deephaven/components';
import { ListView as DHListViewJSApi } from '@deephaven/jsapi-components';
import { SerializedListViewProps, useListViewProps } from './useListViewProps';
import {
SerializedListViewProps,
useListViewProps,
} from './hooks/useListViewProps';
import ObjectView from './ObjectView';
import useReExportedTable from './useReExportedTable';
import useReExportedTable from './hooks/useReExportedTable';

function ListView(props: SerializedListViewProps): JSX.Element | null {
export function ListView(props: SerializedListViewProps): JSX.Element | null {
const settings = useSelector(getSettings<RootState>);
const { children, ...listViewProps } = useListViewProps(props);

Expand Down
6 changes: 3 additions & 3 deletions plugins/ui/src/js/src/elements/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { Picker as DHPicker } from '@deephaven/components';
import { Picker as DHPickerJSApi } from '@deephaven/jsapi-components';
import { isElementOfType } from '@deephaven/react-hooks';
import { getSettings, RootState } from '@deephaven/redux';
import { SerializedPickerProps, usePickerProps } from './usePickerProps';
import { SerializedPickerProps, usePickerProps } from './hooks/usePickerProps';
import ObjectView from './ObjectView';
import useReExportedTable from './useReExportedTable';
import useReExportedTable from './hooks/useReExportedTable';

function Picker(props: SerializedPickerProps): JSX.Element | null {
export function Picker(props: SerializedPickerProps): JSX.Element | null {
const settings = useSelector(getSettings<RootState>);
const { children, ...pickerProps } = usePickerProps(props);

Expand Down
8 changes: 4 additions & 4 deletions plugins/ui/src/js/src/elements/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import {
import {
SerializedFocusEventProps,
SerializedKeyboardEventProps,
} from './SerializedPropTypes';
import { useFocusEventCallback } from './spectrum/useFocusEventCallback';
import { useKeyboardEventCallback } from './spectrum/useKeyboardEventCallback';
} from './model/SerializedPropTypes';
import { useFocusEventCallback } from './hooks/useFocusEventCallback';
import { useKeyboardEventCallback } from './hooks/useKeyboardEventCallback';

export type SerializedRadioProps = SerializedFocusEventProps<
SerializedKeyboardEventProps<DHRadioProps>
>;

function Radio({
export function Radio({
onFocus: serializedOnFocus,
onBlur: serializedOnBlur,
onKeyDown: serializedOnKeyDown,
Expand Down
6 changes: 3 additions & 3 deletions plugins/ui/src/js/src/elements/RadioGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
RadioGroupProps as DHRadioGroupProps,
} from '@deephaven/components';
import { Orientation } from '@react-types/shared';
import { SerializedFocusEventProps } from './SerializedPropTypes';
import { useFocusEventCallback } from './spectrum/useFocusEventCallback';
import { SerializedFocusEventProps } from './model/SerializedPropTypes';
import { useFocusEventCallback } from './hooks/useFocusEventCallback';

export type SerializedRadioGroupProps = Omit<
SerializedFocusEventProps<DHRadioGroupProps>,
Expand All @@ -13,7 +13,7 @@ export type SerializedRadioGroupProps = Omit<
orientation?: Orientation | Uppercase<Orientation>;
};

function RadioGroup({
export function RadioGroup({
onFocus: serializedOnFocus,
onBlur: serializedOnBlur,
orientation: orientationMaybeUppercase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const VALUE_CHANGE_DEBOUNCE = 250;

const EMPTY_FUNCTION = () => undefined;

function RangeSlider(props: DHCRangeSliderProps): JSX.Element {
export function RangeSlider(props: DHCRangeSliderProps): JSX.Element {
const {
defaultValue = { start: 0, end: 0 },
value: propValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const VALUE_CHANGE_DEBOUNCE = 250;

const EMPTY_FUNCTION = () => undefined;

function Slider(props: DHCSliderProps): JSX.Element {
export function Slider(props: DHCSliderProps): JSX.Element {
const {
defaultValue = 0,
value: propValue,
Expand Down
109 changes: 0 additions & 109 deletions plugins/ui/src/js/src/elements/SpectrumElementUtils.ts

This file was deleted.

30 changes: 0 additions & 30 deletions plugins/ui/src/js/src/elements/SpectrumElementView.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
TabPanelsProps as DHCTabPanelsProps,
} from '@deephaven/components';

function TabPanels(props: DHCTabPanelsProps<React.ReactNode>): JSX.Element {
export function TabPanels(
props: DHCTabPanelsProps<React.ReactNode>
): JSX.Element {
const { UNSAFE_style: unsafeStyle, ...otherProps } = props;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface TextFieldProps extends DHCTextFieldProps {
onChange?: (value: string) => Promise<void>;
}

function TextField(props: TextFieldProps): JSX.Element {
export function TextField(props: TextFieldProps): JSX.Element {
const {
defaultValue = '',
value: propValue,
Expand Down
6 changes: 3 additions & 3 deletions plugins/ui/src/js/src/elements/UITable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import type { dh } from '@deephaven/jsapi-types';
import Log from '@deephaven/log';
import { getSettings, RootState } from '@deephaven/redux';
import { EMPTY_ARRAY } from '@deephaven/utils';
import { UITableProps } from './UITableUtils';
import UITableMouseHandler from './UITableMouseHandler';
import { UITableProps } from './utils/UITableUtils';
import UITableMouseHandler from './utils/UITableMouseHandler';

const log = Log.module('@deephaven/js-plugin-ui/UITable');

function UITable({
export function UITable({
onCellPress,
onCellDoublePress,
onColumnPress,
Expand Down
8 changes: 8 additions & 0 deletions plugins/ui/src/js/src/elements/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export * from './useButtonProps';
export * from './useFocusEventCallback';
export * from './useKeyboardEventCallback';
export * from './useListViewProps';
export * from './usePickerProps';
export * from './usePressEventCallback';
export * from './useReExportedTable';
export * from './useSelectionProps';
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { usePressEventCallback } from './usePressEventCallback';
import { useFocusEventCallback } from './useFocusEventCallback';
import { useKeyboardEventCallback } from './useKeyboardEventCallback';
import { mapSpectrumProps } from './mapSpectrumProps';
import { SerializedButtonEventProps } from '../SerializedPropTypes';
import { SerializedButtonEventProps } from '../model/SerializedPropTypes';
import { wrapTextChildren } from '../utils';

// returns SpectrumButtonProps
export function useButtonProps<T>(props: SerializedButtonEventProps<T>): T {
Expand All @@ -15,6 +15,7 @@ export function useButtonProps<T>(props: SerializedButtonEventProps<T>): T {
onBlur: propOnBlur,
onKeyDown: propOnKeyDown,
onKeyUp: propOnKeyUp,
children,
...otherProps
} = props;

Expand All @@ -36,7 +37,8 @@ export function useButtonProps<T>(props: SerializedButtonEventProps<T>): T {
onBlur,
onKeyDown,
onKeyUp,
...mapSpectrumProps(otherProps),
children: wrapTextChildren(children),
...otherProps,
} as T;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FocusEvent, useCallback } from 'react';
import getTargetName from './EventUtils';
import { getTargetName } from '../utils';

export function serializeFocusEvent(event: FocusEvent): SerializedFocusEvent {
const { relatedTarget, target, type } = event;
Expand Down
Loading

0 comments on commit bbce797

Please sign in to comment.