Skip to content

Commit 960fd3c

Browse files
committed
feat(editor): enhance ControlsClientPage with friendly date formatting and UI improvements
- Added a helper function to format dates in a user-friendly manner. - Introduced a custom column configuration for displaying formatted dates in the grid. - Adjusted column widths for better layout and readability. - Enhanced search functionality in RelationalCell to include sublabels. - Cleaned up unused create control dialog functionality in the ControlsClientPage.
1 parent b764f6d commit 960fd3c

File tree

4 files changed

+121
-54
lines changed

4 files changed

+121
-54
lines changed

apps/framework-editor/app/(pages)/controls/ControlsClientPage.tsx

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import {
2727
DataSheetGrid,
2828
dateColumn,
2929
keyColumn,
30-
textColumn
30+
textColumn,
31+
type CellProps,
3132
} from 'react-datasheet-grid';
3233
import 'react-datasheet-grid/dist/style.css';
3334

@@ -53,9 +54,44 @@ const controlsSortConfig: SortConfig<ControlsPageSortableColumnKey> = {
5354
updatedAt: 'number',
5455
};
5556

57+
// Helper function to format dates in a friendly way
58+
const formatFriendlyDate = (date: Date | string | number | null | undefined): string => {
59+
if (date === null || date === undefined) return '';
60+
const d = new Date(date);
61+
if (isNaN(d.getTime())) return 'Invalid Date'; // Handle invalid date objects
62+
return new Intl.DateTimeFormat(undefined, { // 'undefined' uses the browser's default locale
63+
year: 'numeric',
64+
month: 'long',
65+
day: 'numeric',
66+
hour: 'numeric',
67+
minute: '2-digit',
68+
hour12: true,
69+
}).format(d);
70+
};
71+
72+
// Custom base column configuration for displaying friendly dates
73+
const friendlyDateColumnBase: Partial<Column<Date | null, any, string>> = {
74+
component: ({ rowData }: CellProps<Date | null, any>) => (
75+
<div
76+
style={{
77+
padding: '5px',
78+
whiteSpace: 'nowrap',
79+
overflow: 'hidden',
80+
textOverflow: 'ellipsis',
81+
width: '100%',
82+
height: '100%',
83+
display: 'flex',
84+
alignItems: 'center'
85+
}}
86+
title={formatFriendlyDate(rowData)}
87+
>
88+
{formatFriendlyDate(rowData)}
89+
</div>
90+
),
91+
// copyValue can be added if needed: ({ rowData }) => formatFriendlyDate(rowData),
92+
};
93+
5694
export function ControlsClientPage({ initialControls }: ControlsClientPageProps) {
57-
const [isCreateDialogOpen, setIsCreateDialogOpen] = useState(false);
58-
5995
const initialGridData: ControlsPageGridData[] = useMemo(() => {
6096
return initialControls.map(control => {
6197
let cDate: Date | null = null;
@@ -137,8 +173,8 @@ export function ControlsClientPage({ initialControls }: ControlsClientPageProps)
137173
}, [sortedDataWithPotentialTimestamps]);
138174

139175
const columns: Column<ControlsPageGridData>[] = [
140-
{ ...keyColumn('name', textColumn), title: 'Name', minWidth: 150 },
141-
{ ...keyColumn('description', textColumn), title: 'Description', minWidth: 250 },
176+
{ ...keyColumn('name', textColumn), title: 'Name', minWidth: 300 },
177+
{ ...keyColumn('description', textColumn), title: 'Description', minWidth: 420, grow: 1 },
142178
{
143179
...(relationalColumn<ControlsPageGridData, 'policyTemplates'> ({
144180
itemsKey: 'policyTemplates',
@@ -221,8 +257,27 @@ export function ControlsClientPage({ initialControls }: ControlsClientPageProps)
221257
createdRowIds: createdRowIds,
222258
})),
223259
},
224-
{ ...keyColumn('createdAt', dateColumn), title: 'Created At', minWidth: 180, disabled: true },
225-
{ ...keyColumn('updatedAt', dateColumn), title: 'Updated At', minWidth: 180, disabled: true },
260+
{
261+
...keyColumn('createdAt', friendlyDateColumnBase),
262+
title: 'Created At',
263+
minWidth: 220, // Adjusted minWidth
264+
disabled: true
265+
},
266+
{
267+
...keyColumn('updatedAt', friendlyDateColumnBase),
268+
title: 'Updated At',
269+
minWidth: 220, // Adjusted minWidth
270+
disabled: true
271+
},
272+
{
273+
...keyColumn(
274+
'id',
275+
textColumn as Partial<Column<string, any, string>>
276+
),
277+
title: 'ID',
278+
minWidth: 300,
279+
disabled: true
280+
},
226281
];
227282

228283
return (
@@ -239,9 +294,6 @@ export function ControlsClientPage({ initialControls }: ControlsClientPageProps)
239294
isDirty={isDirty}
240295
onCommit={handleCommit}
241296
onCancel={handleCancel}
242-
showCreateButton={true}
243-
onCreateClick={() => setIsCreateDialogOpen(true)}
244-
createButtonLabel="Create New Control"
245297
commitButtonDetailText={changesSummaryString}
246298
/>
247299

@@ -271,14 +323,6 @@ export function ControlsClientPage({ initialControls }: ControlsClientPageProps)
271323
updatedAt: new Date(),
272324
})}
273325
/>
274-
275-
<CreateControlDialog
276-
isOpen={isCreateDialogOpen}
277-
onOpenChange={setIsCreateDialogOpen}
278-
onControlCreated={() => {
279-
setIsCreateDialogOpen(false);
280-
}}
281-
/>
282326
</PageLayout>
283327
);
284328
}

