Skip to content

Commit

Permalink
[Chore] added more properties to export layer type (#1613)
Browse files Browse the repository at this point in the history
- more type exports
- upgrade typescript to 4.2.3
- fix withLocalSelector typing

Signed-off-by: Shan He <heshan0131@gmail.com>
Co-authored-by: Giuseppe Macrì <macri.giuseppe@gmail.com>
  • Loading branch information
heshan0131 and macrigiuseppe committed Sep 19, 2021
1 parent 0931a55 commit a810ee1
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
"tape": "^4.9.2",
"tape-catch": "^1.0.6",
"typedoc-plugin-markdown": "^3.0.11",
"typescript": "3.8.3",
"typescript": "4.2.3",
"uber-licence": "^3.1.1",
"url-loader": "^4.1.1",
"watchify": "^3.6.1",
Expand Down
3 changes: 3 additions & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ export {injector, provideRecipesToInjector, withState} from './injector';
// Common Components
export {default as CloudTile} from './modals/cloud-tile';
export {default as FileUploadFactory, FileUpload} from './common/file-uploader/file-upload';
export {default as FileDrop} from './common/file-uploader/file-drop';
export {default as UploadButton} from './common/file-uploader/upload-button';
export {default as DatasetLabel} from './common/dataset-label';
export {default as ItemSelector} from './common/item-selector/item-selector';
export {default as Typeahead} from './common/item-selector/typeahead';
Expand All @@ -174,6 +176,7 @@ export {default as CanvasHack} from './common/data-table/canvas';
export {default as MapLayerSelector} from './common/map-layer-selector';
export {default as VerticalToolbar} from './common/vertical-toolbar';
export {default as ToolbarItem} from './common/toolbar-item';
export {SharingUrl} from './modals/share-map-modal';
export {default as TippyTooltip} from './common/tippy-tooltip';

// side pane components
Expand Down
7 changes: 2 additions & 5 deletions src/connect/with-local-selector.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import {Component} from 'react';
import {ComponentType} from 'react';
import KeplerGlContext from 'components/context';
import {ConnectedComponent} from 'react-redux';

interface ContextSelector {
(state: any, context: any): KeplerGlContext;
}

export default function withLocalSelector<P, S>(
component: ConnectedComponent<P, S>
): Component<P, S>;
export default function withLocalSelector(ParentComponent: ComponentType): ComponentType;
47 changes: 38 additions & 9 deletions src/layers/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {RGBColor, RGBAColor} from '../reducers/types';
import {Field, Datasets, KeplerTable} from '../reducers/vis-state-updaters';
import {LayerTextLabel, ColorRange, ColorUI, LayerVisConfig} from './layer-factory';
import {RGBColor, RGBAColor, GpuFilter, MapState, Field, Filter, Datasets} from '../reducers';
import {LayerTextLabel, ColorRange, ColorUI, VisConfigRange} from './layer-factory';

export {LAYER_VIS_CONFIGS, LayerVisConfig} from './layer-factory';

export type LayerColumns = {
[key: string]: {value: string | null; fieldIdx: number; optional?: boolean};
Expand Down Expand Up @@ -38,6 +39,10 @@ export type LayerConfig = {
animation: {
enabled: boolean;
};

heightField: VisualChannelField;
heightDomain: VisualChannelDomain;
heightScale: string;
};

export type VisualChannel = {
Expand All @@ -48,8 +53,8 @@ export type VisualChannel = {
range: string;
key: string;
channelScaleType: string;
nullValue: any;
defaultMeasure: any;
nullValue?: any;
defaultMeasure?: any;
accessor?: string;
condition?: (config: any) => boolean;
getAttributeValue?: (config: any) => (d: any) => any;
Expand All @@ -67,10 +72,11 @@ export class Layer {
} & Partial<LayerConfig>
);
id: string;
type: string;
get type(): string;
get visualChannels(): {[key: string]: VisualChannel};

config: LayerConfig;
visConfigSettings: any;
visualChannels: {[key: string]: VisualChannel};
_oldDataUpdateTriggers: any;
hasAllColumns(): boolean;
updateLayerConfig(p: Partial<LayerConfig>): Layer;
Expand All @@ -81,10 +87,33 @@ export class Layer {
updateLayerColorUI(prop: string, newConfig: Partial<ColorUI>): Layer;
isValidToSave(): boolean;
validateVisualChannel(channel: string);
getVisualChannelDescription(key: string): {label: string, measure: string};

static findDefaultLayerProps(dataset: KeplerTable, foundLayers?: any[]);
// static findDefaultColumnField(defaultFields, allFields)
getVisualChannelDescription(key: string): VisualChannelDescription;
isLayerHovered(objectInfo: any): boolean;
hasHoveredObject(objectInfo: any): any | null;
getHoverData(object: any, allData?: KeplerTable['allData'], fields?: KeplerTable['fields']): any;
registerVisConfig(config: LayerVisConfig): any;
getDefaultLayerConfig(config: {[key: string]: any}): any;
getColorScale(
colorScale: string,
colorDomain: VisualChannelDomain,
colorRange: VisConfigRange
): () => any | null;
getVisChannelScale(
heightScale: string,
heightDomain: VisualChannelDomain,
heightRange: VisConfigRange
): () => any | null;
getEncodedChannelValue(
scale: (value) => any,
data: any[],
field: VisualChannelField,
nullValue: any,
getValue: (value) => any
): any;
getDefaultDeckLayerProps(props: {idx: number; gpuFilter: GpuFilter; mapState: MapState}): any;
}

export type LayerClassesType = {
Expand All @@ -104,5 +133,5 @@ export type LayerClassesType = {
};
export const LayerClasses: LayerClassesType;

export type OVERLAY_TYPE = {[key: string]: string}
export type OVERLAY_TYPE = {[key: string]: string};
export const LAYER_ID_LENGTH: number;
2 changes: 2 additions & 0 deletions src/reducers/vis-state-updaters.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,5 @@ export const DEFAULT_EDITOR: Editor;

export function computeSplitMapLayers(layers: Array<Layer>): Array<Layer>;
export function closeSpecificMapAtIndex(state: VisState, action: unknown);

export {ProtoDataset} from '../actions/actions';
2 changes: 1 addition & 1 deletion src/utils/table-utils/kepler-table.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export type FilterDatasetOpt = {
ignoreDomain?: boolean;
};

export function sortDatasetByColumn(dataset: Dataset, column: string, mode?: string): Dataset;
export function sortDatasetByColumn(dataset: KeplerTable, column: string, mode?: string): Dataset;

export function findPointFieldPairs(fields: Field[]): FieldPair[];

Expand Down
20 changes: 9 additions & 11 deletions src/utils/table-utils/kepler-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,10 @@ export function sortDatasetByColumn(dataset, column, mode) {
const sortBy = SORT_ORDER[mode] || SORT_ORDER.ASCENDING;

if (sortBy === SORT_ORDER.UNSORT) {
return {
...dataset,
sortColumn: {},
sortOrder: null
};
dataset.sortColumn = {};
dataset.sortOrder = null;

return dataset;
}

const sortFunction = sortBy === SORT_ORDER.ASCENDING ? ascending : descending;
Expand All @@ -462,13 +461,12 @@ export function sortDatasetByColumn(dataset, column, mode) {
sortFunction(dataContainer.valueAt(a, fieldIndex), dataContainer.valueAt(b, fieldIndex))
);

return {
...dataset,
sortColumn: {
[column]: sortBy
},
sortOrder
dataset.sortColumn = {
[column]: sortBy
};
dataset.sortOrder = sortOrder;

return dataset;
}

export function copyTable(original) {
Expand Down
4 changes: 3 additions & 1 deletion test/node/reducers/vis-state-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4615,6 +4615,8 @@ test('#visStateReducer -> APPLY_CPU_FILTER has multi datasets', t => {
test('#visStateReducer -> SORT_TABLE_COLUMN', t => {
const initialState = CloneDeep(StateWFiles.visState);
const previousDataset1 = initialState.datasets[testCsvDataId];
const previousKeys = Object.keys(previousDataset1);

// sort with default mode
const nextState = reducer(initialState, VisStateActions.sortTableColumn());
t.equal(nextState, initialState, 'state should not change when input is given');
Expand Down Expand Up @@ -4653,7 +4655,7 @@ test('#visStateReducer -> SORT_TABLE_COLUMN', t => {
21
];
const newKeys = Object.keys(nextState2.datasets[testCsvDataId]);
const addedKeys = newKeys.filter(k => !Object.keys(previousDataset1).includes(k));
const addedKeys = newKeys.filter(k => !previousKeys.includes(k));

t.deepEqual(
addedKeys,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14581,10 +14581,10 @@ typedoc@^0.19.2:
shelljs "^0.8.4"
typedoc-default-themes "^0.11.4"

typescript@3.8.3:
version "3.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==
typescript@4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.2.3.tgz#39062d8019912d43726298f09493d598048c1ce3"
integrity sha512-qOcYwxaByStAWrBf4x0fibwZvMRG+r4cQoTjbPtUlrWjBHbmCAww1i448U0GJ+3cNNEtebDteo/cHOR3xJ4wEw==

ua-parser-js@^0.7.18:
version "0.7.28"
Expand Down

0 comments on commit a810ee1

Please sign in to comment.