Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
 * this file dictates the shape of the data used in the ranker component.
 */
 
//represents a column of data
export interface ColumnData {
  id: string;
  title: string;
  itemIds: string[];
}
 
//represents an item living in a column
export interface InputItem {
  id: string;
  title?: string;
  body?: string;
  html?: string;
}
 
//represents the entire board of columns and items
export interface BoardData {
  items: { [id: string]: InputItem };
  columns: { [id: string]: ColumnData };
  columnOrder: string[];
}
 
//represents a column of data
export interface NewColumnData {
  id: string;
  title: string;
}
//represents the entire board of columns and items
export interface NewBoardData {
  items: { [id: string]: InputItem };
  columns: NewColumnData[];
  itemIds: Record<string, string[]>;
}
 
/**
 * assumed input data structure:
 * id: string
 * title: string
 * body: string
 */
 
export const transformData = (columns: Array<InputItem[]>, titles: string[]) => {
  /* loop through input data and create query data object used for ranker component */
 
  const queryData: BoardData = {
    items: {},
    columns: {},
    columnOrder: [],
  };
 
  columns.forEach((items, idx) => {
    const id = String(idx);
 
    queryData.columns[id] = {
      id,
      title: titles[idx] || "",
      itemIds: items.map((item) => item.id),
    };
 
    items.forEach((item) => {
      queryData.items[item.id] = item;
    });
 
    queryData.columnOrder.push(id);
  });
 
  return queryData;
};