@object-ui/plugin-view 3.1.1 → 3.1.3
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/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +22 -0
- package/dist/index.js +240 -239
- package/dist/index.umd.cjs +3 -3
- package/package.json +8 -8
- package/src/ObjectView.tsx +7 -6
- package/src/__tests__/ObjectView.test.tsx +41 -1
- package/src/__tests__/config-sync-integration.test.tsx +1 -1
- package/src/__tests__/registration.test.tsx +0 -32
package/src/ObjectView.tsx
CHANGED
|
@@ -384,7 +384,7 @@ export const ObjectView: React.FC<ObjectViewProps> = ({
|
|
|
384
384
|
return;
|
|
385
385
|
}
|
|
386
386
|
if (layout === 'page' && schema.onNavigate) {
|
|
387
|
-
const recordId = record.
|
|
387
|
+
const recordId = record.id || record._id;
|
|
388
388
|
schema.onNavigate(recordId as string | number, 'edit');
|
|
389
389
|
} else {
|
|
390
390
|
setFormMode('edit');
|
|
@@ -396,7 +396,7 @@ export const ObjectView: React.FC<ObjectViewProps> = ({
|
|
|
396
396
|
// Handle view action (read a record)
|
|
397
397
|
const handleView = useCallback((record: Record<string, unknown>) => {
|
|
398
398
|
if (layout === 'page' && schema.onNavigate) {
|
|
399
|
-
const recordId = record.
|
|
399
|
+
const recordId = record.id || record._id;
|
|
400
400
|
schema.onNavigate(recordId as string | number, 'view');
|
|
401
401
|
} else {
|
|
402
402
|
setFormMode('view');
|
|
@@ -418,8 +418,8 @@ export const ObjectView: React.FC<ObjectViewProps> = ({
|
|
|
418
418
|
return; // Do nothing
|
|
419
419
|
}
|
|
420
420
|
if (navigationConfig.mode === 'new_window' || navigationConfig.openNewTab) {
|
|
421
|
-
const recordId = record.
|
|
422
|
-
const url = `/${schema.objectName}/${recordId}`;
|
|
421
|
+
const recordId = record.id || record._id;
|
|
422
|
+
const url = `/${schema.objectName}/${encodeURIComponent(String(recordId))}`;
|
|
423
423
|
window.open(url, '_blank');
|
|
424
424
|
return;
|
|
425
425
|
}
|
|
@@ -436,7 +436,7 @@ export const ObjectView: React.FC<ObjectViewProps> = ({
|
|
|
436
436
|
return;
|
|
437
437
|
}
|
|
438
438
|
if (navigationConfig.mode === 'page') {
|
|
439
|
-
const recordId = record.
|
|
439
|
+
const recordId = record.id || record._id;
|
|
440
440
|
if (schema.onNavigate) {
|
|
441
441
|
schema.onNavigate(recordId as string | number, 'view');
|
|
442
442
|
}
|
|
@@ -727,7 +727,7 @@ export const ObjectView: React.FC<ObjectViewProps> = ({
|
|
|
727
727
|
// Build form schema
|
|
728
728
|
const buildFormSchema = (): ObjectFormSchema => {
|
|
729
729
|
const recordId = selectedRecord
|
|
730
|
-
? ((selectedRecord.
|
|
730
|
+
? ((selectedRecord.id || selectedRecord._id) as string | number | undefined)
|
|
731
731
|
: undefined;
|
|
732
732
|
|
|
733
733
|
return {
|
|
@@ -882,6 +882,7 @@ export const ObjectView: React.FC<ObjectViewProps> = ({
|
|
|
882
882
|
addRecord: activeView?.addRecord ?? (schema as any).addRecord,
|
|
883
883
|
conditionalFormatting: activeView?.conditionalFormatting ?? (schema as any).conditionalFormatting,
|
|
884
884
|
quickFilters: activeView?.quickFilters ?? (schema as any).quickFilters,
|
|
885
|
+
userFilters: activeView?.userFilters ?? (schema as any).userFilters,
|
|
885
886
|
showRecordCount: activeView?.showRecordCount ?? (schema as any).showRecordCount,
|
|
886
887
|
allowPrinting: activeView?.allowPrinting ?? (schema as any).allowPrinting,
|
|
887
888
|
virtualScroll: activeView?.virtualScroll ?? (schema as any).virtualScroll,
|
|
@@ -25,7 +25,7 @@ vi.mock('@object-ui/react', () => ({
|
|
|
25
25
|
vi.mock('@object-ui/plugin-grid', () => ({
|
|
26
26
|
ObjectGrid: ({ schema, onRowClick }: any) => (
|
|
27
27
|
<div data-testid="object-grid" data-object={schema?.objectName}>
|
|
28
|
-
<button data-testid="grid-row" onClick={() => onRowClick?.({
|
|
28
|
+
<button data-testid="grid-row" onClick={() => onRowClick?.({ id: '1', name: 'Test' })}>
|
|
29
29
|
Row 1
|
|
30
30
|
</button>
|
|
31
31
|
</div>
|
|
@@ -661,5 +661,45 @@ describe('ObjectView', () => {
|
|
|
661
661
|
expect(callSchema?.showFilters).toBe(false);
|
|
662
662
|
expect(callSchema?.showSort).toBe(false);
|
|
663
663
|
});
|
|
664
|
+
|
|
665
|
+
it('should propagate userFilters from activeView in renderListView', async () => {
|
|
666
|
+
const schema: ObjectViewSchema = {
|
|
667
|
+
type: 'object-view',
|
|
668
|
+
objectName: 'contacts',
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
const renderListViewSpy = vi.fn(({ schema: listSchema }: any) => (
|
|
672
|
+
<div data-testid="custom-list">Custom ListView</div>
|
|
673
|
+
));
|
|
674
|
+
|
|
675
|
+
const views = [
|
|
676
|
+
{
|
|
677
|
+
id: 'v1',
|
|
678
|
+
label: 'View 1',
|
|
679
|
+
type: 'grid' as const,
|
|
680
|
+
userFilters: {
|
|
681
|
+
element: 'dropdown' as const,
|
|
682
|
+
fields: [{ field: 'status' }],
|
|
683
|
+
},
|
|
684
|
+
},
|
|
685
|
+
];
|
|
686
|
+
|
|
687
|
+
render(
|
|
688
|
+
<ObjectView
|
|
689
|
+
schema={schema}
|
|
690
|
+
dataSource={mockDataSource}
|
|
691
|
+
views={views}
|
|
692
|
+
activeViewId="v1"
|
|
693
|
+
renderListView={renderListViewSpy}
|
|
694
|
+
/>,
|
|
695
|
+
);
|
|
696
|
+
|
|
697
|
+
expect(renderListViewSpy).toHaveBeenCalled();
|
|
698
|
+
const callSchema = renderListViewSpy.mock.calls[0]?.[0]?.schema;
|
|
699
|
+
expect(callSchema?.userFilters).toEqual({
|
|
700
|
+
element: 'dropdown',
|
|
701
|
+
fields: [{ field: 'status' }],
|
|
702
|
+
});
|
|
703
|
+
});
|
|
664
704
|
});
|
|
665
705
|
});
|
|
@@ -32,7 +32,7 @@ vi.mock('@object-ui/react', () => ({
|
|
|
32
32
|
vi.mock('@object-ui/plugin-grid', () => ({
|
|
33
33
|
ObjectGrid: ({ schema, onRowClick }: any) => (
|
|
34
34
|
<div data-testid="object-grid" data-object={schema?.objectName}>
|
|
35
|
-
<button data-testid="grid-row" onClick={() => onRowClick?.({
|
|
35
|
+
<button data-testid="grid-row" onClick={() => onRowClick?.({ id: '1', name: 'Test' })}>
|
|
36
36
|
Row 1
|
|
37
37
|
</button>
|
|
38
38
|
</div>
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ObjectUI
|
|
3
|
-
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { describe, it, expect } from 'vitest';
|
|
10
|
-
import { ObjectView, ViewSwitcher, FilterUI, SortUI } from '../index';
|
|
11
|
-
|
|
12
|
-
describe('Plugin View Registration', () => {
|
|
13
|
-
it('exports ObjectView component', () => {
|
|
14
|
-
expect(ObjectView).toBeDefined();
|
|
15
|
-
expect(typeof ObjectView).toBe('function');
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('exports ViewSwitcher component', () => {
|
|
19
|
-
expect(ViewSwitcher).toBeDefined();
|
|
20
|
-
expect(typeof ViewSwitcher).toBe('function');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('exports FilterUI component', () => {
|
|
24
|
-
expect(FilterUI).toBeDefined();
|
|
25
|
-
expect(typeof FilterUI).toBe('function');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('exports SortUI component', () => {
|
|
29
|
-
expect(SortUI).toBeDefined();
|
|
30
|
-
expect(typeof SortUI).toBe('function');
|
|
31
|
-
});
|
|
32
|
-
});
|