Skip to content

Commit

Permalink
fix types in datatable, datagrid-extras
Browse files Browse the repository at this point in the history
  • Loading branch information
heswell committed Jan 8, 2023
1 parent ec67b4f commit 11ad734
Show file tree
Hide file tree
Showing 29 changed files with 567 additions and 449 deletions.
76 changes: 37 additions & 39 deletions vuu-ui/packages/vuu-data/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,45 @@ let _connectionId = 0;
export const connectionId = {
get nextValue() {
return _connectionId++;
}
},
};

export const msgType = {
connect: 'connect',
connectionStatus: 'connection-status',
getFilterData: 'GetFilterData',
rowData: 'rowData',
rowSet: 'rowset',
select: 'select',
selectAll: 'selectAll',
selectNone: 'selectNone',
selected: 'selected',
snapshot: 'snapshot',
update: 'update',
createLink: 'createLink',
disable: 'disable',
enable: 'enable',
suspend: 'suspend',
resume: 'resume',
connect: "connect",
connectionStatus: "connection-status",
getFilterData: "GetFilterData",
rowData: "rowData",
rowSet: "rowset",
select: "select",
selectAll: "selectAll",
selectNone: "selectNone",
selected: "selected",
snapshot: "snapshot",
update: "update",
createLink: "createLink",
disable: "disable",
enable: "enable",
suspend: "suspend",
resume: "resume",

addSubscription: 'AddSubscription',
closeTreeNode: 'closeTreeNode',
columnList: 'ColumnList',
data: 'data',
openTreeNode: 'openTreeNode',
aggregate: 'aggregate',
filter: 'filter',
filterQuery: 'filterQuery',
filterData: 'filterData',
getSearchData: 'GetSearchData',
groupBy: 'groupBy',
modifySubscription: 'ModifySubscription',
searchData: 'searchData',
setColumns: 'setColumns',
setGroupState: 'setGroupState',
setViewRange: 'setViewRange',
size: 'size',
sort: 'sort',
subscribed: 'Subscribed',
tableList: 'TableList',
unsubscribe: 'TerminateSubscription',
viewRangeChanged: 'ViewRangeChanged'
addSubscription: "AddSubscription",
closeTreeNode: "closeTreeNode",
columnList: "ColumnList",
data: "data",
openTreeNode: "openTreeNode",
aggregate: "aggregate",
filter: "filter",
filterQuery: "filterQuery",
filterData: "filterData",
getSearchData: "GetSearchData",
groupBy: "groupBy",
modifySubscription: "ModifySubscription",
searchData: "searchData",
setGroupState: "setGroupState",
size: "size",
sort: "sort",
subscribed: "Subscribed",
tableList: "TableList",
unsubscribe: "TerminateSubscription",
viewRangeChanged: "ViewRangeChanged",
};
7 changes: 7 additions & 0 deletions vuu-ui/packages/vuu-data/src/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export interface DataSourceEnabledMessage extends MessageWithClientViewportId {
type: "enabled";
}

