Skip to content

Commit c9aa71e

Browse files
committed
Save edit summary to revision when editing schema
1 parent 4ebc46e commit c9aa71e

8 files changed

Lines changed: 40 additions & 35 deletions

File tree

resources/ext.neowiki/src/application/SchemaRepository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Schema } from '@/domain/Schema.ts';
33

44
export interface SchemaRepository extends SchemaLookup {
55

6-
saveSchema( schema: Schema ): Promise<void>;
6+
saveSchema( schema: Schema, comment?: string ): Promise<void>;
77

88
}
99

resources/ext.neowiki/src/components/SchemaEditor/EditSchemaPage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const handleSave = async ( summary: string ): Promise<void> => {
2929
if ( !schemaEditor.value ) {
3030
return;
3131
}
32-
await saveSchema( schemaEditor.value.getSchema(), summary );
32+
await saveSchema( schemaEditor.value.getSchema(), summary || 'Update schema via NeoWiki UI' );
3333
};
3434
</script>
3535

resources/ext.neowiki/src/components/SchemaEditor/SchemaEditorDialog.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const handleSave = async ( summary: string ): Promise<void> => {
5454
}
5555
5656
const schema = schemaEditor.value.getSchema();
57-
await saveSchema( schema, summary );
57+
await saveSchema( schema, summary || 'Update schema via NeoWiki UI' );
5858
emit( 'saved', schema );
5959
open.value = false;
6060
};

resources/ext.neowiki/src/composables/useSchemaSaver.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,16 @@ import { NeoWikiServices } from '@/NeoWikiServices';
22
import { Schema } from '@/domain/Schema';
33

44
interface UseSchemaSaverReturn {
5-
saveSchema: ( schema: Schema, editSummary: string ) => Promise<void>;
5+
saveSchema: ( schema: Schema, comment?: string ) => Promise<void>;
66
}
77

88
export function useSchemaSaver(): UseSchemaSaverReturn {
99
const schemaRepository = NeoWikiServices.getSchemaRepository();
1010

11-
const saveSchema = async ( schema: Schema, editSummary: string ): Promise<void> => {
11+
const saveSchema = async ( schema: Schema, comment?: string ): Promise<void> => {
1212
try {
13-
// TODO: Save edit summary to revision so it shows on the history page
14-
await schemaRepository.saveSchema( schema );
15-
mw.notify(
16-
editSummary || 'No edit summary provided.',
17-
{
18-
title: `Updated ${ schema.getName() } schema`,
19-
type: 'success',
20-
},
21-
);
13+
await schemaRepository.saveSchema( schema, comment );
14+
mw.notify( `Updated ${ schema.getName() } schema`, { type: 'success' } );
2215
} catch ( error ) {
2316
mw.notify(
2417
error instanceof Error ? error.message : String( error ),

resources/ext.neowiki/src/persistence/RestSchemaRepository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ export class RestSchemaRepository implements SchemaRepository {
6161
return await response.json();
6262
}
6363

64-
public async saveSchema( schema: Schema ): Promise<void> {
64+
public async saveSchema( schema: Schema, comment?: string ): Promise<void> {
6565
const status = await this.pageSaver.savePage(
6666
`Schema:${ encodeURIComponent( schema.getName() ) }`,
6767
this.serializeSchema( schema ),
68-
'Update schema via NeoWiki UI',
68+
comment || 'Update schema via NeoWiki REST API',
6969
'NeoWikiSchema',
7070
);
7171

resources/ext.neowiki/src/stores/SchemaStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export const useSchemaStore = defineStore( 'schema', {
3636
await Promise.all( schemaNames.map( ( name ) => this.getOrFetchSchema( name ) ) );
3737
return schemaNames;
3838
},
39-
async saveSchema( schema: Schema ): Promise<void> {
40-
await NeoWikiExtension.getInstance().getSchemaRepository().saveSchema( schema );
39+
async saveSchema( schema: Schema, comment?: string ): Promise<void> {
40+
await NeoWikiExtension.getInstance().getSchemaRepository().saveSchema( schema, comment );
4141
this.setSchema( schema.getName(), schema );
4242
},
4343
},

resources/ext.neowiki/tests/composables/useSchemaSaver.spec.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,32 @@ describe( 'useSchemaSaver', () => {
3030
new PropertyDefinitionList( [] ),
3131
);
3232

33+
const expectSuccessNotification = ( schema: Schema ): void => expect( mw.notify ).toHaveBeenCalledWith(
34+
`Updated ${ schema.getName() } schema`,
35+
expect.objectContaining( {
36+
type: 'success',
37+
} ),
38+
);
39+
3340
it( 'saves schema successfully and notifies user', async () => {
3441
const { saveSchema } = useSchemaSaver();
3542
const schema = createMockSchema();
3643
const summary = 'Test Summary';
3744

3845
await saveSchema( schema, summary );
3946

40-
expect( mockSaveSchema ).toHaveBeenCalledWith( schema );
41-
expect( mw.notify ).toHaveBeenCalledWith(
42-
summary,
43-
expect.objectContaining( {
44-
title: 'Updated TestSchema schema',
45-
type: 'success',
46-
} ),
47-
);
47+
expect( mockSaveSchema ).toHaveBeenCalledWith( schema, summary );
48+
expectSuccessNotification( schema );
4849
} );
4950

5051
it( 'uses default summary if none provided', async () => {
5152
const { saveSchema } = useSchemaSaver();
5253
const schema = createMockSchema();
5354

54-
await saveSchema( schema, '' );
55+
await saveSchema( schema );
5556

56-
expect( mw.notify ).toHaveBeenCalledWith(
57-
'No edit summary provided.',
58-
expect.any( Object ),
59-
);
57+
expect( mockSaveSchema ).toHaveBeenCalledWith( schema, undefined );
58+
expectSuccessNotification( schema );
6059
} );
6160

6261
it( 'handles save error and notifies user', async () => {

resources/ext.neowiki/tests/persistence/RestSchemaRepository.neo4j.spec.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,33 @@ describe( 'RestSchemaRepository', () => {
9999
it( 'should call the correct API endpoint with the right parameters', async () => {
100100
vi.spyOn( pageSaver, 'savePage' );
101101

102+
await repository.saveSchema( testSchema, 'Comment for the edit' );
103+
104+
expect( pageSaver.savePage ).toHaveBeenCalledWith(
105+
'Schema:TestSchema',
106+
'{"serialized":"TestSchema"}',
107+
'Comment for the edit',
108+
'NeoWikiSchema',
109+
);
110+
} );
111+
112+
it( 'should use default summary if none provided', async () => {
113+
vi.spyOn( pageSaver, 'savePage' );
114+
102115
await repository.saveSchema( testSchema );
103116

104117
expect( pageSaver.savePage ).toHaveBeenCalledWith(
105118
'Schema:TestSchema',
106119
'{"serialized":"TestSchema"}',
107-
'Update schema via NeoWiki UI',
120+
'Update schema via NeoWiki REST API',
108121
'NeoWikiSchema',
109122
);
110123
} );
111124

112125
it( 'should throw an error if the API response failed', async () => {
113126
repository = new RestSchemaRepository( apiUrl, mockHttpClient, mockSerializer, new FailingPageSaver() );
114127

115-
await expect( repository.saveSchema( testSchema ) )
128+
await expect( repository.saveSchema( testSchema, 'Comment for the edit' ) )
116129
.rejects
117130
.toThrow( 'Error saving schema: Some reason' );
118131
} );
@@ -126,12 +139,12 @@ describe( 'RestSchemaRepository', () => {
126139

127140
vi.spyOn( pageSaver, 'savePage' );
128141

129-
await repository.saveSchema( schemaWithSpecialChars );
142+
await repository.saveSchema( schemaWithSpecialChars, 'Comment for the edit' );
130143

131144
expect( pageSaver.savePage ).toHaveBeenCalledWith(
132145
'Schema:Test%2FSchema%20With%3ASpaces',
133146
expect.anything(),
134-
expect.anything(),
147+
'Comment for the edit',
135148
expect.anything(),
136149
);
137150
} );

0 commit comments

Comments
 (0)