Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dmckenzie_ui_flex_def…
Browse files Browse the repository at this point in the history
…aults
  • Loading branch information
dsmmcken committed Apr 17, 2024
2 parents 08c7dcc + a4761cc commit 23a5f24
Show file tree
Hide file tree
Showing 30 changed files with 276 additions and 78 deletions.
10 changes: 5 additions & 5 deletions plugins/plotly-express/src/js/src/PlotlyExpressChartModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class PlotlyExpressChartModel extends ChartModel {
return this.layout;
}

override close() {
override close(): void {
super.close();
this.widget?.close();
this.widget = undefined;
Expand Down Expand Up @@ -180,7 +180,7 @@ export class PlotlyExpressChartModel extends ChartModel {
this.widget = undefined;
}

updateLayout(data: PlotlyChartWidgetData) {
updateLayout(data: PlotlyChartWidgetData): void {
const { figure } = data;
const { plotly } = figure;
const { layout: plotlyLayout = {} } = plotly;
Expand Down Expand Up @@ -255,7 +255,7 @@ export class PlotlyExpressChartModel extends ChartModel {
this.fireUpdate(this.getData());
}

addTable(id: number, table: Table) {
addTable(id: number, table: Table): void {
if (this.tableReferenceMap.has(id)) {
return;
}
Expand All @@ -267,7 +267,7 @@ export class PlotlyExpressChartModel extends ChartModel {
}
}

subscribeTable(id: number) {
subscribeTable(id: number): void {
const table = this.tableReferenceMap.get(id);
const columnReplacements = this.tableColumnReplacementMap.get(id);

Expand All @@ -292,7 +292,7 @@ export class PlotlyExpressChartModel extends ChartModel {
}
}

removeTable(id: number) {
removeTable(id: number): void {
this.subscriptionCleanupMap.get(id)?.();
this.tableSubscriptionMap.get(id)?.close();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { useApi } from '@deephaven/jsapi-bootstrap';
import PlotlyExpressChartModel from './PlotlyExpressChartModel.js';
import { useHandleSceneTicks } from './useHandleSceneTicks.js';

export function PlotlyExpressChartPanel(props: WidgetPanelProps<Widget>) {
export function PlotlyExpressChartPanel(
props: WidgetPanelProps<Widget>
): JSX.Element {
const dh = useApi();
const { fetch, metadata = {}, ...rest } = props;
const containerRef = useRef<HTMLDivElement>(null);
Expand Down
8 changes: 4 additions & 4 deletions plugins/plotly-express/src/js/src/PlotlyExpressChartUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import type { Data, PlotlyDataLayoutConfig } from 'plotly.js';
import type { Table, Widget } from '@deephaven/jsapi-types';

export interface PlotlyChartWidget {
getDataAsBase64(): string;
exportedObjects: { fetch(): Promise<Table> }[];
addEventListener(
getDataAsBase64: () => string;
exportedObjects: { fetch: () => Promise<Table> }[];
addEventListener: (
type: string,
fn: (event: CustomEvent<PlotlyChartWidget>) => () => void
): void;
) => void;
}

export interface PlotlyChartWidgetData {
Expand Down
2 changes: 1 addition & 1 deletion plugins/plotly-express/src/js/src/useHandleSceneTicks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PlotlyExpressChartModel from './PlotlyExpressChartModel.js';
export function useHandleSceneTicks(
model: PlotlyExpressChartModel | undefined,
container: HTMLDivElement | null
) {
): void {
useEffect(() => {
// Plotly scenes and geo views reset when our data ticks
// Pause rendering data updates when the user is manipulating a scene
Expand Down
256 changes: 219 additions & 37 deletions plugins/ui/DESIGN.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions plugins/ui/src/js/src/elements/ElementUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type ObjectNode = {
*/
export type ElementNode<
K extends string = string,
P extends Record<string, unknown> = Record<string, unknown>
P extends Record<string, unknown> = Record<string, unknown>,
> = {
/**
* The type of this element. Can be something like `deephaven.ui.components.Panel`, or
Expand All @@ -37,7 +37,7 @@ export type ElementNode<

export type ElementNodeWithChildren<
K extends string = string,
P extends Record<string, unknown> = Record<string, unknown>
P extends Record<string, unknown> = Record<string, unknown>,
> = ElementNode<K, P> & {
props: React.PropsWithChildren<P>;
};
Expand Down
2 changes: 1 addition & 1 deletion plugins/ui/src/js/src/elements/ObjectView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { dh } from '@deephaven/jsapi-types';
const log = Log.module('@deephaven/js-plugin-ui/ObjectView');

export type ObjectViewProps = { object: dh.WidgetExportedObject };
function ObjectView(props: ObjectViewProps) {
function ObjectView(props: ObjectViewProps): JSX.Element {
const { object } = props;
log.info('Object is', object);
const { type } = object;
Expand Down
2 changes: 1 addition & 1 deletion plugins/ui/src/js/src/elements/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type WrappedDHPickerJSApiProps = Omit<DHPickerJSApiProps, 'table'> & {
export type PickerProps = (DHPickerProps | WrappedDHPickerJSApiProps) &
SerializedPickerEventProps;

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

Expand Down
2 changes: 1 addition & 1 deletion plugins/ui/src/js/src/elements/UITable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function UITable({
sorts,
alwaysFetchColumns,
table: exportedTable,
}: UITableProps) {
}: UITableProps): JSX.Element | null {
const dh = useApi();
const [model, setModel] = useState<IrisGridModel>();
const [columns, setColumns] = useState<dh.Table['columns']>();
Expand Down
2 changes: 1 addition & 1 deletion plugins/ui/src/js/src/elements/spectrum/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { SerializedButtonEventProps, useButtonProps } from './useButtonProps';

function ActionButton(
props: SpectrumActionButtonProps & SerializedButtonEventProps
) {
): JSX.Element {
const buttonProps = useButtonProps(props);

// eslint-disable-next-line react/jsx-props-no-spreading
Expand Down
5 changes: 4 additions & 1 deletion plugins/ui/src/js/src/elements/spectrum/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
} from '@adobe/react-spectrum';
import { SerializedButtonEventProps, useButtonProps } from './useButtonProps';

function Button(props: SpectrumButtonProps & SerializedButtonEventProps) {
function Button(
variant: SpectrumButtonProps['variant'],
props: SpectrumButtonProps & SerializedButtonEventProps
): JSX.Element {
const buttonProps = useButtonProps(props);

// eslint-disable-next-line react/jsx-props-no-spreading
Expand Down
2 changes: 1 addition & 1 deletion plugins/ui/src/js/src/elements/spectrum/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function Form(
props: SpectrumFormProps & {
onSubmit?: (data: { [key: string]: FormDataEntryValue }) => void;
}
) {
): JSX.Element {
const { onSubmit: propOnSubmit, ...otherProps } = props;

const onSubmit = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion plugins/ui/src/js/src/elements/spectrum/RangeSlider.tsx
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: SpectrumRangeSliderProps) {
function RangeSlider(props: SpectrumRangeSliderProps): JSX.Element {
const {
defaultValue = { start: 0, end: 0 },
value: propValue,
Expand Down
2 changes: 1 addition & 1 deletion plugins/ui/src/js/src/elements/spectrum/Slider.tsx
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: SpectrumSliderProps) {
function Slider(props: SpectrumSliderProps): JSX.Element {
const {
defaultValue = 0,
value: propValue,
Expand Down
4 changes: 3 additions & 1 deletion plugins/ui/src/js/src/elements/spectrum/TabPanels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
SpectrumTabPanelsProps,
} from '@adobe/react-spectrum';

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

return (
Expand Down
2 changes: 1 addition & 1 deletion plugins/ui/src/js/src/elements/spectrum/TextField.tsx
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 TextField(props: SpectrumTextFieldProps) {
function TextField(props: SpectrumTextFieldProps): JSX.Element {
const {
defaultValue = '',
value: propValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import mapSpectrumChildren from './mapSpectrumChildren';
* @param props Props to map as spectrum props
*/
export function mapSpectrumProps<
T extends PropsWithChildren<Record<string, unknown>>
T extends PropsWithChildren<Record<string, unknown>>,
>(props: T): T {
return {
...props,
Expand Down
7 changes: 5 additions & 2 deletions plugins/ui/src/js/src/elements/spectrum/useButtonProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export type SerializedButtonEventProps = {
onKeyUp?: SerializedKeyboardEventCallback;
};

export function useButtonProps<T>(props: SerializedButtonEventProps & T) {
// returns SpectrumButtonProps
export function useButtonProps<T>(
props: SerializedButtonEventProps & T
): T & SerializedButtonEventProps {
const {
onPress: propOnPress,
onPressStart: propsOnPressStart,
Expand Down Expand Up @@ -75,5 +78,5 @@ export function useButtonProps<T>(props: SerializedButtonEventProps & T) {
onKeyDown,
onKeyUp,
...mapSpectrumProps(otherProps),
};
} as T & SerializedButtonEventProps;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export type SerializedFocusEventCallback = (
* @param callback FocusEvent callback to be called with the serialized event
* @returns A callback to be passed into the Spectrum component that transforms the event and calls the provided callback
*/
export function useFocusEventCallback(callback?: SerializedFocusEventCallback) {
export function useFocusEventCallback(
callback?: SerializedFocusEventCallback
): (e: FocusEvent) => void {
return useCallback(
(e: FocusEvent) => {
callback?.(serializeFocusEvent(e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type SerializedKeyboardEventCallback = (
*/
export function useKeyboardEventCallback(
callback?: SerializedKeyboardEventCallback
) {
): (e: KeyboardEvent) => void {
return useCallback(
(e: KeyboardEvent) => {
callback?.(serializeKeyboardEvent(e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export type SerializedPressEventCallback = (
* @param callback PressEvent callback to be called with the serialized event
* @returns A callback to be passed into the Spectrum component that transforms the event and calls the provided callback
*/
export function usePressEventCallback(callback?: SerializedPressEventCallback) {
export function usePressEventCallback(
callback?: SerializedPressEventCallback
): (e: PressEvent) => void {
return useCallback(
(e: PressEvent) => {
callback?.(serializePressEvent(e));
Expand Down
6 changes: 4 additions & 2 deletions plugins/ui/src/js/src/elements/usePickerProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export interface SerializedPickerEventProps {
* @param props Props to wrap
* @returns Wrapped props
*/
export function usePickerProps<T>(props: SerializedPickerEventProps & T) {
export function usePickerProps<T>(
props: SerializedPickerEventProps & T
): T & SerializedPickerEventProps {
const { onFocus, onBlur, onKeyDown, onKeyUp, ...otherProps } = props;

const serializedOnFocus = useFocusEventCallback(onFocus);
Expand All @@ -44,5 +46,5 @@ export function usePickerProps<T>(props: SerializedPickerEventProps & T) {
// handles nested children inside of `Item` and `Section` components, so
// we are intentionally not wrapping `otherProps` in `mapSpectrumProps`
...otherProps,
};
} as T & SerializedPickerEventProps;
}
2 changes: 1 addition & 1 deletion plugins/ui/src/js/src/layout/ParentItemContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ContentItem } from '@deephaven/golden-layout';

export const ParentItemContext = createContext<ContentItem | null>(null);

export function useParentItem() {
export function useParentItem(): ContentItem {
const layoutManager = useLayoutManager();
const parentContextItem = useContext(ParentItemContext);
const parentItem = useMemo(
Expand Down
2 changes: 1 addition & 1 deletion plugins/ui/src/js/src/layout/PortalPanelManagerContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type PortalPanelMap = ReadonlyMap<string, HTMLElement>;
export const PortalPanelManagerContext =
React.createContext<PortalPanelMap | null>(null);

export function usePortalPanelManager() {
export function usePortalPanelManager(): PortalPanelMap {
return useContextOrThrow(PortalPanelManagerContext, 'PortalPanelManager');
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/ui/src/js/src/layout/ReactPanelContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export const ReactPanelContext = createContext<string | null>(null);
* Gets the panel ID from the nearest panel context.
* @returns The panel ID or null if not in a panel
*/
export function usePanelId() {
export function usePanelId(): string | null {
return useContext(ReactPanelContext);
}
2 changes: 1 addition & 1 deletion plugins/ui/src/js/src/widget/DashboardWidgetHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function DashboardWidgetHandler({
onClose,
onDataChange,
...otherProps
}: DashboardWidgetHandlerProps) {
}: DashboardWidgetHandlerProps): JSX.Element {
const handleClose = useCallback(() => {
log.debug('handleClose', id);
onClose?.(id);
Expand Down
2 changes: 1 addition & 1 deletion plugins/ui/src/js/src/widget/DocumentHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function DocumentHandler({
initialData: data = EMPTY_OBJECT,
onDataChange = EMPTY_FUNCTION,
onClose,
}: DocumentHandlerProps) {
}: DocumentHandlerProps): JSX.Element {
log.debug('Rendering document', widget);
const panelOpenCountRef = useRef(0);
const panelIdIndex = useRef(0);
Expand Down
2 changes: 1 addition & 1 deletion plugins/ui/src/js/src/widget/WidgetHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function WidgetHandler({
fetch,
widget: descriptor,
initialData: initialDataProp,
}: WidgetHandlerProps) {
}: WidgetHandlerProps): JSX.Element | null {
const [widget, setWidget] = useState<dh.Widget>();
const [document, setDocument] = useState<ReactNode>();
const [initialData] = useState(initialDataProp);
Expand Down
4 changes: 2 additions & 2 deletions plugins/ui/src/js/src/widget/WidgetTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { dh } from '@deephaven/jsapi-types';

export function makeDocumentUpdatedJsonRpc(
document: Record<string, unknown> = {}
) {
): { jsonrpc: string; method: string; params: string[] } {
return {
jsonrpc: '2.0',
method: 'documentUpdated',
Expand All @@ -14,7 +14,7 @@ export function makeDocumentUpdatedJsonRpc(

export function makeDocumentUpdatedJsonRpcString(
document: Record<string, unknown> = {}
) {
): string {
return JSON.stringify(makeDocumentUpdatedJsonRpc(document));
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/ui/src/js/src/widget/WidgetTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { dh } from '@deephaven/jsapi-types';
export type WidgetId = string;

export interface WidgetMessageDetails {
getDataAsBase64(): string;
getDataAsString(): string;
getDataAsBase64: () => string;
getDataAsString: () => string;
exportedObjects: dh.WidgetExportedObject[];
}

Expand Down

0 comments on commit 23a5f24

Please sign in to comment.