export interface DataSourceColumnsMessage extends MessageWithClientViewportId {
type: "columns";
columns: VuuColumns;
}
export interface DataSourceFilterMessage extends MessageWithClientViewportId {
type: "filter";
filter: Filter;
Expand Down Expand Up @@ -120,6 +124,7 @@ export interface DataSourceVisualLinksMessage

export type DataSourceCallbackMessage =
| DataSourceAggregateMessage
| DataSourceColumnsMessage
| DataSourceDataMessage
| DataSourceDisabledMessage
| DataSourceEnabledMessage
Expand All @@ -135,6 +140,7 @@ export type DataSourceCallbackMessage =
const datasourceMessages = [
"aggregate",
"viewport-update",
"columns",
"disabled",
"enabled",
"filter",
Expand Down Expand Up @@ -220,6 +226,7 @@ export interface DataSource extends IEventEmitter {
rowCount: number | undefined;
select: (selected: number[]) => void;
setRange: (from: number, to: number) => void;
setSubscribedColumns: (columns: string[]) => void;
/** Set the title associated with this viewport in UI. This can be used as a link target */
setTitle?: (title: string) => void;
sort: (sort: VuuSort) => void;
Expand Down
22 changes: 11 additions & 11 deletions vuu-ui/packages/vuu-data/src/remote-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { MenuRpcResponse } from "./vuuUIMessageTypes";
// };

/*-----------------------------------------------------------------
A RemoteDataView manages a single subscription via the ServerProxy
A RemoteDataSource manages a single subscription via the ServerProxy
----------------------------------------------------------------*/
export class RemoteDataSource extends EventEmitter implements DataSource {
private bufferSize: number;
Expand Down Expand Up @@ -236,18 +236,18 @@ export class RemoteDataSource extends EventEmitter implements DataSource {
return this;
}

setColumns(columns: string[]) {
this.columns = columns;
return this;
}

setSubscribedColumns(columns: string[]) {
if (
columns.length !== this.columns.length ||
!columns.every((columnName) => this.columns.includes(columnName))
) {
if (this.viewport) {
this.columns = columns;
// ???

const message = {
viewport: this.viewport,
type: "setColumns",
columns,
} as const;
if (this.server) {
this.server.send(message);
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions vuu-ui/packages/vuu-data/src/server-proxy/server-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
VuuUIMessageOutSubscribe,
VuuUIMessageOutUnsubscribe,
VuuUIMessageOutViewRange,
VuuUIMessageOutColumns,
} from "../vuuUIMessageTypes";
import { DataSourceCallbackMessage } from "../data-source";
import {
Expand Down Expand Up @@ -239,6 +240,13 @@ export class ServerProxy {
this.sendIfReady(request, requestId, viewport.status === "subscribed");
}

private setColumns(viewport: Viewport, message: VuuUIMessageOutColumns) {
const requestId = nextRequestId();
const { columns } = message;
const request = viewport.columnRequest(requestId, columns);
this.sendIfReady(request, requestId, viewport.status === "subscribed");
}

private select(viewport: Viewport, message: VuuUIMessageOutSelect) {
const requestId = nextRequestId();
const { selected } = message;
Expand Down Expand Up @@ -390,6 +398,8 @@ export class ServerProxy {
return this.createLink(viewport, message);
case "removeLink":
return this.removeLink(viewport);
case "setColumns":
return this.setColumns(viewport, message);
default:
}
}
Expand Down
17 changes: 17 additions & 0 deletions vuu-ui/packages/vuu-data/src/server-proxy/viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ interface Aggregate {
data: VuuAggregation[];
type: "aggregate";
}
interface Columns {
data: string[];
type: "columns";
}
interface Selection {
data: number[];
type: "selection";
Expand All @@ -76,6 +80,7 @@ type RemoveVisualLink = ClientToServerRemoveLink;
type AsyncOperation =
| Aggregate
| ChangeViewportRange
| Columns
| CreateVisualLink
| RemoveVisualLink
| Disable
Expand Down Expand Up @@ -265,6 +270,10 @@ export class Viewport {
type: "groupBy",
groupBy: null,
};
} else if (type === "columns") {
console.log("columns changed");
this.columns = data;
return { clientViewportId, type, ...data };
} else if (type === "filter") {
this.filterSpec = { filter: data.filterQuery };
this.filter = data.filter;
Expand Down Expand Up @@ -475,6 +484,14 @@ export class Viewport {
} as ClientToServerDisable;
}

columnRequest(requestId: string, columns: string[]) {
this.awaitOperation(requestId, {
type: "columns",
data: columns,
});
return this.createRequest({ columns });
}

filterRequest(
requestId: string,
filter: Filter | undefined,
Expand Down
5 changes: 5 additions & 0 deletions vuu-ui/packages/vuu-data/src/vuuUIMessageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ export interface RequestMessage {
requestId: string;
}

export interface VuuUIMessageOutColumns extends ViewportMessageOut {
type: "setColumns";
columns: string[];
}
export interface VuuUIMessageOutViewRange extends ViewportMessageOut {
type: "setViewRange";
range: {
Expand Down Expand Up @@ -202,6 +206,7 @@ export interface VuuUIMessageOutGroupby extends ViewportMessageOut {
export type VuuUIMessageOutViewport =
| VuuUIMessageOutAggregate
| VuuUIMessageOutCloseTreeNode
| VuuUIMessageOutColumns
| VuuUIMessageOutCreateLink
| VuuUIMessageOutFilterQuery
| VuuUIMessageOutDisable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { Button } from "@salt-ds/core";

import "./ColumnExpressionInput.css";
import { Expression } from "./column-language-parser";

const classBase = "vuuColumnExpressionInput";

Expand All @@ -15,20 +16,17 @@ export interface ColumnExpressionInputProps
HTMLAttributes<HTMLDivElement> {
existingFilter?: Filter;
onSubmitExpression?: (
filter: Filter | undefined,
filterQuery: string,
filterName?: string
expression: Expression | undefined,
source: string
) => void;
}

export const ColumnExpressionInput = ({
existingFilter,
onSubmitExpression: onSubmitFilter,
onSubmitExpression,
suggestionProvider,
}: ColumnExpressionInputProps) => {
const { editorRef, clearInput } = useColumnExpressionEditor({
existingFilter,
onSubmitExpression: onSubmitFilter,
onSubmitExpression,
suggestionProvider,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ColumnDescriptor } from "@finos/vuu-datagrid-types";
import { List } from "@heswell/salt-lab";
import { Button, Text, useIdMemo as useId } from "@salt-ds/core";
import { Dispatch, HTMLAttributes, useCallback, useState } from "react";
import { ColumnAction } from "../settings-panel/useColumns";
import { ColumnAction } from "../settings-panel/useGridSettings";

import "./ColumnPicker.css";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ColumnDescriptor } from "@finos/vuu-datagrid-types";
import { Dropdown, Panel, PanelProps } from "@heswell/salt-lab";
import cx from "classnames";
import { Dispatch, useMemo } from "react";
import { ColumnAction } from "../settings-panel/useColumns";
import { ColumnAction } from "../settings-panel/useGridSettings";
import { NumericColumnPanel } from "./NumericColumnPanel";
import { StringColumnPanel } from "./StringColumnPanel";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { ColumnTypePanel } from "../column-type-panel";

import "./ColumnSettingsPanel.css";
import { ColumnAction } from "./useColumns";
import { ColumnAction } from "./useGridSettings";

const classBase = "vuuColumnSettingsPanel";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
useState,
} from "react";
import { ColumnPicker } from "../column-picker";
import { GridSettingsPanel } from "./GridSettingsPanel";
import { ColumnSettingsPanel } from "./ColumnSettingsPanel";
import { useColumns } from "./useColumns";
import { useGridSettings } from "./useGridSettings";

import "./DatagridSettingsPanel.css";
import { Stack, StackProps } from "@finos/vuu-layout";
Expand Down Expand Up @@ -48,12 +49,9 @@ export const DatagridSettingsPanel = ({
}: DatagridSettingsPanelProps) => {
console.log(`DatagridSettingsPanel render`);

const [config, setConfig] = useState<GridConfig>(gridConfig);
const [selectedTabIndex, setSelectedTabIndex] = useState(0);

const { columns: chosenColumns, dispatchColumnAction } = useColumns(
gridConfig.columns
);
const { gridSettings, dispatchColumnAction } = useGridSettings(gridConfig);

const [selectedColumnName, setSelectedColumnName] = useState<string | null>(
null
Expand All @@ -67,15 +65,9 @@ export const DatagridSettingsPanel = ({

const handleApply = useCallback(
(evt: MouseEvent, closePanel = false) => {
onConfigChange?.(
{
...config,
columns: chosenColumns,
},
closePanel
);
onConfigChange?.(gridSettings, closePanel);
},
[chosenColumns, config, onConfigChange]
[gridSettings, onConfigChange]
);

const handleTabSelectionChanged = useCallback((selectedTabIndex: number) => {
Expand All @@ -90,7 +82,8 @@ export const DatagridSettingsPanel = ({
const selectedColumn =
selectedColumnName === null
? null
: chosenColumns.find((col) => col.name === selectedColumnName) ?? null;
: gridSettings.columns.find((col) => col.name === selectedColumnName) ??
null;

const tabstripProps: StackProps["TabstripProps"] = {
activeTabIndex: selectedTabIndex,
Expand All @@ -111,9 +104,11 @@ export const DatagridSettingsPanel = ({
onTabSelectionChanged={handleTabSelectionChanged}
showTabs
>
<Panel className={`${classBase}-gridSettings`} title="Grid Settings">
<Text styleAs="h4">Grid Settings</Text>
</Panel>
<GridSettingsPanel
config={gridSettings}
dispatchColumnAction={dispatchColumnAction}
title="Grid Settings"
/>

<div
className={`${classBase}-columnPanels`}
Expand All @@ -122,7 +117,7 @@ export const DatagridSettingsPanel = ({
>
<ColumnPicker
availableColumns={availableColumns}
chosenColumns={chosenColumns}
chosenColumns={gridSettings.columns}
dispatchColumnAction={dispatchColumnAction}
onSelectionChange={handleColumnSelected}
selectedColumn={selectedColumn}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vuuGridSettingsPanel {
--saltFormField-label-width: 150px;
}
Loading

0 comments on commit 11ad734

Please sign in to comment.