Skip to content

Commit 7b03cbf

Browse files
JuliRossiclaude
andcommitted
fix(drive-integration): disable Yes radio and block save when content type has no reference fields
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 8f8befe commit 7b03cbf

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

apps/drive-integration/src/locations/Page/components/review/mapping/edit-modals/AddEntryForm.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ export const isAddEntrySaveDisabled = (
4646
if (!state.contentTypeId) return true;
4747
if (state.isReference === null) return true;
4848
if (state.isReference) {
49-
if (!state.referenceEntryId) return true;
5049
const referenceFieldOptions = getReferenceFieldOptions(contentTypes, state.contentTypeId);
50+
if (referenceFieldOptions.length === 0) return true;
51+
if (!state.referenceEntryId) return true;
5152
if (referenceFieldOptions.length > 1 && !state.referenceFieldId) return true;
5253
}
5354
return state.selectedFieldIds.length === 0;
@@ -100,6 +101,7 @@ export const AddEntryForm = ({
100101
[contentTypes, state.contentTypeId]
101102
);
102103
const showReferenceFieldSelect = referenceFieldOptions.length > 1;
104+
const canBeReference = referenceFieldOptions.length > 0;
103105
const hasContentType = Boolean(state.contentTypeId);
104106

105107
const handleContentTypeChange = (contentTypeId: string) => {
@@ -156,6 +158,7 @@ export const AddEntryForm = ({
156158
name="is-reference"
157159
value="yes"
158160
isChecked={state.isReference === true}
161+
isDisabled={!canBeReference}
159162
onChange={() => handleReferenceChange(true)}>
160163
Yes
161164
</Radio>

apps/drive-integration/test/locations/Page/components/modals/AddEntryForm.spec.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ const contentTypes = [
3939
{ id: 'title', name: 'Title', type: 'Symbol' },
4040
],
4141
},
42+
{
43+
sys: { id: 'tag' },
44+
name: 'Tag',
45+
fields: [{ id: 'label', name: 'Label', type: 'Symbol' }],
46+
},
4247
];
4348

4449
const existingEntries = [
@@ -207,6 +212,15 @@ describe('AddEntryForm', () => {
207212
expect(screen.queryByText('Which field should connect to this reference?')).toBeNull();
208213
});
209214

215+
it('disables Yes radio when content type has no reference fields', async () => {
216+
renderForm(makeState({ contentTypeId: 'tag' }));
217+
218+
await waitFor(() => {
219+
expect(screen.getByLabelText('Yes')).toBeDisabled();
220+
expect(screen.getByLabelText('No')).not.toBeDisabled();
221+
});
222+
});
223+
210224
it('hides entry and reference field selects when No is selected', async () => {
211225
renderForm(
212226
makeState({
@@ -356,6 +370,20 @@ describe('AddEntryForm', () => {
356370
)
357371
).toBe(false);
358372
});
373+
374+
it('is disabled when Yes but content type has no reference fields', () => {
375+
expect(
376+
isAddEntrySaveDisabled(
377+
makeState({
378+
contentTypeId: 'tag',
379+
isReference: true,
380+
referenceEntryId: 'entry-1',
381+
selectedFieldIds: ['label'],
382+
}),
383+
contentTypes as any
384+
)
385+
).toBe(true);
386+
});
359387
});
360388

361389
describe('toAddEntryFormParams', () => {

0 commit comments

Comments
 (0)