Skip to content

Commit

Permalink
refactor(sanity): rename BundleIconEditorPicker to ReleaseIconEditorP…
Browse files Browse the repository at this point in the history
…icker
  • Loading branch information
RitaDias committed Sep 5, 2024
1 parent 99defea commit a292196
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function ReleaseBadge(
{icon && (
<Box flex="none">
<Text size={1}>
<Icon data-testid={`bundle-badge-icon-${icon.toString()}`} symbol={icon} />
<Icon data-testid={`release-badge-icon-${icon.toString()}`} symbol={icon} />
</Text>
</Box>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {type CalendarLabels} from '../../../../ui-components/inputs/DateInputs/c
import {DateTimeInput} from '../../../../ui-components/inputs/DateInputs/DateTimeInput'
import {getCalendarLabels} from '../../../form/inputs/DateInputs/utils'
import {type BundleDocument} from '../../../store/bundles/types'
import {BundleIconEditorPicker, type BundleIconEditorPickerValue} from './BundleIconEditorPicker'
import {ReleaseIconEditorPicker, type ReleaseIconEditorPickerValue} from './ReleaseIconEditorPicker'

interface BaseBundleDocument extends Partial<BundleDocument> {
hue: ColorHueKey
Expand Down Expand Up @@ -50,7 +50,7 @@ export function ReleaseForm(props: {
publishedAt ? dateFormatter.format(new Date(publishedAt)) : undefined,
)

const iconValue: BundleIconEditorPickerValue = useMemo(
const iconValue: ReleaseIconEditorPickerValue = useMemo(
() => ({
icon: icon ?? DEFAULT_BUNDLE.icon,
hue: hue ?? DEFAULT_BUNDLE.hue,
Expand Down Expand Up @@ -89,7 +89,7 @@ export function ReleaseForm(props: {
)

const handleIconValueChange = useCallback(
(pickedIcon: BundleIconEditorPickerValue) => {
(pickedIcon: ReleaseIconEditorPickerValue) => {
onChange({...value, icon: pickedIcon.icon, hue: pickedIcon.hue})
},
[onChange, value],
Expand All @@ -98,7 +98,7 @@ export function ReleaseForm(props: {
return (
<Stack space={5}>
<Flex>
<BundleIconEditorPicker onChange={handleIconValueChange} value={iconValue} />
<ReleaseIconEditorPicker onChange={handleIconValueChange} value={iconValue} />
</Flex>
<Stack space={3}>
<FormFieldHeaderText title={t('bundle.form.title')} validation={titleErrors} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const IconPickerFlex = styled(Flex)`
max-width: 269px;
`

export interface BundleIconEditorPickerValue {
export interface ReleaseIconEditorPickerValue {
hue: BundleDocument['hue']
icon: BundleDocument['icon']
}

export function BundleIconEditorPicker(props: {
onChange: (value: BundleIconEditorPickerValue) => void
value: BundleIconEditorPickerValue
export function ReleaseIconEditorPicker(props: {
onChange: (value: ReleaseIconEditorPickerValue) => void
value: ReleaseIconEditorPickerValue
}): JSX.Element {
const {onChange, value} = props

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import {beforeEach, describe, expect, it, jest} from '@jest/globals'
import {fireEvent, render, screen} from '@testing-library/react'

import {createTestProvider} from '../../../../../../test/testUtils/TestProvider'
import {BundleIconEditorPicker, type BundleIconEditorPickerValue} from '../BundleIconEditorPicker'
import {
ReleaseIconEditorPicker,
type ReleaseIconEditorPickerValue,
} from '../ReleaseIconEditorPicker'

jest.mock('sanity', () => ({
useTranslation: jest.fn().mockReturnValue({t: jest.fn()}),
}))

describe('BundleIconEditorPicker', () => {
const onChangeMock = jest.fn()
const valueMock: BundleIconEditorPickerValue = {
const valueMock: ReleaseIconEditorPickerValue = {
hue: 'gray',
icon: 'cube',
}
Expand All @@ -19,7 +22,7 @@ describe('BundleIconEditorPicker', () => {
onChangeMock.mockClear()

const wrapper = await createTestProvider()
render(<BundleIconEditorPicker onChange={onChangeMock} value={valueMock} />, {wrapper})
render(<ReleaseIconEditorPicker onChange={onChangeMock} value={valueMock} />, {wrapper})
})

it('should render the icon picker button', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/sanity/src/core/releases/tool/detail/ReleaseSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {AvatarStack, Box, Flex, Heading, Stack, Text, useToast} from '@sanity/ui
import {type RefObject, useCallback, useEffect, useMemo, useState} from 'react'

import {
BundleIconEditorPicker,
type BundleIconEditorPickerValue,
} from '../../../bundles/components/dialog/BundleIconEditorPicker'
ReleaseIconEditorPicker,
type ReleaseIconEditorPickerValue,
} from '../../../bundles/components/dialog/ReleaseIconEditorPicker'
import {RelativeTime} from '../../../components/RelativeTime'
import {UserAvatar} from '../../../components/userAvatar/UserAvatar'
import {Translate, useTranslation} from '../../../i18n'
Expand Down Expand Up @@ -47,7 +47,7 @@ export function ReleaseSummary(props: ReleaseSummaryProps) {
const {t} = useTranslation(releasesLocaleNamespace)
const {updateBundle} = useBundleOperations()

const [iconValue, setIconValue] = useState<BundleIconEditorPickerValue>(setIconHue({hue, icon}))
const [iconValue, setIconValue] = useState<ReleaseIconEditorPickerValue>(setIconHue({hue, icon}))
const toast = useToast()
const handleIconValueChange = useCallback(
async (value: {hue: BundleDocument['hue']; icon: BundleDocument['icon']}) => {
Expand Down Expand Up @@ -105,7 +105,7 @@ export function ReleaseSummary(props: ReleaseSummaryProps) {
<>
<Stack space={4} data-testid="summary" paddingTop={6} paddingBottom={5}>
<Flex>
<BundleIconEditorPicker onChange={handleIconValueChange} value={iconValue} />
<ReleaseIconEditorPicker onChange={handleIconValueChange} value={iconValue} />
</Flex>

<Heading size={2} style={{margin: '1px 0'}} as="h1">
Expand Down

0 comments on commit a292196

Please sign in to comment.