dp-widgets-framework 1.5.8 → 1.5.9
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/dist/index.esm.js +58 -4
- package/dist/index.js +57 -3
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -7,7 +7,7 @@ import * as LabelPrimitive from '@radix-ui/react-label';
|
|
|
7
7
|
import { cva } from 'class-variance-authority';
|
|
8
8
|
import * as SwitchPrimitives from '@radix-ui/react-switch';
|
|
9
9
|
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
10
|
-
import { ChevronDown, ChevronUp, Check, AlertCircle, MoveUp, MoveDown, Trash2, Plus, Bot, Type, Layout, LayoutGrid, BarChart as BarChart$1, Filter, Search, ArrowUp, ArrowDown, ChevronRight, RefreshCw, Send, X, AlignVerticalSpaceAround, LineChart as LineChart$1, PieChart as PieChart$1, Table, FileText, SlidersHorizontal,
|
|
10
|
+
import { ChevronDown, ChevronUp, Check, AlertCircle, MoveUp, MoveDown, Trash2, Plus, Bot, Type, Layout, LayoutGrid, BarChart as BarChart$1, Filter, Search, ArrowUp, ArrowDown, ChevronRight, RefreshCw, Send, Loader2, X, AlignVerticalSpaceAround, LineChart as LineChart$1, PieChart as PieChart$1, Table, FileText, SlidersHorizontal, GripHorizontal, Edit, MessageCircleX, Edit2 } from 'lucide-react';
|
|
11
11
|
import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
|
|
12
12
|
import { Slot } from '@radix-ui/react-slot';
|
|
13
13
|
import { debounce as debounce$1 } from 'lodash';
|
|
@@ -39387,10 +39387,12 @@ function TableSelectionConfirmation({ ambiguousColumns, resolvedColumns, message
|
|
|
39387
39387
|
}, className: "w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary-500", children: [jsxRuntimeExports.jsx("option", { value: "", children: "Select a table..." }), col.tables.map((table) => (jsxRuntimeExports.jsx("option", { value: table, children: table }, table)))] })] }, col.column))) }) }), jsxRuntimeExports.jsxs("div", { className: "flex gap-2 pt-3 border-t border-gray-200", children: [jsxRuntimeExports.jsx(Button, { onClick: onCancel, variant: "outline", className: "flex-1", children: "Cancel" }), jsxRuntimeExports.jsx(Button, { onClick: handleSubmit, disabled: !allSelected, className: "flex-1 bg-primary-600 hover:bg-primary-700 text-white disabled:bg-gray-400", children: "Confirm Selection" })] })] }));
|
|
39388
39388
|
}
|
|
39389
39389
|
function FiltersContent({ filterGroups, showHeader, onFilterChange, widget, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout, filterState, onApplyFilters, isEditing = false, }) {
|
|
39390
|
+
var _a;
|
|
39390
39391
|
const hasCalledRef = useRef(false);
|
|
39391
39392
|
const [expandedGroups, setExpandedGroups] = useState({});
|
|
39392
39393
|
const [selectedFilters, setSelectedFilters] = useState({});
|
|
39393
39394
|
const [searchQueries, setSearchQueries] = useState({});
|
|
39395
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
39394
39396
|
const isEmpty = filterGroups.length === 0;
|
|
39395
39397
|
const handleRefresh = async () => {
|
|
39396
39398
|
if (query) {
|
|
@@ -39428,6 +39430,29 @@ function FiltersContent({ filterGroups, showHeader, onFilterChange, widget, appe
|
|
|
39428
39430
|
});
|
|
39429
39431
|
setExpandedGroups(initialExpanded);
|
|
39430
39432
|
}, [filterGroups]);
|
|
39433
|
+
// Initialize selected filters from widget.config.filters
|
|
39434
|
+
useEffect(() => {
|
|
39435
|
+
var _a;
|
|
39436
|
+
if (((_a = widget.config) === null || _a === void 0 ? void 0 : _a.filters) && filterGroups.length > 0) {
|
|
39437
|
+
const initialSelectedFilters = {};
|
|
39438
|
+
Object.entries(widget.config.filters).forEach(([groupId, labels]) => {
|
|
39439
|
+
const group = filterGroups.find(g => g.id === groupId);
|
|
39440
|
+
if (group && Array.isArray(labels)) {
|
|
39441
|
+
// Convert labels back to option IDs
|
|
39442
|
+
const optionIds = labels
|
|
39443
|
+
.map(label => {
|
|
39444
|
+
const option = group.options.find(opt => opt.label === label);
|
|
39445
|
+
return option === null || option === void 0 ? void 0 : option.id;
|
|
39446
|
+
})
|
|
39447
|
+
.filter((id) => id !== undefined);
|
|
39448
|
+
if (optionIds.length > 0) {
|
|
39449
|
+
initialSelectedFilters[groupId] = optionIds;
|
|
39450
|
+
}
|
|
39451
|
+
}
|
|
39452
|
+
});
|
|
39453
|
+
setSelectedFilters(initialSelectedFilters);
|
|
39454
|
+
}
|
|
39455
|
+
}, [(_a = widget.config) === null || _a === void 0 ? void 0 : _a.filters, filterGroups]);
|
|
39431
39456
|
const toggleGroup = (groupId) => {
|
|
39432
39457
|
setExpandedGroups((prev) => (Object.assign(Object.assign({}, prev), { [groupId]: !prev[groupId] })));
|
|
39433
39458
|
};
|
|
@@ -39491,7 +39516,7 @@ function FiltersContent({ filterGroups, showHeader, onFilterChange, widget, appe
|
|
|
39491
39516
|
if (onFilterChange) {
|
|
39492
39517
|
onFilterChange({});
|
|
39493
39518
|
}
|
|
39494
|
-
}, className: "py-1.5 text-sm font-medium text-primary-600 hover:text-primary-800 hover:bg-primary-50 rounded-md transition-colors px-2", children: "Clear All Filters" })) : (jsxRuntimeExports.jsx("div", {})), jsxRuntimeExports.jsx(Button, { onClick: () => {
|
|
39519
|
+
}, className: "py-1.5 text-sm font-medium text-primary-600 hover:text-primary-800 hover:bg-primary-50 rounded-md transition-colors px-2", children: "Clear All Filters" })) : (jsxRuntimeExports.jsx("div", {})), jsxRuntimeExports.jsx(Button, { onClick: async () => {
|
|
39495
39520
|
// Convert option IDs back to original label values
|
|
39496
39521
|
const filtersWithLabels = {};
|
|
39497
39522
|
filterGroups.forEach((group) => {
|
|
@@ -39501,8 +39526,37 @@ function FiltersContent({ filterGroups, showHeader, onFilterChange, widget, appe
|
|
|
39501
39526
|
return (option === null || option === void 0 ? void 0 : option.label) || optionId;
|
|
39502
39527
|
});
|
|
39503
39528
|
});
|
|
39504
|
-
|
|
39505
|
-
|
|
39529
|
+
// Call API to update widget config with filters
|
|
39530
|
+
if (widgetBackendUrl && widgetId) {
|
|
39531
|
+
setIsSubmitting(true);
|
|
39532
|
+
try {
|
|
39533
|
+
const response = await fetch(`${widgetBackendUrl}/api/widgets/${widgetId}/config`, {
|
|
39534
|
+
method: 'PATCH',
|
|
39535
|
+
headers: {
|
|
39536
|
+
'Content-Type': 'application/json',
|
|
39537
|
+
},
|
|
39538
|
+
body: JSON.stringify({
|
|
39539
|
+
config: Object.assign(Object.assign({}, widget.config), { filters: filtersWithLabels }),
|
|
39540
|
+
}),
|
|
39541
|
+
});
|
|
39542
|
+
if (!response.ok) {
|
|
39543
|
+
throw new Error('Failed to update widget config');
|
|
39544
|
+
}
|
|
39545
|
+
// Call the onApplyFilters callback after successful API call
|
|
39546
|
+
onApplyFilters === null || onApplyFilters === void 0 ? void 0 : onApplyFilters(filtersWithLabels);
|
|
39547
|
+
}
|
|
39548
|
+
catch (error) {
|
|
39549
|
+
console.error('Error updating widget config:', error);
|
|
39550
|
+
}
|
|
39551
|
+
finally {
|
|
39552
|
+
setIsSubmitting(false);
|
|
39553
|
+
}
|
|
39554
|
+
}
|
|
39555
|
+
else {
|
|
39556
|
+
// Fallback if no backend URL - just call the callback
|
|
39557
|
+
onApplyFilters === null || onApplyFilters === void 0 ? void 0 : onApplyFilters(filtersWithLabels);
|
|
39558
|
+
}
|
|
39559
|
+
}, disabled: isEditing || isSubmitting, className: `${isEditing || isSubmitting ? 'bg-gray-400 cursor-not-allowed' : 'bg-primary-600 hover:bg-primary-700'} text-white`, title: isEditing ? 'Save the layout first to apply filters' : '', children: isSubmitting ? (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }), "Applying..."] })) : ('Apply Filters') })] }) })] }));
|
|
39506
39560
|
}
|
|
39507
39561
|
function CopilotKitFilters({ widget, showHeader, onFilterChange, onResetReady, widgetBackendUrl, datasetId, onApplyFilters, isEditing = false, }) {
|
|
39508
39562
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
package/dist/index.js
CHANGED
|
@@ -39414,10 +39414,12 @@ function TableSelectionConfirmation({ ambiguousColumns, resolvedColumns, message
|
|
|
39414
39414
|
}, className: "w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-primary-500", children: [jsxRuntimeExports.jsx("option", { value: "", children: "Select a table..." }), col.tables.map((table) => (jsxRuntimeExports.jsx("option", { value: table, children: table }, table)))] })] }, col.column))) }) }), jsxRuntimeExports.jsxs("div", { className: "flex gap-2 pt-3 border-t border-gray-200", children: [jsxRuntimeExports.jsx(Button, { onClick: onCancel, variant: "outline", className: "flex-1", children: "Cancel" }), jsxRuntimeExports.jsx(Button, { onClick: handleSubmit, disabled: !allSelected, className: "flex-1 bg-primary-600 hover:bg-primary-700 text-white disabled:bg-gray-400", children: "Confirm Selection" })] })] }));
|
|
39415
39415
|
}
|
|
39416
39416
|
function FiltersContent({ filterGroups, showHeader, onFilterChange, widget, appendMessage, query, isFirstLoad, widgetBackendUrl, widgetId, startLoadingTimeout, clearLoadingTimeout, filterState, onApplyFilters, isEditing = false, }) {
|
|
39417
|
+
var _a;
|
|
39417
39418
|
const hasCalledRef = React.useRef(false);
|
|
39418
39419
|
const [expandedGroups, setExpandedGroups] = React.useState({});
|
|
39419
39420
|
const [selectedFilters, setSelectedFilters] = React.useState({});
|
|
39420
39421
|
const [searchQueries, setSearchQueries] = React.useState({});
|
|
39422
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
39421
39423
|
const isEmpty = filterGroups.length === 0;
|
|
39422
39424
|
const handleRefresh = async () => {
|
|
39423
39425
|
if (query) {
|
|
@@ -39455,6 +39457,29 @@ function FiltersContent({ filterGroups, showHeader, onFilterChange, widget, appe
|
|
|
39455
39457
|
});
|
|
39456
39458
|
setExpandedGroups(initialExpanded);
|
|
39457
39459
|
}, [filterGroups]);
|
|
39460
|
+
// Initialize selected filters from widget.config.filters
|
|
39461
|
+
React.useEffect(() => {
|
|
39462
|
+
var _a;
|
|
39463
|
+
if (((_a = widget.config) === null || _a === void 0 ? void 0 : _a.filters) && filterGroups.length > 0) {
|
|
39464
|
+
const initialSelectedFilters = {};
|
|
39465
|
+
Object.entries(widget.config.filters).forEach(([groupId, labels]) => {
|
|
39466
|
+
const group = filterGroups.find(g => g.id === groupId);
|
|
39467
|
+
if (group && Array.isArray(labels)) {
|
|
39468
|
+
// Convert labels back to option IDs
|
|
39469
|
+
const optionIds = labels
|
|
39470
|
+
.map(label => {
|
|
39471
|
+
const option = group.options.find(opt => opt.label === label);
|
|
39472
|
+
return option === null || option === void 0 ? void 0 : option.id;
|
|
39473
|
+
})
|
|
39474
|
+
.filter((id) => id !== undefined);
|
|
39475
|
+
if (optionIds.length > 0) {
|
|
39476
|
+
initialSelectedFilters[groupId] = optionIds;
|
|
39477
|
+
}
|
|
39478
|
+
}
|
|
39479
|
+
});
|
|
39480
|
+
setSelectedFilters(initialSelectedFilters);
|
|
39481
|
+
}
|
|
39482
|
+
}, [(_a = widget.config) === null || _a === void 0 ? void 0 : _a.filters, filterGroups]);
|
|
39458
39483
|
const toggleGroup = (groupId) => {
|
|
39459
39484
|
setExpandedGroups((prev) => (Object.assign(Object.assign({}, prev), { [groupId]: !prev[groupId] })));
|
|
39460
39485
|
};
|
|
@@ -39518,7 +39543,7 @@ function FiltersContent({ filterGroups, showHeader, onFilterChange, widget, appe
|
|
|
39518
39543
|
if (onFilterChange) {
|
|
39519
39544
|
onFilterChange({});
|
|
39520
39545
|
}
|
|
39521
|
-
}, className: "py-1.5 text-sm font-medium text-primary-600 hover:text-primary-800 hover:bg-primary-50 rounded-md transition-colors px-2", children: "Clear All Filters" })) : (jsxRuntimeExports.jsx("div", {})), jsxRuntimeExports.jsx(Button, { onClick: () => {
|
|
39546
|
+
}, className: "py-1.5 text-sm font-medium text-primary-600 hover:text-primary-800 hover:bg-primary-50 rounded-md transition-colors px-2", children: "Clear All Filters" })) : (jsxRuntimeExports.jsx("div", {})), jsxRuntimeExports.jsx(Button, { onClick: async () => {
|
|
39522
39547
|
// Convert option IDs back to original label values
|
|
39523
39548
|
const filtersWithLabels = {};
|
|
39524
39549
|
filterGroups.forEach((group) => {
|
|
@@ -39528,8 +39553,37 @@ function FiltersContent({ filterGroups, showHeader, onFilterChange, widget, appe
|
|
|
39528
39553
|
return (option === null || option === void 0 ? void 0 : option.label) || optionId;
|
|
39529
39554
|
});
|
|
39530
39555
|
});
|
|
39531
|
-
|
|
39532
|
-
|
|
39556
|
+
// Call API to update widget config with filters
|
|
39557
|
+
if (widgetBackendUrl && widgetId) {
|
|
39558
|
+
setIsSubmitting(true);
|
|
39559
|
+
try {
|
|
39560
|
+
const response = await fetch(`${widgetBackendUrl}/api/widgets/${widgetId}/config`, {
|
|
39561
|
+
method: 'PATCH',
|
|
39562
|
+
headers: {
|
|
39563
|
+
'Content-Type': 'application/json',
|
|
39564
|
+
},
|
|
39565
|
+
body: JSON.stringify({
|
|
39566
|
+
config: Object.assign(Object.assign({}, widget.config), { filters: filtersWithLabels }),
|
|
39567
|
+
}),
|
|
39568
|
+
});
|
|
39569
|
+
if (!response.ok) {
|
|
39570
|
+
throw new Error('Failed to update widget config');
|
|
39571
|
+
}
|
|
39572
|
+
// Call the onApplyFilters callback after successful API call
|
|
39573
|
+
onApplyFilters === null || onApplyFilters === void 0 ? void 0 : onApplyFilters(filtersWithLabels);
|
|
39574
|
+
}
|
|
39575
|
+
catch (error) {
|
|
39576
|
+
console.error('Error updating widget config:', error);
|
|
39577
|
+
}
|
|
39578
|
+
finally {
|
|
39579
|
+
setIsSubmitting(false);
|
|
39580
|
+
}
|
|
39581
|
+
}
|
|
39582
|
+
else {
|
|
39583
|
+
// Fallback if no backend URL - just call the callback
|
|
39584
|
+
onApplyFilters === null || onApplyFilters === void 0 ? void 0 : onApplyFilters(filtersWithLabels);
|
|
39585
|
+
}
|
|
39586
|
+
}, disabled: isEditing || isSubmitting, className: `${isEditing || isSubmitting ? 'bg-gray-400 cursor-not-allowed' : 'bg-primary-600 hover:bg-primary-700'} text-white`, title: isEditing ? 'Save the layout first to apply filters' : '', children: isSubmitting ? (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx(lucideReact.Loader2, { className: "mr-2 h-4 w-4 animate-spin" }), "Applying..."] })) : ('Apply Filters') })] }) })] }));
|
|
39533
39587
|
}
|
|
39534
39588
|
function CopilotKitFilters({ widget, showHeader, onFilterChange, onResetReady, widgetBackendUrl, datasetId, onApplyFilters, isEditing = false, }) {
|
|
39535
39589
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|