Skip to content

Commit 542afb4

Browse files
committed
refactor(vue3): migrate CertificateChain to script setup ts
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 67f419a commit 542afb4

1 file changed

Lines changed: 43 additions & 55 deletions

File tree

src/components/validation/CertificateChain.vue

Lines changed: 43 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -70,74 +70,62 @@
7070
</div>
7171
</template>
7272

73-
<script>
73+
<script setup lang="ts">
7474
import { t } from '@nextcloud/l10n'
7575
import NcButton from '@nextcloud/vue/components/NcButton'
7676
import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper'
7777
import NcListItem from '@nextcloud/vue/components/NcListItem'
7878
import Moment from '@nextcloud/moment'
79+
import { ref } from 'vue'
7980
8081
import {
8182
mdiUnfoldLessHorizontal,
8283
mdiUnfoldMoreHorizontal,
8384
} from '@mdi/js'
8485
85-
export default {
86+
defineOptions({
8687
name: 'CertificateChain',
87-
components: {
88-
NcButton,
89-
NcIconSvgWrapper,
90-
NcListItem,
91-
},
92-
props: {
93-
chain: {
94-
type: Array,
95-
required: true,
96-
},
97-
},
98-
setup() {
99-
return {
100-
mdiUnfoldLessHorizontal,
101-
mdiUnfoldMoreHorizontal,
102-
t,
103-
}
104-
},
105-
data() {
106-
return {
107-
chainOpen: false,
108-
}
109-
},
110-
methods: {
111-
formatTimestamp(timestamp) {
112-
if (!timestamp) return ''
113-
return Moment.unix(timestamp).format('LLL')
114-
},
115-
getToggleAriaLabel() {
116-
if (this.chainOpen) {
117-
// TRANSLATORS: Button label read by screen readers. Clicking it hides the list of certificates in the trust chain (the digital identity cards behind the signature)
118-
return t('libresign', 'Collapse certificate chain')
119-
}
120-
// TRANSLATORS: Button label read by screen readers. Clicking it reveals the list of certificates in the trust chain (the digital identity cards behind the signature)
121-
return t('libresign', 'Expand certificate chain')
122-
},
123-
getCertItemLabel(certIndex) {
124-
if (certIndex === 0) {
125-
// TRANSLATORS: Label read by screen readers to identify the first certificate — the one belonging to the person who actually signed the document
126-
return t('libresign', 'Signer certificate')
127-
}
128-
// TRANSLATORS: Label read by screen readers to identify additional certificates higher up in the trust chain. {index} is a number starting at 2 (e.g. "Certificate 2" is the issuing authority of the signer, "Certificate 3" is the authority above that, and so on)
129-
return t('libresign', 'Certificate {index}', { index: certIndex + 1 })
130-
},
131-
getCertRoleLabel(certIndex) {
132-
if (certIndex === 0) {
133-
// TRANSLATORS: Label shown next to the name of the person or entity who signed the document. Their identity is proven by their certificate.
134-
return t('libresign', 'Signer:')
135-
}
136-
// TRANSLATORS: Label shown next to the name of the Certificate Authority (CA) that issued the certificate above it in the chain. A CA is an organization trusted to verify and certify digital identities, like a notary or government agency.
137-
return t('libresign', 'Issuer:')
138-
},
139-
},
88+
})
89+
90+
defineProps<{
91+
chain: Array<Record<string, any>>
92+
}>()
93+
94+
const chainOpen = ref(false)
95+
96+
function formatTimestamp(timestamp?: number) {
97+
if (!timestamp) return ''
98+
return Moment.unix(timestamp).format('LLL')
14099
}
100+
101+
function getToggleAriaLabel() {
102+
if (chainOpen.value) {
103+
return t('libresign', 'Collapse certificate chain')
104+
}
105+
return t('libresign', 'Expand certificate chain')
106+
}
107+
108+
function getCertItemLabel(certIndex: number) {
109+
if (certIndex === 0) {
110+
return t('libresign', 'Signer certificate')
111+
}
112+
return t('libresign', 'Certificate {index}', { index: certIndex + 1 })
113+
}
114+
115+
function getCertRoleLabel(certIndex: number) {
116+
if (certIndex === 0) {
117+
return t('libresign', 'Signer:')
118+
}
119+
return t('libresign', 'Issuer:')
120+
}
121+
122+
defineExpose({
123+
chainOpen,
124+
formatTimestamp,
125+
getToggleAriaLabel,
126+
getCertItemLabel,
127+
getCertRoleLabel,
128+
})
141129
</script>
142130

143131
<style scoped lang="scss">

0 commit comments

Comments
 (0)