Skip to content

Commit

Permalink
feat: add developer managed scopes to app reg modal (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidma415 authored Nov 16, 2023
1 parent e98d2e9 commit 6a7eb8c
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 11 deletions.
98 changes: 88 additions & 10 deletions src/components/ViewSpecRegistrationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,25 @@
</div>
</template>
<template #name="{ row }">
<p
class="table-text"
:data-testid="`register-${row.name}`"
>
{{ row.name }}
</p>
<div class="name-container">
<p
class="table-text"
:data-testid="`register-${row.name}`"
>
{{ row.name }}
</p>
<div v-if="selectedApplication === row.id">
<KMultiselect
v-if="availableScopes.length"
v-model="selectedScopes"
:label="helpText.applicationRegistration.availableScopesLabel"
data-testid="analytics-service-filter"
class="analytics-service-filter"
:items="mappedAvailableScopes"
@change="handleChangedItem"
/>
</div>
</div>
</template>
</KTable>
</div>
Expand Down Expand Up @@ -101,14 +114,16 @@
</template>

<script lang="ts">
import { computed, defineComponent, ref, onMounted } from 'vue'
import { computed, defineComponent, ref, onMounted, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useMachine } from '@xstate/vue'
import { createMachine } from 'xstate'
import useToaster from '@/composables/useToaster'
import usePortalApi from '@/hooks/usePortalApi'
import { useI18nStore } from '@/stores'
import getMessageFromError from '@/helpers/getMessageFromError'
import useLDFeatureFlag from '@/hooks/useLDFeatureFlag'
import { FeatureFlags } from '@/constants/feature-flags'
export default defineComponent({
name: 'ViewSpecRegistrationModal',
Expand Down Expand Up @@ -142,10 +157,26 @@ export default defineComponent({
const helpText = useI18nStore().state.helpText
const errorMessage = ref('')
const selectedApplication = ref('')
const availableScopes = ref([])
const selectedScopes = ref([])
const useDeveloperManagedScopes = useLDFeatureFlag(FeatureFlags.DeveloperManagedScopes, false)
const applications = ref([])
const key = ref(0)
const fetcherCacheKey = computed(() => key.value.toString())
const mappedAvailableScopes = computed(() => {
if (!availableScopes.value.length) {
return []
}
return availableScopes.value.map((scope) => {
return {
label: scope,
value: scope
}
})
})
const tableHeaders = [
{ label: 'Name', key: 'name' }
]
Expand Down Expand Up @@ -248,9 +279,18 @@ export default defineComponent({
})
}
const submitSelection = () => {
const handleChangedItem = (item) => {
if (!item) { return }
const itemAdded = selectedScopes.value.filter(curr => curr.value === item.value)
// If a new item selected, set its `selected` state to true
item.selected = !!itemAdded.length
}
const submitSelection = async () => {
send('CLICK_SUBMIT')
portalApiV2.value.service.registrationsApi.createApplicationRegistration({
await portalApiV2.value.service.registrationsApi.createApplicationRegistration({
applicationId: selectedApplication.value,
createRegistrationPayload: {
product_version_id: props.version.id
Expand Down Expand Up @@ -285,7 +325,29 @@ export default defineComponent({
searchStr.value = ''
}
onMounted(() => {
watch(() => selectedApplication.value, (newSelectedApplication, oldSelectedApplication) => {
// We reset selectedScopes if we change applications
if (newSelectedApplication !== oldSelectedApplication && selectedScopes.value.length) {
selectedScopes.value = []
}
})
watch([() => props.product, () => props.version], async () => {
if (props.product && props.version && useDeveloperManagedScopes) {
await portalApiV2.value.service.versionsApi.getProductVersion({
productId: props.product.id,
versionId: props.version.id
}).then((res) => {
const registrationConfigs = res.data.registration_configs
if (registrationConfigs?.length && registrationConfigs[0].available_scopes) {
availableScopes.value = registrationConfigs[0].available_scopes
}
})
}
})
onMounted(async () => {
if (props.initialSelectedApplication) {
searchStr.value = props.initialSelectedApplication
}
Expand All @@ -299,6 +361,10 @@ export default defineComponent({
applications,
selectedApplication,
helpText,
handleChangedItem,
availableScopes,
mappedAvailableScopes,
selectedScopes,
rowAttrsFn,
fetcher,
modalText,
Expand Down Expand Up @@ -328,6 +394,12 @@ export default defineComponent({
td {
color: var(--section_colors-body) !important;
}
.k-input-label {
color: var(--section_colors-body);
font-weight: 400;
width: 100%;
}
}
// TODO: kui vars
Expand All @@ -339,6 +411,12 @@ export default defineComponent({
}
}
.name-container {
display: flex;
align-items: center;
justify-content: space-between;
}
</style>

<style lang="scss">
Expand Down
2 changes: 1 addition & 1 deletion src/constants/feature-flags.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export enum FeatureFlags {
//
DeveloperManagedScopes = 'tdx-3460-developer-managed-scopes'
}
1 change: 1 addition & 0 deletions src/locales/ca_ES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export const ca_ES: I18nType = {
noAvailableApplications: 'Actualment no teniu cap aplicació per registrar.',
noFoundApplications: translationNeeded(en.applicationRegistration.noFoundApplications),
searchPlaceholder: translationNeeded(en.applicationRegistration.searchPlaceholder),
availableScopesLabel: translationNeeded(en.applicationRegistration.availableScopesLabel),
noApplications: 'Sense aplicacions',
selectApplication: 'Seleccionar aplicació',
createNewApplication: 'Crear nova aplicació +',
Expand Down
1 change: 1 addition & 0 deletions src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export const de: I18nType = {
noAvailableApplications: 'Aktuell haben Sie noch keine Applikationen registriert.',
noFoundApplications: translationNeeded(en.applicationRegistration.noFoundApplications),
searchPlaceholder: translationNeeded(en.applicationRegistration.searchPlaceholder),
availableScopesLabel: translationNeeded(en.applicationRegistration.availableScopesLabel),
noApplications: 'Keine Applikationen',
selectApplication: 'Applikation auswählen',
createNewApplication: 'Neue Applikation anlegen +',
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export const en = {
createApplication: 'Create an Application',
searchPlaceholder: 'Search applications',
cancelButton: 'Cancel',
availableScopesLabel: 'Select scopes',
registeredApplicationsProduct: 'The following applications are already registered to this product:',
modalApplicationRegistrationDefault: {
title: (serviceName: string, productVersion: string) => `Register for ${serviceName} - ${productVersion}`,
Expand Down
1 change: 1 addition & 0 deletions src/locales/es_ES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export const es_ES: I18nType = {
noAvailableApplications: 'Actualmente no hay aplicaciones disponibles para registrarse.',
noFoundApplications: translationNeeded(en.applicationRegistration.noFoundApplications),
searchPlaceholder: translationNeeded(en.applicationRegistration.searchPlaceholder),
availableScopesLabel: translationNeeded(en.applicationRegistration.availableScopesLabel),
noApplications: 'No hay aplicaciones',
selectApplication: 'Seleccionar aplicación',
createNewApplication: 'Crear aplicación nueva +',
Expand Down
1 change: 1 addition & 0 deletions src/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export const fr: I18nType = {
noAvailableApplications: 'Vous n\'avez actuellement aucune application à enregistrer.',
noFoundApplications: translationNeeded(en.applicationRegistration.noFoundApplications),
searchPlaceholder: translationNeeded(en.applicationRegistration.searchPlaceholder),
availableScopesLabel: translationNeeded(en.applicationRegistration.availableScopesLabel),
noApplications: 'Aucune application',
selectApplication: 'Sélectionner une application',
createNewApplication: 'Créer une nouvelle application +',
Expand Down
1 change: 1 addition & 0 deletions src/locales/i18n-type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export interface I18nType {
cancelButton: string;
registeredApplicationsProduct: string;
searchPlaceholder: string;
availableScopesLabel: string;
modalApplicationRegistrationDefault: {
title: (serviceName: string, productVersion: string) => string;
buttonText: string;
Expand Down

0 comments on commit 6a7eb8c

Please sign in to comment.