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

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

@ -25,6 +25,7 @@ const isOpenColorPicker = ref(false)
vModel.value.meta = { vModel.value.meta = {
...columnDefaultMeta[UITypes.Checkbox], ...columnDefaultMeta[UITypes.Checkbox],
...(vModel.value.meta || {}), ...(vModel.value.meta || {}),
icon: extractCheckboxIcon(vModel.value.meta || {}),
} }
// antdv doesn't support object as value // 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 = { vModel.value.meta = {
...columnDefaultMeta[UITypes.Rating], ...columnDefaultMeta[UITypes.Rating],
...(vModel.value.meta || {}), ...(vModel.value.meta || {}),
icon: extractRatingIcon(vModel.value.meta || {}),
} }
// antdv doesn't support object as value // 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) { if (parsedMeta.icon) {
icon.checked = parsedMeta.icon.checked || icon.checked icon.checked = parsedMeta.icon.checked || icon.checked
icon.unchecked = parsedMeta.icon.unchecked || icon.unchecked icon.unchecked = parsedMeta.icon.unchecked || icon.unchecked
} else if (typeof parsedMeta.iconIndex === 'number' && checkboxIconList[parsedMeta.iconIndex]) { } else if (typeof parsedMeta.iconIdx === 'number' && checkboxIconList[parsedMeta.iconIdx]) {
icon.checked = checkboxIconList[parsedMeta.iconIndex].checked icon.checked = checkboxIconList[parsedMeta.iconIdx].checked
icon.unchecked = checkboxIconList[parsedMeta.iconIndex].unchecked icon.unchecked = checkboxIconList[parsedMeta.iconIdx].unchecked
} }
return icon return icon
} }
@ -341,9 +341,9 @@ function extractRatingIcon(meta: string | Record<string, any> = null) {
if (parsedMeta.icon) { if (parsedMeta.icon) {
icon.full = parsedMeta.icon.full || icon.full icon.full = parsedMeta.icon.full || icon.full
icon.empty = parsedMeta.icon.empty || icon.empty icon.empty = parsedMeta.icon.empty || icon.empty
} else if (typeof parsedMeta.iconIndex === 'number' && ratingIconList[parsedMeta.iconIndex]) { } else if (typeof parsedMeta.iconIdx === 'number' && ratingIconList[parsedMeta.iconIdx]) {
icon.full = ratingIconList[parsedMeta.iconIndex].full icon.full = ratingIconList[parsedMeta.iconIdx].full
icon.empty = ratingIconList[parsedMeta.iconIndex].empty icon.empty = ratingIconList[parsedMeta.iconIdx].empty
} }
return icon return icon
} }
@ -361,4 +361,5 @@ export {
checkboxIconList, checkboxIconList,
ratingIconList, ratingIconList,
extractCheckboxIcon, extractCheckboxIcon,
extractRatingIcon,
} }

Loading…
Cancel
Save