Skip to content
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

Feat/add tag binding #90

Merged
merged 24 commits into from
Oct 11, 2023
Merged

Feat/add tag binding #90

merged 24 commits into from
Oct 11, 2023

Conversation

Lerri-Cofannos
Copy link
Collaborator

@Lerri-Cofannos Lerri-Cofannos commented Oct 6, 2023

Waiting for TagsAPI routes to be functional.
Ticket for logs table
Ticket for details page
Screenshot 2023-10-11 at 09 53 09
Screenshot 2023-10-11 at 09 52 58

@Lerri-Cofannos Lerri-Cofannos marked this pull request as ready for review October 10, 2023 14:14

const colourPicker = (colour: string): string => {
const blueStyle = "bg-theodo-turquoise hover:bg-omnilog-clear-blue";
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this colourPicker specific to the button? If so, maybe include that in the name? Before I understood the function I thought if might be better living outside this folder, but actually it's looks specific to button? Probably good to make this clear in the name

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 can add it in the name, but this function is not exported so I thought it was clear that the scope was restrained to this file. I will rename it to buttonColourPicker.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason that this component can't extend your non-icon button?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The style of both components are a bit different: this one has grey scale colours and is a circle.

Comment on lines 49 to 51
<Button colour="blue" onClick={() => {}}>
Useless Validation
</Button>
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was to prepare for the "Create New Tag" button, but since it would be pushed to prod before this feature appears, then I'll remove it. I'll also remove the "Cancel" button which is redundant with the top exit button of the Popup component

@@ -3,7 +3,7 @@ import { Button } from "@/components/atoms/Button";
import { CardAtom } from "@/components/atoms/CardAtom";
import { useNavigation } from "@/hooks/useNavigation";
import { LogData } from "@/types/logDisplayOptions";
import { ColumnContentTags } from "./components/ColumnContentTags";
import { ColumnContentTags } from "../components/ColumnContentTags";
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious why some of your imports are relative and others are absolute?

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 took the habit of writing the imports that are linked to the same feature as relative, and the ones which are not as absolute. Is this bad practice ?

import { MouseEventHandler } from "react";

type ButtonIconProps = {
onClick: MouseEventHandler<HTMLButtonElement> | (() => void);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need two types here? Why not just mouse event handler?

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 thought that the two were too different, but you are right, casting () => void to the event handler works great!

export const Popup = ({ children, open, setOpen }: PopupProps) => {
return (
<Transition.Root show={open} as={Fragment}>
<Dialog as="div" className="relative z-10" onClose={() => {}}>
Copy link
Contributor

Choose a reason for hiding this comment

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

close is a different ticket im assuming?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Close is a compulsory prop of the Dialog component. It is called when clicking outside of the modal. I deactivated that behaviour to avoid a bug. The bug was that exiting with such a click navigated the user to the corresponding log. I suspect that the event that I had caught with e.stopPropagate in openPopup is freed and thus a click is made on the log's row, making the user navigate to it. I did not find a quick solution on the documentation.

Copy link
Contributor

Choose a reason for hiding this comment

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

How do users close the dialog in this case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is a button in the top right corner (see screenshot)

logId: string;
}) => {
const [tagArray, setTagArray] = useState<Tag[]>(tags);
const addTag = (tag: Tag) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

so this is just setting it locally for now?

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, the idea is to update the database and the UI at the same time so that the user sees the new tag on his log without having to refresh the whole page. To do that I had to store the tags in this state.

};

export const TagPopup = ({ logId, addTagToDisplay }: TagPopupProps) => {
const { isPopupOpen, openPopup, setIsPopupOpen, tags, selectTag } =
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems odd. Wouldn't setIsPopUpOpen be dependent on the openPopup call? I don't think we need this much state

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe it's needed but this seems a bit confusing to me

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The openPopup is dependent on setIsOpenPopup, but adds an event handler to prevent click propagation. I have replaced the function setIsOpenPopup with closePopup to stay consistent in the naming

});
};

const compareStrings = (stringA: string, stringB: string): number => {
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm I thought sort basically did this by default, interesting you needed to define a sort function yourself since its a basic string sort

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't you just do return newTagArray.sort(tagA.toLowerCase(), tagB.toLowerCase());

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 did a little research and found a built-in function that compares string based on alphabetical order. New commit incoming!

setIsPopupOpen(true);
};

return { isPopupOpen, openPopup, setIsPopupOpen, tags, selectTag };
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I feel like you shouldn't need to expose setIsPopupOpen outside fo this hook, like an openPopUp and closePopUp method shoudl only be exposed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch! I'll add a commit for this.

@Lerri-Cofannos Lerri-Cofannos merged commit 15227d0 into main Oct 11, 2023
1 check passed
@Lerri-Cofannos Lerri-Cofannos deleted the feat/add-tag-binding branch October 11, 2023 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants