Skip to content

Commit

Permalink
fix(*): replace useuniqueid with useid [KHCP-14269]
Browse files Browse the repository at this point in the history
  • Loading branch information
portikM committed Dec 5, 2024
1 parent d7c837e commit 05ba34a
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 60 deletions.
5 changes: 2 additions & 3 deletions src/components/KCatalog/KCatalog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@

<script setup lang="ts">
import type { PropType } from 'vue'
import { ref, computed, onMounted, watch, useSlots } from 'vue'
import { ref, computed, onMounted, watch, useSlots, useId } from 'vue'
import type {
CatalogItem,
CatalogPreferences,
Expand All @@ -177,7 +177,6 @@ import KEmptyState from '@/components/KEmptyState/KEmptyState.vue'
import KButton from '@/components/KButton/KButton.vue'
import KPagination from '@/components/KPagination/KPagination.vue'
import KCatalogItem from './KCatalogItem.vue'
import useUniqueId from '@/composables/useUniqueId'
const { useRequest, useDebounce, useSwrvState } = useUtilities()
const DEFAULT_PAGE_SIZE = 15
Expand Down Expand Up @@ -372,7 +371,7 @@ const emit = defineEmits<{
const slots = useSlots()
const catalogId = useUniqueId()
const catalogId = useId()
const getInitialPageSize = (): number => {
const initialPageSize = props.paginationPageSizes?.[0]
Expand Down
5 changes: 2 additions & 3 deletions src/components/KCheckbox/KCheckbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@

<script lang="ts" setup>
import type { PropType } from 'vue'
import { computed, useAttrs, useSlots } from 'vue'
import { computed, useAttrs, useId, useSlots } from 'vue'
import type { LabelAttributes } from '@/types'
import KLabel from '@/components/KLabel/KLabel.vue'
import { CheckSmallIcon, IndeterminateSmallIcon } from '@kong/icons'
import { KUI_ICON_SIZE_40 } from '@kong/design-tokens'
import useUniqueId from '@/composables/useUniqueId'
const props = defineProps({
modelValue: {
Expand Down Expand Up @@ -110,7 +109,7 @@ const emit = defineEmits<{
const slots = useSlots()
const attrs = useAttrs()
const inputId = attrs.id ? String(attrs.id) : useUniqueId()
const inputId = attrs.id ? String(attrs.id) : useId()
const hasLabel = computed((): boolean => !!(props.label || slots.default))
const isDisabled = computed((): boolean => attrs?.disabled !== undefined && String(attrs?.disabled) !== 'false')
Expand Down
5 changes: 2 additions & 3 deletions src/components/KCollapse/KCollapse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@

<script lang="ts" setup>
import type { PropType } from 'vue'
import { computed, ref, useSlots, watch } from 'vue'
import { computed, ref, useId, useSlots, watch } from 'vue'
import type { TriggerAlignment, HeaderTag } from '@/types'
import { TriggerAlignmentArray, HeaderTags } from '@/types'
import { ChevronRightIcon } from '@kong/icons'
import { KUI_ICON_SIZE_40 } from '@kong/design-tokens'
import useUniqueId from '@/composables/useUniqueId'
const props = defineProps({
// Is the KCollapse collapsed? Defaults to true-->
Expand Down Expand Up @@ -113,7 +112,7 @@ const emit = defineEmits<{
(e: 'update:modelValue', value: boolean): void;
}>()
const contentId = useUniqueId()
const contentId = useId()
const isCollapsed = ref<boolean>(true)
const modelValueChanged = ref<boolean>(false)
Expand Down
5 changes: 2 additions & 3 deletions src/components/KCopy/KCopy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@

<script setup lang="ts">
import type { PropType } from 'vue'
import { computed, ref, watch, onMounted, onUnmounted } from 'vue'
import { computed, ref, watch, onMounted, onUnmounted, useId } from 'vue'
import { ResizeObserverHelper } from '@/utilities/resizeObserverHelper'
import { CopyIcon } from '@kong/icons'
import KClipboardProvider from '@/components/KClipboardProvider'
import KTooltip from '@/components/KTooltip/KTooltip.vue'
import { KUI_ICON_SIZE_30 } from '@kong/design-tokens'
import useUniqueId from '@/composables/useUniqueId'
const props = defineProps({
/**
Expand Down Expand Up @@ -140,7 +139,7 @@ const props = defineProps({
},
})
const copyButtonElementId = useUniqueId()
const copyButtonElementId = useId()
const tooltipText = ref<string>('')
const nonSuccessText = computed((): string => {
Expand Down
5 changes: 2 additions & 3 deletions src/components/KFileUpload/KFileUpload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ defineOptions({
})
import type { PropType } from 'vue'
import { computed, ref, useAttrs, useSlots, watch } from 'vue'
import { computed, ref, useAttrs, useId, useSlots, watch } from 'vue'
import KLabel from '@/components/KLabel/KLabel.vue'
import KInput from '@/components/KInput/KInput.vue'
import KButton from '@/components/KButton/KButton.vue'
import useUtilities from '@/composables/useUtilities'
import useUniqueId from '@/composables/useUniqueId'
const props = defineProps({
labelAttributes: {
Expand Down Expand Up @@ -135,7 +134,7 @@ const emit = defineEmits<{
const { stripRequiredLabel } = useUtilities()
const fileInputId = attrs.id ? String(attrs.id) : useUniqueId()
const fileInputId = attrs.id ? String(attrs.id) : useId()
const modifiedAttrs = computed(() => {
const $attrs = { ...attrs }
Expand Down
7 changes: 3 additions & 4 deletions src/components/KInput/KInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,12 @@
</template>

<script setup lang="ts">
import { computed, ref, watch, useSlots, useAttrs, onMounted, nextTick } from 'vue'
import { computed, ref, watch, useSlots, useAttrs, onMounted, nextTick, useId } from 'vue'
import type { PropType } from 'vue'
import type { LabelAttributes, LimitExceededData } from '@/types'
import useUtilities from '@/composables/useUtilities'
import KLabel from '@/components/KLabel/KLabel.vue'
import { KUI_ICON_SIZE_40 } from '@kong/design-tokens'
import useUniqueId from '@/composables/useUniqueId'
import { VisibilityIcon, VisibilityOffIcon } from '@kong/icons'
const props = defineProps({
Expand Down Expand Up @@ -176,8 +175,8 @@ const slots = useSlots()
const attrs = useAttrs()
const isRequired = computed((): boolean => attrs?.required !== undefined && String(attrs?.required) !== 'false')
const inputId = attrs.id ? String(attrs.id) : useUniqueId()
const helpTextId = useUniqueId()
const inputId = attrs.id ? String(attrs.id) : useId()
const helpTextId = useId()
const strippedLabel = computed((): string => stripRequiredLabel(props.label, isRequired.value))
const hasLabelTooltip = computed((): boolean => !!(props.labelAttributes?.info || slots['label-tooltip']))
Expand Down
5 changes: 2 additions & 3 deletions src/components/KInputSwitch/KInputSwitch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@

<script lang="ts" setup>
import type { PropType } from 'vue'
import { computed, ref, useAttrs } from 'vue'
import useUniqueId from '@/composables/useUniqueId'
import { computed, ref, useAttrs, useId } from 'vue'
const props = defineProps({
/**
Expand Down Expand Up @@ -100,7 +99,7 @@ const attrs = useAttrs()
const switchInputElement = ref<HTMLInputElement | null>(null)
const inputId = attrs.id ? String(attrs.id) : useUniqueId()
const inputId = attrs.id ? String(attrs.id) : useId()
/**
* Strips falsy `disabled` attribute, so it does not fall onto native <a> elements.
Expand Down
5 changes: 2 additions & 3 deletions src/components/KLabel/KLabel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@

<script setup lang="ts">
import type { PropType } from 'vue'
import { computed, useSlots } from 'vue'
import { computed, useId, useSlots } from 'vue'
import KTooltip from '@/components/KTooltip/KTooltip.vue'
import type { TooltipAttributes } from '@/types'
import { InfoIcon } from '@kong/icons'
import { KUI_COLOR_TEXT_NEUTRAL } from '@kong/design-tokens'
import useUniqueId from '@/composables/useUniqueId'
const props = defineProps({
info: {
Expand Down Expand Up @@ -66,7 +65,7 @@ const slots = useSlots()
const hasTooltip = computed((): boolean => !!(props.help || props.info || slots.tooltip))
const tooltipId = useUniqueId()
const tooltipId = useId()
</script>

<style lang="scss" scoped>
Expand Down
9 changes: 4 additions & 5 deletions src/components/KMultiselect/KMultiselect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@

<script lang="ts">
import type { Ref, PropType } from 'vue'
import { ref, computed, watch, nextTick, onMounted, onUnmounted, useAttrs, useSlots } from 'vue'
import { ref, computed, watch, nextTick, onMounted, onUnmounted, useAttrs, useSlots, useId } from 'vue'
import useUtilities from '@/composables/useUtilities'
import KBadge from '@/components/KBadge/KBadge.vue'
import KInput from '@/components/KInput/KInput.vue'
Expand All @@ -300,7 +300,6 @@ import { KUI_ICON_SIZE_40 } from '@kong/design-tokens'
import { ResizeObserverHelper } from '@/utilities/resizeObserverHelper'
import { sanitizeInput } from '@/utilities/sanitizeInput'
import { useEventListener } from '@vueuse/core'
import useUniqueId from '@/composables/useUniqueId'
// functions used in prop validators
const getValues = (items: MultiselectItem[]) => {
Expand Down Expand Up @@ -495,8 +494,8 @@ const defaultKPopAttributes = {
const key = ref(0)
const stagingKey = ref(0)
const multiselectWrapperId = attrs.id ? String(attrs.id) : useUniqueId() // unique id for the KLabel `for` attribute
const multiselectKey = useUniqueId()
const multiselectWrapperId = attrs.id ? String(attrs.id) : useId() // unique id for the KLabel `for` attribute
const multiselectKey = useId()
const multiselectElement = ref<HTMLDivElement | null>(null)
const multiselectInputElement = ref<InstanceType<typeof KInput> | null>(null)
Expand Down Expand Up @@ -835,7 +834,7 @@ const handleAddItem = (): void => {
const pos = unfilteredItems.value.length + 1
const item: MultiselectItem = {
label: sanitizeInput(filterString.value + ''),
value: useUniqueId(),
value: useId(),
key: `${sanitizeInput(filterString.value).replace(/ /gi, '-')?.replace(/[^a-z0-9-_]/gi, '')}-${pos}`,
}
emit('item-added', item)
Expand Down
7 changes: 3 additions & 4 deletions src/components/KPop/KPop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
</template>

<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount, computed, watch } from 'vue'
import { ref, onMounted, onBeforeUnmount, computed, watch, useId } from 'vue'
import type { PropType } from 'vue'
import { useFloating, autoUpdate, autoPlacement, flip, shift } from '@floating-ui/vue'
import type { PopPlacements, PopTrigger } from '@/types'
Expand All @@ -92,7 +92,6 @@ import KButton from '@/components/KButton/KButton.vue'
import useUtilities from '@/composables/useUtilities'
import { CloseIcon } from '@kong/icons'
import { KUI_ICON_SIZE_30 } from '@kong/design-tokens'
import useUniqueId from '@/composables/useUniqueId'
const props = defineProps({
buttonText: {
Expand Down Expand Up @@ -163,8 +162,8 @@ const emit = defineEmits(['open', 'close', 'popover-click'])
const { getSizeFromString } = useUtilities()
const popoverId = useUniqueId()
const titleId = useUniqueId()
const popoverId = useId()
const titleId = useId()
const kPopoverElement = ref<HTMLElement | null>(null)
const triggerWrapperElement = ref<HTMLElement | null>(null)
const popoverElement = ref<HTMLElement | null>(null)
Expand Down
5 changes: 2 additions & 3 deletions src/components/KRadio/KRadio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@

<script lang="ts">
import type { PropType } from 'vue'
import { computed, useAttrs, useSlots } from 'vue'
import { computed, useAttrs, useId, useSlots } from 'vue'
import type { RadioTypes, LabelAttributes } from '@/types'
import { RadioTypesArray } from '@/types'
import KLabel from '@/components/KLabel/KLabel.vue'
import useUniqueId from '@/composables/useUniqueId'
export default {
inheritAttrs: false,
Expand Down Expand Up @@ -177,7 +176,7 @@ const props = defineProps({
const slots = useSlots()
const attrs = useAttrs()
const inputId = attrs.id ? String(attrs.id) : useUniqueId()
const inputId = attrs.id ? String(attrs.id) : useId()
const isDisabled = computed((): boolean => attrs?.disabled !== undefined && String(attrs?.disabled) !== 'false')
const hasLabel = computed((): boolean => !!(props.label || slots.default))
// for regular radio we only show description if there is a label or default slot
Expand Down
9 changes: 4 additions & 5 deletions src/components/KSelect/KSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@

<script setup lang="ts">
import type { Ref, PropType } from 'vue'
import { ref, computed, watch, nextTick, useAttrs, useSlots, onUnmounted, onMounted } from 'vue'
import { ref, computed, watch, nextTick, useAttrs, useSlots, onUnmounted, onMounted, useId } from 'vue'
import useUtilities from '@/composables/useUtilities'
import KLabel from '@/components/KLabel/KLabel.vue'
import KInput from '@/components/KInput/KInput.vue'
Expand All @@ -220,7 +220,6 @@ import type {
import { ChevronDownIcon, CloseIcon, ProgressIcon } from '@kong/icons'
import { ResizeObserverHelper } from '@/utilities/resizeObserverHelper'
import { sanitizeInput } from '@/utilities/sanitizeInput'
import useUniqueId from '@/composables/useUniqueId'
import { useEventListener } from '@vueuse/core'
defineOptions({
Expand Down Expand Up @@ -364,7 +363,7 @@ const emit = defineEmits<{
const attrs = useAttrs()
const slots = useSlots()
const selectInputId = attrs.id ? String(attrs.id) : useUniqueId()
const selectInputId = attrs.id ? String(attrs.id) : useId()
const isDropdownOpen = ref<boolean>(false)
Expand Down Expand Up @@ -405,7 +404,7 @@ const uniqueFilterQuery = computed((): boolean => {
return true
})
const selectWrapperId = useUniqueId() // unique id for the KPop target
const selectWrapperId = useId() // unique id for the KPop target
const selectedItem = ref<SelectItem | null>(null)
const selectItems = ref<SelectItem[]>([])
const inputFocused = ref<boolean>(false)
Expand Down Expand Up @@ -506,7 +505,7 @@ const handleAddItem = (): void => {
const pos = (selectItems.value?.length || 0) + 1
const item: SelectItem = {
label: sanitizeInput(filterQuery.value),
value: useUniqueId(),
value: useId(),
key: `${sanitizeInput(filterQuery.value).replace(/ /gi, '-')?.replace(/[^a-z0-9-_]/gi, '')}-${pos}`,
custom: true,
}
Expand Down
5 changes: 2 additions & 3 deletions src/components/KTable/KTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@

<script setup lang="ts">
import type { Ref, PropType } from 'vue'
import { ref, watch, computed, onMounted, useAttrs, useSlots } from 'vue'
import { ref, watch, computed, onMounted, useAttrs, useSlots, useId } from 'vue'
import KButton from '@/components/KButton/KButton.vue'
import KEmptyState from '@/components/KEmptyState/KEmptyState.vue'
import KSkeleton from '@/components/KSkeleton/KSkeleton.vue'
Expand All @@ -276,7 +276,6 @@ import type {
import { EmptyStateIconVariants } from '@/types'
import { KUI_COLOR_TEXT_NEUTRAL, KUI_ICON_SIZE_30 } from '@kong/design-tokens'
import ColumnVisibilityMenu from './../KTableView/ColumnVisibilityMenu.vue'
import useUniqueId from '@/composables/useUniqueId'
const { useDebounce, useRequest, useSwrvState, clientSideSorter: defaultClientSideSorter, getSizeFromString } = useUtilities()
Expand Down Expand Up @@ -512,7 +511,7 @@ const emit = defineEmits<{
const attrs = useAttrs()
const slots = useSlots()
const tableId = useUniqueId()
const tableId = useId()
const defaultFetcherProps = {
pageSize: 15,
page: 1,
Expand Down
5 changes: 2 additions & 3 deletions src/components/KTableData/KTableData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@

<script setup lang="ts">
import type { Ref } from 'vue'
import { ref, watch, computed, onMounted, useSlots } from 'vue'
import { ref, watch, computed, onMounted, useSlots, useId } from 'vue'
import KTableView from '@/components/KTableView/KTableView.vue'
import useUtilities from '@/composables/useUtilities'
import type {
Expand All @@ -178,7 +178,6 @@ import type {
RowExpandPayload,
} from '@/types'
import { EmptyStateIconVariants } from '@/types'
import useUniqueId from '@/composables/useUniqueId'
import { getInitialPageSize, DEFAULT_PAGE_SIZE } from '@/utilities'
const props = withDefaults(defineProps<TableDataProps>(), {
Expand Down Expand Up @@ -236,7 +235,7 @@ const emit = defineEmits<{
(e: 'update:row-expanded', data: RowExpandPayload): void
}>()
const tableId = useUniqueId()
const tableId = useId()
const tableData = ref<Record<string, any>[]>([])
const tableHeaders = computed((): TableDataHeader[] => props.sortable ? props.headers : props.headers.map((header) => ({ ...header, sortable: false })))
Expand Down
5 changes: 2 additions & 3 deletions src/components/KTextArea/KTextArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@
</template>

<script lang="ts">
import { ref, computed, watch, useAttrs, useSlots } from 'vue'
import { ref, computed, watch, useAttrs, useSlots, useId } from 'vue'
import useUtilities from '@/composables/useUtilities'
import KLabel from '@/components/KLabel/KLabel.vue'
import type { TextAreaLimitExceed } from '@/types'
import useUniqueId from '@/composables/useUniqueId'
const DEFAULT_CHARACTER_LIMIT = 2048
Expand Down Expand Up @@ -161,7 +160,7 @@ const value = computed({
},
})
const textAreaId = attrs.id ? String(attrs.id) : useUniqueId()
const textAreaId = attrs.id ? String(attrs.id) : useId()
const modifiedAttrs = computed((): Record<string, any> => {
const $attrs = { ...attrs }
Expand Down
Loading

0 comments on commit 05ba34a

Please sign in to comment.