diff --git a/packages/sanity/src/core/bundles/components/BundleMenu.tsx b/packages/sanity/src/core/bundles/components/BundleMenu.tsx index 5037e2cfe31..77fdb72937c 100644 --- a/packages/sanity/src/core/bundles/components/BundleMenu.tsx +++ b/packages/sanity/src/core/bundles/components/BundleMenu.tsx @@ -30,14 +30,14 @@ interface BundleListProps { */ export function BundleMenu(props: BundleListProps): JSX.Element { const {bundles, loading, actions, button} = props - const hasBundles = bundles && bundles.filter((b) => !isDraftOrPublished(b.name)).length > 0 + const hasBundles = bundles && bundles.filter((b) => !isDraftOrPublished(b.slug)).length > 0 const {currentGlobalBundle, setPerspective} = usePerspective() const handleBundleChange = useCallback( (bundle: Partial) => () => { - if (bundle.name) { - setPerspective(bundle.name) + if (bundle.slug) { + setPerspective(bundle.slug) } }, [setPerspective], @@ -58,7 +58,7 @@ export function BundleMenu(props: BundleListProps): JSX.Element { <> ) : undefined } @@ -72,14 +72,14 @@ export function BundleMenu(props: BundleListProps): JSX.Element { {bundles - .filter((b) => !isDraftOrPublished(b.name) && !b.archivedAt) + .filter((b) => !isDraftOrPublished(b.slug) && !b.archivedAt) .map((b) => ( @@ -103,8 +103,8 @@ export function BundleMenu(props: BundleListProps): JSX.Element { diff --git a/packages/sanity/src/core/bundles/components/__tests__/BundleMenu.test.tsx b/packages/sanity/src/core/bundles/components/__tests__/BundleMenu.test.tsx index 4ea68ce7ccc..4e94a4eb6cb 100644 --- a/packages/sanity/src/core/bundles/components/__tests__/BundleMenu.test.tsx +++ b/packages/sanity/src/core/bundles/components/__tests__/BundleMenu.test.tsx @@ -29,7 +29,7 @@ describe('BundleMenu', () => { hue: 'magenta', _id: 'db76c50e-358b-445c-a57c-8344c588a5d5', _type: 'bundle', - name: 'spring-drop', + slug: 'spring-drop', _rev: '6z08CvvPnPe5pWSKJ5zPRR', icon: 'heart-filled', description: 'What a spring drop, allergies galore 🌸', @@ -47,7 +47,7 @@ describe('BundleMenu', () => { _createdAt: '2024-07-02T11:37:06Z', _rev: '6z08CvvPnPe5pWSKJ5zJiK', _updatedAt: '2024-07-02T11:37:06Z', - name: 'autumn-drop', + slug: 'autumn-drop', authorId: '', }, { @@ -60,7 +60,7 @@ describe('BundleMenu', () => { _type: 'bundle', hue: 'red', _id: 'f6b2c2cc-1732-4465-bfb3-dd205b5d78e9', - name: 'summer-drop', + slug: 'summer-drop', authorId: '', }, ] @@ -133,7 +133,7 @@ describe('BundleMenu', () => { act(() => { expect(screen.getByText(mockBundles[0].title)).toBeInTheDocument() - expect(screen.getByTestId(`${mockBundles[0].name}-checkmark-icon`)).toBeInTheDocument() + expect(screen.getByTestId(`${mockBundles[0].slug}-checkmark-icon`)).toBeInTheDocument() }) }) diff --git a/packages/sanity/src/core/bundles/components/dialog/BundleForm.tsx b/packages/sanity/src/core/bundles/components/dialog/BundleForm.tsx index 86ce254e078..69f443a374f 100644 --- a/packages/sanity/src/core/bundles/components/dialog/BundleForm.tsx +++ b/packages/sanity/src/core/bundles/components/dialog/BundleForm.tsx @@ -55,15 +55,11 @@ export function BundleForm(props: { const handleBundleTitleChange = useCallback( (event: React.ChangeEvent) => { const pickedTitle = event.target.value - const pickedNameExists = - data && data.find((bundle) => bundle.name === speakingurl(pickedTitle)) + const newSlug = speakingurl(pickedTitle) + const slugExists = data && data.find((bundle) => bundle.slug === newSlug) const isEmptyTitle = pickedTitle.trim() === '' && !isInitialRender - if ( - isDraftOrPublished(pickedTitle) || - pickedNameExists || - (isEmptyTitle && !isInitialRender) - ) { + if (isDraftOrPublished(pickedTitle) || slugExists || (isEmptyTitle && !isInitialRender)) { if (isEmptyTitle && !isInitialRender) { // if the title is empty and it's not the first opening of the dialog, show an error // TODO localize text @@ -77,7 +73,7 @@ export function BundleForm(props: { {level: 'error', message: "Title cannot be 'drafts' or 'published'", path: []}, ]) } - if (pickedNameExists) { + if (slugExists) { // if the bundle already exists, show an error // TODO localize text setTitleErrors([{level: 'error', message: 'Bundle already exists', path: []}]) @@ -90,7 +86,7 @@ export function BundleForm(props: { } setIsInitialRender(false) - onChange({...value, title: pickedTitle, name: speakingurl(pickedTitle)}) + onChange({...value, title: pickedTitle, slug: newSlug}) }, [data, isInitialRender, onChange, onError, value], ) diff --git a/packages/sanity/src/core/bundles/components/dialog/CreateBundleDialog.tsx b/packages/sanity/src/core/bundles/components/dialog/CreateBundleDialog.tsx index 5ee6e606a6e..71de6d3ff91 100644 --- a/packages/sanity/src/core/bundles/components/dialog/CreateBundleDialog.tsx +++ b/packages/sanity/src/core/bundles/components/dialog/CreateBundleDialog.tsx @@ -18,7 +18,7 @@ export function CreateBundleDialog(props: CreateBundleDialogProps): JSX.Element const [hasErrors, setHasErrors] = useState(false) const [value, setValue] = useState>({ - name: '', + slug: '', title: '', hue: 'gray', icon: 'cube', @@ -31,7 +31,7 @@ export function CreateBundleDialog(props: CreateBundleDialogProps): JSX.Element const handleOnSubmit = useCallback( async (event: FormEvent) => { - if (value.name) { + if (value.slug) { try { event.preventDefault() setIsCreating(true) @@ -41,7 +41,7 @@ export function CreateBundleDialog(props: CreateBundleDialogProps): JSX.Element console.error(err) } finally { setIsCreating(false) - setPerspective(value.name) + setPerspective(value.slug) onCreate() } } diff --git a/packages/sanity/src/core/bundles/components/dialog/__tests__/BundleForm.test.tsx b/packages/sanity/src/core/bundles/components/dialog/__tests__/BundleForm.test.tsx index 620325324ca..1490ddfd31b 100644 --- a/packages/sanity/src/core/bundles/components/dialog/__tests__/BundleForm.test.tsx +++ b/packages/sanity/src/core/bundles/components/dialog/__tests__/BundleForm.test.tsx @@ -43,7 +43,7 @@ describe('BundleForm', () => { icon: 'heart-filled', _id: 'db76c50e-358b-445c-a57c-8344c588a5d5', _type: 'bundle', - name: 'spring-drop', + slug: 'spring-drop', hue: 'magenta', _createdAt: '2024-07-02T11:37:51Z', }, @@ -69,7 +69,7 @@ describe('BundleForm', () => { const titleInput = screen.getByTestId('bundle-form-title') fireEvent.change(titleInput, {target: {value: 'Bundle 1'}}) - expect(onChangeMock).toHaveBeenCalledWith({...valueMock, title: 'Bundle 1', name: 'bundle-1'}) + expect(onChangeMock).toHaveBeenCalledWith({...valueMock, title: 'Bundle 1', slug: 'bundle-1'}) }) it('should call onChange when description textarea value changes', () => { diff --git a/packages/sanity/src/core/bundles/components/dialog/__tests__/CreateBundleDialog.test.tsx b/packages/sanity/src/core/bundles/components/dialog/__tests__/CreateBundleDialog.test.tsx index e58bb8b43db..5d5b8e570f0 100644 --- a/packages/sanity/src/core/bundles/components/dialog/__tests__/CreateBundleDialog.test.tsx +++ b/packages/sanity/src/core/bundles/components/dialog/__tests__/CreateBundleDialog.test.tsx @@ -60,9 +60,9 @@ describe('CreateBundleDialog', () => { expect(onCancelMock).toHaveBeenCalled() }) - it('should call createBundle, setPerspective, and onCreate when form is submitted with a valid name', async () => { + it('should call createBundle, setPerspective, and onCreate when form is submitted with a valid slug', async () => { const value: Partial = { - name: 'bundle-1', + slug: 'bundle-1', title: 'Bundle 1', hue: 'gray', icon: 'cube', @@ -77,7 +77,7 @@ describe('CreateBundleDialog', () => { await expect(useBundleOperations().createBundle).toHaveBeenCalledWith(value) - expect(usePerspective().setPerspective).toHaveBeenCalledWith(value.name) + expect(usePerspective().setPerspective).toHaveBeenCalledWith(value.slug) expect(onCreateMock).toHaveBeenCalled() }) }) diff --git a/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx b/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx index 7980c0e8777..6b435e23824 100644 --- a/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx +++ b/packages/sanity/src/core/bundles/components/panes/BundleActions.tsx @@ -25,7 +25,7 @@ interface BundleActionsProps { */ export function BundleActions(props: BundleActionsProps): JSX.Element { const {currentGlobalBundle, documentId, documentType} = props - const {name, title} = currentGlobalBundle + const {slug, title} = currentGlobalBundle const {data: bundles, loading} = useBundles() const documentStore = useDocumentStore() @@ -51,15 +51,15 @@ export function BundleActions(props: BundleActionsProps): JSX.Element { dummyFetch.current = fetchVersions() } await dummyFetch.current - setIsInVersion(versionDocumentExists(documentVersions, name)) + setIsInVersion(versionDocumentExists(documentVersions, slug)) } fetchVersionsInner() - }, [bundles, documentId, fetchVersions, documentVersions, name]) + }, [bundles, documentId, fetchVersions, documentVersions, slug]) const handleAddVersion = useCallback(async () => { // only add to version if there isn't already a version in that bundle of this doc - if (versionDocumentExists(documentVersions, name)) { + if (versionDocumentExists(documentVersions, slug)) { toast.push({ status: 'error', title: `There's already a version of this document in the bundle ${title}`, @@ -67,7 +67,7 @@ export function BundleActions(props: BundleActionsProps): JSX.Element { return } - const bundleId = `${name}.${documentId}` + const bundleId = `${slug}.${documentId}` setCreatingVersion(true) @@ -88,7 +88,7 @@ export function BundleActions(props: BundleActionsProps): JSX.Element { documentStore.pair, documentType, documentVersions, - name, + slug, newVersion, title, toast, @@ -98,7 +98,7 @@ export function BundleActions(props: BundleActionsProps): JSX.Element { return (