@mohsinonxrm/pptb-fetchxml-studio 1.0.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.
Files changed (74) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/README.md +250 -0
  3. package/eslint.config.js +23 -0
  4. package/index.html +71 -0
  5. package/package.json +53 -0
  6. package/public/vite.svg +1 -0
  7. package/src/app/AppShell.tsx +1733 -0
  8. package/src/assets/20px-Microsoft_Office_Excel_(2025/342/200/223present).svg.png +0 -0
  9. package/src/assets/react.svg +1 -0
  10. package/src/features/fetchxml/api/dataverseMetadata.ts +192 -0
  11. package/src/features/fetchxml/api/excelExport.ts +318 -0
  12. package/src/features/fetchxml/api/formattedValues.ts +107 -0
  13. package/src/features/fetchxml/api/pptbClient.ts +2635 -0
  14. package/src/features/fetchxml/model/displaySettings.ts +18 -0
  15. package/src/features/fetchxml/model/fetchxml.ts +346 -0
  16. package/src/features/fetchxml/model/fetchxmlIntellisense.ts +583 -0
  17. package/src/features/fetchxml/model/fetchxmlParser.ts +708 -0
  18. package/src/features/fetchxml/model/layoutxml.ts +372 -0
  19. package/src/features/fetchxml/model/nodes.ts +255 -0
  20. package/src/features/fetchxml/model/operators.ts +624 -0
  21. package/src/features/fetchxml/model/treeUtils.ts +174 -0
  22. package/src/features/fetchxml/state/builderStore.tsx +1160 -0
  23. package/src/features/fetchxml/state/cache.ts +393 -0
  24. package/src/features/fetchxml/ui/Dialogs/BulkDeleteDialog.tsx +352 -0
  25. package/src/features/fetchxml/ui/Dialogs/DeleteConfirmDialog.tsx +396 -0
  26. package/src/features/fetchxml/ui/Dialogs/SaveViewDialog.tsx +612 -0
  27. package/src/features/fetchxml/ui/Dialogs/SolutionPicker.tsx +114 -0
  28. package/src/features/fetchxml/ui/Dialogs/WorkflowPickerDialog.tsx +437 -0
  29. package/src/features/fetchxml/ui/LeftPane/PropertiesPanel/editors/AttributeEditor.tsx +214 -0
  30. package/src/features/fetchxml/ui/LeftPane/PropertiesPanel/editors/ConditionEditor.tsx +533 -0
  31. package/src/features/fetchxml/ui/LeftPane/PropertiesPanel/editors/FetchOptionsEditor.tsx +296 -0
  32. package/src/features/fetchxml/ui/LeftPane/PropertiesPanel/editors/FilterEditor.tsx +106 -0
  33. package/src/features/fetchxml/ui/LeftPane/PropertiesPanel/editors/LinkEntityEditor.tsx +433 -0
  34. package/src/features/fetchxml/ui/LeftPane/PropertiesPanel/editors/OrderEditor.tsx +161 -0
  35. package/src/features/fetchxml/ui/LeftPane/PropertiesPanel/editors/ValueOfPicker.tsx +194 -0
  36. package/src/features/fetchxml/ui/LeftPane/PropertiesPanel.tsx +225 -0
  37. package/src/features/fetchxml/ui/LeftPane/TreeView.tsx +604 -0
  38. package/src/features/fetchxml/ui/RightPane/AddColumnsPanel.tsx +800 -0
  39. package/src/features/fetchxml/ui/RightPane/ColumnConfigDialog.tsx +170 -0
  40. package/src/features/fetchxml/ui/RightPane/DataGridCellRenderers.tsx +356 -0
  41. package/src/features/fetchxml/ui/RightPane/EditColumnsPanel.tsx +372 -0
  42. package/src/features/fetchxml/ui/RightPane/FetchXmlEditor.tsx +399 -0
  43. package/src/features/fetchxml/ui/RightPane/FormattedValueUtils.ts +189 -0
  44. package/src/features/fetchxml/ui/RightPane/LayoutXmlViewer.tsx +171 -0
  45. package/src/features/fetchxml/ui/RightPane/PreviewTabs.tsx +471 -0
  46. package/src/features/fetchxml/ui/RightPane/ResultsCommandBar.tsx +430 -0
  47. package/src/features/fetchxml/ui/RightPane/ResultsGrid.tsx +983 -0
  48. package/src/features/fetchxml/ui/RightPane/XmlTextArea.tsx +65 -0
  49. package/src/features/fetchxml/ui/Settings/SettingsDrawer.tsx +175 -0
  50. package/src/features/fetchxml/ui/Toolbar/EntitySelector.tsx +788 -0
  51. package/src/features/fetchxml/ui/Toolbar/LoadViewPicker.tsx +274 -0
  52. package/src/features/fetchxml/ui/Toolbar/SaveViewButton.tsx +174 -0
  53. package/src/main.tsx +11 -0
  54. package/src/shared/components/AttributePicker.tsx +138 -0
  55. package/src/shared/components/BetweenInputPicker.tsx +120 -0
  56. package/src/shared/components/BooleanValuePicker.tsx +165 -0
  57. package/src/shared/components/DateTimeInputPicker.tsx +170 -0
  58. package/src/shared/components/DynamicValueList.tsx +128 -0
  59. package/src/shared/components/ExcelIcon.tsx +30 -0
  60. package/src/shared/components/MultiValuePicker.tsx +178 -0
  61. package/src/shared/components/NumericInputPicker.tsx +156 -0
  62. package/src/shared/components/OptionSetValuePicker.tsx +150 -0
  63. package/src/shared/components/RelationshipPicker.tsx +268 -0
  64. package/src/shared/contexts/ThemeContext.tsx +19 -0
  65. package/src/shared/hooks/useAccessMode.ts +77 -0
  66. package/src/shared/hooks/useLazyMetadata.ts +132 -0
  67. package/src/shared/hooks/usePptbContext.ts +170 -0
  68. package/src/shared/hooks/usePublisherFilter.ts +214 -0
  69. package/src/shared/hooks/useSolutionFilter.ts +162 -0
  70. package/src/shared/utils/debug.ts +87 -0
  71. package/tsconfig.app.json +28 -0
  72. package/tsconfig.json +7 -0
  73. package/tsconfig.node.json +26 -0
  74. package/vite.config.ts +7 -0
@@ -0,0 +1,372 @@
1
+ /**
2
+ * Edit Columns Panel (Drawer)
3
+ * Shows selected columns with reorder/remove options
4
+ * Matches Power Apps Model-Driven Apps UX
5
+ */
6
+
7
+ import { useState, useCallback, useEffect, useRef } from "react";
8
+ import {
9
+ DrawerBody,
10
+ DrawerHeader,
11
+ DrawerHeaderTitle,
12
+ OverlayDrawer,
13
+ Button,
14
+ makeStyles,
15
+ tokens,
16
+ Text,
17
+ Toolbar,
18
+ ToolbarButton,
19
+ } from "@fluentui/react-components";
20
+ import {
21
+ Dismiss24Regular,
22
+ ArrowUp20Regular,
23
+ ArrowDown20Regular,
24
+ Delete20Regular,
25
+ Add20Regular,
26
+ ArrowReset20Regular,
27
+ ReOrder16Regular,
28
+ } from "@fluentui/react-icons";
29
+ import type { LayoutColumn } from "../../model/layoutxml";
30
+
31
+ const useStyles = makeStyles({
32
+ drawer: {
33
+ width: "400px",
34
+ },
35
+ headerActions: {
36
+ display: "flex",
37
+ gap: tokens.spacingHorizontalS,
38
+ },
39
+ columnList: {
40
+ display: "flex",
41
+ flexDirection: "column",
42
+ gap: tokens.spacingVerticalXS,
43
+ marginTop: tokens.spacingVerticalM,
44
+ },
45
+ columnItem: {
46
+ display: "flex",
47
+ alignItems: "center",
48
+ gap: tokens.spacingHorizontalS,
49
+ padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalM}`,
50
+ backgroundColor: tokens.colorNeutralBackground1,
51
+ border: `1px solid ${tokens.colorNeutralStroke2}`,
52
+ borderRadius: tokens.borderRadiusMedium,
53
+ cursor: "grab",
54
+ userSelect: "none",
55
+ "&:hover": {
56
+ backgroundColor: tokens.colorNeutralBackground1Hover,
57
+ border: `1px solid ${tokens.colorNeutralStroke1Hover}`,
58
+ },
59
+ },
60
+ columnItemSelected: {
61
+ backgroundColor: tokens.colorNeutralBackground1Selected,
62
+ border: `1px solid ${tokens.colorBrandStroke1}`,
63
+ },
64
+ columnItemDragging: {
65
+ opacity: 0.5,
66
+ cursor: "grabbing",
67
+ },
68
+ columnItemDragOver: {
69
+ borderTop: `2px solid ${tokens.colorBrandStroke1}`,
70
+ marginTop: "-2px",
71
+ },
72
+ dragHandle: {
73
+ cursor: "grab",
74
+ color: tokens.colorNeutralForeground3,
75
+ display: "flex",
76
+ alignItems: "center",
77
+ },
78
+ columnName: {
79
+ flex: 1,
80
+ overflow: "hidden",
81
+ textOverflow: "ellipsis",
82
+ whiteSpace: "nowrap",
83
+ },
84
+ columnActions: {
85
+ display: "flex",
86
+ gap: tokens.spacingHorizontalXXS,
87
+ },
88
+ footer: {
89
+ display: "flex",
90
+ justifyContent: "flex-end",
91
+ gap: tokens.spacingHorizontalS,
92
+ padding: tokens.spacingVerticalM,
93
+ borderTop: `1px solid ${tokens.colorNeutralStroke1}`,
94
+ marginTop: "auto",
95
+ },
96
+ emptyState: {
97
+ display: "flex",
98
+ flexDirection: "column",
99
+ alignItems: "center",
100
+ justifyContent: "center",
101
+ padding: tokens.spacingVerticalXXL,
102
+ color: tokens.colorNeutralForeground3,
103
+ textAlign: "center",
104
+ },
105
+ });
106
+
107
+ export interface EditColumnsPanelProps {
108
+ /** Whether the panel is open */
109
+ open: boolean;
110
+ /** Columns to display for editing */
111
+ columns: LayoutColumn[];
112
+ /** Entity display name for the title */
113
+ entityDisplayName?: string;
114
+ /** Called when panel is closed */
115
+ onClose: () => void;
116
+ /** Called when Apply is clicked with the updated columns */
117
+ onApply: (columns: LayoutColumn[]) => void;
118
+ /** Called when user wants to add columns */
119
+ onAddColumns: () => void;
120
+ /** Called to reset columns to default */
121
+ onResetToDefault?: () => void;
122
+ }
123
+
124
+ export function EditColumnsPanel({
125
+ open,
126
+ columns,
127
+ entityDisplayName,
128
+ onClose,
129
+ onApply,
130
+ onAddColumns,
131
+ onResetToDefault,
132
+ }: EditColumnsPanelProps) {
133
+ const styles = useStyles();
134
+ const [localColumns, setLocalColumns] = useState<LayoutColumn[]>([]);
135
+ const [selectedIndex, setSelectedIndex] = useState<number | null>(null);
136
+ const [draggedIndex, setDraggedIndex] = useState<number | null>(null);
137
+ const [dragOverIndex, setDragOverIndex] = useState<number | null>(null);
138
+ const dragNodeRef = useRef<HTMLDivElement | null>(null);
139
+
140
+ // Initialize local state when panel opens or columns change
141
+ useEffect(() => {
142
+ if (open && columns.length > 0) {
143
+ setLocalColumns([...columns]);
144
+ setSelectedIndex(null);
145
+ }
146
+ }, [open, columns]);
147
+
148
+ // Drag and drop handlers
149
+ const handleDragStart = useCallback((e: React.DragEvent<HTMLDivElement>, index: number) => {
150
+ setDraggedIndex(index);
151
+ dragNodeRef.current = e.currentTarget;
152
+ e.dataTransfer.effectAllowed = "move";
153
+ e.dataTransfer.setData("text/plain", index.toString());
154
+ // Add a slight delay to allow the drag image to be captured
155
+ setTimeout(() => {
156
+ if (dragNodeRef.current) {
157
+ dragNodeRef.current.style.opacity = "0.5";
158
+ }
159
+ }, 0);
160
+ }, []);
161
+
162
+ const handleDragEnd = useCallback(() => {
163
+ setDraggedIndex(null);
164
+ setDragOverIndex(null);
165
+ if (dragNodeRef.current) {
166
+ dragNodeRef.current.style.opacity = "1";
167
+ dragNodeRef.current = null;
168
+ }
169
+ }, []);
170
+
171
+ const handleDragOver = useCallback(
172
+ (e: React.DragEvent<HTMLDivElement>, index: number) => {
173
+ e.preventDefault();
174
+ e.dataTransfer.dropEffect = "move";
175
+ if (draggedIndex !== null && draggedIndex !== index) {
176
+ setDragOverIndex(index);
177
+ }
178
+ },
179
+ [draggedIndex]
180
+ );
181
+
182
+ const handleDragLeave = useCallback(() => {
183
+ setDragOverIndex(null);
184
+ }, []);
185
+
186
+ const handleDrop = useCallback(
187
+ (e: React.DragEvent<HTMLDivElement>, targetIndex: number) => {
188
+ e.preventDefault();
189
+ if (draggedIndex === null || draggedIndex === targetIndex) {
190
+ setDragOverIndex(null);
191
+ return;
192
+ }
193
+
194
+ setLocalColumns((prev) => {
195
+ const newColumns = [...prev];
196
+ const [removed] = newColumns.splice(draggedIndex, 1);
197
+ // Adjust target index if we removed from before it
198
+ const adjustedTarget = draggedIndex < targetIndex ? targetIndex - 1 : targetIndex;
199
+ newColumns.splice(adjustedTarget, 0, removed);
200
+ return newColumns;
201
+ });
202
+
203
+ // Update selection to follow the moved item
204
+ setSelectedIndex(draggedIndex < targetIndex ? targetIndex - 1 : targetIndex);
205
+ setDraggedIndex(null);
206
+ setDragOverIndex(null);
207
+ },
208
+ [draggedIndex]
209
+ );
210
+
211
+ const moveColumn = useCallback((index: number, direction: "up" | "down") => {
212
+ setLocalColumns((prev) => {
213
+ const newColumns = [...prev];
214
+ const targetIndex = direction === "up" ? index - 1 : index + 1;
215
+
216
+ if (targetIndex < 0 || targetIndex >= newColumns.length) {
217
+ return prev;
218
+ }
219
+
220
+ // Swap columns
221
+ [newColumns[index], newColumns[targetIndex]] = [newColumns[targetIndex], newColumns[index]];
222
+ return newColumns;
223
+ });
224
+ // Update selection to follow the moved item
225
+ setSelectedIndex((prev) =>
226
+ prev === index ? (direction === "up" ? index - 1 : index + 1) : prev
227
+ );
228
+ }, []);
229
+
230
+ const removeColumn = useCallback((index: number) => {
231
+ setLocalColumns((prev) => prev.filter((_, i) => i !== index));
232
+ setSelectedIndex(null);
233
+ }, []);
234
+
235
+ const handleApply = useCallback(() => {
236
+ onApply(localColumns);
237
+ }, [localColumns, onApply]);
238
+
239
+ const handleColumnClick = useCallback((index: number) => {
240
+ setSelectedIndex((prev) => (prev === index ? null : index));
241
+ }, []);
242
+
243
+ return (
244
+ <OverlayDrawer
245
+ open={open}
246
+ onOpenChange={(_e, data) => !data.open && onClose()}
247
+ position="end"
248
+ size="medium"
249
+ className={styles.drawer}
250
+ >
251
+ <DrawerHeader>
252
+ <DrawerHeaderTitle
253
+ action={
254
+ <Button
255
+ appearance="subtle"
256
+ aria-label="Close"
257
+ icon={<Dismiss24Regular />}
258
+ onClick={onClose}
259
+ />
260
+ }
261
+ >
262
+ Edit columns{entityDisplayName ? `: ${entityDisplayName}` : ""}
263
+ </DrawerHeaderTitle>
264
+ </DrawerHeader>
265
+ <DrawerBody>
266
+ <Toolbar size="small">
267
+ <ToolbarButton icon={<Add20Regular />} onClick={onAddColumns} aria-label="Add columns">
268
+ Add columns
269
+ </ToolbarButton>
270
+ {onResetToDefault && (
271
+ <ToolbarButton
272
+ icon={<ArrowReset20Regular />}
273
+ onClick={onResetToDefault}
274
+ aria-label="Reset to default"
275
+ >
276
+ Reset to default
277
+ </ToolbarButton>
278
+ )}
279
+ </Toolbar>
280
+
281
+ {localColumns.length === 0 ? (
282
+ <div className={styles.emptyState}>
283
+ <Text>No columns selected</Text>
284
+ <Text size={200}>Click "Add columns" to add columns to the view</Text>
285
+ </div>
286
+ ) : (
287
+ <div className={styles.columnList}>
288
+ {localColumns.map((column, index) => {
289
+ const isDragging = draggedIndex === index;
290
+ const isDragOver = dragOverIndex === index;
291
+ return (
292
+ <div
293
+ key={column.name}
294
+ className={`${styles.columnItem} ${
295
+ selectedIndex === index ? styles.columnItemSelected : ""
296
+ } ${isDragging ? styles.columnItemDragging : ""} ${
297
+ isDragOver ? styles.columnItemDragOver : ""
298
+ }`}
299
+ onClick={() => handleColumnClick(index)}
300
+ role="button"
301
+ tabIndex={0}
302
+ draggable
303
+ onDragStart={(e) => handleDragStart(e, index)}
304
+ onDragEnd={handleDragEnd}
305
+ onDragOver={(e) => handleDragOver(e, index)}
306
+ onDragLeave={handleDragLeave}
307
+ onDrop={(e) => handleDrop(e, index)}
308
+ onKeyDown={(e) => {
309
+ if (e.key === "Enter" || e.key === " ") {
310
+ handleColumnClick(index);
311
+ }
312
+ }}
313
+ >
314
+ <span className={styles.dragHandle}>
315
+ <ReOrder16Regular />
316
+ </span>
317
+ <span className={styles.columnName}>{column.displayName || column.name}</span>
318
+ <div className={styles.columnActions}>
319
+ <Button
320
+ appearance="subtle"
321
+ size="small"
322
+ icon={<ArrowUp20Regular />}
323
+ disabled={index === 0}
324
+ onClick={(e) => {
325
+ e.stopPropagation();
326
+ moveColumn(index, "up");
327
+ }}
328
+ title="Move up"
329
+ aria-label="Move up"
330
+ />
331
+ <Button
332
+ appearance="subtle"
333
+ size="small"
334
+ icon={<ArrowDown20Regular />}
335
+ disabled={index === localColumns.length - 1}
336
+ onClick={(e) => {
337
+ e.stopPropagation();
338
+ moveColumn(index, "down");
339
+ }}
340
+ title="Move down"
341
+ aria-label="Move down"
342
+ />
343
+ <Button
344
+ appearance="subtle"
345
+ size="small"
346
+ icon={<Delete20Regular />}
347
+ onClick={(e) => {
348
+ e.stopPropagation();
349
+ removeColumn(index);
350
+ }}
351
+ title="Remove"
352
+ aria-label="Remove column"
353
+ />
354
+ </div>
355
+ </div>
356
+ );
357
+ })}
358
+ </div>
359
+ )}
360
+
361
+ <div className={styles.footer}>
362
+ <Button appearance="secondary" onClick={onClose}>
363
+ Cancel
364
+ </Button>
365
+ <Button appearance="primary" onClick={handleApply}>
366
+ Apply
367
+ </Button>
368
+ </div>
369
+ </DrawerBody>
370
+ </OverlayDrawer>
371
+ );
372
+ }