-
Notifications
You must be signed in to change notification settings - Fork 902
chore(site): remove template version editor xservice #10490
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
Changes from 1 commit
c290855
93df525
b3c712c
10d6b4e
7eb5c91
c024a1d
e7713fe
f782c7d
8bf23af
5502077
20d6100
9d1ca61
c73f976
86735c9
86d7a6d
e748fe8
71e8920
8a7fae6
2769cfe
4893156
32934ed
209e364
66ea796
353f325
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ import { Helmet } from "react-helmet-async"; | |
import { useNavigate, useParams } from "react-router-dom"; | ||
import { pageTitle } from "utils/page"; | ||
import { templateVersionEditorMachine } from "xServices/templateVersionEditor/templateVersionEditorXService"; | ||
import { useMutation, useQuery } from "react-query"; | ||
import { useMutation, useQuery, useQueryClient } from "react-query"; | ||
import { | ||
createTemplateVersion, | ||
templateByName, | ||
|
@@ -20,22 +20,30 @@ import { | |
isAllowedFile, | ||
} from "utils/templateVersion"; | ||
import { watchBuildLogsByTemplateVersionId } from "api/api"; | ||
import { ProvisionerJobLog, TemplateVersion } from "api/typesGenerated"; | ||
import { ProvisionerJobLog } from "api/typesGenerated"; | ||
|
||
type Params = { | ||
version: string; | ||
template: string; | ||
}; | ||
|
||
export const TemplateVersionEditorPage: FC = () => { | ||
const queryClient = useQueryClient(); | ||
const navigate = useNavigate(); | ||
const { version: versionName, template: templateName } = | ||
useParams() as Params; | ||
const orgId = useOrganizationId(); | ||
const [currentVersionName, setCurrentVersionName] = useState(versionName); | ||
const templateQuery = useQuery(templateByName(orgId, templateName)); | ||
const templateVersionQuery = useQuery( | ||
templateVersionByName(orgId, templateName, versionName), | ||
const templateVersionOptions = templateVersionByName( | ||
orgId, | ||
templateName, | ||
currentVersionName, | ||
); | ||
const templateVersionQuery = useQuery({ | ||
...templateVersionOptions, | ||
keepPreviousData: true, | ||
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. Just making sure: this is for making the UX nicer, right? It just makes sure that if the page needs to load in new version data, the UI doesn't unload while that's happening? 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. Exactly! |
||
}); | ||
const fileQuery = useQuery({ | ||
...file(templateVersionQuery.data?.job.file_id ?? ""), | ||
enabled: templateVersionQuery.isSuccess, | ||
|
@@ -49,8 +57,6 @@ export const TemplateVersionEditorPage: FC = () => { | |
const createTemplateVersionMutation = useMutation( | ||
createTemplateVersion(orgId), | ||
); | ||
const [currentVersionOnEditor, setCurrentVersionOnEditor] = | ||
useState<TemplateVersion>(); | ||
|
||
// Initialize file tree | ||
useEffect(() => { | ||
|
@@ -69,50 +75,47 @@ export const TemplateVersionEditorPage: FC = () => { | |
} | ||
}, [fileQuery.data, sendEvent]); | ||
|
||
// Initialize current version used on editor | ||
useEffect(() => { | ||
if (templateVersionQuery.data) { | ||
setCurrentVersionOnEditor(templateVersionQuery.data); | ||
} | ||
}, [templateVersionQuery.data]); | ||
|
||
// Watch version logs | ||
const [logs, setLogs] = useState<ProvisionerJobLog[]>([]); | ||
const templateVersionId = templateVersionQuery.data?.id; | ||
const refetchTemplateVersion = templateVersionQuery.refetch; | ||
const templateVersionStatus = templateVersionQuery.data?.job.status; | ||
useEffect(() => { | ||
if (!currentVersionOnEditor) { | ||
if (!templateVersionId || !templateVersionStatus) { | ||
return; | ||
} | ||
|
||
if (templateVersionStatus !== "running") { | ||
return; | ||
} | ||
|
||
const socket = watchBuildLogsByTemplateVersionId( | ||
currentVersionOnEditor.id, | ||
{ | ||
onMessage: (log) => { | ||
setLogs((logs) => [...logs, log]); | ||
}, | ||
onDone: () => { | ||
sendEvent({ type: "BUILD_DONE" }); | ||
}, | ||
onError: (error) => { | ||
console.error(error); | ||
}, | ||
const socket = watchBuildLogsByTemplateVersionId(templateVersionId, { | ||
onMessage: (log) => { | ||
setLogs((logs) => [...logs, log]); | ||
}, | ||
onDone: async () => { | ||
await refetchTemplateVersion(); | ||
}, | ||
); | ||
onError: (error) => { | ||
console.error(error); | ||
}, | ||
}); | ||
|
||
return () => { | ||
socket.close(); | ||
}; | ||
}, [currentVersionOnEditor, sendEvent]); | ||
}, [refetchTemplateVersion, templateVersionId, templateVersionStatus]); | ||
|
||
return ( | ||
<> | ||
<Helmet> | ||
<title>{pageTitle(`${templateName} · Template Editor`)}</title> | ||
</Helmet> | ||
|
||
{templateQuery.data && currentVersionOnEditor && fileTree && ( | ||
{templateQuery.data && templateVersionQuery.data && fileTree && ( | ||
<TemplateVersionEditor | ||
template={templateQuery.data} | ||
templateVersion={currentVersionOnEditor} | ||
templateVersion={templateVersionQuery.data} | ||
isBuildingNewVersion={Boolean(editorState.context.version)} | ||
defaultFileTree={fileTree} | ||
onPreview={async (newFileTree) => { | ||
|
@@ -134,7 +137,11 @@ export const TemplateVersionEditorPage: FC = () => { | |
file_id: serverFile.hash, | ||
}); | ||
setLogs([]); | ||
setCurrentVersionOnEditor(newVersion); | ||
setCurrentVersionName(newVersion.name); | ||
queryClient.setQueryData( | ||
templateVersionOptions.queryKey, | ||
newVersion, | ||
); | ||
sendEvent({ | ||
type: "CREATED_VERSION", | ||
data: newVersion, | ||
|
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.
I recommend reviewing this file by looking into it without the diff.