-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Next image service #5272
Closed
Closed
[WIP] Next image service #5272
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ec2a0b0
Draft ideas
JedWatson cdf4b25
Changed default
JedWatson 5f5f730
Updating types
JedWatson 7d9b71d
Renamed example to images, put newly agreed upon types in types.ts file
rohan-deshpande 99eeed5
Added blurHash to relevant types
rohan-deshpande File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,13 +19,75 @@ const { withAuth } = createAuth({ | |
}, | ||
}); | ||
|
||
export type ImageInTheDatabase = { | ||
mode: 'local' | 'cloud'; | ||
// e.g 'c8cd1b99-8647-4b7e-a5d1-6693c79620a9' | ||
id: string; | ||
// source image extension | ||
ext: string; | ||
// blur hash | ||
// blurhash: { hash: string; x: number; y: number }; | ||
// metadata about the source image | ||
filesize: number; | ||
width: number; | ||
height: number; | ||
}; | ||
|
||
/* | ||
type UpdateImageInput { | ||
upload: Upload | ||
set: GraphqlImageInputType | ||
delete: boolean; | ||
} | ||
|
||
mutation updatePost { | ||
image: UpdateImageInput | ||
} | ||
*/ | ||
|
||
export type GraphqlImageInputType = { | ||
field: { | ||
mode: 'local' | 'cloud'; | ||
id: string; | ||
width: number; | ||
height: number; | ||
// blurhash: { hash: string; x: number; y: number }; | ||
extension: string; | ||
filesize: number; | ||
}; | ||
}; | ||
export type GraphqlImageOutputType = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. enum ImageObjectFit { FIXED INTRINSIC RESPONSIVE FILL }
ImageOutputType {
id: ID!
extension: TEXT!
src: TEXT
width: INTEGER
height: INTEGER
blurHash: { hash: TEXT, x: INTEGER, y: INTEGER }
fileSize: INTEGER
# Mabes add this later?
transform (
# This is "whatever the Next image component accepts"
width: INTEGER
height: INTEGER
quality: INTEGER
objectFit: ObjectFit
) {
src: TEXT
width: INTEGER
height: INTEGER
}
} |
||
field: { | ||
mode: 'local' | 'cloud'; | ||
id: string; | ||
// https://image.keystone.cloud/thinkmill/{id}.{ext} | ||
// {keystone.config.publicPath}/{id}.{ext} | ||
src: string; | ||
width: number; | ||
height: number; | ||
// blurhash: { hash: string; x: number; y: number }; | ||
extension: string; | ||
filesize: number; | ||
}; | ||
}; | ||
|
||
export default withAuth( | ||
config({ | ||
db: { | ||
adapter: 'prisma_postgresql', | ||
url: process.env.DATABASE_URL || 'postgres://keystone5:k3yst0n3@localhost:5432/todo-example', | ||
}, | ||
lists, | ||
images: { | ||
/* could be 'cloud' */ | ||
upload: 'local', | ||
local: { | ||
/* where images get stored when uploaded */ | ||
uploadPath: './public/images', | ||
/* the basePath for where image are served from */ | ||
publicPath: '/images', | ||
}, | ||
}, | ||
ui: { | ||
isAccessAllowed: ({ session }) => !!session, | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// @ts-ignore | ||
import { Text } from '@keystone-next/fields-legacy'; | ||
import type { FieldType, BaseGeneratedListTypes } from '@keystone-next/types'; | ||
import { resolveView } from '../../resolve-view'; | ||
import type { FieldConfig } from '../../interfaces'; | ||
|
||
export type ImageFieldConfig< | ||
TGeneratedListTypes extends BaseGeneratedListTypes | ||
> = FieldConfig<TGeneratedListTypes> & { | ||
isRequired?: boolean; | ||
isIndexed?: boolean; | ||
}; | ||
|
||
export const image = <TGeneratedListTypes extends BaseGeneratedListTypes>( | ||
config: ImageFieldConfig<TGeneratedListTypes> = {} | ||
): FieldType<TGeneratedListTypes> => ({ | ||
type: Text, | ||
config, | ||
views: resolveView('image/views'), | ||
getAdminMeta: () => ({ | ||
/* ?? */ | ||
}), | ||
}); |
43 changes: 43 additions & 0 deletions
43
packages-next/fields/src/types/image/tests/test-fixtures.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { AdapterName } from '@keystone-next/test-utils-legacy'; | ||
import { text } from '..'; | ||
|
||
export const name = 'Text'; | ||
export const typeFunction = text; | ||
export const exampleValue = () => 'foo'; | ||
export const exampleValue2 = () => 'bar'; | ||
export const supportsUnique = true; | ||
export const fieldName = 'testField'; | ||
|
||
export const getTestFields = () => ({ name: text(), testField: text() }); | ||
|
||
export const initItems = () => { | ||
return [ | ||
{ name: 'a', testField: '' }, | ||
{ name: 'b', testField: 'other' }, | ||
{ name: 'c', testField: 'FOOBAR' }, | ||
{ name: 'd', testField: 'fooBAR' }, | ||
{ name: 'e', testField: 'foobar' }, | ||
{ name: 'f', testField: null }, | ||
{ name: 'g' }, | ||
]; | ||
}; | ||
|
||
export const storedValues = () => [ | ||
{ name: 'a', testField: '' }, | ||
{ name: 'b', testField: 'other' }, | ||
{ name: 'c', testField: 'FOOBAR' }, | ||
{ name: 'd', testField: 'fooBAR' }, | ||
{ name: 'e', testField: 'foobar' }, | ||
{ name: 'f', testField: null }, | ||
{ name: 'g', testField: null }, | ||
]; | ||
|
||
export const supportedFilters = (adapterName: AdapterName) => [ | ||
'null_equality', | ||
'equality', | ||
adapterName !== 'prisma_sqlite' && 'equality_case_insensitive', | ||
'in_empty_null', | ||
'in_value', | ||
adapterName !== 'prisma_sqlite' && 'string', | ||
adapterName !== 'prisma_sqlite' && 'string_case_insensitive', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* @jsx jsx */ | ||
|
||
import { CellContainer, CellLink } from '@keystone-next/admin-ui/components'; | ||
import { | ||
CardValueComponent, | ||
CellComponent, | ||
FieldController, | ||
FieldControllerConfig, | ||
FieldProps, | ||
} from '@keystone-next/types'; | ||
import { jsx } from '@keystone-ui/core'; | ||
import { FieldContainer, FieldLabel, TextInput } from '@keystone-ui/fields'; | ||
|
||
export const Field = ({ field, value, onChange, autoFocus }: FieldProps<typeof controller>) => ( | ||
<FieldContainer> | ||
<FieldLabel>{field.label}</FieldLabel> | ||
{onChange ? ( | ||
<TextInput | ||
autoFocus={autoFocus} | ||
onChange={event => onChange(event.target.value)} | ||
value={value} | ||
/> | ||
) : ( | ||
value | ||
)} | ||
</FieldContainer> | ||
); | ||
|
||
export const Cell: CellComponent = ({ item, field, linkTo }) => { | ||
let value = item[field.path] + ''; | ||
return linkTo ? <CellLink {...linkTo}>{value}</CellLink> : <CellContainer>{value}</CellContainer>; | ||
}; | ||
Cell.supportsLinkTo = true; | ||
|
||
export const CardValue: CardValueComponent = ({ item, field }) => { | ||
return ( | ||
<FieldContainer> | ||
<FieldLabel>{field.label}</FieldLabel> | ||
{item[field.path]} | ||
</FieldContainer> | ||
); | ||
}; | ||
|
||
type Config = FieldControllerConfig; | ||
|
||
export const controller = (config: Config): FieldController<string, string> => { | ||
return { | ||
path: config.path, | ||
label: config.label, | ||
graphqlSelection: config.path, | ||
defaultValue: '', | ||
deserialize: data => { | ||
const value = data[config.path]; | ||
return typeof value === 'string' ? value : ''; | ||
}, | ||
serialize: value => ({ [config.path]: value }), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably only need
mode
andid
for the input type,mode
would be optional