mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-20 07:10:02 +00:00
Update StepsDialog steps switching (#2692)
Signed-off-by: Sergei Ogorelkov <sergei.ogorelkov@xored.com>
This commit is contained in:
parent
1d2ec57fae
commit
ad4d65a591
@ -13,6 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { SvelteComponent } from 'svelte'
|
||||||
import { getResource } from '@hcengineering/platform'
|
import { getResource } from '@hcengineering/platform'
|
||||||
import type { AnyComponent } from '../types'
|
import type { AnyComponent } from '../types'
|
||||||
// import Icon from './Icon.svelte'
|
// import Icon from './Icon.svelte'
|
||||||
@ -20,6 +21,8 @@
|
|||||||
import ErrorBoundary from './internal/ErrorBoundary'
|
import ErrorBoundary from './internal/ErrorBoundary'
|
||||||
import Loading from './Loading.svelte'
|
import Loading from './Loading.svelte'
|
||||||
|
|
||||||
|
// Reference to rendered component instance
|
||||||
|
export let innerRef: SvelteComponent | undefined = undefined
|
||||||
export let is: AnyComponent
|
export let is: AnyComponent
|
||||||
export let props = {}
|
export let props = {}
|
||||||
export let shrink: boolean = false
|
export let shrink: boolean = false
|
||||||
@ -36,11 +39,11 @@
|
|||||||
{:then Ctor}
|
{:then Ctor}
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
{#if $$slots.default !== undefined}
|
{#if $$slots.default !== undefined}
|
||||||
<Ctor {...props} on:change on:close on:open on:click on:delete on:action>
|
<Ctor bind:this={innerRef} {...props} on:change on:close on:open on:click on:delete on:action>
|
||||||
<slot />
|
<slot />
|
||||||
</Ctor>
|
</Ctor>
|
||||||
{:else}
|
{:else}
|
||||||
<Ctor {...props} on:change on:close on:open on:click on:delete on:action />
|
<Ctor bind:this={innerRef} {...props} on:change on:close on:open on:click on:delete on:action />
|
||||||
{/if}
|
{/if}
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
{:catch err}
|
{:catch err}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Asset, IntlString } from '@hcengineering/platform'
|
import type { Asset, IntlString } from '@hcengineering/platform'
|
||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher, SvelteComponent } from 'svelte'
|
||||||
import ui from '../plugin'
|
import ui from '../plugin'
|
||||||
import {
|
import {
|
||||||
AnySvelteComponent,
|
AnySvelteComponent,
|
||||||
@ -43,7 +43,8 @@
|
|||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
let currentStep: DialogStep | undefined
|
let step: SvelteComponent | undefined
|
||||||
|
let currentStepModel: DialogStep | undefined
|
||||||
let currentStepIndex = 0
|
let currentStepIndex = 0
|
||||||
let isStepValid = false
|
let isStepValid = false
|
||||||
let isSaving = false
|
let isSaving = false
|
||||||
@ -70,26 +71,26 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function completeCurrentStep () {
|
async function completeCurrentStep () {
|
||||||
if (!currentStep?.onDone) {
|
if (!step?.done) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
isSaving = true
|
isSaving = true
|
||||||
try {
|
try {
|
||||||
await currentStep.onDone()
|
await step.done()
|
||||||
} finally {
|
} finally {
|
||||||
isSaving = false
|
isSaving = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: currentStep = steps[currentStepIndex]
|
$: currentStepModel = steps[currentStepIndex]
|
||||||
$: stepIndex = currentStepIndex
|
$: stepIndex = currentStepIndex
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
||||||
<Panel bind:panelWidth bind:innerWidth bind:useMaxWidth {floatAside} {allowClose} isAside isHeader on:close>
|
<Panel bind:panelWidth bind:innerWidth bind:useMaxWidth {floatAside} {allowClose} isAside isHeader on:close>
|
||||||
<svelte:fragment slot="title">
|
<svelte:fragment slot="title">
|
||||||
{@const additionalStepInfo = currentStep?.additionalInfo}
|
{@const additionalStepInfo = currentStepModel?.additionalInfo}
|
||||||
|
|
||||||
<div class="popupPanel-title__content-container antiTitle">
|
<div class="popupPanel-title__content-container antiTitle">
|
||||||
<div class="icon-wrapper">
|
<div class="icon-wrapper">
|
||||||
@ -122,8 +123,8 @@
|
|||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
|
|
||||||
<svelte:fragment slot="header">
|
<svelte:fragment slot="header">
|
||||||
{@const stepName = currentStep?.name}
|
{@const stepName = currentStepModel?.name}
|
||||||
{@const stepDescription = currentStep?.description}
|
{@const stepDescription = currentStepModel?.description}
|
||||||
|
|
||||||
<div class="header header-row between">
|
<div class="header header-row between">
|
||||||
{#if stepName}<h4 class="no-margin"><Label label={stepName} /></h4>{/if}
|
{#if stepName}<h4 class="no-margin"><Label label={stepName} /></h4>{/if}
|
||||||
@ -164,8 +165,8 @@
|
|||||||
</Scroller>
|
</Scroller>
|
||||||
</svelte:fragment>
|
</svelte:fragment>
|
||||||
|
|
||||||
{#if currentStep?.component}
|
{#if currentStepModel?.component}
|
||||||
{@const { component, props } = currentStep}
|
{@const { component, props } = currentStepModel}
|
||||||
{@const isMobile = $deviceInfo.isMobile}
|
{@const isMobile = $deviceInfo.isMobile}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
@ -176,9 +177,9 @@
|
|||||||
class:max={!isMobile && useMaxWidth}
|
class:max={!isMobile && useMaxWidth}
|
||||||
>
|
>
|
||||||
{#if typeof component === 'string'}
|
{#if typeof component === 'string'}
|
||||||
<Component is={component} {props} on:change={handleComponentChange} />
|
<Component bind:innerRef={step} is={component} {props} on:change={handleComponentChange} />
|
||||||
{:else}
|
{:else}
|
||||||
<svelte:component this={component} {...props} on:change={handleComponentChange} />
|
<svelte:component this={component} bind:this={step} {...props} on:change={handleComponentChange} />
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -299,5 +299,4 @@ export interface DialogStep {
|
|||||||
readonly additionalInfo?: string
|
readonly additionalInfo?: string
|
||||||
readonly component: AnyComponent | AnySvelteComponent
|
readonly component: AnyComponent | AnySvelteComponent
|
||||||
props?: Record<string, any>
|
props?: Record<string, any>
|
||||||
readonly onDone?: () => Promise<void> | void
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user