Browse Source

fix : added select component in role selection

pull/7181/head
musharaf-nocodb 9 months ago
parent
commit
ed8743cd32
  1. 53
      packages/nc-gui/components/roles/Selector.vue

53
packages/nc-gui/components/roles/Selector.vue

@ -2,6 +2,7 @@
import { RoleDescriptions } from 'nocodb-sdk' import { RoleDescriptions } from 'nocodb-sdk'
import type { RoleLabels } from 'nocodb-sdk' import type { RoleLabels } from 'nocodb-sdk'
import { toRef } from '#imports' import { toRef } from '#imports'
import type { SelectValue } from 'ant-design-vue/es/select'
const props = withDefaults( const props = withDefaults(
defineProps<{ defineProps<{
@ -21,47 +22,55 @@ const props = withDefaults(
const roleRef = toRef(props, 'role') const roleRef = toRef(props, 'role')
const inheritRef = toRef(props, 'inherit') const inheritRef = toRef(props, 'inherit')
const descriptionRef = toRef(props, 'description') const descriptionRef = toRef(props, 'description')
const isDropdownOpen = ref(false)
const dropdownRef = ref(null)
const sizeRef = toRef(props, 'size') const sizeRef = toRef(props, 'size')
onClickOutside(dropdownRef, () => (isDropdownOpen.value = false))
function onChangeRole(val: SelectValue) {
props.onRoleChange(val as keyof typeof RoleLabels)
isDropdownOpen.value = false
}
</script> </script>
<template> <template>
<NcDropdown size="lg" class="nc-roles-selector"> <div size="lg" ref="dropdownRef" class="nc-roles-selector relative" @click="isDropdownOpen = !isDropdownOpen">
<RolesBadge data-testid="roles" :role="roleRef" :inherit="inheritRef === role" clickable :size="sizeRef" /> <RolesBadge data-testid="roles" :role="roleRef" :inherit="inheritRef === role" :size="sizeRef" />
<template #overlay> <a-select
<div class="nc-role-select-dropdown flex flex-col gap-1 p-2"> v-model:value="roleRef"
<div class="flex flex-col gap-1"> :open="isDropdownOpen"
<div :dropdown-match-select-width="false"
dropdown-class-name="!rounded-lg !h-fit max-w-64"
class="py-1 !absolute top-0 left-0 w-full h-full z-10 text-xs opacity-0"
@change="onChangeRole"
>
<a-select-option
v-for="rl in props.roles" v-for="rl in props.roles"
:key="rl" :key="rl"
v-e="['c:workspace:settings:user-role-change']" v-e="['c:workspace:settings:user-role-change']"
:value="rl" :value="rl"
:selected="rl === roleRef"
@click="props.onRoleChange(rl)"
> >
<div <div
class="flex flex-col py-1.5 rounded-lg px-2 gap-1 bg-transparent cursor-pointer hover:bg-gray-100"
:class="{ :class="{
'w-[350px]': descriptionRef, 'w-[350px]': descriptionRef,
'w-[200px]': !descriptionRef, 'w-[200px]': !descriptionRef,
}" }"
class="flex flex-col nc-role-select-dropdown gap-1"
> >
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
<RolesBadge <RolesBadge :class="`nc-role-select-${rl}`" :role="rl" :inherit="inheritRef === rl" :border="false" />
class="!bg-white hover:!bg-gray-100" <GeneralIcon v-if="rl === roleRef" icon="check" class="text-primary" />
:class="`nc-role-select-${rl}`"
:role="rl"
:inherit="inheritRef === rl"
:border="false"
/>
<GeneralIcon v-if="rl === roleRef" icon="check" class="text-primary"/>
</div> </div>
<div v-if="descriptionRef" class="text-gray-500">{{ RoleDescriptions[rl] }}</div> <div v-if="descriptionRef" class="text-gray-500">{{ RoleDescriptions[rl] }}</div>
</div> </div>
</a-select-option>
</a-select>
</div> </div>
</div>
</div>
</template>
</NcDropdown>
</template> </template>
<style scoped lang="scss"></style> <style lang="scss">
.ant-select-item-option-content {
white-space: normal; /* Change from 'nowrap' to 'normal' */
}
</style>

Loading…
Cancel
Save