-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature(frontend): Add onBefore signal for actions
### Changelog: * Feature(frontend): Add onBefore signal for actions. * Feature(frontend): Add showConfirmationModal utility. * Fix(frontend): Fix buttons type in confirmation modal. Closes: vst/vst-utils#648+ See merge request vst/vst-utils!661
- Loading branch information
Showing
14 changed files
with
295 additions
and
132 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createApp, createSchema, useTestCtx } from '#unittests'; | ||
import { hookViewOperation } from '../signals'; | ||
|
||
test('operations hooks', async () => { | ||
const onBefore = vitest.fn((() => { | ||
return { | ||
prevent: true, | ||
}; | ||
}) satisfies Parameters<typeof hookViewOperation>[0]['onBefore']); | ||
|
||
hookViewOperation({ path: '/user/new/', operation: 'save', onBefore }); | ||
|
||
await createApp({ schema: createSchema() }); | ||
const { screen, app, user } = useTestCtx(); | ||
|
||
await app.router.push('/user/new/'); | ||
|
||
const saveBtn = await screen.findByTitle('Save'); | ||
await user.click(saveBtn); | ||
|
||
expect(onBefore).toBeCalledTimes(1); | ||
expect(onBefore).toBeCalledWith({ | ||
operation: app.views.get('/user/new/')!.actions.get('save'), | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { shallowRef } from 'vue'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const _currentConfirmationModal = shallowRef<{ | ||
title: string; | ||
text: string; | ||
confirmButtonText?: string; | ||
cancelButtonText?: string; | ||
|
||
confirm: () => void; | ||
reject: () => void; | ||
}>(); | ||
|
||
export function showConfirmationModal(params: { | ||
title: string; | ||
text: string; | ||
confirmButtonText?: string; | ||
cancelButtonText?: string; | ||
}): Promise<boolean> { | ||
return new Promise((resolve) => { | ||
_currentConfirmationModal.value = { | ||
...params, | ||
confirm: () => { | ||
_currentConfirmationModal.value = undefined; | ||
resolve(true); | ||
}, | ||
reject: () => { | ||
_currentConfirmationModal.value = undefined; | ||
resolve(false); | ||
}, | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.