-
Notifications
You must be signed in to change notification settings - Fork 898
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 |
---|---|---|
|
@@ -53,13 +53,7 @@ export const TemplateVersionEditorPage: FC = () => { | |
...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, | ||
}); | ||
const [fileTree, setFileTree] = useState<FileTree>(); | ||
const uploadFileMutation = useMutation(uploadFile()); | ||
const currentTarFileRef = useRef<TarReader | null>(null); | ||
const createTemplateVersionMutation = useMutation( | ||
createTemplateVersion(orgId), | ||
); | ||
|
@@ -70,38 +64,12 @@ export const TemplateVersionEditorPage: FC = () => { | |
const { logs, setLogs } = useVersionLogs(templateVersionQuery.data, { | ||
onDone: templateVersionQuery.refetch, | ||
}); | ||
|
||
// Initialize file tree | ||
useEffect(() => { | ||
const initializeFileTree = async (file: ArrayBuffer) => { | ||
const tarReader = new TarReader(); | ||
await tarReader.readFile(file); | ||
currentTarFileRef.current = tarReader; | ||
const fileTree = await createTemplateVersionFileTree(tarReader); | ||
setFileTree(fileTree); | ||
}; | ||
|
||
if (fileQuery.data) { | ||
initializeFileTree(fileQuery.data).catch(() => { | ||
console.error("Error on initializing the editor"); | ||
}); | ||
} | ||
}, [fileQuery.data]); | ||
|
||
// Handling missing variables | ||
const missingVariablesQuery = useQuery({ | ||
...templateVersionVariables(templateVersionQuery.data?.id ?? ""), | ||
enabled: | ||
templateVersionQuery.data?.job.error_code === | ||
"REQUIRED_TEMPLATE_VARIABLES", | ||
}); | ||
const [isMissingVariablesDialogOpen, setIsMissingVariablesDialogOpen] = | ||
useState(false); | ||
useEffect(() => { | ||
if (missingVariablesQuery.data) { | ||
setIsMissingVariablesDialogOpen(true); | ||
} | ||
}, [missingVariablesQuery.data]); | ||
const { fileTree, tarFile } = useFileTree(templateVersionQuery.data); | ||
const { | ||
missingVariables, | ||
setIsMissingVariablesDialogOpen, | ||
isMissingVariablesDialogOpen, | ||
} = useMissingVariables(templateVersionQuery.data); | ||
|
||
// Handling publishing | ||
const [isPublishingDialogOpen, setIsPublishingDialogOpen] = useState(false); | ||
|
@@ -123,12 +91,12 @@ export const TemplateVersionEditorPage: FC = () => { | |
templateVersion={templateVersionQuery.data} | ||
defaultFileTree={fileTree} | ||
onPreview={async (newFileTree) => { | ||
if (!currentTarFileRef.current) { | ||
if (!tarFile) { | ||
return; | ||
} | ||
setLogs([]); | ||
const newVersionFile = await generateVersionFiles( | ||
currentTarFileRef.current, | ||
tarFile, | ||
newFileTree, | ||
); | ||
const serverFile = await uploadFileMutation.mutateAsync( | ||
|
@@ -191,7 +159,7 @@ export const TemplateVersionEditorPage: FC = () => { | |
resources={resourcesQuery.data} | ||
buildLogs={logs} | ||
isPromptingMissingVariables={isMissingVariablesDialogOpen} | ||
missingVariables={missingVariablesQuery.data} | ||
missingVariables={missingVariables} | ||
onSubmitMissingVariableValues={async (values) => { | ||
if (!uploadFileMutation.data) { | ||
return; | ||
|
@@ -221,11 +189,39 @@ export const TemplateVersionEditorPage: FC = () => { | |
); | ||
}; | ||
|
||
const useFileTree = (templateVersion: TemplateVersion | undefined) => { | ||
const tarFileRef = useRef<TarReader | null>(null); | ||
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. I don't know the full set of problems that this component is trying to solve, but my gut feeling is that it might make sense to combine type TarInfo = {
reader: TarReader;
tree: FileTree;
};
// Type (TarInfo | undefined)
const [tarState, setTarState] = useState<TarInfo>();
const initializeFileTree = async (file: ArrayBuffer) => {
const tarReader = new TarReader();
await tarReader.readFile(file);
const fileTree = await createTemplateVersionFileTree(tarReader);
setTarState({ reader: tarReader, file: fileTree });
};
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. Awesome points. 1 - I think makes sense 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. Moved it to a single state call! |
||
const fileQuery = useQuery({ | ||
...file(templateVersion?.job.file_id ?? ""), | ||
enabled: templateVersion !== undefined, | ||
}); | ||
const [fileTree, setFileTree] = useState<FileTree>(); | ||
useEffect(() => { | ||
const initializeFileTree = async (file: ArrayBuffer) => { | ||
const tarReader = new TarReader(); | ||
await tarReader.readFile(file); | ||
tarFileRef.current = tarReader; | ||
const fileTree = await createTemplateVersionFileTree(tarReader); | ||
setFileTree(fileTree); | ||
}; | ||
|
||
if (fileQuery.data) { | ||
initializeFileTree(fileQuery.data).catch(() => { | ||
console.error("Error on initializing the editor"); | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
} | ||
}, [fileQuery.data]); | ||
|
||
return { | ||
fileTree, | ||
tarFile: tarFileRef.current, | ||
}; | ||
}; | ||
|
||
const useVersionLogs = ( | ||
templateVersion: TemplateVersion | undefined, | ||
options: { onDone: () => Promise<unknown> }, | ||
) => { | ||
// Watch version logs | ||
const [logs, setLogs] = useState<ProvisionerJobLog[]>(); | ||
const templateVersionId = templateVersion?.id; | ||
const refetchTemplateVersion = options.onDone; | ||
|
@@ -263,6 +259,27 @@ const useVersionLogs = ( | |
}; | ||
}; | ||
|
||
const useMissingVariables = (templateVersion: TemplateVersion | undefined) => { | ||
const { data: missingVariables } = useQuery({ | ||
...templateVersionVariables(templateVersion?.id ?? ""), | ||
enabled: templateVersion?.job.error_code === "REQUIRED_TEMPLATE_VARIABLES", | ||
}); | ||
const [isMissingVariablesDialogOpen, setIsMissingVariablesDialogOpen] = | ||
useState(false); | ||
|
||
useEffect(() => { | ||
if (missingVariables) { | ||
setIsMissingVariablesDialogOpen(true); | ||
} | ||
}, [missingVariables]); | ||
|
||
return { | ||
missingVariables, | ||
isMissingVariablesDialogOpen, | ||
setIsMissingVariablesDialogOpen, | ||
}; | ||
}; | ||
|
||
const generateVersionFiles = async ( | ||
tarReader: TarReader, | ||
fileTree: FileTree, | ||
|
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.