Skip to content

Commit

Permalink
Change image ref (#5582)
Browse files Browse the repository at this point in the history
* update image ref to explicitly include field type

* update iamge field copy and paste button txt

* changesets

* fix test

* Update .changeset/violet-starfishes-punch.md

* omit path separators

* Update .changeset/thirty-bobcats-change.md

Co-authored-by: Mitchell Hamilton <mitchell@hamil.town>
  • Loading branch information
gwyneplaine and emmatown committed May 3, 2021
1 parent b7aeb23 commit 49dd468
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/thirty-bobcats-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@keystone-next/fields': major
'@keystone-next/keystone': major
---

Changed image ref to now be `${mode}:image:${id}`.
5 changes: 5 additions & 0 deletions .changeset/violet-starfishes-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/utils-legacy': major
---

Updated parseImageRef and getRef to accept a different signature for the image ref.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const crudTests = (keystoneTestWrapper: any) => {
});
expect(data).not.toBe(null);
expect(data.avatar).toEqual({
ref: `local:${data.avatar.id}.jpg`,
ref: `local:image:${data.avatar.id}.jpg`,
src: `/images/${data.avatar.id}.jpg`,
id: data.avatar.id,
__typename: 'LocalImageFieldOutput',
Expand Down
4 changes: 2 additions & 2 deletions packages-next/fields/src/types/image/views/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function ImgView({
</a>
</Text>
<Button size="small" tone="passive" onClick={copyRef}>
Copy
Copy Ref
</Button>
</Stack>
<Text size="xsmall">{`${value.data.width} x ${value.data.height} (${bytes(
Expand Down Expand Up @@ -254,7 +254,7 @@ function ImgView({
});
}}
>
Paste
Paste Ref
</Button>
) : null}
{value.kind === 'from-server' && (
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ export const humanize = (str: string) => {
.join(' ');
};

const IMAGEREGEX = /^(local):([^:\n]+)\.(gif|jpg|png|webp)$/;
const IMAGEREGEX = /^(local):image:([^\\\/:\n]+)\.(gif|jpg|png|webp)$/;
const FILEREGEX = /^(local):file:([^\\\/:\n]+)/;

export const getImageRef = (mode: ImageMode, id: string, extension: ImageExtension) =>
`${mode}:${id}.${extension}`;
`${mode}:image:${id}.${extension}`;

export const getFileRef = (mode: FileMode, name: string) => `${mode}:file:${name}`;
export const parseFileRef = (ref: string) => {
Expand Down

1 comment on commit 49dd468

@vercel
Copy link

@vercel vercel bot commented on 49dd468 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.