Skip to content

Commit

Permalink
Add field descriptions (#7578)
Browse files Browse the repository at this point in the history
* Add field descriptions

Co-authored-by: Mitchell Hamilton <[email protected]>

* updates for graphql

* schema update for example document field

* Update for tests

* update tests

* Add description to Cards of relationship field

* Little things

* Changesets

Co-authored-by: Mitchell Hamilton <[email protected]>
Co-authored-by: mitchellhamilton <[email protected]>
  • Loading branch information
3 people committed Jun 10, 2022
1 parent 52e5477 commit 29db9b5
Show file tree
Hide file tree
Showing 64 changed files with 210 additions and 53 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-coins-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-ui/fields': minor
---

Added `FieldDescription` component
7 changes: 7 additions & 0 deletions .changeset/spicy-dragons-poke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@keystone-6/cloudinary': minor
'@keystone-6/core': minor
'@keystone-6/fields-document': minor
---

Added `ui.description` option to fields to show a description below the label in the Admin UI
26 changes: 26 additions & 0 deletions design-system/packages/fields/src/FieldDescription.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** @jsxRuntime classic */
/** @jsx jsx */

import { jsx, useTheme } from '@keystone-ui/core';

type FieldDescriptionProps = {
id: string;
children: string | null;
};

export const FieldDescription = (props: FieldDescriptionProps) => {
const { spacing, palette } = useTheme();
if (props.children === null) {
return null;
}
return (
<div
css={{
color: palette.neutral700,
marginBottom: spacing.small,
minWidth: 120,
}}
{...props}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const ControlLabel = ({
fontSize: size.fontSize,
lineHeight: typography.leading.tight,
marginLeft: spacing.small,
paddingTop: spacing.xsmall,
userSelect: 'none',
}}
>
Expand Down
1 change: 1 addition & 0 deletions design-system/packages/fields/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { Checkbox, CheckboxControl } from './Checkbox';
export { FieldContainer } from './FieldContainer';
export { FieldLabel } from './FieldLabel';
export { FieldLegend } from './FieldLegend';
export { FieldDescription } from './FieldDescription';
export { Radio } from './Radio';
export { Switch } from './Switch';
export { TextArea } from './TextArea';
Expand Down
1 change: 1 addition & 0 deletions examples-staging/assets-local/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples-staging/assets-s3/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples-staging/auth/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples-staging/basic/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples-staging/ecommerce/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples-staging/embedded-nextjs/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples-staging/graphql-api-endpoint/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples-staging/roles/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples/blog/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples/custom-admin-ui-logo/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples/custom-admin-ui-navigation/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples/custom-admin-ui-pages/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples/custom-field-view/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples/custom-field/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
4 changes: 3 additions & 1 deletion examples/custom-field/stars-field/views.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { FieldContainer, FieldLabel, TextInput } from '@keystone-ui/fields';
import { FieldContainer, FieldDescription, FieldLabel, TextInput } from '@keystone-ui/fields';
import { CellLink, CellContainer } from '@keystone-6/core/admin-ui/components';

import {
Expand All @@ -15,6 +15,7 @@ import { StarsInput } from './stars-input';
export const Field = ({ field, value, onChange, autoFocus }: FieldProps<typeof controller>) => (
<FieldContainer as="fieldset">
<FieldLabel as="legend">{field.label}</FieldLabel>
<FieldDescription id={`${field.path}-description`}>{field.description}</FieldDescription>
<StarsInput maxStars={field.maxStars} onChange={onChange} value={value} autoFocus={autoFocus} />
</FieldContainer>
);
Expand Down Expand Up @@ -48,6 +49,7 @@ export const controller = (
maxStars: config.fieldMeta.maxStars,
path: config.path,
label: config.label,
description: config.description,
graphqlSelection: config.path,
defaultValue: null,
deserialize: data => {
Expand Down
1 change: 1 addition & 0 deletions examples/default-values/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples/document-field/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples/extend-graphql-schema-graphql-ts/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples/extend-graphql-schema-nexus/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples/extend-graphql-schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples/json/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples/rest-api/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples/task-manager/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples/testing/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples/virtual-field/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
1 change: 1 addition & 0 deletions examples/with-auth/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ type KeystoneAdminUIListMeta {
type KeystoneAdminUIFieldMeta {
path: String!
label: String!
description: String
isOrderable: Boolean!
isFilterable: Boolean!
fieldMeta: JSON
Expand Down
3 changes: 2 additions & 1 deletion packages/cloudinary/src/views/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { jsx, Stack, useTheme } from '@keystone-ui/core';
import { useEffect, useMemo, useRef, useState } from 'react';

import { FieldContainer, FieldLabel } from '@keystone-ui/fields';
import { FieldContainer, FieldDescription, FieldLabel } from '@keystone-ui/fields';
import { Pill } from '@keystone-ui/pill';
import { Button } from '@keystone-ui/button';
import { FieldProps } from '@keystone-6/core/types';
Expand Down Expand Up @@ -48,6 +48,7 @@ export function Field({
return (
<FieldContainer>
<FieldLabel>{field.label}</FieldLabel>
<FieldDescription id={`${field.path}-description`}>{field.description}</FieldDescription>
{value.kind === 'from-server' || value.kind === 'upload' ? (
<Stack gap="small">
{imagePath && errorMessage === undefined && <Image src={imagePath} alt={field.path} />}
Expand Down
1 change: 1 addition & 0 deletions packages/cloudinary/src/views/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const controller = (config: FieldControllerConfig): CloudinaryImageContro
return {
path: config.path,
label: config.label,
description: config.description,
graphqlSelection: `${config.path} {
id
filename
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const controller = (
return {
path: config.path,
label: config.label,
description: config.description,
graphqlSelection: config.path,
idFieldKind: config.fieldMeta.kind,
defaultValue: undefined,
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/admin-ui/admin-meta-graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const staticAdminMetaQuery = gql`
__typename
path
label
description
fieldMeta
viewsIndex
customViewsIndex
Expand Down Expand Up @@ -91,6 +92,7 @@ export type StaticAdminMetaQuery = {
__typename: 'KeystoneAdminUIFieldMeta';
path: string;
label: string;
description: Maybe<string>;
fieldMeta: Maybe<JSONValue>;
viewsIndex: number;
customViewsIndex: Maybe<number>;
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/admin-ui/system/createAdminMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export function createAdminMeta(
}
adminMetaRoot.listsByKey[key].fields.push({
label: field.label ?? humanize(fieldKey),
description: field.ui?.description ?? null,
viewsIndex: getViewId(field.views),
customViewsIndex: field.ui?.views === undefined ? null : getViewId(field.ui.views),
fieldMeta: null,
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/admin-ui/system/getAdminMetaSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function getAdminMetaSchema({
fields: {
path: graphql.field({ type: graphql.nonNull(graphql.String) }),
label: graphql.field({ type: graphql.nonNull(graphql.String) }),
description: graphql.field({ type: graphql.String }),
isOrderable: graphql.field({
type: graphql.nonNull(graphql.Boolean),
resolve(rootVal, args, context) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/admin-ui/utils/useAdminMeta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export function useAdminMeta(adminMetaHash: string, fieldViews: FieldViews) {
listKey: list.key,
fieldMeta: field.fieldMeta,
label: field.label,
description: field.description,
path: field.path,
customViews,
}),
Expand Down
Loading

0 comments on commit 29db9b5

Please sign in to comment.