Skip to content

Content: UUID Field Revamp #2549

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 18 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const TooltipBody = ({
primaryTypographyProps={{
fontSize: 14,
fontWeight: 700,
color: "text.primary",
}}
secondaryTypographyProps={{
variant: "body3",
Expand Down
123 changes: 88 additions & 35 deletions src/shell/components/FieldTypeUUID/FieldTypeUUID.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import React, { useEffect } from "react";
import cx from "classnames";
import { v4 as uuidv4 } from "uuid";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faClipboard } from "@fortawesome/free-solid-svg-icons";
import { Input } from "@zesty-io/core/Input";

import {
TextField,
InputAdornment,
Tooltip,
IconButton,
tooltipClasses,
} from "@mui/material";
import styles from "./FieldTypeUUID.less";
import TagIcon from "@mui/icons-material/Tag";
import ContentCopyRoundedIcon from "@mui/icons-material/ContentCopyRounded";
import CheckIcon from "@mui/icons-material/Check";

export const FieldTypeUUID = React.memo(function FieldTypeUUID(props) {
// console.log("FieldTypeUUID:render");

const [isCopied, setIsCopied] = React.useState(false);
useEffect(() => {
// NOTE may want to add a check to ensure the itemZUID is 'new'
if (props.name && !props.value) {
Expand All @@ -18,39 +23,87 @@ export const FieldTypeUUID = React.memo(function FieldTypeUUID(props) {
}
}, []);

// Set isCopied to false after 5 seconds
useEffect(() => {
if (isCopied) {
const timeout = setTimeout(() => {
setIsCopied(false);
}, 5000);
// Clear timeout if the component is unmounted
return () => clearTimeout(timeout);
}
}, [isCopied]);

return (
<label className={cx(styles.FieldTypeUUID, props.className)}>
<div className={styles.DateFieldTypeInput}>
<FontAwesomeIcon
className={styles.Icon}
icon={faClipboard}
aria-hidden="true"
title="Click to Copy"
onClick={(e) => {
const input = document.createElement("input");
document.body.appendChild(input);
input.value = props.value;
input.focus();
input.select();
const result = document.execCommand("copy");
input.remove();
if (result === "unsuccessful") {
return props.dispatch(
notify({
type: "error",
message: "Failed to copy the team ID to your clipboard",
})
);
}
<div>
<Tooltip
slotProps={{
popper: {
modifiers: [
{
name: "offset",
options: {
offset: [0, -47],
},
},
],
},
}}
/>
placement="top"
title="This field cannot be edited"
>
<TextField
required={props.required}
value={props.value || ""}
readOnly={true}
fullWidth
type="text"
sx={{
caretColor: "transparent", // This is to hide the cursor in the input field
Copy link
Contributor

@agalin920 agalin920 Feb 26, 2024

Choose a reason for hiding this comment

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

This seems like bad very bad UX. Why would we want a user to lose track of their cursor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not the cursor, actually but just the caret to make the button behave like disabled. it's just the blinking cursor along text inputs.

input text can't be modified i did this just to hide the blinking cursor inside textfield @agalin920

Copy link
Contributor

Choose a reason for hiding this comment

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

We have not followed this pattern. Use the pattern where the input is properly disabled but the read only style text color is changed

}}
InputProps={{
startAdornment: (
<InputAdornment position="start" sx={{ marginRight: 0 }}>
<TagIcon fontSize="small" />
</InputAdornment>
),

<Input
type="text"
readOnly={true}
required={props.required}
defaultValue={props.value || ""}
/>
endAdornment: (
<InputAdornment position="end">
<IconButton
size="small"
onClick={() => {
const input = document.createElement("input");
document.body.appendChild(input);
input.value = props.value;
input.focus();
input.select();
const result = document.execCommand("copy");
input.remove();
if (result === "unsuccessful") {
return props.dispatch(
notify({
type: "error",
message:
"Failed to copy the team ID to your clipboard",
})
);
}
setIsCopied(true);
}}
>
{isCopied ? (
<CheckIcon fontSize="small" />
) : (
<ContentCopyRoundedIcon fontSize="small" />
)}
</IconButton>
</InputAdornment>
),
}}
/>
</Tooltip>
</div>
</label>
);
Expand Down