Skip to content

chore(site): remove create template xservice #10112

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

Merged
merged 17 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor ImportStarterTemplateView
  • Loading branch information
BrunoQuaresma committed Oct 6, 2023
commit db14220cc986ac4d2f73d918c7af55121cf1ab53
7 changes: 2 additions & 5 deletions site/src/pages/CreateTemplatePage/CreateTemplatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Helmet } from "react-helmet-async";
import { useNavigate, useSearchParams } from "react-router-dom";
import { pageTitle } from "utils/page";
import { DuplicateTemplateView } from "./DuplicateTemplateView";
import { ImportStarterTemplateView } from "./ImportStarterTemplateView";

const CreateTemplatePage: FC = () => {
const navigate = useNavigate();
Expand Down Expand Up @@ -49,7 +50,7 @@ const CreateTemplatePage: FC = () => {
{searchParams.has("fromTemplate") ? (
<DuplicateTemplateView />
) : searchParams.has("exampleId") ? (
<ImportStaterTemplateView />
<ImportStarterTemplateView />
) : (
<UploadTemplateView />
)}
Expand Down Expand Up @@ -97,10 +98,6 @@ const CreateTemplatePage: FC = () => {
);
};

const ImportStaterTemplateView = () => {
return <div>Import</div>;
};

const UploadTemplateView = () => {
return <div>Upload</div>;
};
Expand Down
69 changes: 69 additions & 0 deletions site/src/pages/CreateTemplatePage/ImportStarterTemplateView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { useQuery, useMutation } from "@tanstack/react-query";
import { templateVersionLogs } from "api/queries/templateVersions";
import {
JobError,
createTemplate,
templateExamples,
} from "api/queries/templates";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { useOrganizationId } from "hooks";
import { useNavigate, useSearchParams } from "react-router-dom";
import { CreateTemplateForm } from "./CreateTemplateForm";
import { Loader } from "components/Loader/Loader";
import { useDashboard } from "components/Dashboard/DashboardProvider";
import { firstVersion, getFormPermissions, newTemplate } from "./utils";

export const ImportStarterTemplateView = () => {
const navigate = useNavigate();
const organizationId = useOrganizationId();
const [searchParams] = useSearchParams();
const templateExamplesQuery = useQuery(templateExamples(organizationId));
const templateExample = templateExamplesQuery.data?.find(
(e) => e.id === searchParams.get("exampleId")!,
);

const isLoading = templateExamplesQuery.isLoading;
const loadingError = templateExamplesQuery.error;

const dashboard = useDashboard();
const formPermissions = getFormPermissions(dashboard.entitlements);

const createTemplateMutation = useMutation(createTemplate());
const createError = createTemplateMutation.error;
const isJobError = createError instanceof JobError;
const templateVersionLogsQuery = useQuery({
...templateVersionLogs(isJobError ? createError.version.id : ""),
enabled: isJobError,
});

if (isLoading) {
return <Loader />;
}

if (loadingError) {
return <ErrorAlert error={loadingError} />;
}

return (
<CreateTemplateForm
{...formPermissions}
starterTemplate={templateExample!}
error={createTemplateMutation.error}
isSubmitting={createTemplateMutation.isLoading}
onCancel={() => navigate(-1)}
jobError={isJobError ? createError.job.error : undefined}
logs={templateVersionLogsQuery.data}
onSubmit={async (formData) => {
const template = await createTemplateMutation.mutateAsync({
organizationId,
version: firstVersion(
templateExample!,
formData.user_variable_values,
),
template: newTemplate(formData),
});
navigate(`/templates/${template.name}`);
}}
/>
);
};