-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(notifications): add
clients tab
See: BEDS-188
- Loading branch information
1 parent
040f770
commit 5cf390f
Showing
6 changed files
with
279 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<script lang="ts" setup> | ||
const props = defineProps<{ | ||
optionIdentifier: string, | ||
optionLabel: string, | ||
options: any[], | ||
optionValue: string, | ||
screenreaderHeading?: string, | ||
screenreaderText: string, | ||
text: string, | ||
}>() | ||
const hasOptions = computed(() => !!props.options.length) | ||
const popover = ref() | ||
const isVisible = ref(false) | ||
const toggle = (event: Event) => { | ||
popover.value?.toggle(event) | ||
isVisible.value = !isVisible.value | ||
} | ||
const idScreenreaderHeading = useId() | ||
const handleFocus = () => { | ||
const screenreaderHeadingElement = document.getElementById(idScreenreaderHeading) | ||
screenreaderHeadingElement?.focus() | ||
} | ||
const emit = defineEmits<{ | ||
change: [{ | ||
id: number, | ||
value: boolean, | ||
}], | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<span> | ||
<button | ||
type="button" | ||
class="bc-dropdown-toggle__button" | ||
:aria-label="screenreaderText" | ||
@click="hasOptions && toggle($event)" | ||
> | ||
<span>{{ text }}</span> | ||
<IconChevron | ||
v-if="hasOptions" | ||
width="0.5rem" | ||
:direction="isVisible ? 'left' : 'bottom'" | ||
/> | ||
</button> | ||
|
||
<Popover | ||
ref="popover" | ||
unstyled | ||
@keydown.esc.stop | ||
@show="handleFocus" | ||
@hide="isVisible = false" | ||
> | ||
<ul | ||
class="content" | ||
> | ||
<BcScreenreaderOnly | ||
:id="idScreenreaderHeading" | ||
tabindex="-1" | ||
tag="h2" | ||
> | ||
{{ props.screenreaderHeading }} | ||
</BcScreenreaderOnly> | ||
<li | ||
v-for="option in props.options" | ||
:key="option[props.optionIdentifier]" | ||
class="content-item" | ||
> | ||
<label | ||
class="content-item__label" | ||
:for="`${option[props.optionIdentifier]}`" | ||
> | ||
{{ option[optionLabel] }} | ||
</label> | ||
<BcToggle | ||
v-model="option.is_subscribed" | ||
:input-id="`${option[props.optionIdentifier]}`" | ||
@update:model-value="emit('change', { | ||
id: option[props.optionIdentifier], | ||
value: option[props.optionValue], | ||
})" | ||
/> | ||
</li> | ||
</ul> | ||
</Popover> | ||
</span> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
.content { | ||
margin-block: 0.25rem; | ||
max-width: 25rem; | ||
min-width: 15rem; | ||
padding: var(--padding); | ||
border-radius: var(--border-radius); | ||
border: 1px solid var(--input-border-color); | ||
background-color: var(--input-background); | ||
list-style: none; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 0.25rem; | ||
} | ||
.content-item { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
gap: 0.625rem; | ||
&__label { | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} | ||
} | ||
.bc-dropdown-toggle__button { | ||
padding-inline: 0.5rem; | ||
padding-block: 0.25rem; | ||
width: 9rem; | ||
background-color: var(--input-background); | ||
border-radius: var(--border-radius); | ||
border: 1px solid var(--input-border-color); | ||
color: var(--input-active-text-color); | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
} | ||
</style> |
110 changes: 110 additions & 0 deletions
110
frontend/components/notifications/management/NotificationsManagementClients.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<script lang="ts" setup> | ||
const { t: $t } = useTranslation() | ||
const notificationsManagementStore = useNotificationsManagementStore() | ||
await notificationsManagementStore.getSettings() | ||
const executionClients = computed( | ||
() => notificationsManagementStore.settings.clients.filter(client => client.category === 'execution_layer'), | ||
) | ||
const consensusClients = computed( | ||
() => notificationsManagementStore.settings.clients.filter(client => client.category === 'consensus_layer'), | ||
) | ||
const otherClients = computed( | ||
() => notificationsManagementStore.settings.clients.filter(client => client.category === 'other'), | ||
) | ||
const screenreaderTextExcutionClients = computed( | ||
() => executionClients.value.length | ||
? $t('notifications.clients.settings.screenreader.edit_notifications', [ | ||
executionClients.value.length, | ||
$t('notifications.clients.settings.execution_clients'), | ||
]) | ||
: $t('notifications.clients.settings.screenreader.empty_clients'), | ||
) | ||
const screenreaderTextConsensusClients = computed( | ||
() => consensusClients.value.length | ||
? $t('notifications.clients.settings.screenreader.edit_notifications', [ | ||
consensusClients.value.length, | ||
$t('notifications.clients.settings.execution_clients'), | ||
]) | ||
: $t('notifications.clients.settings.screenreader.empty_clients'), | ||
) | ||
const screenreaderTextOtherClients = computed( | ||
() => executionClients.value.length | ||
? $t('notifications.clients.settings.screenreader.edit_notifications', [ | ||
executionClients.value.length, | ||
$t('notifications.clients.settings.execution_clients'), | ||
]) | ||
: $t('notifications.clients.settings.screenreader.empty_clients'), | ||
) | ||
const setNotificationForClient = ({ | ||
id, | ||
value, | ||
}: { | ||
id: number, | ||
value: boolean, | ||
}, | ||
) => { | ||
notificationsManagementStore.setNotificationForClient({ | ||
client_id: id, | ||
is_subscribed: value, | ||
}) | ||
} | ||
</script> | ||
|
||
<template> | ||
<BcTabPanel> | ||
<BcListSection> | ||
<span class="grid-span-2"> | ||
{{ $t('notifications.clients.settings.execution_clients') }} | ||
</span> | ||
<BcDropdownToggle | ||
:options="executionClients" | ||
option-label="name" | ||
option-value="is_subscribed" | ||
option-identifier="id" | ||
:screenreader-text="screenreaderTextExcutionClients" | ||
:screenreader-heading="$t('notifications.clients.settings.execution_clients')" | ||
:text="$t('notifications.clients.settings.clients', [executionClients.length])" | ||
@change="setNotificationForClient" | ||
/> | ||
<span class="grid-span-2"> | ||
{{ $t('notifications.clients.settings.consensus_clients') }} | ||
</span> | ||
<BcDropdownToggle | ||
:options="consensusClients" | ||
option-label="name" | ||
option-value="is_subscribed" | ||
option-identifier="id" | ||
:screenreader-text="screenreaderTextConsensusClients" | ||
:screenreader-heading="$t('notifications.clients.settings.consensus_clients')" | ||
:text="$t('notifications.clients.settings.clients', [consensusClients.length])" | ||
@change="setNotificationForClient" | ||
/> | ||
<span class="grid-span-2"> | ||
{{ $t('notifications.clients.settings.other_clients') }} | ||
</span> | ||
<BcDropdownToggle | ||
:options="otherClients" | ||
option-label="name" | ||
option-value="is_subscribed" | ||
option-identifier="id" | ||
:screenreader-text="screenreaderTextOtherClients" | ||
:screenreader-heading="$t('notifications.clients.settings.other_clients')" | ||
:text="$t('notifications.clients.settings.clients', [otherClients.length])" | ||
@change="setNotificationForClient" | ||
/> | ||
</BcListSection> | ||
</BcTabPanel> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
.toggle { | ||
justify-content: end; | ||
margin: 0; | ||
} | ||
.grid-span-2{ | ||
grid-column: span 2; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters