Skip to content

Commit

Permalink
Singletons as lists
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Aug 30, 2022
1 parent ed736e3 commit b483800
Show file tree
Hide file tree
Showing 55 changed files with 272 additions and 78 deletions.
1 change: 1 addition & 0 deletions examples/assets-local/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
Expand Down
1 change: 1 addition & 0 deletions examples/assets-s3/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
Expand Down
1 change: 1 addition & 0 deletions examples/auth/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
Expand Down
1 change: 1 addition & 0 deletions examples/basic/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
Expand Down
53 changes: 53 additions & 0 deletions examples/blog/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,41 @@ input PostRelateToManyForCreateInput {
connect: [PostWhereUniqueInput!]
}

type Settings {
id: ID!
siteName: String
}

input SettingsWhereUniqueInput {
id: ID
}

input SettingsWhereInput {
AND: [SettingsWhereInput!]
OR: [SettingsWhereInput!]
NOT: [SettingsWhereInput!]
id: IDFilter
siteName: StringFilter
}

input SettingsOrderByInput {
id: OrderDirection
siteName: OrderDirection
}

input SettingsUpdateInput {
siteName: String
}

input SettingsUpdateArgs {
where: SettingsWhereUniqueInput! = { id: 1 }
data: SettingsUpdateInput!
}

input SettingsCreateInput {
siteName: String
}

"""
The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
"""
Expand All @@ -226,6 +261,15 @@ type Mutation {
updateAuthors(data: [AuthorUpdateArgs!]!): [Author]
deleteAuthor(where: AuthorWhereUniqueInput!): Author
deleteAuthors(where: [AuthorWhereUniqueInput!]!): [Author]
createSettings(data: SettingsCreateInput!): Settings
createManySettings(data: [SettingsCreateInput!]!): [Settings]
updateSettings(
where: SettingsWhereUniqueInput! = { id: 1 }
data: SettingsUpdateInput!
): Settings
updateManySettings(data: [SettingsUpdateArgs!]!): [Settings]
deleteSettings(where: SettingsWhereUniqueInput! = { id: 1 }): Settings
deleteManySettings(where: [SettingsWhereUniqueInput!]!): [Settings]
}

type Query {
Expand All @@ -245,6 +289,14 @@ type Query {
): [Author!]
author(where: AuthorWhereUniqueInput!): Author
authorsCount(where: AuthorWhereInput! = {}): Int
manySettings(
where: SettingsWhereInput! = { id: { equals: 1 } }
orderBy: [SettingsOrderByInput!]! = []
take: Int
skip: Int! = 0
): [Settings!]
settings(where: SettingsWhereUniqueInput! = { id: 1 }): Settings
manySettingsCount(where: SettingsWhereInput! = { id: { equals: 1 } }): Int
keystone: KeystoneMeta!
}

Expand Down Expand Up @@ -274,6 +326,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
Expand Down
5 changes: 5 additions & 0 deletions examples/blog/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ model Author {
name String @default("")
email String @unique @default("")
posts Post[] @relation("Post_author")
}

model Settings {
id Int @id @default(autoincrement())
siteName String @default("")
}
16 changes: 16 additions & 0 deletions examples/blog/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,20 @@ export const lists = {
posts: relationship({ ref: 'Post.author', many: true }),
},
}),
Settings: list({
db: {
idField: {
kind: 'autoincrement',
},
},
isSingleton: true,
fields: {
siteName: text(),
},
}),
// Settings2: singleton({
// fields: {
// siteName: text(),
// },
// }),
};
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 @@ -274,6 +274,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
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 @@ -274,6 +274,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
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 @@ -274,6 +274,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
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 @@ -277,6 +277,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
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 @@ -154,6 +154,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
Expand Down
1 change: 1 addition & 0 deletions examples/custom-session-validation/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
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 @@ -274,6 +274,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
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 @@ -289,6 +289,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
Expand Down
1 change: 1 addition & 0 deletions examples/ecommerce/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
Expand Down
1 change: 1 addition & 0 deletions examples/embedded-nextjs/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
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 @@ -283,6 +283,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
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 @@ -276,6 +276,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
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 @@ -298,6 +298,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
Expand Down
1 change: 1 addition & 0 deletions examples/extend-graphql-subscriptions/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
Expand Down
1 change: 1 addition & 0 deletions examples/graphql-api-endpoint/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
Expand Down
1 change: 1 addition & 0 deletions examples/json/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
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 @@ -275,6 +275,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
Expand Down
1 change: 1 addition & 0 deletions examples/roles/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
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 @@ -275,6 +275,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
Expand Down
1 change: 1 addition & 0 deletions examples/testing/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
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 @@ -285,6 +285,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
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 @@ -317,6 +317,7 @@ type KeystoneAdminUIListMeta {
fields: [KeystoneAdminUIFieldMeta!]!
initialSort: KeystoneAdminUISort
isHidden: Boolean!
isSingleton: Boolean
}

type KeystoneAdminUIFieldMeta {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ type ListCardProps = {
const ListCard = ({ listKey, count, hideCreate }: ListCardProps) => {
const { colors, palette, radii, spacing } = useTheme();
const list = useList(listKey);
const countNum = count.type === 'success' ? count.count : 0;

// on delete of singleton, go to homepage
return (
<div css={{ position: 'relative' }}>
<Link
href={`/${list.path}`}
href={
list.isSingleton ? `/${list.path}/${countNum === 1 ? '1' : 'create'}` : `/${list.path}`
}
css={{
backgroundColor: colors.background,
borderColor: colors.border,
Expand Down Expand Up @@ -62,7 +67,7 @@ const ListCard = ({ listKey, count, hideCreate }: ListCardProps) => {
'No access'
)}
</Link>
{hideCreate === false && (
{hideCreate === false && !list.isSingleton && (
<CreateButton title={`Create ${list.singular}`} href={`/${list.path}/create`}>
<PlusIcon size="large" />
<VisuallyHidden>Create {list.singular}</VisuallyHidden>
Expand Down
Loading

0 comments on commit b483800

Please sign in to comment.