Skip to content
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

Fixed updating file size, name and tags #587

Merged
merged 2 commits into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 6 additions & 8 deletions packages/api-files/src/plugins/graphql.js
@@ -1,13 +1,11 @@
// @flow
import { gql } from "apollo-server-lambda";
import { emptyResolver } from "@webiny/commodo-graphql";
import { type PluginType } from "@webiny/api/types";
import { hasScope } from "@webiny/api-security";
import { resolveCreate, resolveGet } from "@webiny/commodo-graphql";
import { resolveCreate, resolveGet, resolveUpdate } from "@webiny/commodo-graphql";

import listFiles from "./resolvers/listFiles";
import listTags from "./resolvers/listTags";
import updateFileBySrc from "./resolvers/updateFileBySrc";
import uploadFile from "./resolvers/uploadFile";
import uploadFiles from "./resolvers/uploadFiles";
import createFiles from "./resolvers/createFiles";
Expand Down Expand Up @@ -54,7 +52,7 @@ export default ([
error: FileError
data: UploadFileResponseData
}

type UploadFilesResponse {
error: FileError
data: JSON!
Expand Down Expand Up @@ -138,7 +136,7 @@ export default ([
uploadFiles(data: [UploadFileInput]!): UploadFilesResponse
createFile(data: FileInput!): FileResponse
createFiles(data: [FileInput]!): CreateFilesResponse
updateFileBySrc(src: String!, data: FileInput!): FileResponse
updateFile(id: ID!, data: FileInput!): FileResponse
deleteFile(id: ID!): FilesDeleteResponse

# Install File manager
Expand Down Expand Up @@ -179,8 +177,8 @@ export default ([
uploadFile,
uploadFiles,
createFile: resolveCreate(getFile),
updateFile: resolveUpdate(getFile),
createFiles,
updateFileBySrc: updateFileBySrc,
deleteFile,
install
}
Expand All @@ -195,10 +193,10 @@ export default ([
FilesMutation: {
uploadFile: hasScope("files:file:crud"),
createFile: hasScope("files:file:crud"),
updateFileBySrc: hasScope("files:file:crud"),
updateFile: hasScope("files:file:crud"),
deleteFile: hasScope("files:file:crud")
}
}
}
}
]: Array<PluginType>);
]: Array<Object>);
35 changes: 0 additions & 35 deletions packages/api-files/src/plugins/resolvers/updateFileBySrc.js

This file was deleted.

Expand Up @@ -43,7 +43,7 @@ export default data => {
name: key,
key,
type: contentType,
size: payload.size,
size: data.size,
}
};
};
Expand Up @@ -8,7 +8,7 @@ import { ButtonSecondary, ButtonPrimary } from "@webiny/ui/Button";
import { Input } from "@webiny/ui/Input";
import { Form } from "@webiny/form";
import { ReactComponent as EditIcon } from "./../icons/round-edit-24px.svg";
import { UPDATE_FILE_BY_SRC, LIST_FILES } from "./../graphql";
import { UPDATE_FILE, LIST_FILES } from "./../graphql";
import { useSnackbar } from "@webiny/app-admin/hooks/useSnackbar";
import { useFileManager } from "./../FileManagerContext";

Expand Down Expand Up @@ -37,21 +37,21 @@ function Name({ file }: *) {
onSubmit={async ({ name }) => {
setEdit(false);
await client.mutate({
mutation: UPDATE_FILE_BY_SRC,
mutation: UPDATE_FILE,
variables: {
src: file.src,
id: file.id,
data: { name }
},
update: (cache, updated) => {
const newFileData = get(updated, "data.files.updateFileBySrc.data");
const newFileData = get(updated, "data.files.updateFile.data");
const data = cloneDeep(
cache.readQuery({
query: LIST_FILES,
variables: queryParams
})
);

data.blockFiles.listFiles.data.forEach(item => {
data.files.listFiles.data.forEach(item => {
if (item.src === newFileData.src) {
item.name = newFileData.name;
}
Expand Down
Expand Up @@ -6,7 +6,7 @@ import { useApolloClient } from "react-apollo";
import { get, cloneDeep } from "lodash";
import { Chips, Chip } from "@webiny/ui/Chips";
import { Tags as TagsComponent } from "@webiny/ui/Tags";
import { UPDATE_FILE_BY_SRC, LIST_FILES, LIST_TAGS } from "./../graphql";
import { UPDATE_FILE, LIST_FILES, LIST_TAGS } from "./../graphql";
import { ReactComponent as EditIcon } from "./../icons/round-edit-24px.svg";
import { useFileManager } from "./../FileManagerContext";
import { Hotkeys } from "react-hotkeyz";
Expand Down Expand Up @@ -41,16 +41,16 @@ function Tags({ file }) {
setSaving(true);
client
.mutate({
mutation: UPDATE_FILE_BY_SRC,
mutation: UPDATE_FILE,
variables: {
src: file.src,
id: file.id,
data: { tags: currentTags }
},
refetchQueries: [{ query: LIST_TAGS }],
update: (cache, updated) => {
const newFileData = get(
updated,
"data.files.updateFileBySrc.data"
"data.files.updateFile.data"
);

// 1. Update files list cache
Expand All @@ -61,8 +61,8 @@ function Tags({ file }) {
})
);

data.blockFiles.listFiles.data.forEach(item => {
if (item.src === newFileData.src) {
data.files.listFiles.data.forEach(item => {
if (item.key === newFileData.key) {
item.tags = newFileData.tags;
}
});
Expand Down
8 changes: 5 additions & 3 deletions packages/app-admin/src/components/FileManager/graphql.js
Expand Up @@ -5,6 +5,7 @@ const fileFields = /* GraphQL */ `
__typename
id
name
key
src
size
type
Expand Down Expand Up @@ -51,11 +52,12 @@ export const CREATE_FILE = gql`
}
`;

export const UPDATE_FILE_BY_SRC = gql`
mutation UpdateFile($src: String!, $data: FileInput!) {
export const UPDATE_FILE = gql`
mutation UpdateFile($id: ID!, $data: FileInput!) {
files {
updateFileBySrc(src: $src, data: $data) {
updateFile(id: $id, data: $data) {
data {
id
src
name
tags
Expand Down
4 changes: 1 addition & 3 deletions packages/app/src/plugins/fileUploaderPlugin.js
@@ -1,5 +1,4 @@
// @flow
import type { FileUploaderPlugin } from "@webiny/app/types";
import gql from "graphql-tag";
import get from "lodash.get";

Expand All @@ -10,7 +9,6 @@ const UPLOAD_FILE = gql`
data {
data
file {
src
type
name
size
Expand All @@ -25,7 +23,7 @@ const UPLOAD_FILE = gql`
}
`;

export default (): FileUploaderPlugin => ({
export default () => ({
type: "file-uploader",
name: "file-uploader",
upload: async (file: File, { apolloClient }) => {
Expand Down