Browse Source

refactor: extract icon based on index

pull/9660/head
Pranav C 1 month ago
parent
commit
8e1c05090c
  1. 8
      packages/nc-gui/components/cell/Rating.vue
  2. 1
      packages/nc-gui/components/smartsheet/column/CheckboxOptions.vue
  3. 1
      packages/nc-gui/components/smartsheet/column/RatingOptions.vue
  4. 13
      packages/nc-gui/utils/columnUtils.ts

8
packages/nc-gui/components/cell/Rating.vue

@ -1,4 +1,6 @@
<script setup lang="ts">
import { extractRatingIcon } from '../../utils/columnUtils'
interface Props {
modelValue?: number | null | undefined
}
@ -16,11 +18,9 @@ const rowHeight = inject(RowHeightInj, ref(undefined))
const isExpandedFormOpen = inject(IsExpandedFormOpenInj, ref(false))!
const ratingMeta = computed(() => {
const icon = extractRatingIcon(column?.value?.meta)
return {
icon: {
full: 'mdi-star',
empty: 'mdi-star-outline',
},
icon,
color: '#fcb401',
max: 5,
...parseProp(column.value?.meta),

1
packages/nc-gui/components/smartsheet/column/CheckboxOptions.vue

@ -25,6 +25,7 @@ const isOpenColorPicker = ref(false)
vModel.value.meta = {
...columnDefaultMeta[UITypes.Checkbox],
...(vModel.value.meta || {}),
icon: extractCheckboxIcon(vModel.value.meta || {}),
}
// antdv doesn't support object as value

1
packages/nc-gui/components/smartsheet/column/RatingOptions.vue

@ -22,6 +22,7 @@ const isOpenColorPicker = ref(false)
vModel.value.meta = {
...columnDefaultMeta[UITypes.Rating],
...(vModel.value.meta || {}),
icon: extractRatingIcon(vModel.value.meta || {}),
}
// antdv doesn't support object as value

13
packages/nc-gui/utils/columnUtils.ts

@ -323,9 +323,9 @@ function extractCheckboxIcon(meta: string | Record<string, any> = null) {
if (parsedMeta.icon) {
icon.checked = parsedMeta.icon.checked || icon.checked
icon.unchecked = parsedMeta.icon.unchecked || icon.unchecked
} else if (typeof parsedMeta.iconIndex === 'number' && checkboxIconList[parsedMeta.iconIndex]) {
icon.checked = checkboxIconList[parsedMeta.iconIndex].checked
icon.unchecked = checkboxIconList[parsedMeta.iconIndex].unchecked
} else if (typeof parsedMeta.iconIdx === 'number' && checkboxIconList[parsedMeta.iconIdx]) {
icon.checked = checkboxIconList[parsedMeta.iconIdx].checked
icon.unchecked = checkboxIconList[parsedMeta.iconIdx].unchecked
}
return icon
}
@ -341,9 +341,9 @@ function extractRatingIcon(meta: string | Record<string, any> = null) {
if (parsedMeta.icon) {
icon.full = parsedMeta.icon.full || icon.full
icon.empty = parsedMeta.icon.empty || icon.empty
} else if (typeof parsedMeta.iconIndex === 'number' && ratingIconList[parsedMeta.iconIndex]) {
icon.full = ratingIconList[parsedMeta.iconIndex].full
icon.empty = ratingIconList[parsedMeta.iconIndex].empty
} else if (typeof parsedMeta.iconIdx === 'number' && ratingIconList[parsedMeta.iconIdx]) {
icon.full = ratingIconList[parsedMeta.iconIdx].full
icon.empty = ratingIconList[parsedMeta.iconIdx].empty
}
return icon
}
@ -361,4 +361,5 @@ export {
checkboxIconList,
ratingIconList,
extractCheckboxIcon,
extractRatingIcon,
}

Loading…
Cancel
Save