Skip to content

Commit

Permalink
fix(web): improve project import (#1199)
Browse files Browse the repository at this point in the history
Co-authored-by: airslice <[email protected]>
  • Loading branch information
mkumbobeaty and airslice authored Oct 29, 2024
1 parent 9959544 commit d2a9662
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ const ProjectGridViewItem: FC<ProjectProps> = ({
handleProjectStarClick,
handleProjectRemoveModal,
handleProjectRemove
// exportModalVisible,
// closeExportModal,
// handleExportProject
} = useHooks({
project,
selectedProjectId,
Expand Down Expand Up @@ -101,17 +98,6 @@ const ProjectGridViewItem: FC<ProjectProps> = ({
onProjectRemove={() => handleProjectRemove(project.id)}
/>
)}
{/* MEMO: this modal will be used in the future */}
{/* <Modal visible={exportModalVisible} size="small">
<ModalPanel
title={t("Export Project")}
actions={actions}
onCancel={closeExportModal}
appearance="normal"
>
<ModalContent />
</ModalPanel>
</Modal> */}
</>
);
};
Expand Down Expand Up @@ -185,8 +171,3 @@ const CardTitle = styled("div")(({ theme }) => ({
textOverflow: "ellipsis",
cursor: "pointer"
}));

// const ModalContent = styled("div")(() => ({
// width: "100%",
// height: "272px"
// }));
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ const ProjectListViewItem: FC<ProjectProps> = ({
handleProjectStarClick,
handleProjectRemoveModal,
handleProjectRemove
// exportModalVisible,
// closeExportModal,
// handleExportProject
} = useHooks({
project,
selectedProjectId,
Expand Down Expand Up @@ -130,17 +127,6 @@ const ProjectListViewItem: FC<ProjectProps> = ({
onProjectRemove={() => handleProjectRemove(project.id)}
/>
)}
{/* MEMO: this modal will be used in the future */}
{/* <Modal visible={exportModalVisible} size="small">
<ModalPanel
title={t("Export Project")}
actions={actions}
onCancel={closeExportModal}
appearance="normal"
>
<ModalContent />
</ModalPanel>
</Modal> */}
</>
);
};
Expand Down Expand Up @@ -230,8 +216,3 @@ const TitleWrapper = styled("div")(({ theme }) => ({
overflow: "hidden",
textOverflow: "ellipsis"
}));

// const ModalContent = styled("div")(() => ({
// width: "100%",
// height: "272px"
// }));
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ export default ({
const [isStarred, setIsStarred] = useState(project.starred);
const [projectRemoveModalVisible, setProjectRemoveModalVisible] =
useState(false);
// MEMO: this modal state and function will be used in the future
// const [exportModalVisible, setExportModalVisible] = useState(false);

const handleProjectNameChange = useCallback((newValue: string) => {
setProjectName(newValue);
Expand Down Expand Up @@ -70,13 +68,7 @@ export default ({
const handleExportProject = useCallback(async () => {
if (!project.id) return;

const result = await useExportProject(project.id);

if (result.status === "success") {
console.log("export success");
} else {
console.error("Failed to export project:", result.status);
}
await useExportProject(project.id);
}, [useExportProject, project.id]);

useEffect(() => {
Expand All @@ -102,7 +94,7 @@ export default ({
},
{
id: "export",
title: t("Export"),
title: t("Export (Experimental)"),
icon: "downloadSimple",
onClick: () => handleExportProject()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,16 @@ export default (workspaceId?: string) => {
async (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
if (file) {
const result = await useImportProject(file);
const result = await useImportProject({
teamId: workspaceId || "",
file
});
if (result.status === "success") {
await refetch();
}
}
},
[useImportProject, refetch]
[useImportProject, workspaceId, refetch]
);

// project remove
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,6 @@ const Projects: FC<{ workspaceId?: string }> = ({ workspaceId }) => {

const fileInputRef = useRef<HTMLInputElement>(null);

// const actions = useMemo(
// () => (
// <>
// <Button
// title={t("Cancel")}
// appearance={"secondary"}
// onClick={closeExportModal}
// />
// <Button
// title={t("Export")}
// appearance={"primary"}
// onClick={handleExportProject}
// />
// </>
// ),
// [handleExportProject, closeExportModal, t]
// );

return (
<ManagerWrapper onClick={() => handleProjectSelect(undefined)}>
<ManagerHeader
Expand All @@ -90,7 +72,7 @@ const Projects: FC<{ workspaceId?: string }> = ({ workspaceId }) => {
/>
<ManagerHeaderButton
key={"import-project"}
title={t("Import")}
title={t("Import (Experimental)")}
managerSize="large"
icon="signIn"
appearance="secondary"
Expand Down
9 changes: 5 additions & 4 deletions web/src/services/api/projectApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
DeleteProjectInput,
ArchiveProjectMutationVariables,
UpdateProjectBasicAuthMutationVariables,
UpdateProjectAliasMutationVariables
UpdateProjectAliasMutationVariables,
ImportProjectInput
} from "@reearth/services/gql/__gen__/graphql";
import {
ARCHIVE_PROJECT,
Expand Down Expand Up @@ -527,12 +528,12 @@ export default () => {
const [importProjectMutation] = useMutation(IMPORT_PROJECT);

const useImportProject = useCallback(
async (file: File) => {
if (!file) return { status: "error" };
async (input: ImportProjectInput) => {
if (!input) return { status: "error" };

try {
const { data, errors } = await importProjectMutation({
variables: { file }
variables: { ...input }
});

if (errors || !data?.importProject) {
Expand Down
4 changes: 2 additions & 2 deletions web/src/services/gql/__gen__/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const documents = {
"\n mutation DeleteProject($projectId: ID!) {\n deleteProject(input: { projectId: $projectId }) {\n projectId\n }\n }\n": types.DeleteProjectDocument,
"\n query GetStarredProjects($teamId: ID!) {\n starredProjects(teamId: $teamId) {\n\t\t\t\tnodes {\n\t\t\t\t\tid\n\t\t\t\t\tname\n\t\t\t\t\tstarred\n scene {\n id\n }\n\t\t\t\t}\n\t\t\t\ttotalCount\n\t\t\t}\n }\n": types.GetStarredProjectsDocument,
"\n mutation ExportProject($projectId: ID!) {\n exportProject(input: { projectId: $projectId }) {\n projectDataPath\n }\n }\n": types.ExportProjectDocument,
"\n mutation ImportProject($file: Upload!) {\n importProject(input: { file: $file }) {\n projectData\n }\n }\n": types.ImportProjectDocument,
"\n mutation ImportProject($teamId: ID!, $file: Upload!) {\n importProject(input: { teamId: $teamId, file: $file }) {\n projectData\n }\n }\n": types.ImportProjectDocument,
"\n query GetDeletedProjects($teamId: ID!) {\n deletedProjects(teamId: $teamId) {\n\t\t\tnodes {\n\t\t\t\tid\n\t\t\t\tname\n\t\t\t\tisDeleted\n imageUrl\n\t\t\t\t}\n\t\t\ttotalCount\n\t\t}\n }\n": types.GetDeletedProjectsDocument,
"\n mutation UpdatePropertyValue(\n $propertyId: ID!\n $schemaGroupId: ID\n $itemId: ID\n $fieldId: ID!\n $value: Any\n $type: ValueType!\n $lang: Lang\n ) {\n updatePropertyValue(\n input: {\n propertyId: $propertyId\n schemaGroupId: $schemaGroupId\n itemId: $itemId\n fieldId: $fieldId\n value: $value\n type: $type\n }\n ) {\n property {\n id\n ...PropertyFragment\n layer {\n id\n ...Layer1Fragment\n }\n }\n }\n }\n": types.UpdatePropertyValueDocument,
"\n mutation AddPropertyItem(\n $propertyId: ID!\n $schemaGroupId: ID!\n $lang: Lang\n ) {\n addPropertyItem(\n input: {\n propertyId: $propertyId\n schemaGroupId: $schemaGroupId\n }\n ) {\n property {\n id\n ...PropertyFragment\n layer {\n id\n ...Layer1Fragment\n }\n }\n }\n }\n": types.AddPropertyItemDocument,
Expand Down Expand Up @@ -306,7 +306,7 @@ export function gql(source: "\n mutation ExportProject($projectId: ID!) {\n
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function gql(source: "\n mutation ImportProject($file: Upload!) {\n importProject(input: { file: $file }) {\n projectData\n }\n }\n"): (typeof documents)["\n mutation ImportProject($file: Upload!) {\n importProject(input: { file: $file }) {\n projectData\n }\n }\n"];
export function gql(source: "\n mutation ImportProject($teamId: ID!, $file: Upload!) {\n importProject(input: { teamId: $teamId, file: $file }) {\n projectData\n }\n }\n"): (typeof documents)["\n mutation ImportProject($teamId: ID!, $file: Upload!) {\n importProject(input: { teamId: $teamId, file: $file }) {\n projectData\n }\n }\n"];
/**
* The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
Expand Down
4 changes: 3 additions & 1 deletion web/src/services/gql/__gen__/graphql.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions web/src/services/gql/queries/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ export const EXPORT_PROJECT = gql(`
`);

export const IMPORT_PROJECT = gql(`
mutation ImportProject($file: Upload!) {
importProject(input: { file: $file }) {
mutation ImportProject($teamId: ID!, $file: Upload!) {
importProject(input: { teamId: $teamId, file: $file }) {
projectData
}
}
Expand Down
4 changes: 2 additions & 2 deletions web/src/services/i18n/translations/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Last Created: ''
First Created: ''
Last Updated: ''
New Project: ''
Import: ''
Import (Experimental): ''
All projects: ''
Search Result for: ''
Project Name: ''
Expand All @@ -46,7 +46,7 @@ Created At: ''
No Project has been created yet: ''
Rename: ''
Project Setting: ''
Export: ''
Export (Experimental): ''
Move to Recycle Bin: ''
Create new project: ''
Project Name *: ''
Expand Down
6 changes: 3 additions & 3 deletions web/src/services/i18n/translations/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ No Member match your search.: ''
Last Created: ''
First Created: ''
Last Updated: ''
New Project: ''
Import: ''
New Project: 新規プロジェクト
Import (Experimental): ''
All projects: ''
Search Result for: ''
Project Name: ''
Expand All @@ -46,7 +46,7 @@ Created At: ''
No Project has been created yet: ''
Rename: 名称変更
Project Setting: プロジェクト設定
Export: エクスポート
Export (Experimental): ''
Move to Recycle Bin: ''
Create new project: ''
Project Name *: ''
Expand Down

0 comments on commit d2a9662

Please sign in to comment.