Skip to content

Commit 71ac9b0

Browse files
committed
store last modified at diagram level
1 parent f6f473b commit 71ac9b0

File tree

7 files changed

+27
-12
lines changed

7 files changed

+27
-12
lines changed

packages/compass-data-modeling/src/components/diagram-card.spec.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ describe('DiagramCard', () => {
1010
id: 'test-diagram',
1111
connectionId: 'test-connection',
1212
name: 'Test Diagram',
13+
createdAt: '2023-10-01T00:00:00.000Z',
14+
updatedAt: '2023-10-03T00:00:00.000Z',
1315
edits: [
1416
{
1517
id: 'edit-id',
@@ -29,7 +31,6 @@ describe('DiagramCard', () => {
2931
},
3032
},
3133
] as [Edit],
32-
lastModified: new Date('2025-01-01').getTime(),
3334
databases: 'someDatabase',
3435
},
3536
onOpen: () => {},
@@ -41,6 +42,6 @@ describe('DiagramCard', () => {
4142
render(<DiagramCard {...props} />);
4243
expect(screen.getByText('Test Diagram')).to.be.visible;
4344
expect(screen.getByText('someDatabase')).to.be.visible;
44-
expect(screen.getByText('Last modified: January 1, 2025')).to.be.visible;
45+
expect(screen.getByText('Last modified: October 3, 2023')).to.be.visible;
4546
});
4647
});

packages/compass-data-modeling/src/components/diagram-card.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,14 @@ export function DiagramCard({
7979
onDelete,
8080
}: {
8181
diagram: MongoDBDataModelDescription & {
82-
lastModified: number;
8382
databases: string;
8483
};
8584
onOpen: (diagram: MongoDBDataModelDescription) => void;
8685
onRename: (id: string) => void;
8786
onDelete: (id: string) => void;
8887
}) {
8988
const darkmode = useDarkMode();
90-
const formattedDate = useFormattedDate(diagram.lastModified);
89+
const formattedDate = useFormattedDate(new Date(diagram.updatedAt).getTime());
9190
return (
9291
<Card
9392
className={diagramCardStyles}

packages/compass-data-modeling/src/components/saved-diagrams-list.spec.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ const storageItems: MongoDBDataModelDescription[] = [
1515
{
1616
id: '1',
1717
name: 'One',
18+
createdAt: '2023-10-01T00:00:00.000Z',
19+
updatedAt: '2023-10-03T00:00:00.000Z',
1820
edits: [
1921
{
2022
id: 'edit-id-1',
21-
timestamp: '2023-10-01T00:00:00.000Z',
23+
timestamp: '2023-10-02T00:00:00.000Z',
2224
type: 'SetModel',
2325
model: {
2426
collections: [
@@ -39,6 +41,8 @@ const storageItems: MongoDBDataModelDescription[] = [
3941
{
4042
id: '2',
4143
name: 'Two',
44+
createdAt: '2023-10-02T00:00:00.000Z',
45+
updatedAt: '2023-10-04T00:00:00.000Z',
4246
edits: [
4347
{
4448
id: 'edit-id-2',
@@ -63,6 +67,8 @@ const storageItems: MongoDBDataModelDescription[] = [
6367
{
6468
id: '3',
6569
name: 'Three',
70+
createdAt: '2023-10-01T00:00:00.000Z',
71+
updatedAt: '2023-10-05T00:00:00.000Z',
6672
edits: [
6773
{
6874
id: 'edit-id-3',

packages/compass-data-modeling/src/components/saved-diagrams-list.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const sortBy = [
3434
label: 'Name',
3535
},
3636
{
37-
name: 'lastModified',
37+
name: 'updatedAt',
3838
label: 'Last Modified',
3939
},
4040
] as const;
@@ -141,7 +141,6 @@ export const SavedDiagramsList: React.FunctionComponent<{
141141
const { items, status } = useDataModelSavedItems();
142142
const decoratedItems = useMemo<
143143
(MongoDBDataModelDescription & {
144-
lastModified: number;
145144
databases: string;
146145
})[]
147146
>(() => {
@@ -151,7 +150,6 @@ export const SavedDiagramsList: React.FunctionComponent<{
151150
);
152151
return {
153152
...item,
154-
lastModified: Date.parse(item.edits[item.edits.length - 1].timestamp),
155153
databases: Array.from(databases).join(', '),
156154
};
157155
});

packages/compass-data-modeling/src/services/data-model-storage.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ export const MongoDBDataModelDescriptionSchema = z.object({
8989
connectionId: z.string().nullable(),
9090

9191
edits: z.array(EditSchema).nonempty(),
92+
93+
createdAt: z.string().datetime(),
94+
updatedAt: z.string().datetime(),
9295
});
9396

9497
export type MongoDBDataModelDescription = z.output<

packages/compass-data-modeling/src/store/diagram.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ const loadedDiagram: MongoDBDataModelDescription = {
5555
id: 'diagram-id',
5656
name: 'diagram-name',
5757
connectionId: 'connection-id',
58+
createdAt: '2023-10-01T00:00:00.000Z',
59+
updatedAt: '2023-10-05T00:00:00.000Z',
5860
edits: [{ type: 'SetModel', model } as Edit],
5961
};
6062

packages/compass-data-modeling/src/store/diagram.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ export const diagramReducer: Reducer<DiagramState> = (
8888
) => {
8989
if (isAction(action, DiagramActionTypes.OPEN_DIAGRAM)) {
9090
return {
91-
id: action.diagram.id,
92-
connectionId: action.diagram.connectionId,
93-
name: action.diagram.name,
91+
...action.diagram,
9492
edits: {
9593
prev: [],
9694
current: action.diagram.edits,
@@ -104,6 +102,8 @@ export const diagramReducer: Reducer<DiagramState> = (
104102
id: new UUID().toString(),
105103
name: action.name,
106104
connectionId: action.connectionId,
105+
createdAt: new Date().toISOString(),
106+
updatedAt: new Date().toISOString(),
107107
edits: {
108108
prev: [],
109109
current: [
@@ -138,6 +138,7 @@ export const diagramReducer: Reducer<DiagramState> = (
138138
return {
139139
...state,
140140
name: action.name,
141+
updatedAt: new Date().toISOString(),
141142
};
142143
}
143144
if (isAction(action, DiagramActionTypes.APPLY_EDIT)) {
@@ -149,6 +150,7 @@ export const diagramReducer: Reducer<DiagramState> = (
149150
next: [],
150151
},
151152
editErrors: undefined,
153+
updatedAt: new Date().toISOString(),
152154
};
153155
}
154156
if (isAction(action, DiagramActionTypes.APPLY_EDIT_FAILED)) {
@@ -169,6 +171,7 @@ export const diagramReducer: Reducer<DiagramState> = (
169171
current: newCurrent,
170172
next: [...state.edits.next, state.edits.current],
171173
},
174+
updatedAt: new Date().toISOString(),
172175
};
173176
}
174177
if (isAction(action, DiagramActionTypes.REDO_EDIT)) {
@@ -183,6 +186,7 @@ export const diagramReducer: Reducer<DiagramState> = (
183186
current: newCurrent,
184187
next: [...state.edits.next],
185188
},
189+
updatedAt: new Date().toISOString(),
186190
};
187191
}
188192
return state;
@@ -345,10 +349,12 @@ export function getCurrentDiagramFromState(
345349
id,
346350
connectionId,
347351
name,
352+
createdAt,
353+
updatedAt,
348354
edits: { current: edits },
349355
} = state.diagram;
350356

351-
return { id, connectionId, name, edits };
357+
return { id, connectionId, name, edits, createdAt, updatedAt };
352358
}
353359

354360
export const selectCurrentModel = memoize(getCurrentModel);

0 commit comments

Comments
 (0)