Skip to content

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

Merged
merged 24 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
Fix loading state and tabs code to make it clear
  • Loading branch information
BrunoQuaresma committed Nov 1, 2023
commit 9d1ca6190343c9dc41a2df9ab02b9d6e13e3161b
23 changes: 12 additions & 11 deletions site/src/pages/TemplateVersionEditorPage/TemplateVersionEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ export const TemplateVersionEditor: FC<TemplateVersionEditorProps> = ({
onCancelSubmitMissingVariableValues,
}) => {
const theme = useTheme();
// If resources are provided, show them by default!
// This is for Storybook!
const [selectedTab, setSelectedTab] = useState(() => (resources ? 1 : 0));
const [selectedTab, setSelectedTab] = useState<
"logs" | "resources" | undefined // Undefined is to hide the tab
>();
const [fileTree, setFileTree] = useState(defaultFileTree);
const [createFileOpen, setCreateFileOpen] = useState(false);
const [deleteFileOpen, setDeleteFileOpen] = useState<string>();
Expand All @@ -126,7 +126,7 @@ export const TemplateVersionEditor: FC<TemplateVersionEditorProps> = ({
const triggerPreview = useCallback(() => {
onPreview(fileTree);
// Switch to the build log!
setSelectedTab(0);
setSelectedTab("logs");
}, [fileTree, onPreview]);

// Stop ctrl+s from saving files and make ctrl+enter trigger a preview.
Expand Down Expand Up @@ -159,11 +159,12 @@ export const TemplateVersionEditor: FC<TemplateVersionEditorProps> = ({
previousVersion.current = templateVersion;
return;
}

if (
["running", "pending"].includes(previousVersion.current.job.status) &&
templateVersion.job.status === "succeeded"
) {
setSelectedTab(1);
setSelectedTab("resources");
setDirty(false);
}
previousVersion.current = templateVersion;
Expand Down Expand Up @@ -358,9 +359,9 @@ export const TemplateVersionEditor: FC<TemplateVersionEditorProps> = ({
<div css={styles.tabs}>
<button
css={styles.tab}
className={selectedTab === 0 ? "active" : ""}
className={selectedTab === "logs" ? "active" : ""}
onClick={() => {
setSelectedTab(0);
setSelectedTab("logs");
}}
>
{templateVersion.job.status !== "succeeded" ? (
Expand All @@ -374,9 +375,9 @@ export const TemplateVersionEditor: FC<TemplateVersionEditorProps> = ({
{!disableUpdate && (
<button
css={styles.tab}
className={selectedTab === 1 ? "active" : ""}
className={selectedTab === "resources" ? "active" : ""}
onClick={() => {
setSelectedTab(1);
setSelectedTab("resources");
}}
>
<PreviewIcon />
Expand All @@ -389,7 +390,7 @@ export const TemplateVersionEditor: FC<TemplateVersionEditorProps> = ({
css={[
styles.panel,
{
display: selectedTab !== 0 ? "none" : "flex",
display: selectedTab !== "logs" ? "none" : "flex",
flexDirection: "column",
},
]}
Expand Down Expand Up @@ -427,7 +428,7 @@ export const TemplateVersionEditor: FC<TemplateVersionEditorProps> = ({
styles.panel,
{
paddingBottom: theme.spacing(2),
display: selectedTab !== 1 ? "none" : undefined,
display: selectedTab !== "resources" ? "none" : undefined,
},
]}
>
Expand Down
Copy link
Collaborator Author

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.

Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const TemplateVersionEditorPage: FC = () => {
}, [fileQuery.data]);

// Watch version logs
const [logs, setLogs] = useState<ProvisionerJobLog[]>([]);
const [logs, setLogs] = useState<ProvisionerJobLog[]>();
const templateVersionId = templateVersionQuery.data?.id;
const refetchTemplateVersion = templateVersionQuery.refetch;
const templateVersionStatus = templateVersionQuery.data?.job.status;
Expand All @@ -99,10 +99,11 @@ export const TemplateVersionEditorPage: FC = () => {
return;
}

setLogs([]);
setLogs(undefined);

const socket = watchBuildLogsByTemplateVersionId(templateVersionId, {
onMessage: (log) => {
setLogs((logs) => [...logs, log]);
setLogs((logs) => (logs ? [...logs, log] : [log]));
},
onDone: async () => {
await refetchTemplateVersion();
Expand Down Expand Up @@ -151,7 +152,9 @@ export const TemplateVersionEditorPage: FC = () => {
template={templateQuery.data}
templateVersion={templateVersionQuery.data}
isBuildingNewVersion={
templateVersionQuery.data.job.status === "running"
templateVersionQuery.data.job.status === "running" ||
uploadFileMutation.isLoading ||
createTemplateVersionMutation.isLoading
}
defaultFileTree={fileTree}
onPreview={async (newFileTree) => {
Expand Down Expand Up @@ -208,10 +211,17 @@ export const TemplateVersionEditorPage: FC = () => {
`/templates/${templateName}/workspace?${params.toString()}`,
);
}}
disablePreview={templateVersionQuery.data.job.status !== "succeeded"}
disableUpdate={
disablePreview={
templateVersionQuery.data.job.status === "running" ||
templateVersionQuery.data.job.status === "succeeded"
(templateVersionQuery.data.job.status === "succeeded" &&
templateVersionQuery.data.name !== initialVersionName) ||
createTemplateVersionMutation.isLoading
}
disableUpdate={
templateVersionQuery.data.job.status !== "succeeded" ||
templateVersionQuery.data.name === initialVersionName ||
templateVersionQuery.data.name ===
lastSuccessfulPublishedVersion?.name
}
resources={resourcesQuery.data}
buildLogs={logs}
Expand Down