|
16 | 16 | */ |
17 | 17 | import type { Attribute, Sort } from 'stores/PaginationTypes'; |
18 | 18 |
|
| 19 | +import type { ExtensionColumnGroups } from './hooks/useStreamsOverviewExtensions'; |
19 | 20 | import { METRIC_COLUMN_IDS, METRIC_COLUMN_TITLES } from './metricColumns'; |
20 | 21 |
|
| 22 | +export const STREAM_VIEW_VARIANTS = { |
| 23 | + default: '' as const, |
| 24 | + routing: 'routing' as const, |
| 25 | + performance: 'performance' as const, |
| 26 | +}; |
| 27 | + |
| 28 | +const SHARED_LAYOUT = { |
| 29 | + entityTableId: 'streams', |
| 30 | + defaultPageSize: 20, |
| 31 | + defaultSort: { attributeId: 'title', direction: 'asc' } as Sort, |
| 32 | +}; |
| 33 | + |
21 | 34 | const getStreamTableElements = ( |
22 | 35 | isPipelineColumnPermitted: boolean, |
23 | 36 | extensionAttributes?: { |
24 | 37 | attributeNames?: Array<string>; |
25 | 38 | attributes?: Array<Attribute>; |
26 | 39 | }, |
| 40 | + extensionColumnGroups?: ExtensionColumnGroups, |
27 | 41 | ) => { |
28 | | - const defaultLayout = { |
29 | | - entityTableId: 'streams', |
30 | | - defaultPageSize: 20, |
31 | | - defaultSort: { attributeId: 'title', direction: 'asc' } as Sort, |
32 | | - defaultDisplayedAttributes: [ |
33 | | - 'title', |
34 | | - 'index_set_title', |
35 | | - 'rules', |
36 | | - ...(isPipelineColumnPermitted ? ['pipelines'] : []), |
37 | | - 'outputs', |
38 | | - 'archiving', |
39 | | - ...(extensionAttributes?.attributeNames || []), |
40 | | - 'destination_filters', |
41 | | - 'disabled', |
42 | | - 'throughput', |
43 | | - ], |
44 | | - defaultColumnOrder: [ |
45 | | - 'title', |
46 | | - 'index_set_title', |
47 | | - 'rules', |
48 | | - 'outputs', |
49 | | - 'archiving', |
50 | | - ...(extensionAttributes?.attributeNames || []), |
51 | | - 'destination_filters', |
52 | | - 'disabled', |
53 | | - 'throughput', |
54 | | - METRIC_COLUMN_IDS.messageCount, |
55 | | - METRIC_COLUMN_IDS.avgProcessingTime, |
56 | | - METRIC_COLUMN_IDS.maxProcessingTime, |
57 | | - METRIC_COLUMN_IDS.associatedInputs, |
58 | | - ...(isPipelineColumnPermitted ? ['pipelines', METRIC_COLUMN_IDS.routingPipelines] : []), |
59 | | - 'created_at', |
60 | | - ], |
| 42 | + const extRouting = extensionColumnGroups?.routing ?? []; |
| 43 | + const extPerformance = extensionColumnGroups?.performance ?? []; |
| 44 | + |
| 45 | + const groupedIds = new Set([...extRouting, ...extPerformance]); |
| 46 | + const ungroupedExtNames = (extensionAttributes?.attributeNames ?? []).filter((id) => !groupedIds.has(id)); |
| 47 | + |
| 48 | + const defaultCols = [ |
| 49 | + 'title', |
| 50 | + 'index_set_title', |
| 51 | + 'rules', |
| 52 | + ...(isPipelineColumnPermitted ? ['pipelines'] : []), |
| 53 | + 'destination_filters', |
| 54 | + 'disabled', |
| 55 | + 'throughput', |
| 56 | + ]; |
| 57 | + |
| 58 | + const routingCols = [ |
| 59 | + METRIC_COLUMN_IDS.associatedInputs, |
| 60 | + ...(isPipelineColumnPermitted ? [METRIC_COLUMN_IDS.routingPipelines] : []), |
| 61 | + 'outputs', |
| 62 | + ...extRouting, |
| 63 | + 'archiving', |
| 64 | + ]; |
| 65 | + |
| 66 | + const performanceCols = [ |
| 67 | + METRIC_COLUMN_IDS.messageCount, |
| 68 | + ...extPerformance, |
| 69 | + METRIC_COLUMN_IDS.avgProcessingTime, |
| 70 | + METRIC_COLUMN_IDS.maxProcessingTime, |
| 71 | + ]; |
| 72 | + |
| 73 | + const defaultColumnOrder = [ |
| 74 | + ...defaultCols, |
| 75 | + ...routingCols, |
| 76 | + ...performanceCols, |
| 77 | + ...ungroupedExtNames, |
| 78 | + 'created_at', |
| 79 | + ]; |
| 80 | + |
| 81 | + const defaultVariantLayout = { |
| 82 | + ...SHARED_LAYOUT, |
| 83 | + defaultColumnOrder, |
| 84 | + defaultDisplayedAttributes: defaultCols, |
| 85 | + }; |
| 86 | + |
| 87 | + const routingVariantLayout = { |
| 88 | + ...SHARED_LAYOUT, |
| 89 | + layoutVariant: STREAM_VIEW_VARIANTS.routing, |
| 90 | + defaultColumnOrder, |
| 91 | + defaultDisplayedAttributes: [...defaultCols, ...routingCols], |
| 92 | + }; |
| 93 | + |
| 94 | + const performanceVariantLayout = { |
| 95 | + ...SHARED_LAYOUT, |
| 96 | + layoutVariant: STREAM_VIEW_VARIANTS.performance, |
| 97 | + defaultColumnOrder, |
| 98 | + defaultDisplayedAttributes: [...defaultCols, ...performanceCols], |
61 | 99 | }; |
62 | 100 |
|
63 | 101 | const additionalAttributes: Array<Attribute> = [ |
64 | 102 | { id: 'index_set_title', title: 'Index Set', sortable: true, permissions: ['indexsets:read'] }, |
65 | 103 | { id: 'throughput', title: 'Throughput' }, |
66 | 104 | { id: 'rules', title: 'Stream Rules' }, |
67 | 105 | ...(isPipelineColumnPermitted ? [{ id: 'pipelines', title: 'Pipelines' }] : []), |
68 | | - { id: 'outputs', title: 'Outputs' }, |
69 | | - { id: 'archiving', title: 'Archiving' }, |
70 | | - ...(extensionAttributes?.attributes || []), |
71 | 106 | { id: 'destination_filters', title: 'Filter Rules' }, |
72 | | - { id: METRIC_COLUMN_IDS.messageCount, title: METRIC_COLUMN_TITLES[METRIC_COLUMN_IDS.messageCount] }, |
73 | | - { id: METRIC_COLUMN_IDS.avgProcessingTime, title: METRIC_COLUMN_TITLES[METRIC_COLUMN_IDS.avgProcessingTime] }, |
74 | | - { id: METRIC_COLUMN_IDS.maxProcessingTime, title: METRIC_COLUMN_TITLES[METRIC_COLUMN_IDS.maxProcessingTime] }, |
75 | 107 | { id: METRIC_COLUMN_IDS.associatedInputs, title: METRIC_COLUMN_TITLES[METRIC_COLUMN_IDS.associatedInputs] }, |
76 | 108 | ...(isPipelineColumnPermitted |
77 | 109 | ? [{ id: METRIC_COLUMN_IDS.routingPipelines, title: METRIC_COLUMN_TITLES[METRIC_COLUMN_IDS.routingPipelines] }] |
78 | 110 | : []), |
| 111 | + { id: 'outputs', title: 'Outputs' }, |
| 112 | + ...(extensionAttributes?.attributes || []), |
| 113 | + { id: 'archiving', title: 'Archiving' }, |
| 114 | + { id: METRIC_COLUMN_IDS.messageCount, title: METRIC_COLUMN_TITLES[METRIC_COLUMN_IDS.messageCount] }, |
| 115 | + { id: METRIC_COLUMN_IDS.avgProcessingTime, title: METRIC_COLUMN_TITLES[METRIC_COLUMN_IDS.avgProcessingTime] }, |
| 116 | + { id: METRIC_COLUMN_IDS.maxProcessingTime, title: METRIC_COLUMN_TITLES[METRIC_COLUMN_IDS.maxProcessingTime] }, |
79 | 117 | ]; |
80 | 118 |
|
81 | 119 | return { |
82 | | - defaultLayout, |
| 120 | + defaultVariantLayout, |
| 121 | + routingVariantLayout, |
| 122 | + performanceVariantLayout, |
83 | 123 | additionalAttributes, |
84 | 124 | }; |
85 | 125 | }; |
|
0 commit comments