@camunda/camunda-composite-components 0.22.4 → 0.22.5
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.
- package/lib/esm/package.json +98 -0
- package/lib/esm/src/api/api.d.ts +29 -0
- package/lib/esm/src/api/api.js +92 -0
- package/lib/esm/src/api/clusters.d.ts +10 -0
- package/lib/esm/src/api/clusters.js +32 -0
- package/lib/esm/src/api/endpoints.const.d.ts +22 -0
- package/lib/esm/src/api/endpoints.const.js +70 -0
- package/lib/esm/src/api/help-center.d.ts +42 -0
- package/lib/esm/src/api/help-center.js +56 -0
- package/lib/esm/src/api/jwt.utils.d.ts +5 -0
- package/lib/esm/src/api/jwt.utils.js +26 -0
- package/lib/esm/src/api/notifications.d.ts +41 -0
- package/lib/esm/src/api/notifications.js +170 -0
- package/lib/esm/src/api/organizations.d.ts +15 -0
- package/lib/esm/src/api/organizations.js +16 -0
- package/lib/esm/src/api/profile.d.ts +20 -0
- package/lib/esm/src/api/profile.js +48 -0
- package/lib/esm/src/api/status.d.ts +7 -0
- package/lib/esm/src/api/status.js +46 -0
- package/lib/esm/src/assets/c3-icons.d.ts +5 -0
- package/lib/esm/src/assets/c3-icons.js +5 -0
- package/lib/esm/src/assets/c3-icons.types.d.ts +3 -0
- package/lib/esm/src/assets/c3-icons.types.js +6 -0
- package/lib/esm/src/components/c3-app-teaser/app-teaser-cards-config.d.ts +5 -0
- package/lib/esm/src/components/c3-app-teaser/app-teaser-cards-config.js +94 -0
- package/lib/esm/src/components/c3-app-teaser/app-teaser-cards.d.ts +17 -0
- package/lib/esm/src/components/c3-app-teaser/app-teaser-cards.js +31 -0
- package/lib/esm/src/components/c3-app-teaser/app-teaster-card.d.ts +14 -0
- package/lib/esm/src/components/c3-app-teaser/app-teaster-card.js +24 -0
- package/lib/esm/src/components/c3-app-teaser/c3-app-teaser-page.d.ts +9 -0
- package/lib/esm/src/components/c3-app-teaser/c3-app-teaser-page.js +48 -0
- package/lib/esm/src/components/c3-app-teaser/c3-app-teaser-page.test.d.ts +1 -0
- package/lib/esm/src/components/c3-app-teaser/c3-app-teaser-page.test.js +33 -0
- package/lib/esm/src/components/c3-app-teaser/c3-app-teaser.d.ts +14 -0
- package/lib/esm/src/components/c3-app-teaser/c3-app-teaser.js +53 -0
- package/lib/esm/src/components/c3-cluster-tag/c3-cluster-tag.d.ts +6 -0
- package/lib/esm/src/components/c3-cluster-tag/c3-cluster-tag.js +84 -0
- package/lib/esm/src/components/c3-cluster-tag/c3-cluster-tag.test.d.ts +1 -0
- package/lib/esm/src/components/c3-cluster-tag/c3-cluster-tag.test.js +13 -0
- package/lib/esm/src/components/c3-cluster-tag/c3-cluster-tag.types.d.ts +26 -0
- package/lib/esm/src/components/c3-cluster-tag/c3-cluster-tag.types.js +11 -0
- package/lib/esm/src/components/c3-data-table/c3-data-table.d.ts +3 -0
- package/lib/esm/src/components/c3-data-table/c3-data-table.js +509 -0
- package/lib/esm/src/components/c3-data-table/c3-data-table.types.d.ts +122 -0
- package/lib/esm/src/components/c3-data-table/c3-data-table.types.js +6 -0
- package/lib/esm/src/components/c3-data-table/link-button/link-button.d.ts +3 -0
- package/lib/esm/src/components/c3-data-table/link-button/link-button.js +15 -0
- package/lib/esm/src/components/c3-data-table/link-button/link-button.types.d.ts +8 -0
- package/lib/esm/src/components/c3-data-table/link-button/link-button.types.js +6 -0
- package/lib/esm/src/components/c3-empty-state/c3-empty-state.d.ts +3 -0
- package/lib/esm/src/components/c3-empty-state/c3-empty-state.js +15 -0
- package/lib/esm/src/components/c3-empty-state/c3-empty-state.test.d.ts +1 -0
- package/lib/esm/src/components/c3-empty-state/c3-empty-state.test.js +25 -0
- package/lib/esm/src/components/c3-empty-state/c3-empty-state.types.d.ts +29 -0
- package/lib/esm/src/components/c3-empty-state/c3-empty-state.types.js +6 -0
- package/lib/esm/src/components/c3-help-center/c3-help-center-provider.d.ts +19 -0
- package/lib/esm/src/components/c3-help-center/c3-help-center-provider.js +58 -0
- package/lib/esm/src/components/c3-help-center/c3-help-center.d.ts +16 -0
- package/lib/esm/src/components/c3-help-center/c3-help-center.js +218 -0
- package/lib/esm/src/components/c3-help-center/c3-help-center.types.d.ts +43 -0
- package/lib/esm/src/components/c3-help-center/c3-help-center.types.js +6 -0
- package/lib/esm/src/components/c3-help-center/defaultHelpCenterConfig.d.ts +10 -0
- package/lib/esm/src/components/c3-help-center/defaultHelpCenterConfig.js +17 -0
- package/lib/esm/src/components/c3-help-center/help-center-hint.d.ts +4 -0
- package/lib/esm/src/components/c3-help-center/help-center-hint.js +15 -0
- package/lib/esm/src/components/c3-help-center/help-center.d.ts +18 -0
- package/lib/esm/src/components/c3-help-center/help-center.js +189 -0
- package/lib/esm/src/components/c3-help-center/recommendations.d.ts +4 -0
- package/lib/esm/src/components/c3-help-center/recommendations.js +55 -0
- package/lib/esm/src/components/c3-help-center/styles.d.ts +4 -0
- package/lib/esm/src/components/c3-help-center/styles.js +48 -0
- package/lib/esm/src/components/c3-help-center/tabs/feedback.d.ts +9 -0
- package/lib/esm/src/components/c3-help-center/tabs/feedback.js +141 -0
- package/lib/esm/src/components/c3-help-center/tabs/tabContent.d.ts +20 -0
- package/lib/esm/src/components/c3-help-center/tabs/tabContent.js +22 -0
- package/lib/esm/src/components/c3-help-center/tabs/tabContentSkeleton.d.ts +2 -0
- package/lib/esm/src/components/c3-help-center/tabs/tabContentSkeleton.js +26 -0
- package/lib/esm/src/components/c3-help-center/tile.d.ts +10 -0
- package/lib/esm/src/components/c3-help-center/tile.js +61 -0
- package/lib/esm/src/components/c3-navigation/c3-info-button.d.ts +4 -0
- package/lib/esm/src/components/c3-navigation/c3-info-button.js +9 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-actions/c3-action-buttons.d.ts +6 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-actions/c3-action-buttons.js +18 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-actions/c3-action-buttons.types.d.ts +10 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-actions/c3-action-buttons.types.js +6 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-appbar/c3-navigation-appbar.d.ts +4 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-appbar/c3-navigation-appbar.js +380 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-appbar/components.d.ts +2 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-appbar/components.js +21 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-sidebar/c3-info-sidebar.d.ts +6 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-sidebar/c3-info-sidebar.js +38 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar-element.d.ts +12 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar-element.js +68 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar.d.ts +10 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar.js +87 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar.types.d.ts +81 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-sidebar/c3-navigation-sidebar.types.js +6 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-sidebar/c3-notification-sidebar.d.ts +5 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-sidebar/c3-notification-sidebar.js +107 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-sidebar/c3-sidebar-state-provider.d.ts +29 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-sidebar/c3-sidebar-state-provider.js +54 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-sidebar/c3-user-sidebar.d.ts +6 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-sidebar/c3-user-sidebar.js +57 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-sidebar/components.d.ts +2 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation-sidebar/components.js +11 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation.d.ts +7 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation.js +262 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation.test.d.ts +1 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation.test.js +89 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation.types.d.ts +97 -0
- package/lib/esm/src/components/c3-navigation/c3-navigation.types.js +6 -0
- package/lib/esm/src/components/c3-navigation/c3-notification-provider/c3-notification-container.d.ts +13 -0
- package/lib/esm/src/components/c3-navigation/c3-notification-provider/c3-notification-container.js +100 -0
- package/lib/esm/src/components/c3-navigation/c3-notification-provider/c3-notification-provider.d.ts +19 -0
- package/lib/esm/src/components/c3-navigation/c3-notification-provider/c3-notification-provider.js +110 -0
- package/lib/esm/src/components/c3-navigation/c3-org-name.d.ts +6 -0
- package/lib/esm/src/components/c3-navigation/c3-org-name.js +34 -0
- package/lib/esm/src/components/c3-navigation/c3-org-sidebar/c3-org-sidebar.d.ts +6 -0
- package/lib/esm/src/components/c3-navigation/c3-org-sidebar/c3-org-sidebar.js +188 -0
- package/lib/esm/src/components/c3-navigation/c3-org-sidebar/components.d.ts +29 -0
- package/lib/esm/src/components/c3-navigation/c3-org-sidebar/components.js +92 -0
- package/lib/esm/src/components/c3-navigation/helpers.d.ts +8 -0
- package/lib/esm/src/components/c3-navigation/helpers.js +58 -0
- package/lib/esm/src/components/c3-navigation/index.d.ts +2 -0
- package/lib/esm/src/components/c3-navigation/index.js +8 -0
- package/lib/esm/src/components/c3-navigation/stories/story-helpers.d.ts +35 -0
- package/lib/esm/src/components/c3-navigation/stories/story-helpers.js +264 -0
- package/lib/esm/src/components/c3-navigation/stories/story-templates.d.ts +9 -0
- package/lib/esm/src/components/c3-navigation/stories/story-templates.js +38 -0
- package/lib/esm/src/components/c3-onboarding-survey/c3-onboarding-survey.d.ts +14 -0
- package/lib/esm/src/components/c3-onboarding-survey/c3-onboarding-survey.js +94 -0
- package/lib/esm/src/components/c3-onboarding-survey/defaultOnboardingConfig.d.ts +16 -0
- package/lib/esm/src/components/c3-onboarding-survey/defaultOnboardingConfig.js +8 -0
- package/lib/esm/src/components/c3-onboarding-survey/elements/dropdownSelect.d.ts +15 -0
- package/lib/esm/src/components/c3-onboarding-survey/elements/dropdownSelect.js +58 -0
- package/lib/esm/src/components/c3-onboarding-survey/elements/inlineNotification.d.ts +3 -0
- package/lib/esm/src/components/c3-onboarding-survey/elements/inlineNotification.js +10 -0
- package/lib/esm/src/components/c3-onboarding-survey/elements/radioGroupMulti.d.ts +7 -0
- package/lib/esm/src/components/c3-onboarding-survey/elements/radioGroupMulti.js +53 -0
- package/lib/esm/src/components/c3-onboarding-survey/elements/radioGroupSingle.d.ts +7 -0
- package/lib/esm/src/components/c3-onboarding-survey/elements/radioGroupSingle.js +36 -0
- package/lib/esm/src/components/c3-onboarding-survey/elements/textField.d.ts +6 -0
- package/lib/esm/src/components/c3-onboarding-survey/elements/textField.js +14 -0
- package/lib/esm/src/components/c3-onboarding-survey/helpers.d.ts +1 -0
- package/lib/esm/src/components/c3-onboarding-survey/helpers.js +10 -0
- package/lib/esm/src/components/c3-onboarding-survey/onboarding.types.d.ts +30 -0
- package/lib/esm/src/components/c3-onboarding-survey/onboarding.types.js +13 -0
- package/lib/esm/src/components/c3-onboarding-survey/onboardingModal.d.ts +25 -0
- package/lib/esm/src/components/c3-onboarding-survey/onboardingModal.js +52 -0
- package/lib/esm/src/components/c3-onboarding-survey/onboardingPage.d.ts +21 -0
- package/lib/esm/src/components/c3-onboarding-survey/onboardingPage.js +35 -0
- package/lib/esm/src/components/c3-onboarding-survey/onboardingSurvey.d.ts +17 -0
- package/lib/esm/src/components/c3-onboarding-survey/onboardingSurvey.js +148 -0
- package/lib/esm/src/components/c3-onboarding-survey/step.d.ts +7 -0
- package/lib/esm/src/components/c3-onboarding-survey/step.js +44 -0
- package/lib/esm/src/components/c3-page/c3-breadcrumb/c3-breadcrumb.d.ts +3 -0
- package/lib/esm/src/components/c3-page/c3-breadcrumb/c3-breadcrumb.js +28 -0
- package/lib/esm/src/components/c3-page/c3-breadcrumb/c3-breadcrumb.types.d.ts +19 -0
- package/lib/esm/src/components/c3-page/c3-breadcrumb/c3-breadcrumb.types.js +6 -0
- package/lib/esm/src/components/c3-page/c3-page.d.ts +4 -0
- package/lib/esm/src/components/c3-page/c3-page.js +16 -0
- package/lib/esm/src/components/c3-page/c3-page.test.d.ts +1 -0
- package/lib/esm/src/components/c3-page/c3-page.test.js +25 -0
- package/lib/esm/src/components/c3-page/c3-page.types.d.ts +18 -0
- package/lib/esm/src/components/c3-page/c3-page.types.js +6 -0
- package/lib/esm/src/components/c3-page/c3-tabs/c3-tabs.d.ts +3 -0
- package/lib/esm/src/components/c3-page/c3-tabs/c3-tabs.js +37 -0
- package/lib/esm/src/components/c3-page/c3-tabs/c3-tabs.types.d.ts +14 -0
- package/lib/esm/src/components/c3-page/c3-tabs/c3-tabs.types.js +6 -0
- package/lib/esm/src/components/c3-responsive-stack/c3-responsive-stack.d.ts +2 -0
- package/lib/esm/src/components/c3-responsive-stack/c3-responsive-stack.js +18 -0
- package/lib/esm/src/components/c3-user-configuration/authToken.d.ts +30 -0
- package/lib/esm/src/components/c3-user-configuration/authToken.js +30 -0
- package/lib/esm/src/components/c3-user-configuration/c3-profile-provider/c3-profile-provider.d.ts +26 -0
- package/lib/esm/src/components/c3-user-configuration/c3-profile-provider/c3-profile-provider.js +117 -0
- package/lib/esm/src/components/c3-user-configuration/c3-profile-provider/carbon-theme-provider.d.ts +13 -0
- package/lib/esm/src/components/c3-user-configuration/c3-profile-provider/carbon-theme-provider.js +29 -0
- package/lib/esm/src/components/c3-user-configuration/c3-user-configuration-provider.d.ts +54 -0
- package/lib/esm/src/components/c3-user-configuration/c3-user-configuration-provider.js +43 -0
- package/lib/esm/src/components/styles.d.ts +13 -0
- package/lib/esm/src/components/styles.js +90 -0
- package/lib/esm/src/components/test-utils.d.ts +3 -0
- package/lib/esm/src/components/test-utils.js +32 -0
- package/lib/esm/src/contexts/c3-cluster-update-manager.d.ts +12 -0
- package/lib/esm/src/contexts/c3-cluster-update-manager.js +27 -0
- package/lib/esm/src/hooks/useApi.d.ts +20 -0
- package/lib/esm/src/hooks/useApi.js +54 -0
- package/lib/esm/src/index.d.ts +23 -0
- package/lib/esm/src/index.js +19 -0
- package/lib/esm/src/utils/camunda.d.ts +21 -0
- package/lib/esm/src/utils/camunda.js +59 -0
- package/lib/esm/src/utils/camunda.types.d.ts +63 -0
- package/lib/esm/src/utils/camunda.types.js +6 -0
- package/lib/esm/src/utils/versionCheck.utils.d.ts +15 -0
- package/lib/esm/src/utils/versionCheck.utils.js +79 -0
- package/package.json +2 -2
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
|
|
4
|
+
* under one or more contributor license agreements. Licensed under a commercial license.
|
|
5
|
+
* You may not use this file except in compliance with the commercial license.
|
|
6
|
+
*/
|
|
7
|
+
import { Button, CodeSnippet, DataTableSkeleton, Link, MenuButton, MenuItem, MultiSelect, OverflowMenu, OverflowMenuItem, Pagination, Select, SelectItem, Table, TableBody, TableCell, TableContainer, TableExpandedRow, TableExpandHeader, TableExpandRow, TableHead, TableHeader, TableRow, TableSelectAll, TableSelectRow, TableToolbar, TableToolbarContent, TableToolbarSearch, } from '@carbon/react';
|
|
8
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
9
|
+
import styled from 'styled-components';
|
|
10
|
+
import { LinkButton } from './link-button/link-button.js';
|
|
11
|
+
const ToolbarWrapper = styled(TableToolbarContent) `
|
|
12
|
+
@media (max-width: 768px) {
|
|
13
|
+
flex-wrap: wrap !important;
|
|
14
|
+
block-size: auto !important;
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
const overrideHistoryMethods = (onChange) => {
|
|
18
|
+
const originalReplaceState = window.history.replaceState;
|
|
19
|
+
window.history.replaceState = (...args) => {
|
|
20
|
+
originalReplaceState.apply(window.history, args);
|
|
21
|
+
onChange();
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
function areValuesTheSame(a, b) {
|
|
25
|
+
return a.sort().join(' ') === b.sort().join(' ');
|
|
26
|
+
}
|
|
27
|
+
export const C3DataTable = ({ data, headers, options, toolbar: singleToolbar, toolbars, isLoading, title, description, actions, id, queryPrefix = '', }) => {
|
|
28
|
+
if (singleToolbar && toolbars) {
|
|
29
|
+
throw new Error('you should either have `toolbar` or `toolbars` but not both');
|
|
30
|
+
}
|
|
31
|
+
if (!toolbars && singleToolbar) {
|
|
32
|
+
toolbars = [singleToolbar];
|
|
33
|
+
}
|
|
34
|
+
const allToolbarItems = toolbars?.flat() ?? [];
|
|
35
|
+
// preparation
|
|
36
|
+
const tableOptions = {
|
|
37
|
+
pageSize: options?.pageSize || 10,
|
|
38
|
+
pageSizes: options?.pageSizes || [10, 20, 30, 40, 50],
|
|
39
|
+
tableSize: options?.tableSize || 'lg',
|
|
40
|
+
useZebraStyles: options?.useZebraStyles || false,
|
|
41
|
+
showPagination: data.length > 10,
|
|
42
|
+
actionsUseOverflowMenuMinItems: options?.actionsUseOverflowMenuMinItems || 3,
|
|
43
|
+
};
|
|
44
|
+
const headerKeys = headers.map((header) => header.key);
|
|
45
|
+
let component = (_jsx(DataTableSkeleton, { headers: headers.map((header) => {
|
|
46
|
+
return { header: header.label };
|
|
47
|
+
}) }));
|
|
48
|
+
const [currentPage, setCurrentPage] = useState(1);
|
|
49
|
+
const [currentPageSize, setCurrentPageSize] = useState(tableOptions.pageSize);
|
|
50
|
+
const [inputData, setInputData] = useState([]);
|
|
51
|
+
const [filteredData, setFilteredData] = useState([]);
|
|
52
|
+
const [selectedItems, selectItem] = useState([]);
|
|
53
|
+
const toggleSelectedItem = (id) => {
|
|
54
|
+
if (selectedItems.includes(id)) {
|
|
55
|
+
selectItem(selectedItems.filter((item) => item !== id));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
selectItem([...selectedItems, id]);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const toggleSelectAllOnPage = () => {
|
|
62
|
+
if (selectedItems.length === 0) {
|
|
63
|
+
selectItem(getDataForCurrentPage().map((row) => row.id));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
selectItem([]);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const itemIsSelected = (id) => selectedItems.includes(id);
|
|
70
|
+
const currentFilters = useRef(new Map());
|
|
71
|
+
const [currentSorting, setCurrentSorting] = useState({
|
|
72
|
+
key: '',
|
|
73
|
+
sortDirection: 'NONE',
|
|
74
|
+
});
|
|
75
|
+
const [currentRowExpanded, setCurrentRowExpanded] = useState([]);
|
|
76
|
+
const [urlStates, setUrlStates] = useState({});
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
const handleUrlChange = () => {
|
|
79
|
+
const params = new URLSearchParams(window.location.search);
|
|
80
|
+
setUrlStates(Object.fromEntries(params));
|
|
81
|
+
};
|
|
82
|
+
overrideHistoryMethods(handleUrlChange);
|
|
83
|
+
handleUrlChange();
|
|
84
|
+
window.addEventListener('popstate', handleUrlChange);
|
|
85
|
+
return () => {
|
|
86
|
+
window.removeEventListener('popstate', handleUrlChange);
|
|
87
|
+
};
|
|
88
|
+
}, []);
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
updateFilteredData();
|
|
91
|
+
}, [data]);
|
|
92
|
+
const updateFilterURLState = (filterName, value) => {
|
|
93
|
+
setTimeout(() => {
|
|
94
|
+
const params = new URLSearchParams(window.location.search);
|
|
95
|
+
const name = `${queryPrefix ? `${queryPrefix}-` : ''}${filterName}`;
|
|
96
|
+
if (Array.from(value).length > 0) {
|
|
97
|
+
params.set(name, value);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
params.delete(name);
|
|
101
|
+
}
|
|
102
|
+
const paramsString = params.size > 0 ? `?${params.toString()}` : '';
|
|
103
|
+
window.history.replaceState({}, '', `${window.location.pathname}${paramsString}`);
|
|
104
|
+
}, 250);
|
|
105
|
+
};
|
|
106
|
+
const updateFilteredData = () => {
|
|
107
|
+
let currentFilteredData = data;
|
|
108
|
+
if (currentFilters.current.size > 0) {
|
|
109
|
+
for (const key of currentFilters.current.keys()) {
|
|
110
|
+
const filter = currentFilters.current.get(key);
|
|
111
|
+
const foundFilter = allToolbarItems
|
|
112
|
+
.filter((item) => item.type === 'multiSelect' ||
|
|
113
|
+
item.type === 'search' ||
|
|
114
|
+
item.type === 'singleSelect')
|
|
115
|
+
.find((currentFilter) => currentFilter.id === key);
|
|
116
|
+
if (foundFilter && filter) {
|
|
117
|
+
if (filter.selectedItems && filter.selectedItems.length > 0) {
|
|
118
|
+
currentFilteredData = currentFilteredData.filter((row) => {
|
|
119
|
+
return foundFilter
|
|
120
|
+
.filter({
|
|
121
|
+
selectedItems: filter.selectedItems,
|
|
122
|
+
row,
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if (typeof filter.searchTerm === 'string' &&
|
|
127
|
+
filter.searchTerm.length >= 0) {
|
|
128
|
+
currentFilteredData = currentFilteredData.filter((row) => {
|
|
129
|
+
return foundFilter
|
|
130
|
+
.filter({
|
|
131
|
+
searchTerm: filter.searchTerm?.trim(),
|
|
132
|
+
row,
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
if (filter.selectedItem && filter.selectedItem?.length > 0) {
|
|
137
|
+
currentFilteredData = currentFilteredData.filter((row) => {
|
|
138
|
+
return foundFilter
|
|
139
|
+
.filter({
|
|
140
|
+
selectedItem: filter.selectedItem,
|
|
141
|
+
row,
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
setFilteredData(currentFilteredData);
|
|
149
|
+
setCurrentPage(1);
|
|
150
|
+
selectItem([]);
|
|
151
|
+
};
|
|
152
|
+
const getQueryKey = (queryName) => {
|
|
153
|
+
const prefix = queryPrefix ? `${queryPrefix}-` : '';
|
|
154
|
+
const query = `${prefix}${queryName}`;
|
|
155
|
+
return query;
|
|
156
|
+
};
|
|
157
|
+
const addUrlStatesToCurrentFilters = () => {
|
|
158
|
+
if (headers && headers.length > 0) {
|
|
159
|
+
for (const header of headers) {
|
|
160
|
+
const query = getQueryKey(header.key);
|
|
161
|
+
if (query && query in urlStates) {
|
|
162
|
+
setCurrentSorting({
|
|
163
|
+
key: header.key,
|
|
164
|
+
sortDirection: urlStates[query],
|
|
165
|
+
});
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (toolbars && toolbars.length > 0) {
|
|
171
|
+
for (const toolbar of toolbars) {
|
|
172
|
+
if (toolbar && toolbar.length > 0) {
|
|
173
|
+
for (const toolbarElement of toolbar) {
|
|
174
|
+
switch (toolbarElement.type) {
|
|
175
|
+
case 'search': {
|
|
176
|
+
const searchElement = toolbarElement;
|
|
177
|
+
const queryName = searchElement?.queryName ?? searchElement.id;
|
|
178
|
+
const query = getQueryKey(queryName);
|
|
179
|
+
if (query && query in urlStates) {
|
|
180
|
+
currentFilters.current.set(searchElement.id, {
|
|
181
|
+
searchTerm: urlStates[query],
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
case 'singleSelect': {
|
|
187
|
+
const element = toolbarElement;
|
|
188
|
+
const queryName = element?.queryName ?? element.id;
|
|
189
|
+
const query = getQueryKey(queryName);
|
|
190
|
+
if (query && query in urlStates) {
|
|
191
|
+
currentFilters.current.set(element.id, {
|
|
192
|
+
selectedItem: urlStates[query],
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case 'multiSelect': {
|
|
198
|
+
const multiSelectElement = toolbarElement;
|
|
199
|
+
const queryName = multiSelectElement?.queryName ?? multiSelectElement.id;
|
|
200
|
+
const query = getQueryKey(queryName);
|
|
201
|
+
if (query && query in urlStates) {
|
|
202
|
+
const queryItems = urlStates[query] ?? '';
|
|
203
|
+
const selectedItems = queryItems.split(',');
|
|
204
|
+
currentFilters.current.set(multiSelectElement.id, {
|
|
205
|
+
id: multiSelectElement.id,
|
|
206
|
+
selectedItems,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
default: {
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
// // work around to sync state data and input data
|
|
221
|
+
if (!areValuesTheSame(data, inputData)) {
|
|
222
|
+
setInputData(data);
|
|
223
|
+
addUrlStatesToCurrentFilters();
|
|
224
|
+
updateFilteredData();
|
|
225
|
+
setCurrentPage(1);
|
|
226
|
+
}
|
|
227
|
+
const getDataForCurrentPage = () => {
|
|
228
|
+
const start = (currentPage - 1) * currentPageSize;
|
|
229
|
+
const end = start + currentPageSize;
|
|
230
|
+
let sortedData = filteredData.toSorted((a, b) => a.originalIndex - b.originalIndex);
|
|
231
|
+
if (currentSorting.key.length > 0) {
|
|
232
|
+
const foundHeader = headers.find((header) => header.key === currentSorting.key);
|
|
233
|
+
if (foundHeader?.sorting) {
|
|
234
|
+
sortedData = filteredData.toSorted((a, b) => {
|
|
235
|
+
switch (currentSorting.sortDirection) {
|
|
236
|
+
case 'ASC':
|
|
237
|
+
return foundHeader.sorting(a, b);
|
|
238
|
+
case 'DESC':
|
|
239
|
+
return foundHeader.sorting(a, b) * -1;
|
|
240
|
+
case 'NONE':
|
|
241
|
+
return a.originalIndex - b.originalIndex;
|
|
242
|
+
default:
|
|
243
|
+
return 0;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const data = sortedData.slice(start, end);
|
|
249
|
+
return data;
|
|
250
|
+
};
|
|
251
|
+
// ==== SORTING ====
|
|
252
|
+
const currentSortDirection = (key) => {
|
|
253
|
+
if (currentSorting.key === key) {
|
|
254
|
+
return currentSorting.sortDirection;
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
return 'NONE';
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
const updateSortDirection = (key) => {
|
|
261
|
+
let sortingDetails = { key, sortDirection: 'ASC' };
|
|
262
|
+
if (currentSorting.key === key) {
|
|
263
|
+
switch (currentSorting.sortDirection) {
|
|
264
|
+
case 'ASC':
|
|
265
|
+
sortingDetails = { key, sortDirection: 'DESC' };
|
|
266
|
+
break;
|
|
267
|
+
case 'DESC':
|
|
268
|
+
sortingDetails = { key, sortDirection: 'NONE' };
|
|
269
|
+
break;
|
|
270
|
+
case 'NONE':
|
|
271
|
+
sortingDetails = { key, sortDirection: 'ASC' };
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
setCurrentSorting(sortingDetails);
|
|
276
|
+
updateFilterURLState(sortingDetails.key, sortingDetails.sortDirection);
|
|
277
|
+
};
|
|
278
|
+
// ==== EXPANSION ====
|
|
279
|
+
const isRowExpanded = (row) => {
|
|
280
|
+
const expanded = currentRowExpanded.includes(row.id);
|
|
281
|
+
return expanded;
|
|
282
|
+
};
|
|
283
|
+
const updateRowExpansion = (row) => {
|
|
284
|
+
const currentlyExpanded = isRowExpanded(row);
|
|
285
|
+
if (currentlyExpanded) {
|
|
286
|
+
setCurrentRowExpanded((rowExpanded) => rowExpanded.filter((id) => id !== row.id));
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
setCurrentRowExpanded((rowExpanded) => [...rowExpanded, row.id]);
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
if (!isLoading) {
|
|
293
|
+
// ==== TOOLBAR ====
|
|
294
|
+
const toolbarRows = [];
|
|
295
|
+
if (toolbars && toolbars.length > 0) {
|
|
296
|
+
toolbars.forEach((toolbar, index) => {
|
|
297
|
+
let toolbarComponent = null;
|
|
298
|
+
let searchComponent = null;
|
|
299
|
+
const toolbarComponents = [];
|
|
300
|
+
if (toolbar && toolbar.length > 0) {
|
|
301
|
+
for (const toolbarElement of toolbar) {
|
|
302
|
+
if (toolbarElement.type === 'singleSelect') {
|
|
303
|
+
const element = toolbarElement;
|
|
304
|
+
const defaultValue = currentFilters.current.get(element.id)?.selectedItem;
|
|
305
|
+
toolbarComponents.push(_jsx("div", { style: { width: 'auto' }, children: _jsx(Select, { size: 'lg', id: element.id, inline: true, value: defaultValue ?? element.defaultValue, disabled: element.disabled, labelText: element.label, onChange: (event) => {
|
|
306
|
+
currentFilters.current.set(element.id, {
|
|
307
|
+
selectedItem: event.target.value,
|
|
308
|
+
});
|
|
309
|
+
updateFilteredData();
|
|
310
|
+
updateFilterURLState(element.queryName ?? element.id, event.target.value);
|
|
311
|
+
}, children: element.items?.map((item) => {
|
|
312
|
+
return (_jsx(SelectItem, { value: item.id, text: item.label }, item.id));
|
|
313
|
+
}) }) }, 'toolbar-singleSelect'));
|
|
314
|
+
}
|
|
315
|
+
if (toolbarElement.type === 'multiItemButton') {
|
|
316
|
+
const multiItemElement = toolbarElement;
|
|
317
|
+
toolbarComponents.push(_jsx(Button, { onClick: () => {
|
|
318
|
+
multiItemElement.multiOnClick(inputData.filter((row) => selectedItems.includes(row.id)));
|
|
319
|
+
}, renderIcon: multiItemElement.icon, disabled: (multiItemElement.disabled &&
|
|
320
|
+
multiItemElement.disabled(inputData.filter((row) => selectedItems.includes(row.id)))) ||
|
|
321
|
+
selectedItems.length === 0, kind: multiItemElement.kind, children: multiItemElement.label }, multiItemElement.id));
|
|
322
|
+
}
|
|
323
|
+
else if (toolbarElement.type === 'multiSelect') {
|
|
324
|
+
const multiSelectElement = toolbarElement;
|
|
325
|
+
const multiSelectItemsInFilter = currentFilters.current.get(multiSelectElement.id)?.selectedItems;
|
|
326
|
+
const selectedItems = multiSelectElement.items?.filter((item) => {
|
|
327
|
+
return multiSelectItemsInFilter?.some((id) => item.id === id);
|
|
328
|
+
});
|
|
329
|
+
toolbarComponents.push(_jsx(MultiSelect, { type: 'inline', size: 'lg', titleText: multiSelectElement?.label, useTitleInItem: true, hideLabel: true, label: multiSelectElement.label ?? '', id: multiSelectElement.id, items: multiSelectElement.items, selectedItems: selectedItems ?? [], onChange: ({ selectedItems }) => {
|
|
330
|
+
const value = selectedItems.map((item) => item.id);
|
|
331
|
+
currentFilters.current.set(multiSelectElement.id, {
|
|
332
|
+
id: multiSelectElement.id,
|
|
333
|
+
selectedItems: value,
|
|
334
|
+
});
|
|
335
|
+
updateFilteredData();
|
|
336
|
+
updateFilterURLState(multiSelectElement.queryName ?? multiSelectElement.id, value);
|
|
337
|
+
} }, multiSelectElement.id));
|
|
338
|
+
}
|
|
339
|
+
else if (toolbarElement.type === 'search') {
|
|
340
|
+
const searchElement = toolbarElement;
|
|
341
|
+
const filterId = searchElement.id ?? searchElement.queryName;
|
|
342
|
+
const defaultValue = currentFilters.current.get(filterId);
|
|
343
|
+
searchComponent = (_jsx(TableToolbarSearch, { placeholder: searchElement.label, persistent: true, onFocus: (event, handleExpand) => {
|
|
344
|
+
handleExpand(event, true);
|
|
345
|
+
if (searchElement.queryName) {
|
|
346
|
+
updateFilterURLState(searchElement?.queryName, '');
|
|
347
|
+
}
|
|
348
|
+
}, defaultValue: defaultValue?.searchTerm ?? '', onBlur: (event, handleExpand) => {
|
|
349
|
+
if (!event.target.value) {
|
|
350
|
+
handleExpand(event, false);
|
|
351
|
+
}
|
|
352
|
+
updateFilterURLState(searchElement.queryName ?? searchElement.id, event.target.value);
|
|
353
|
+
}, onChange: (event) => {
|
|
354
|
+
currentFilters.current.set(filterId, {
|
|
355
|
+
searchTerm: event.target?.value ?? defaultValue?.searchTerm,
|
|
356
|
+
});
|
|
357
|
+
updateFilteredData();
|
|
358
|
+
} }, searchElement.id));
|
|
359
|
+
}
|
|
360
|
+
else if (toolbarElement.type === 'button') {
|
|
361
|
+
const buttonElement = toolbarElement;
|
|
362
|
+
toolbarComponents.push(_jsx(Button, { id: buttonElement.id, onClick: async () => {
|
|
363
|
+
if (buttonElement.onClick) {
|
|
364
|
+
await buttonElement.onClick();
|
|
365
|
+
}
|
|
366
|
+
}, renderIcon: buttonElement.icon, disabled: buttonElement.disabled, kind: buttonElement.kind, children: buttonElement.label }, buttonElement.id));
|
|
367
|
+
}
|
|
368
|
+
else if (toolbarElement.type === 'menuButton') {
|
|
369
|
+
const menuButtonElement = toolbarElement;
|
|
370
|
+
toolbarComponents.push(_jsx(MenuButton, { label: menuButtonElement.label ?? '', disabled: menuButtonElement.disabled, kind: menuButtonElement.kind, menuAlignment: 'bottom', children: menuButtonElement.items.map((item, itemIndex) => (_jsx(MenuItem, { label: item.label, onClick: item.onClick, disabled: item.disabled }, `${menuButtonElement.id}-item-${itemIndex}`))) }, menuButtonElement.id));
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
if (toolbarComponents.length > 0 || !!searchComponent) {
|
|
375
|
+
toolbarComponent = (_jsx(TableToolbar, { "aria-label": 'data table toolbar', children: _jsxs(ToolbarWrapper, { style: {
|
|
376
|
+
justifyContent: toolbarComponents.length > 5 ? 'normal' : 'end',
|
|
377
|
+
flexWrap: toolbarComponents.length > 5 ? 'wrap' : undefined,
|
|
378
|
+
blockSize: toolbarComponents.length > 5 ? 'auto' : '3rem',
|
|
379
|
+
}, children: [searchComponent && (_jsx("div", { style: {
|
|
380
|
+
display: 'flex',
|
|
381
|
+
justifyContent: 'end',
|
|
382
|
+
width: toolbarComponents.length > 5 ? '420px' : '100%',
|
|
383
|
+
}, children: searchComponent })), toolbarComponents] }) }, `toolbarcomponent-${id}-${index}`));
|
|
384
|
+
}
|
|
385
|
+
toolbarRows.push(toolbarComponent);
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
// ==== ACTIONS ====
|
|
389
|
+
const hasActions = actions !== undefined && actions.length > 0;
|
|
390
|
+
const renderActions = (row) => {
|
|
391
|
+
let actionCell = null;
|
|
392
|
+
if (actions && actions.length > 0) {
|
|
393
|
+
actionCell = [];
|
|
394
|
+
if (actions.filter((action) => action.visible === undefined || action.visible(row)).length < tableOptions.actionsUseOverflowMenuMinItems) {
|
|
395
|
+
for (const action of actions.filter((action) => action.visible === undefined || action.visible(row))) {
|
|
396
|
+
if (action.icon) {
|
|
397
|
+
actionCell.push(_jsx(Button, { "data-cy": action.id, kind: action.kind, disabled: action.disabled !== undefined
|
|
398
|
+
? action.disabled(row)
|
|
399
|
+
: undefined, iconDescription: typeof action.label === 'function'
|
|
400
|
+
? action.label(row)
|
|
401
|
+
: action.label, hasIconOnly: true, renderIcon: typeof action.icon === 'function'
|
|
402
|
+
? action.icon(row)
|
|
403
|
+
: action.icon, onClick: (event) => action.onClick(row, event) }, action.id));
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
actionCell.push(_jsx(Button, { "data-cy": action.id, kind: action.kind, disabled: action.disabled !== undefined
|
|
407
|
+
? action.disabled(row)
|
|
408
|
+
: undefined, "aria-label": typeof action.label === 'function'
|
|
409
|
+
? action.label(row)
|
|
410
|
+
: action.label, onClick: (event) => action.onClick(row, event), children: typeof action.label === 'function'
|
|
411
|
+
? action.label(row)
|
|
412
|
+
: action.label }, action.id));
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
const overflowMenuItems = [];
|
|
418
|
+
for (const action of actions.filter((action) => action.visible === undefined || action.visible(row))) {
|
|
419
|
+
overflowMenuItems.push(_jsx(OverflowMenuItem, { itemText: typeof action.label === 'function'
|
|
420
|
+
? action.label(row)
|
|
421
|
+
: action.label, isDelete: action.kind === 'danger', disabled: action.disabled !== undefined
|
|
422
|
+
? action.disabled(row)
|
|
423
|
+
: undefined, onClick: (event) => action.onClick(row, event), hasDivider: action.hasDivider }, action.id));
|
|
424
|
+
}
|
|
425
|
+
actionCell.push(_jsx(OverflowMenu, { flipped: true, children: overflowMenuItems }, 'overflow-menu'));
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
return actionCell;
|
|
429
|
+
};
|
|
430
|
+
// ==== CONTENT ====
|
|
431
|
+
const hasExpansion = getDataForCurrentPage().find((row) => row.expansion) !== undefined;
|
|
432
|
+
const renderHeaders = () => {
|
|
433
|
+
let regularHeaders = headers.map((header) => (_jsx(TableHeader, { isSortable: header.sorting !== undefined, sortDirection: currentSortDirection(header.key), isSortHeader: header.sorting !== undefined, onClick: () => updateSortDirection(header.key), children: header.label }, header.key)));
|
|
434
|
+
if (allToolbarItems?.find((toolbarItem) => toolbarItem.type === 'multiItemButton')) {
|
|
435
|
+
regularHeaders = [
|
|
436
|
+
_jsx(TableSelectAll, { checked: selectedItems.length >= currentPageSize, indeterminate: selectedItems.length > 0 && selectedItems.length < currentPageSize, onSelect: () => toggleSelectAllOnPage(), id: 'allcluster-select-all', name: 'multi-select-all-header' }, 'allcluster-select-all'),
|
|
437
|
+
...regularHeaders,
|
|
438
|
+
];
|
|
439
|
+
}
|
|
440
|
+
return (_jsxs(_Fragment, { children: [hasExpansion && (_jsx(TableExpandHeader, { children: _jsx("span", { style: { height: '0px', width: '0px', fontSize: '0px' }, children: "expand" }) })), regularHeaders, hasActions && (_jsx(TableHeader, { style: { textAlign: 'right' }, children: _jsx("span", { style: { height: '0px', width: '0px', fontSize: '0px' }, children: "actions" }) }))] }));
|
|
441
|
+
};
|
|
442
|
+
const someSelectRow = allToolbarItems?.some((toolBarItem) => toolBarItem.type === 'multiItemButton');
|
|
443
|
+
const renderRow = (row) => {
|
|
444
|
+
const rowCell = (key) => {
|
|
445
|
+
const defaultContent = row[key];
|
|
446
|
+
let content = row[key];
|
|
447
|
+
const foundHeader = headers.find((header) => header.key === key);
|
|
448
|
+
if (foundHeader?.type) {
|
|
449
|
+
switch (foundHeader.type.type) {
|
|
450
|
+
case 'code':
|
|
451
|
+
content = (_jsx(CodeSnippet, { type: foundHeader.type.options?.codeOptions?.type ??
|
|
452
|
+
'inline', children: defaultContent }));
|
|
453
|
+
break;
|
|
454
|
+
case 'link':
|
|
455
|
+
content = (_jsx(Link, { href: foundHeader.type.options.linkOptions.href(row), target: foundHeader.type.options.linkOptions?.target ?? '_self', children: defaultContent }));
|
|
456
|
+
break;
|
|
457
|
+
case 'link-button':
|
|
458
|
+
if (foundHeader.type.options.linkButtonOptions.disabled &&
|
|
459
|
+
foundHeader.type.options.linkButtonOptions.disabled(row)) {
|
|
460
|
+
content = _jsx("strong", { children: defaultContent });
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
content = (_jsx(LinkButton, { label: defaultContent, onClick: () => foundHeader.type.options.linkButtonOptions.onClick(row) }));
|
|
464
|
+
}
|
|
465
|
+
break;
|
|
466
|
+
case 'wrapper':
|
|
467
|
+
content = foundHeader.type.options.wrapperOptions.wrapper(row);
|
|
468
|
+
break;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return (_jsx(TableCell, { onClick: row.onClick ? () => row.onClick() : undefined, style: { cursor: row.onClick ? 'pointer' : undefined }, children: content }, `${row.id}-${key}`));
|
|
472
|
+
};
|
|
473
|
+
let rowComponent = (_jsxs(TableRow, { children: [hasExpansion && someSelectRow && (_jsx(TableCell, { className: 'cds--table-expand' })), allToolbarItems?.find((toolBarItem) => toolBarItem.type === 'multiItemButton') && (_jsx(TableSelectRow, { "aria-label": `select all ${row.id}`, checked: itemIsSelected(row.id), name: `multiselect-row-${row.id}`, id: `multiselect-row-${row.id}`, onSelect: () => {
|
|
474
|
+
toggleSelectedItem(row.id);
|
|
475
|
+
} })), hasExpansion && !row.expansion && !someSelectRow && _jsx(TableCell, {}), headerKeys.map((key) => {
|
|
476
|
+
return rowCell(key);
|
|
477
|
+
}), hasActions && (_jsx(TableCell, { children: _jsx("div", { style: {
|
|
478
|
+
display: 'flex',
|
|
479
|
+
justifyContent: 'flex-end',
|
|
480
|
+
alignItems: 'center',
|
|
481
|
+
}, children: renderActions(row) }) }))] }, `${row.id}-${row.originalIndex}`));
|
|
482
|
+
if (row.expansion) {
|
|
483
|
+
rowComponent = (_jsxs(React.Fragment, { children: [_jsxs(TableExpandRow, { isExpanded: isRowExpanded(row), "aria-label": `row ${row.id}`, onExpand: () => {
|
|
484
|
+
updateRowExpansion(row);
|
|
485
|
+
}, children: [someSelectRow && (_jsx(TableSelectRow, { "aria-label": `select all ${row.id}`, checked: itemIsSelected(row.id), name: `multiselect-row-${row.id}`, id: `multiselect-row-${row.id}`, onSelect: () => {
|
|
486
|
+
toggleSelectedItem(row.id);
|
|
487
|
+
} })), headerKeys.map((key) => rowCell(key)), hasActions && (_jsx(TableCell, { children: _jsx("div", { style: {
|
|
488
|
+
display: 'flex',
|
|
489
|
+
justifyContent: 'flex-end',
|
|
490
|
+
alignItems: 'center',
|
|
491
|
+
}, children: renderActions(row) }) }))] }, row.id), _jsx(TableExpandedRow, { colSpan: headers.length + (hasActions ? 2 : 1), children: row.expansion })] }, row.id));
|
|
492
|
+
}
|
|
493
|
+
return rowComponent;
|
|
494
|
+
};
|
|
495
|
+
// ==== PAGINATION ====
|
|
496
|
+
let paginationComponent = null;
|
|
497
|
+
if (tableOptions.showPagination) {
|
|
498
|
+
paginationComponent = (_jsx(Pagination, { page: currentPage, totalItems: filteredData.length, pageSize: currentPageSize, pageSizes: tableOptions.pageSizes, onChange: (event) => {
|
|
499
|
+
const { page, pageSize } = event;
|
|
500
|
+
setCurrentPage(page);
|
|
501
|
+
setCurrentPageSize(pageSize);
|
|
502
|
+
selectItem([]);
|
|
503
|
+
} }));
|
|
504
|
+
}
|
|
505
|
+
// ==== RENDER ====
|
|
506
|
+
component = (_jsxs(TableContainer, { title: title, description: description, children: [toolbarRows.map((toolbarComponent) => toolbarComponent), _jsxs(Table, { size: tableOptions.tableSize, useZebraStyles: tableOptions.useZebraStyles, children: [_jsx(TableHead, { children: _jsx(TableRow, { children: renderHeaders() }, `tablerow-${id}`) }, `tablehead-${id}`), _jsx(TableBody, { children: getDataForCurrentPage().map((row) => renderRow(row)) }, `tablebody-${id}`)] }, `table-${id}`), paginationComponent] }, `tablecontainer-${id}`));
|
|
507
|
+
}
|
|
508
|
+
return component;
|
|
509
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
export interface RowBaseProps {
|
|
3
|
+
id: string;
|
|
4
|
+
originalIndex: number;
|
|
5
|
+
expansion?: React.ReactNode;
|
|
6
|
+
onClick?: () => void;
|
|
7
|
+
}
|
|
8
|
+
export interface Filter<T extends RowBaseProps> {
|
|
9
|
+
selectedItems?: string[];
|
|
10
|
+
selectedItem?: string;
|
|
11
|
+
row: T;
|
|
12
|
+
searchTerm?: string;
|
|
13
|
+
}
|
|
14
|
+
interface Item {
|
|
15
|
+
id: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}
|
|
18
|
+
export type C3DataTableToolbarProps<T extends RowBaseProps> = C3DataTableToolbarSearchItemProps<T> | C3DataTableToolbarButtonItemProps | C3DataTableToolbarMultiSelectItemProps<T> | C3DataTableToolbarMultiItemButtonProps<T> | C3DataTableToolbarSingleSelectItemProps<T> | C3DataTableToolbarMenuButtonItemProps;
|
|
19
|
+
export interface C3DataTableCommonToolbarProps {
|
|
20
|
+
id: string;
|
|
21
|
+
label?: string;
|
|
22
|
+
icon?: any;
|
|
23
|
+
}
|
|
24
|
+
export interface C3DataTableFilterableToolbarProps<T extends RowBaseProps> {
|
|
25
|
+
filter?: (currentFilter: Filter<T>) => boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface C3DataTableToolbarSearchItemProps<T extends RowBaseProps> extends C3DataTableCommonToolbarProps, C3DataTableFilterableToolbarProps<T> {
|
|
28
|
+
type: 'search';
|
|
29
|
+
queryName?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface C3DataTableToolbarButtonItemProps//<T extends RowBaseProps>
|
|
32
|
+
extends C3DataTableCommonToolbarProps {
|
|
33
|
+
type: 'button';
|
|
34
|
+
onClick: () => void;
|
|
35
|
+
disabled?: boolean;
|
|
36
|
+
kind?: any;
|
|
37
|
+
}
|
|
38
|
+
export interface C3DataTableToolbarMultiSelectItemProps<T extends RowBaseProps> extends C3DataTableCommonToolbarProps, C3DataTableFilterableToolbarProps<T> {
|
|
39
|
+
type: 'multiSelect';
|
|
40
|
+
items?: Item[];
|
|
41
|
+
kind?: any;
|
|
42
|
+
queryName?: string;
|
|
43
|
+
}
|
|
44
|
+
export interface C3DataTableToolbarSingleSelectItemProps<T extends RowBaseProps> extends C3DataTableCommonToolbarProps, C3DataTableFilterableToolbarProps<T> {
|
|
45
|
+
type: 'singleSelect';
|
|
46
|
+
items?: Item[];
|
|
47
|
+
disabled?: boolean;
|
|
48
|
+
kind?: any;
|
|
49
|
+
defaultValue?: any;
|
|
50
|
+
queryName?: string;
|
|
51
|
+
}
|
|
52
|
+
export interface C3DataTableToolbarMultiItemButtonProps<T extends RowBaseProps> extends C3DataTableCommonToolbarProps {
|
|
53
|
+
type: 'multiItemButton';
|
|
54
|
+
multiOnClick: (selectedItems: T[]) => void;
|
|
55
|
+
disabled?: (selectedItems: T[]) => boolean;
|
|
56
|
+
kind?: any;
|
|
57
|
+
}
|
|
58
|
+
export interface C3DataTableToolbarMenuButtonItemProps extends C3DataTableCommonToolbarProps {
|
|
59
|
+
type: 'menuButton';
|
|
60
|
+
disabled?: boolean;
|
|
61
|
+
items: Array<{
|
|
62
|
+
onClick: () => void;
|
|
63
|
+
label: string;
|
|
64
|
+
disabled?: boolean;
|
|
65
|
+
}>;
|
|
66
|
+
kind?: any;
|
|
67
|
+
}
|
|
68
|
+
export interface C3DataTableActionProps<T extends RowBaseProps> {
|
|
69
|
+
id: string;
|
|
70
|
+
kind: any;
|
|
71
|
+
label: ((row: T) => string) | string;
|
|
72
|
+
icon?: ((row: T) => any) | any;
|
|
73
|
+
disabled?: (row: T) => boolean;
|
|
74
|
+
visible?: (row: T) => boolean;
|
|
75
|
+
hasDivider?: boolean;
|
|
76
|
+
onClick: (row: T, event?: any) => void;
|
|
77
|
+
}
|
|
78
|
+
export interface C3DataTableHeaderContentType<T extends RowBaseProps> {
|
|
79
|
+
type: 'text' | 'code' | 'link-button' | 'link' | 'wrapper';
|
|
80
|
+
options?: {
|
|
81
|
+
codeOptions?: {
|
|
82
|
+
type: 'inline' | 'multi' | 'single';
|
|
83
|
+
};
|
|
84
|
+
linkOptions?: {
|
|
85
|
+
href: (row: T) => string;
|
|
86
|
+
target?: string;
|
|
87
|
+
};
|
|
88
|
+
linkButtonOptions?: {
|
|
89
|
+
onClick: (row: T) => void;
|
|
90
|
+
disabled?: (row: T) => boolean;
|
|
91
|
+
};
|
|
92
|
+
wrapperOptions?: {
|
|
93
|
+
wrapper: (row: T) => React.ReactNode;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export interface C3DataTableHeadersProps<T extends RowBaseProps> {
|
|
98
|
+
key: string;
|
|
99
|
+
label: string;
|
|
100
|
+
sorting?: (a: T, b: T) => number;
|
|
101
|
+
type?: C3DataTableHeaderContentType<T>;
|
|
102
|
+
}
|
|
103
|
+
export interface C3DataTableProps<T extends RowBaseProps> {
|
|
104
|
+
id?: string;
|
|
105
|
+
title?: string;
|
|
106
|
+
description?: any;
|
|
107
|
+
headers: C3DataTableHeadersProps<T>[];
|
|
108
|
+
actions?: C3DataTableActionProps<T>[];
|
|
109
|
+
options?: {
|
|
110
|
+
pageSize?: number;
|
|
111
|
+
pageSizes?: number[];
|
|
112
|
+
tableSize?: 'sm' | 'md' | 'lg';
|
|
113
|
+
useZebraStyles?: boolean;
|
|
114
|
+
actionsUseOverflowMenuMinItems?: number;
|
|
115
|
+
};
|
|
116
|
+
data: Array<T>;
|
|
117
|
+
toolbar?: C3DataTableToolbarProps<T>[];
|
|
118
|
+
toolbars?: C3DataTableToolbarProps<T>[][];
|
|
119
|
+
isLoading?: boolean;
|
|
120
|
+
queryPrefix?: string;
|
|
121
|
+
}
|
|
122
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
|
|
4
|
+
* under one or more contributor license agreements. Licensed under a commercial license.
|
|
5
|
+
* You may not use this file except in compliance with the commercial license.
|
|
6
|
+
*/
|
|
7
|
+
import { Link } from '@carbon/react';
|
|
8
|
+
export const LinkButton = ({ label, onClick, style, inline, icon, disabled, }) => {
|
|
9
|
+
if (disabled === undefined) {
|
|
10
|
+
disabled = false;
|
|
11
|
+
}
|
|
12
|
+
const customStyle = style ? style : {};
|
|
13
|
+
const component = (_jsxs(Link, { onClick: () => !disabled && onClick(), inline: inline, style: { cursor: 'pointer', ...customStyle }, disabled: disabled, children: [label, icon && (_jsx("span", { style: { marginLeft: '0.5rem', marginBottom: '-0.2rem' }, children: icon }))] }));
|
|
14
|
+
return component;
|
|
15
|
+
};
|