• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

keplergl / kepler.gl / 12031095165

26 Nov 2024 12:57PM UTC coverage: 69.321% (+22.9%) from 46.466%
12031095165

push

github

web-flow
[feat] create new dataset action (#2778)

* [feat] create new dataset action

- createNewDataEntry now returns a react-palm task to create or update a dataset asynchronously.
- updateVisDataUpdater now returns tasks to create or update a dataset asynchronously, and once done triggers createNewDatasetSuccess action.
- refactoring of demo-app App and Container to functional components

Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
Co-authored-by: Shan He <heshan0131@gmail.com>

5436 of 9079 branches covered (59.87%)

Branch coverage included in aggregate %.

91 of 111 new or added lines in 13 files covered. (81.98%)

8 existing lines in 3 files now uncovered.

11368 of 15162 relevant lines covered (74.98%)

95.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.4
/src/table/src/dataset-utils.ts
1
// SPDX-License-Identifier: MIT
2
// Copyright contributors to the kepler.gl project
3

4
import uniq from 'lodash.uniq';
5
import KeplerTable, {Datasets} from './kepler-table';
6
import {ProtoDataset, RGBColor} from '@kepler.gl/types';
7
import Task from 'react-palm/tasks';
8

9
import {
10
  hexToRgb,
11
  validateInputData,
12
  datasetColorMaker,
13
  getApplicationConfig
14
} from '@kepler.gl/utils';
15

16
// apply a color for each dataset
17
// to use as label colors
18
const datasetColors = [
11✔
19
  '#8F2FBF',
20
  '#005CFF',
21
  '#C06C84',
22
  '#F8B195',
23
  '#547A82',
24
  '#3EACA8',
25
  '#A2D4AB'
26
].map(hexToRgb);
27

28
/** @type {typeof import('./dataset-utils').getNewDatasetColor} */
29
export function getNewDatasetColor(datasets: Datasets): RGBColor {
30
  const presetColors = datasetColors.map(String);
116✔
31
  const usedColors = uniq(Object.values(datasets).map(d => String(d.color))).filter(c =>
116✔
32
    presetColors.includes(c)
29✔
33
  );
34

35
  if (usedColors.length === presetColors.length) {
116!
36
    // if we already depleted the pool of color
37
    return datasetColorMaker.next().value;
×
38
  }
39

40
  let color = datasetColorMaker.next().value;
116✔
41
  while (usedColors.includes(String(color))) {
116✔
42
    color = datasetColorMaker.next().value;
2✔
43
  }
44

45
  return color;
116✔
46
}
47

48
/**
49
 * Take datasets payload from addDataToMap, create datasets entry save to visState
50
 */
51
export function createNewDataEntry(
52
  {info, data, ...opts}: ProtoDataset,
53
  datasets: Datasets = {}
15✔
54
): Datasets {
55
  const validatedData = validateInputData(data);
174✔
56
  if (!validatedData) {
174✔
57
    return {};
3✔
58
  }
59

60
  // check if dataset already exists, and update it when loading data by batches incrementally
61
  if (info && info.id && datasets[info.id]) {
171!
62
    // get keplerTable from datasets
63
    const keplerTable = datasets[info.id];
×
64
    // update the data in keplerTable
NEW
65
    return UPDATE_TABLE_TASK({table: keplerTable, data: validatedData});
×
66
  }
67

68
  info = info || {};
171!
69
  const color = info.color || getNewDatasetColor(datasets);
171✔
70

71
  return CREATE_TABLE_TASK({
171✔
72
    info,
73
    color,
74
    opts,
75
    data: validatedData
76
  });
77
}
78

79
async function updateTable({table, data}) {
NEW
80
  const updated = await table.update(data); // Assuming `table` has an `update` method
×
NEW
81
  return updated;
×
82
}
83

84
async function createTable({info, color, opts, data}) {
85
  const TableClass = getApplicationConfig().table ?? KeplerTable;
14✔
86
  const table = new TableClass({info, color, ...opts});
14✔
87
  await table.importData({data});
14✔
88

89
  return table;
14✔
90
}
91
const UPDATE_TABLE_TASK = Task.fromPromise(updateTable, 'UPDATE_TABLE_TASK');
11✔
92
const CREATE_TABLE_TASK = Task.fromPromise(createTable, 'CREATE_TABLE_TASK');
11✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc