Skip to content

Commit

Permalink
fixed custom views setter issue (#5586)
Browse files Browse the repository at this point in the history
* fixed custom views setter issue

* Add (commented out) custom field views example

Co-authored-by: Jed Watson <jed.watson@me.com>
  • Loading branch information
gautamsi and JedWatson committed May 3, 2021
1 parent 606bb90 commit dbc62ff
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-laws-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/admin-ui': patch
---

Fixed a bug where custom Field views were not able to be used in the Admin UI (object does not have setter error)
29 changes: 29 additions & 0 deletions examples/basic/admin/fieldViews/Test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* @jsx jsx */

import { FieldProps } from '@keystone-next/types';
import { jsx } from '@keystone-ui/core';
import { FieldContainer, FieldLabel, TextArea, TextInput } from '@keystone-ui/fields';
import { controller } from '@keystone-next/fields/types/text/views';

export const Field = ({ field, value, onChange, autoFocus }: FieldProps<typeof controller>) => (
<FieldContainer>
<FieldLabel>{field.label} with custom view</FieldLabel>
{onChange ? (
field.displayMode === 'textarea' ? (
<TextArea
autoFocus={autoFocus}
onChange={event => onChange(event.target.value)}
value={value}
/>
) : (
<TextInput
autoFocus={autoFocus}
onChange={event => onChange(event.target.value)}
value={value}
/>
)
) : (
value
)}
</FieldContainer>
);
3 changes: 3 additions & 0 deletions examples/basic/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ export const lists = createSchema({
Post: list({
fields: {
title: text(),
// TODO: expand this out into a proper example project
// Enable this line to test custom field views
// test: text({ ui: { views: require.resolve('./admin/fieldViews/Test.tsx') } }),
status: select({
options: [
{ label: 'Published', value: 'published' },
Expand Down
2 changes: 1 addition & 1 deletion packages-next/admin-ui/src/utils/useAdminMeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function useAdminMeta(adminMetaHash: string, fieldViews: FieldViews) {
);
}
});
const views = fieldViews[field.viewsIndex];
const views = { ...fieldViews[field.viewsIndex] };
const customViews: Record<string, any> = {};
if (field.customViewsIndex !== null) {
const customViewsSource: FieldViews[number] & Record<string, any> =
Expand Down

1 comment on commit dbc62ff

@vercel
Copy link

@vercel vercel bot commented on dbc62ff May 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.