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

Conversation

BrunoQuaresma
Copy link
Collaborator

Close #9942

@BrunoQuaresma BrunoQuaresma requested a review from a team November 2, 2023 11:22
@BrunoQuaresma BrunoQuaresma self-assigned this Nov 2, 2023
@BrunoQuaresma BrunoQuaresma requested review from Kira-Pilot and removed request for a team November 2, 2023 11:22
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.

@Parkreiner
Copy link
Member

Have 7/8 files done – just need to finish up TemplateVersionEditorPage. Hoping to have this all done soon, but it'll definitely be done by end of day

Copy link
Member

@Parkreiner Parkreiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks really good. Had a couple questions/suggestions, but the only part I have potential concerns about is how useFileTree sets up state

jest
.spyOn(api, "createTemplateVersion")
.mockResolvedValueOnce(MockTemplateVersion);
.mockResolvedValue(newTemplateVersion);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double-checking for my own understanding: is there any real difference between the mock function returning the base MockTemplateVersion value, versus it returning the updated version?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because we are going to use this version to optimistically update the UI.

);
const templateVersionQuery = useQuery({
...templateVersionOptions,
keepPreviousData: true,
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly!

}}
/>
)}
</>
);
};

const useFileTree = (templateVersion: TemplateVersion | undefined) => {
const tarFileRef = useRef<TarReader | null>(null);
Copy link
Member

Choose a reason for hiding this comment

The 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 tarFile and fileTree into one single useState call. Something like this:

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 });
};
  • Right now, it looks like they're always supposed to be used together. Combining them would make sure that it's impossible to have one without the other.
  • tarFile is set up with useRef right now, even though the inner value is referenced directly in render logic. My worry is that if the logic gets more complicated later, someone might update tarFileRef when they want a re-render, but not realize why the screen isn't changing
  • There is the tarFileRef.current write before createTemplateVersionFileTree gets called, but it doesn't seem that delaying the state change until after initializeFileTree resolves would affect anything?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome points.

1 - I think makes sense
2, 3 - This initialization should happen only once

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it to a single state call!

group: file.group,
});
} else {
tar.addFile(file.name, tarReader.getTextFile(file.name) as string, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be some error handling in the off chance tarReader.getTextFile returns undefined?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this specific use case, we can just ignore it for now.


// Optimistically update the template version data job status to make the
// build action feels faster
const onBuildStart = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could some of this functionality be done via useMutation's onMutate and onSuccess callbacks? onMutate also lets you return out a cleanup function

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 don't think so because this is not related to a specific mutation.

Copy link
Member

@Parkreiner Parkreiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My biggest concern got addressed, so I'm going to go ahead and approve, just to make sure you're not blocked

@BrunoQuaresma BrunoQuaresma merged commit c9aeea6 into main Nov 3, 2023
@BrunoQuaresma BrunoQuaresma deleted the bq/refactor-template-editor branch November 3, 2023 00:42
@github-actions github-actions bot locked and limited conversation to collaborators Nov 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Additional Batch #3 - Replace XState by react-query
2 participants