@coreui/react-pro 4.11.0-next.0 → 4.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@ import type {
2
2
  Column,
3
3
  ColumnFilter,
4
4
  ColumnFilterValue,
5
+ Group,
5
6
  Item,
6
7
  Sorter,
7
8
  SorterValue,
@@ -77,12 +78,130 @@ export const getColumnLabel = (column: Column | string) =>
77
78
  : pretifyName(column.key)
78
79
  : pretifyName(column)
79
80
 
80
- export const getColumnNames = (columns: (string | Column)[] | undefined, items: Item[]) =>
81
- columns
82
- ? columns.map((column: Column | string) => {
83
- return typeof column === 'object' ? column.key : column
81
+ // export const getColumnNames = (columns: (string | Column)[] | undefined, items: Item[]) =>
82
+ // columns
83
+ // ? columns.map((column: Column | string) => {
84
+ // return typeof column === 'object' ? column.key : column
85
+ // })
86
+ // : getColumnNamesFromItems(items)
87
+
88
+ export const getColumnNames = (
89
+ columns: (string | Column)[] | undefined,
90
+ items: Item[],
91
+ ): string[] => {
92
+ if (columns) {
93
+ const _columns = []
94
+
95
+ for (const column of columns) {
96
+ if (typeof column === 'object' && column.children) {
97
+ _columns.push(...getColumnNames(column.children, []))
98
+ continue
99
+ }
100
+
101
+ typeof column === 'object' ? _columns.push(column.key) : _columns.push(column)
102
+ }
103
+
104
+ return _columns
105
+ }
106
+
107
+ return getColumnNamesFromItems(items)
108
+ }
109
+
110
+ export const getColumns = (_columns: (Column | Group | string)[]): (Column | string)[] => {
111
+ const columns = []
112
+
113
+ for (const column of _columns) {
114
+ if (typeof column === 'object' && column.group && column.children) {
115
+ columns.push(...getColumns(column.children))
116
+ continue
117
+ }
118
+
119
+ if (typeof column === 'object' && column.children) {
120
+ columns.push(...getColumns(column.children))
121
+ }
122
+
123
+ columns.push(column)
124
+ }
125
+
126
+ return columns
127
+ }
128
+
129
+ export const countColumns = (columns: Column[], counter = 0) => {
130
+ let _counter = counter
131
+ for (const column of columns) {
132
+ if (!column.children) {
133
+ _counter++
134
+ }
135
+
136
+ if (column.children) {
137
+ _counter = countColumns(column.children, _counter)
138
+ }
139
+ }
140
+
141
+ return _counter
142
+ }
143
+
144
+ export const getColumnGroups = (columns: (string | Column)[] | undefined) => {
145
+ const groups = []
146
+
147
+ const traverseColumns = (column: Column, deep = 0, colSpan = 0): Group[] => {
148
+ const groups = []
149
+
150
+ if (column.children) {
151
+ for (const _column of column.children) {
152
+ if (!_column.group) {
153
+ colSpan++
154
+ }
155
+ groups.push(...traverseColumns(_column, deep + 1, colSpan))
156
+ }
157
+ }
158
+
159
+ if (typeof column === 'object' && column.group) {
160
+ const { children, group, ...rest } = column
161
+ groups.push({
162
+ deep: deep,
163
+ label: group,
164
+ ...(children && { colspan: countColumns(children) }),
165
+ ...rest,
84
166
  })
85
- : getColumnNamesFromItems(items)
167
+ }
168
+
169
+ return groups
170
+ }
171
+
172
+ if (columns) {
173
+ for (const column of columns) {
174
+ if (typeof column === 'object' && column.group) {
175
+ const objects = traverseColumns(column)
176
+
177
+ if (objects) {
178
+ for (const object of objects) {
179
+ const { deep, ...rest } = object
180
+
181
+ if (deep === undefined) {
182
+ continue
183
+ }
184
+
185
+ for (let i = 0; i < deep; i++) {
186
+ if (groups[i]) {
187
+ continue
188
+ }
189
+
190
+ groups.push([])
191
+ }
192
+
193
+ if (groups[deep]) {
194
+ groups[deep].push(rest)
195
+ } else {
196
+ groups.push([rest])
197
+ }
198
+ }
199
+ }
200
+ }
201
+ }
202
+ }
203
+ return groups
204
+ }
86
205
 
87
206
  export const getColumnNamesFromItems = (items: Item[]) =>
88
207
  Object.keys(items[0] || {}).filter((el) => el.charAt(0) !== '_')