apps/framework-editor/app/(pages)/controls/components/RelationalCell.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ const RelationalCellComponent = <TRowDataType extends { id?: string }, TItemsKey
8282
// If already fetched, just ensure filteredItems is up-to-date with current search term (e.g. if term was persisted)
8383
setFilteredItems(
8484
allSearchableItems.filter(item =>
85-
item.name.toLowerCase().includes(searchTerm.toLowerCase())
85+
item.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
86+
(item.sublabel && item.sublabel.toLowerCase().includes(searchTerm.toLowerCase()))
8687
)
8788
);
8889
}
@@ -96,7 +97,8 @@ const RelationalCellComponent = <TRowDataType extends { id?: string }, TItemsKey
9697
} else {
9798
setFilteredItems(
9899
allSearchableItems.filter(item =>
99-
item.name.toLowerCase().includes(searchTerm.toLowerCase())
100+
item.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
101+
(item.sublabel && item.sublabel.toLowerCase().includes(searchTerm.toLowerCase()))
100102
)
101103
);
102104
}

apps/framework-editor/app/components/TableToolbar.tsx

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
'use client';
22

3-
import React from 'react';
43
import { Button } from '@comp/ui/button';
54
import { Input } from '@comp/ui/input';
6-
import {
7-
Select,
8-
SelectContent,
9-
SelectItem,
10-
SelectTrigger,
11-
SelectValue
5+
import {
6+
Select,
7+
SelectContent,
8+
SelectItem,
9+
SelectTrigger,
10+
SelectValue
1211
} from '@comp/ui/select';
13-
import { SortAsc, SortDesc, Search as SearchIcon } from 'lucide-react';
12+
import { Search as SearchIcon, SortAsc, SortDesc } from 'lucide-react';
13+
import React from 'react';
1414
// Import types from the common types definition file
15-
import type { SortDirection, SortableColumnOption } from '../types/common';
15+
import type { SortDirection, SortableColumnOption } from '../types/common';
1616

1717
export interface TableToolbarProps {
1818
searchTerm: string;
@@ -48,9 +48,6 @@ export const TableToolbar: React.FC<TableToolbarProps> = ({
4848
onCommit,
4949
onCancel,
5050
commitButtonDetailText = '',
51-
showCreateButton = false,
52-
onCreateClick,
53-
createButtonLabel = 'Create New',
5451
children
5552
}) => {
5653
let commitButtonLabelText = 'No Changes';
@@ -120,11 +117,6 @@ export const TableToolbar: React.FC<TableToolbarProps> = ({
120117
</Button>
121118
</>
122119
)}
123-
{showCreateButton && (
124-
<Button onClick={onCreateClick}>
125-
{createButtonLabel}
126-
</Button>
127-
)}
128120
{children} { /* For any additional elements passed from parent */}
129121
</div>
130122
);

0 commit comments

Comments
 (0)