Skip to content

Commit

Permalink
Merge branch 'master' into pass-session-strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
timleslie authored Feb 15, 2021
2 parents 76d15eb + fdb9d9a commit 8650619
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-cows-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/fields-document': patch
---

Fixed `fields.select` not passing options to the select
5 changes: 5 additions & 0 deletions .changeset/cyan-carrots-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/fields-document': major
---

Changed `NotEditable` component from rendering a div to a span so it can be used for inline elements
5 changes: 5 additions & 0 deletions .changeset/gorgeous-pugs-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/fields-document': minor
---

Added `fields.multiselect` prop field
5 changes: 5 additions & 0 deletions .changeset/grumpy-paws-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': patch
---

Updated `withItemData` to still return the rest of the `session` object if no item was found.
5 changes: 5 additions & 0 deletions .changeset/little-cobras-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/fields-document': patch
---

Fixed documentation in JSDocs for component blocks API
6 changes: 6 additions & 0 deletions .changeset/unlucky-dragons-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@keystone-next/keystone': major
'@keystone-next/types': major
---

Removed `context.graphql.createContext` from `KeystoneContext`.
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/** @jsx jsx */
import { jsx } from '@keystone-ui/core';
import { FieldContainer, FieldLabel, Select, TextInput, Checkbox } from '@keystone-ui/fields';
import {
FieldContainer,
FieldLabel,
Select,
TextInput,
Checkbox,
MultiSelect,
} from '@keystone-ui/fields';
import { HTMLAttributes, ReactElement, ReactNode, useState } from 'react';
import { isValidURL } from '../isValidURL';

Expand All @@ -16,6 +23,10 @@ export type FormField<Value, Options> = {
*/
forceValidation: boolean;
}): ReactElement | null;
/**
* The options are config about the field that are available on the
* preview props when rendering the toolbar and preview component
*/
options: Options;
defaultValue: Value;
/**
Expand Down Expand Up @@ -204,6 +215,7 @@ export const fields = {
onChange(option.value);
}
}}
options={options}
/>
</FieldContainer>
);
Expand All @@ -215,6 +227,43 @@ export const fields = {
},
};
},
multiselect<Option extends { label: string; value: string }>({
label,
options,
defaultValue,
}: {
label: string;
options: readonly Option[];
defaultValue: readonly Option['value'][];
}): FormField<readonly Option['value'][], readonly Option[]> {
const valuesToOption = new Map(options.map(x => [x.value, x]));
return {
kind: 'form',
Input({ value, onChange, autoFocus }) {
return (
<FieldContainer>
<FieldLabel>{label}</FieldLabel>
<MultiSelect
autoFocus={autoFocus}
value={value.map(x => valuesToOption.get(x)!)}
options={options}
onChange={options => {
onChange(options.map(x => x.value));
}}
/>
</FieldContainer>
);
},
options,
defaultValue,
validate(value) {
return (
Array.isArray(value) &&
value.every(value => typeof value === 'string' && valuesToOption.has(value))
);
},
};
},
checkbox({
label,
defaultValue = false,
Expand Down Expand Up @@ -470,14 +519,16 @@ export function component<
}
>(
options: {
/** The preview component shown in the editor */
component: (
props: {
[Key in keyof PropsOption]: ExtractPropFromComponentPropFieldForPreview<PropsOption[Key]>;
}
) => ReactElement | null;
/** The props that the preview component, toolbar and rendered component will receive */
props: PropsOption;
/** The label to show in the insert menu and chrome around the block if chromeless is false */
label: string;
// icon?: ReactElement;
} & (
| {
chromeless: true;
Expand Down Expand Up @@ -508,9 +559,9 @@ export function component<
}

export const NotEditable = ({ children, ...props }: HTMLAttributes<HTMLDivElement>) => (
<div css={{ userSelect: 'none' }} contentEditable={false} {...props}>
<span css={{ userSelect: 'none' }} contentEditable={false} {...props}>
{children}
</div>
</span>
);

type Comp<Props> = (props: Props) => ReactElement | null;
Expand Down
7 changes: 1 addition & 6 deletions packages-next/keystone/src/lib/createContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ export function makeCreateContext({
knex: keystone.adapter.knex,
mongoose: keystone.adapter.mongoose,
prisma: keystone.adapter.prisma,
graphql: {
createContext,
raw: rawGraphQL,
run: runGraphQL,
schema: graphQLSchema,
} as KeystoneGraphQLAPI<any>,
graphql: { raw: rawGraphQL, run: runGraphQL, schema: graphQLSchema },
maxTotalResults: keystone.queryLimits.maxTotalResults,
sudo: () => createContext({ sessionContext, skipAccessControl: true, req }),
exitSudo: () => createContext({ sessionContext, skipAccessControl: false, req }),
Expand Down
8 changes: 4 additions & 4 deletions packages-next/keystone/src/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function withItemData<T extends { listKey: string; itemId: string }>(
!session.itemId ||
!sudoContext.lists[session.listKey]
) {
return;
return session;
}

// NOTE: This is wrapped in a try-catch block because a "not found" result will currently
Expand All @@ -94,15 +94,15 @@ export function withItemData<T extends { listKey: string; itemId: string }>(
where: { id: session.itemId },
resolveFields: fieldSelections[session.listKey] || 'id',
});
// If there is no matching item found, return no session
// If there is no matching item found, return the session without a `data value
if (!item) {
return;
return session;
}
return { ...session, data: item };
} catch (e) {
// TODO: This swallows all errors, we need a way to differentiate between "not found" and
// actual exceptions that should be thrown
return;
return session;
}
},
};
Expand Down
1 change: 0 additions & 1 deletion packages-next/types/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export type KeystoneGraphQLAPI<
// eslint-disable-next-line @typescript-eslint/no-unused-vars
KeystoneListsTypeInfo extends Record<string, BaseGeneratedListTypes>
> = {
createContext: CreateContext;
schema: GraphQLSchema;

run: (args: GraphQLExecutionArguments) => Promise<Record<string, any>>;
Expand Down

0 comments on commit 8650619

Please sign in to comment.