Skip to content

Commit 85dcc66

Browse files
committed
refactor: keep envelope validation ui state local
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent c80e1f6 commit 85dcc66

1 file changed

Lines changed: 38 additions & 38 deletions

File tree

src/components/validation/EnvelopeValidation.vue

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@
5858
</p>
5959
<ul class="documents-list">
6060
<li v-for="(file, fileIndex) in document.files" :key="fileIndex" class="document-item">
61-
<NcListItem :name="file.name" :active="file.opened" @click="toggleFileDetail(file)">
61+
<NcListItem :name="file.name" :active="isFileOpen(fileIndex)" @click="toggleFileDetail(fileIndex)">
6262
<template #icon>
6363
<NcIconSvgWrapper :path="mdiFilePdfBox" :size="44" />
6464
</template>
6565
<template #subname>
66-
<strong>{{ t('libresign', 'Status:') }}</strong> {{ file.statusText }}
66+
<strong>{{ t('libresign', 'Status:') }}</strong> {{ getFileStatusText(file) }}
6767
</template>
6868
<template v-if="!isTouchDevice && file.nodeId" #actions>
6969
<NcActionButton @click.stop="viewFile(file)">
@@ -79,15 +79,15 @@
7979
<NcIconSvgWrapper :path="mdiEye" :size="20" />
8080
</template>
8181
</NcButton>
82-
<NcButton variant="tertiary" :aria-label="file.opened ? t('libresign', 'Hide details') : t('libresign', 'Show details')" @click.stop="toggleFileDetail(file)">
82+
<NcButton variant="tertiary" :aria-label="isFileOpen(fileIndex) ? t('libresign', 'Hide details') : t('libresign', 'Show details')" @click.stop="toggleFileDetail(fileIndex)">
8383
<template #icon>
84-
<NcIconSvgWrapper v-if="file.opened" :path="mdiChevronUp" :size="20" />
84+
<NcIconSvgWrapper v-if="isFileOpen(fileIndex)" :path="mdiChevronUp" :size="20" />
8585
<NcIconSvgWrapper v-else :path="mdiChevronDown" :size="20" />
8686
</template>
8787
</NcButton>
8888
</template>
8989
</NcListItem>
90-
<div v-if="file.opened" class="file-signers">
90+
<div v-if="isFileOpen(fileIndex)" class="file-signers">
9191
<DocumentValidationDetails
9292
:document="file"
9393
/>
@@ -107,7 +107,7 @@
107107
</p>
108108
<ul class="signers-list">
109109
<li v-for="(signer, signerIndex) in document.signers" :key="signerIndex">
110-
<NcListItem :name="getName(signer)" :active="signer.opened" @click="toggleDetail(signer)">
110+
<NcListItem :name="getName(signer)" :active="isSignerOpen(signerIndex)" @click="toggleDetail(signerIndex)">
111111
<template #icon>
112112
<NcAvatar disable-menu :is-no-user="!signer.userId" :size="44" :user="signer.userId ? signer.userId : getName(signer)" :display-name="getName(signer)" />
113113
</template>
@@ -117,15 +117,15 @@
117117
</span>
118118
</template>
119119
<template #extra-actions>
120-
<NcButton variant="tertiary" :aria-label="signer.opened ? t('libresign', 'Hide details') : t('libresign', 'Show details')" @click.stop="toggleDetail(signer)">
120+
<NcButton variant="tertiary" :aria-label="isSignerOpen(signerIndex) ? t('libresign', 'Hide details') : t('libresign', 'Show details')" @click.stop="toggleDetail(signerIndex)">
121121
<template #icon>
122-
<NcIconSvgWrapper v-if="signer.opened" :path="mdiChevronUp" :size="20" />
122+
<NcIconSvgWrapper v-if="isSignerOpen(signerIndex)" :path="mdiChevronUp" :size="20" />
123123
<NcIconSvgWrapper v-else :path="mdiChevronDown" :size="20" />
124124
</template>
125125
</NcButton>
126126
</template>
127127
</NcListItem>
128-
<div v-if="signer.opened" class="signer-details">
128+
<div v-if="isSignerOpen(signerIndex)" class="signer-details">
129129
<NcListItem v-if="signer.request_sign_date" class="detail-item" compact>
130130
<template #name>
131131
<strong>{{ t('libresign', 'Requested on:') }}</strong>
@@ -161,7 +161,7 @@
161161
<script setup lang="ts">
162162
import { n, t } from '@nextcloud/l10n'
163163
import { generateUrl } from '@nextcloud/router'
164-
import { computed, watch } from 'vue'
164+
import { computed, ref, watch } from 'vue'
165165
166166
import {
167167
mdiAccountMultiple,
@@ -180,37 +180,23 @@ import DocumentValidationDetails from './DocumentValidationDetails.vue'
180180
import type {
181181
LoadedValidationEnvelopeDocument,
182182
SignerDetailRecord,
183-
ValidationViewChildFile,
184183
} from '../../types/index'
185184
186185
defineOptions({
187186
name: 'EnvelopeValidation',
188187
})
189188
190-
type EnvelopeFile = Partial<ValidationViewChildFile> & {
191-
opened?: boolean
192-
statusText?: string
193-
signers?: EnvelopeSigner[]
194-
}
189+
type EnvelopeFile = NonNullable<LoadedValidationEnvelopeDocument['files']>[number]
195190
196191
type EnvelopeSigner = Partial<Pick<SignerDetailRecord, 'displayName' | 'email' | 'userId' | 'request_sign_date' | 'remote_address' | 'user_agent'>> & {
197-
opened?: boolean
198192
signed?: string | null
199193
documentsSignedCount?: number
200194
totalDocuments?: number
201195
}
202196
203-
type EnvelopeDocument = {
204-
uuid: LoadedValidationEnvelopeDocument['uuid']
205-
name: LoadedValidationEnvelopeDocument['name']
206-
nodeId: LoadedValidationEnvelopeDocument['nodeId']
207-
nodeType: LoadedValidationEnvelopeDocument['nodeType']
208-
status: LoadedValidationEnvelopeDocument['status'] | string
209-
filesCount?: number
210-
files?: EnvelopeFile[]
197+
type EnvelopeDocument = LoadedValidationEnvelopeDocument & {
211198
signers?: EnvelopeSigner[]
212199
signedDate?: string
213-
[key: string]: unknown
214200
}
215201
216202
const props = withDefaults(defineProps<{
@@ -225,26 +211,38 @@ const props = withDefaults(defineProps<{
225211
})
226212
227213
const { isTouchDevice } = useIsTouchDevice()
214+
const fileOpenState = ref<Record<number, boolean>>({})
215+
const signerOpenState = ref<Record<number, boolean>>({})
228216
229217
const documentStatus = computed(() => getStatusLabel(props.document.status))
230218
231-
function initializeDocument(doc: EnvelopeDocument) {
232-
doc.files?.forEach((file) => {
233-
file.opened = false
234-
file.statusText = getStatusLabel(file.status)
235-
})
219+
function resetDisclosureState() {
220+
fileOpenState.value = {}
221+
signerOpenState.value = {}
236222
}
237223
238224
function dateFromSqlAnsi(date: string) {
239225
return Moment(Date.parse(date)).format('LL LTS')
240226
}
241227
242-
function toggleDetail(signer: EnvelopeSigner) {
243-
signer.opened = !signer.opened
228+
function isSignerOpen(signerIndex: number) {
229+
return !!signerOpenState.value[signerIndex]
230+
}
231+
232+
function toggleDetail(signerIndex: number) {
233+
signerOpenState.value[signerIndex] = !isSignerOpen(signerIndex)
234+
}
235+
236+
function isFileOpen(fileIndex: number) {
237+
return !!fileOpenState.value[fileIndex]
238+
}
239+
240+
function toggleFileDetail(fileIndex: number) {
241+
fileOpenState.value[fileIndex] = !isFileOpen(fileIndex)
244242
}
245243
246-
function toggleFileDetail(file: EnvelopeFile) {
247-
file.opened = !file.opened
244+
function getFileStatusText(file: EnvelopeFile) {
245+
return getStatusLabel(file.status)
248246
}
249247
250248
function getName(signer: EnvelopeSigner) {
@@ -269,14 +267,16 @@ function viewFile(file: EnvelopeFile) {
269267
})
270268
}
271269
272-
watch(() => props.document, (newDoc) => {
273-
initializeDocument(newDoc)
270+
watch(() => props.document, () => {
271+
resetDisclosureState()
274272
}, { immediate: true })
275273
276274
defineExpose({
277275
isTouchDevice,
278276
documentStatus,
279-
initializeDocument,
277+
isSignerOpen,
278+
isFileOpen,
279+
getFileStatusText,
280280
dateFromSqlAnsi,
281281
toggleDetail,
282282
toggleFileDetail,

0 commit comments

Comments
 (0)