-
Notifications
You must be signed in to change notification settings - Fork 83
[6804] Pinia Task 1 - ux-dialog #6813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ac868ef
Convert vuex dialog to pinia with unit tests & setup alias for stores…
n-lark d6bb309
Add click in functionality for stores
n-lark 85a61a8
Remove eslint-import-resolver-webpack and use linting rules instead
n-lark fd1b56b
Reset package-lock.json to parent and fix import order issue
n-lark ab4f510
Merge remote-tracking branch 'origin/6803-pinia-task-1-infrastructure…
n-lark b26c93f
Merge branch '6803-pinia-task-1-infrastructure' into 6804-pinia-task-…
cstns e6f004f
Merge remote-tracking branch 'origin/main' into 6804-pinia-task-1-ux-…
n-lark 059ea9c
Apply PR feedback around spec location, mixins, state, jsconfig & esl…
n-lark 024520f
Delete dialog mixin
n-lark 2fedcde
Remove settings.json file
n-lark e2ffbb1
Update to use mapActions and mapState from pinia instead of setup
n-lark aac9fe5
Update AddDeviceToGroupDialog to use mapActions
n-lark 982c46a
Merge branch 'main' into 6804-pinia-task-1-ux-dialog
cstns a2eef55
Merge branch 'main' into 6804-pinia-task-1-ux-dialog
n-lark 939d6c0
Merge remote-tracking branch 'origin/main' into 6804-pinia-task-1-ux-…
n-lark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| // Barrel export — add store exports here as each task is merged | ||
| export { useUxDialogStore } from './ux-dialog.js' |
This file contains hidden or 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,61 @@ | ||
| import { defineStore } from 'pinia' | ||
|
|
||
| const initialDialogState = () => ({ | ||
| boxClass: null, | ||
|
cstns marked this conversation as resolved.
Outdated
|
||
| cancelLabel: null, | ||
| canBeCanceled: true, | ||
| confirmLabel: null, | ||
| contentClass: '', | ||
| disablePrimary: false, | ||
| header: null, | ||
| html: null, | ||
| is: null, | ||
| kind: null, | ||
| onCancel: null, | ||
| onConfirm: null, | ||
| subHeader: null, | ||
| text: null, | ||
| textLines: null, | ||
| notices: [] | ||
| }) | ||
|
|
||
| export const useUxDialogStore = defineStore('ux-dialog', { | ||
| state: () => ({ | ||
| dialog: initialDialogState() | ||
| }), | ||
| actions: { | ||
| clearDialog (cancelled = false) { | ||
| if (cancelled) { | ||
| this.dialog.onCancel?.() | ||
| } | ||
| this.dialog = initialDialogState() | ||
| }, | ||
| showDialogHandlers ({ payload, onConfirm, onCancel }) { | ||
| this.clearDialog(false) | ||
|
|
||
| if (typeof payload === 'string') { | ||
| this.dialog.content = payload | ||
| } else { | ||
| this.dialog.header = payload.header | ||
| this.dialog.text = payload.text | ||
| this.dialog.textLines = payload.text?.split('\n') | ||
| this.dialog.html = payload.html | ||
| this.dialog.is = payload.is ?? undefined | ||
| this.dialog.confirmLabel = payload.confirmLabel | ||
| this.dialog.cancelLabel = payload.cancelLabel | ||
| this.dialog.kind = payload.kind | ||
| this.dialog.disablePrimary = payload.disablePrimary | ||
| this.dialog.notices = payload.notices | ||
| if (Object.prototype.hasOwnProperty.call(payload, 'canBeCanceled')) { | ||
| this.dialog.canBeCanceled = payload.canBeCanceled | ||
| } | ||
| this.dialog.boxClass = payload.boxClass | ||
| } | ||
| this.dialog.onConfirm = onConfirm | ||
| this.dialog.onCancel = onCancel | ||
| }, | ||
| setDisablePrimary (value) { | ||
| this.dialog.disablePrimary = value | ||
| } | ||
| } | ||
| }) | ||
This file contains hidden or 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,57 @@ | ||
| // frontend/src/tests/stores/ux-dialog.spec.js | ||
| import { createPinia, setActivePinia } from 'pinia' | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import { useUxDialogStore } from '@/stores/ux-dialog.js' | ||
|
|
||
| describe('ux-dialog store', () => { | ||
| beforeEach(() => { | ||
| setActivePinia(createPinia()) | ||
| }) | ||
|
|
||
| it('initializes with empty dialog state', () => { | ||
| const store = useUxDialogStore() | ||
| expect(store.dialog.header).toBeNull() | ||
| expect(store.dialog.text).toBeNull() | ||
| }) | ||
|
|
||
| it('showDialogHandlers sets dialog properties from object payload', () => { | ||
| const store = useUxDialogStore() | ||
| const onConfirm = vi.fn() | ||
| store.showDialogHandlers({ | ||
| payload: { header: 'Delete?', text: 'This cannot be undone.', kind: 'danger' }, | ||
| onConfirm | ||
| }) | ||
| expect(store.dialog.header).toBe('Delete?') | ||
| expect(store.dialog.kind).toBe('danger') | ||
| expect(store.dialog.onConfirm).toBe(onConfirm) | ||
| }) | ||
|
|
||
| it('showDialogHandlers splits text into textLines', () => { | ||
| const store = useUxDialogStore() | ||
| store.showDialogHandlers({ payload: { text: 'Line 1\nLine 2' }, onConfirm: vi.fn() }) | ||
| expect(store.dialog.textLines).toEqual(['Line 1', 'Line 2']) | ||
| }) | ||
|
|
||
| it('clearDialog resets all dialog state', () => { | ||
| const store = useUxDialogStore() | ||
| store.dialog.header = 'Test' | ||
| store.clearDialog() | ||
| expect(store.dialog.header).toBeNull() | ||
| }) | ||
|
|
||
| it('clearDialog(true) calls onCancel before resetting', () => { | ||
| const store = useUxDialogStore() | ||
| const onCancel = vi.fn() | ||
| store.dialog.onCancel = onCancel | ||
| store.clearDialog(true) | ||
| expect(onCancel).toHaveBeenCalledOnce() | ||
| expect(store.dialog.header).toBeNull() | ||
| }) | ||
|
|
||
| it('setDisablePrimary updates the flag', () => { | ||
| const store = useUxDialogStore() | ||
| store.setDisablePrimary(true) | ||
| expect(store.dialog.disablePrimary).toBe(true) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.