From 1cbcc6b075d48b4f2ff48048608803ac0fa94160 Mon Sep 17 00:00:00 2001 From: Nicolas Giard Date: Thu, 13 Oct 2022 01:01:33 +0000 Subject: [PATCH 1/3] feat: js compiled url store --- client/agenda/AgendaDetailsModal.vue | 21 +++++++++++++++++---- client/shared/urls.js | 27 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 client/shared/urls.js diff --git a/client/agenda/AgendaDetailsModal.vue b/client/agenda/AgendaDetailsModal.vue index a58e8f83f26..0a140b8c4e6 100644 --- a/client/agenda/AgendaDetailsModal.vue +++ b/client/agenda/AgendaDetailsModal.vue @@ -152,6 +152,7 @@ import { } from 'naive-ui' import { useAgendaStore } from './store' +import { getUrl } from '../shared/urls' // PROPS @@ -205,10 +206,22 @@ const eventDetails = computed(() => { title: props.event.type === 'regular' ? `${props.event.groupName} (${props.event.acronym})` : props.event.name, showAgenda: props.event.flags.showAgenda, materialsUrl: materialsUrl, - detailsUrl: `/meeting/${agendaStore.meeting.number}/session/${props.event.acronym}/`, - tarUrl: `/meeting/${agendaStore.meeting.number}/agenda/${props.event.acronym}-drafts.tgz`, - pdfUrl: `/meeting/${agendaStore.meeting.number}/agenda/${props.event.acronym}-drafts.pdf`, - notepadUrl: `https://notes.ietf.org/notes-ietf-${agendaStore.meeting.number}-${props.event.type === 'plenary' ? 'plenary' : props.event.acronym}`, + detailsUrl: getUrl('meetingDetails', { + meetingNumber: agendaStore.meeting.number, + eventAcronym: props.event.acronym + }), + tarUrl: getUrl('meetingMaterialsTar', { + meetingNumber: agendaStore.meeting.number, + eventAcronym: props.event.acronym + }), + pdfUrl: getUrl('meetingMaterialsPdf', { + meetingNumber: agendaStore.meeting.number, + eventAcronym: props.event.acronym + }), + notepadUrl: getUrl('meetingNotes', { + meetingNumber: agendaStore.meeting.number, + eventAcronym: props.event.type === 'plenary' ? 'plenary' : props.event.acronym + }) } }) diff --git a/client/shared/urls.js b/client/shared/urls.js new file mode 100644 index 00000000000..bd60a49fd0d --- /dev/null +++ b/client/shared/urls.js @@ -0,0 +1,27 @@ +import template from 'lodash-es/template' +import transform from 'lodash-es/transform' + +const urls = { + meetingDetails: '/meeting/{meetingNumber}/session/{eventAcronym}/', + meetingMaterialsPdf: '/meeting/{meetingNumber}/agenda/{eventAcronym}-drafts.pdf', + meetingMaterialsTar: '/meeting/{meetingNumber}/agenda/{eventAcronym}-drafts.tgz', + meetingNotes: 'https://notes.ietf.org/notes-ietf-{meetingNumber}-{eventAcronym}' +} + +const interpolate = /{([\s\S]+?)}/g +const compiled = transform(urls, (result, value, key) => { + result[key] = template(value, { interpolate }) +}, {}) + +/** + * Get an URL and replace tokens with provided values. + * + * @param {string} key The key of the URL template to use. + * @param {Object} [tokens] An object of tokens to replace in the URL template. + * @returns {string} URL with tokens replaced with the provided values. + */ +export const getUrl = (key, tokens = {}) => { + if (!key) { throw new Error('Must provide a key for getUrl()') } + if (!compiled[key]) { throw new Error('Invalid getUrl() key') } + return compiled[key](tokens) +} From 4c8a3fcbdcf1deb090a6ff8c34ea26ac6b7ce95e Mon Sep 17 00:00:00 2001 From: Nicolas Giard Date: Thu, 13 Oct 2022 20:27:06 +0000 Subject: [PATCH 2/3] feat: use url store for AgendaFilter-MobileBar-QuickAccess components --- client/agenda/AgendaFilter.vue | 3 ++- client/agenda/AgendaMobileBar.vue | 7 ++++--- client/agenda/AgendaQuickAccess.vue | 9 +++++---- client/shared/urls.js | 2 ++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/client/agenda/AgendaFilter.vue b/client/agenda/AgendaFilter.vue index 5209b174ac1..e6ab90a62c8 100644 --- a/client/agenda/AgendaFilter.vue +++ b/client/agenda/AgendaFilter.vue @@ -60,7 +60,7 @@ n-drawer(v-model:show='state.isShown', placement='bottom', :height='state.drawer ) template(#trigger) span.badge BoF - span #[a(href='https://www.ietf.org/how/bofs/', target='_blank') Birds of a Feather] sessions (BoFs) are initial discussions about a particular topic of interest to the IETF community. + span #[a(:href='getUrl(`bofDefinition`)', target='_blank') Birds of a Feather] sessions (BoFs) are initial discussions about a particular topic of interest to the IETF community.