Skip to content

Commit 860fd36

Browse files
committed
type: Add component prop typesafety to dialogs
1 parent f9fd924 commit 860fd36

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed

src/services/dialogService.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import NodeConflictDialogContent from '@/workbench/extensions/manager/components
3434
import NodeConflictFooter from '@/workbench/extensions/manager/components/manager/NodeConflictFooter.vue'
3535
import NodeConflictHeader from '@/workbench/extensions/manager/components/manager/NodeConflictHeader.vue'
3636
import type { ConflictDetectionResult } from '@/workbench/extensions/manager/types/conflictDetectionTypes'
37-
import type { ComponentProps } from 'vue-component-type-helpers'
37+
import type { ComponentAttrs } from 'vue-component-type-helpers'
3838

3939
export type ConfirmationDialogType =
4040
| 'default'
@@ -48,7 +48,7 @@ export const useDialogService = () => {
4848
const dialogStore = useDialogStore()
4949

5050
function showLoadWorkflowWarning(
51-
props: ComponentProps<typeof MissingNodesContent>
51+
props: ComponentAttrs<typeof MissingNodesContent>
5252
) {
5353
dialogStore.showDialog({
5454
key: 'global-missing-nodes',
@@ -74,7 +74,7 @@ export const useDialogService = () => {
7474
}
7575

7676
function showMissingModelsWarning(
77-
props: InstanceType<typeof MissingModelsWarning>['$props']
77+
props: ComponentAttrs<typeof MissingModelsWarning>
7878
) {
7979
dialogStore.showDialog({
8080
key: 'global-missing-models-warning',
@@ -115,7 +115,7 @@ export const useDialogService = () => {
115115
}
116116

117117
function showExecutionErrorDialog(executionError: ExecutionErrorWsMessage) {
118-
const props: InstanceType<typeof ErrorDialogContent>['$props'] = {
118+
const props: ComponentAttrs<typeof ErrorDialogContent> = {
119119
error: {
120120
exceptionType: executionError.exception_type,
121121
exceptionMessage: executionError.exception_message,
@@ -141,7 +141,7 @@ export const useDialogService = () => {
141141
}
142142

143143
function showManagerDialog(
144-
props: InstanceType<typeof ManagerDialogContent>['$props'] = {}
144+
props: ComponentAttrs<typeof ManagerDialogContent> = {}
145145
) {
146146
dialogStore.showDialog({
147147
key: 'global-manager',
@@ -206,7 +206,7 @@ export const useDialogService = () => {
206206
errorMessage: String(error)
207207
}
208208

209-
const props: InstanceType<typeof ErrorDialogContent>['$props'] = {
209+
const props: ComponentAttrs<typeof ErrorDialogContent> = {
210210
error: {
211211
exceptionType: options.title ?? 'Unknown Error',
212212
exceptionMessage: errorProps.errorMessage,
@@ -430,7 +430,7 @@ export const useDialogService = () => {
430430
}
431431

432432
function toggleManagerDialog(
433-
props?: InstanceType<typeof ManagerDialogContent>['$props']
433+
props?: ComponentAttrs<typeof ManagerDialogContent>
434434
) {
435435
if (dialogStore.isDialogOpen('global-manager')) {
436436
dialogStore.closeDialog({ key: 'global-manager' })
@@ -440,7 +440,7 @@ export const useDialogService = () => {
440440
}
441441

442442
function toggleManagerProgressDialog(
443-
props?: InstanceType<typeof ManagerProgressDialogContent>['$props']
443+
props?: ComponentAttrs<typeof ManagerProgressDialogContent>
444444
) {
445445
if (dialogStore.isDialogOpen('global-manager-progress-dialog')) {
446446
dialogStore.closeDialog({ key: 'global-manager-progress-dialog' })

src/stores/dialogStore.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { markRaw, ref } from 'vue'
77
import type { Component } from 'vue'
88

99
import type GlobalDialog from '@/components/dialog/GlobalDialog.vue'
10+
import type { ComponentAttrs } from 'vue-component-type-helpers'
1011

1112
type DialogPosition =
1213
| 'center'
@@ -33,30 +34,39 @@ interface CustomDialogComponentProps {
3334
headless?: boolean
3435
}
3536

36-
export type DialogComponentProps = InstanceType<typeof GlobalDialog>['$props'] &
37+
export type DialogComponentProps = ComponentAttrs<typeof GlobalDialog> &
3738
CustomDialogComponentProps
3839

39-
interface DialogInstance {
40+
interface DialogInstance<
41+
H extends Component = Component,
42+
B extends Component = Component,
43+
F extends Component = Component
44+
> {
4045
key: string
4146
visible: boolean
4247
title?: string
43-
headerComponent?: Component
44-
component: Component
45-
contentProps: Record<string, any>
46-
footerComponent?: Component
47-
footerProps?: Record<string, any>
48+
headerComponent?: H
49+
component: B
50+
contentProps: ComponentAttrs<B>
51+
footerComponent?: F
52+
footerProps?: ComponentAttrs<F>
4853
dialogComponentProps: DialogComponentProps
4954
priority: number
5055
}
5156

52-
export interface ShowDialogOptions {
57+
export interface ShowDialogOptions<
58+
H extends Component = Component,
59+
B extends Component = Component,
60+
F extends Component = Component
61+
> {
5362
key?: string
5463
title?: string
55-
headerComponent?: Component
56-
footerComponent?: Component
57-
component: Component
58-
props?: Record<string, any>
59-
footerProps?: Record<string, any>
64+
headerComponent?: H
65+
footerComponent?: F
66+
component: B
67+
props?: ComponentAttrs<B>
68+
headerProps?: ComponentAttrs<H>
69+
footerProps?: ComponentAttrs<F>
6070
dialogComponentProps?: DialogComponentProps
6171
/**
6272
* Optional priority for dialog stacking.
@@ -203,7 +213,11 @@ export const useDialogStore = defineStore('dialog', () => {
203213
})
204214
}
205215

206-
function showDialog(options: ShowDialogOptions) {
216+
function showDialog<
217+
H extends Component = Component,
218+
B extends Component = Component,
219+
F extends Component = Component
220+
>(options: ShowDialogOptions<H, B, F>) {
207221
const dialogKey = options.key || genDialogKey()
208222

209223
let dialog = dialogStack.value.find((d) => d.key === dialogKey)

0 commit comments

Comments
 (0)