Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit 8381e02

Browse files
authored
feat: quick features (#233)
* feat(logs): show logs in an improved way * feat(EID): add to clipboard button * fix(table): Capilalise first letter * fix(type): make a new isNullish function * fix(function): make success and failed funcions more readable
1 parent f2ad769 commit 8381e02

File tree

7 files changed

+58
-26
lines changed

7 files changed

+58
-26
lines changed

aqueductcore/frontend/src/components/molecules/LogViewer/index.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Box, styled } from "@mui/material";
22

3-
import { logArray } from "types/componentTypes";
3+
import { logType } from "types/componentTypes";
4+
import { isNullish } from "helper/functions";
45

56
interface LogViewerProps {
6-
log: logArray
7+
log: logType[]
78
}
89

910
const LogViewerBox = styled(Box)`
@@ -18,8 +19,14 @@ const LogText = styled("pre")`
1819
`;
1920

2021
const prettyPrint = (log: LogViewerProps['log']) => {
21-
return log.map(logItem => (
22-
`${logItem.label}: \t\t ${logItem.value} \n`
22+
function prettifyValue(value: logType['value']) {
23+
if (value && String(value).includes('\n'))
24+
return String(value).split('\n').map(valueItem => `\n\t\t\t${valueItem}`).join('')
25+
else
26+
return `\t\t"${value}"`
27+
}
28+
return log.filter(logItem => !isNullish(logItem)).map(logItem => (
29+
`${logItem.label}: ${prettifyValue(logItem.value)}\n`
2330
))
2431
};
2532

aqueductcore/frontend/src/components/organisms/ExperimentDetailsActionButtons/index.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import toast from "react-hot-toast";
1010
import { useState } from "react";
1111

1212
import { BorderedButtonWithIcon } from "components/atoms/sharedStyledComponents/BorderedButtonWithIcon"
13+
import { copyToClipboardFailedWithMessage, copyToClipboardWithSuccessMessage } from 'helper/functions';
1314
import { useRemoveTagFromExperiment } from "API/graphql/mutations/experiment/removeTagFromExperiment";
1415
import { useAddTagToExperiment } from "API/graphql/mutations/experiment/addTagToExperiment";
1516
import { useRemoveExperiment } from "API/graphql/mutations/experiment/removeExperiment";
@@ -140,16 +141,8 @@ function ExperimentDetailsActionButtons({ isEditable, isDeletable, experimentDet
140141
navigator.clipboard
141142
.writeText(`${window.location.origin}/aqd/experiments/${experimentDetails.eid}`)
142143
.then(
143-
() => {
144-
toast.success("Copied to clipboard!", {
145-
id: "clipboard",
146-
});
147-
},
148-
() => {
149-
toast.error("Failed! \n Please copy page's URL manually.", {
150-
id: "clipboard-failed",
151-
});
152-
}
144+
() => copyToClipboardWithSuccessMessage(), //Success
145+
() => copyToClipboardFailedWithMessage("Failed! \n Please copy page's URL manually.") //Failure
153146
);
154147
}
155148

aqueductcore/frontend/src/components/organisms/ExperimentDetailsData/index.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { Box, Chip, Grid, List, ListItem, Typography, styled } from "@mui/material"
2-
import { useGetAllTags } from "API/graphql/queries/experiment/getAllTags";
1+
import { Box, Chip, Grid, IconButton, List, ListItem, Typography, styled } from "@mui/material"
2+
import LinkIcon from "@mui/icons-material/Link";
33
import toast from "react-hot-toast";
44
import { useState } from "react";
55

6+
import { copyToClipboardFailedWithMessage, copyToClipboardWithSuccessMessage } from "helper/functions";
67
import { useRemoveTagFromExperiment } from "API/graphql/mutations/experiment/removeTagFromExperiment";
78
import { useAddTagToExperiment } from "API/graphql/mutations/experiment/addTagToExperiment";
89
import { dateFormatter, removeFavouriteAndArchivedTag } from "helper/formatters";
10+
import { useGetAllTags } from "API/graphql/queries/experiment/getAllTags";
911
import { ExperimentDataType, TagType } from "types/globalTypes";
1012
import { MAX_TAGS_VISIBLE_LENGTH } from "constants/constants";
1113
import { EditTags } from "components/molecules/EditTags";
@@ -14,15 +16,13 @@ const ExperimentDetailsTitle = styled(Typography)`
1416
font-weight: 400;
1517
font-size: 0.9rem;
1618
margin-right: ${(props) => `${props.theme.spacing(1)}`};
17-
line-height: ${(props) => `${props.theme.spacing(3)}`};
1819
padding: ${(props) => `${props.theme.spacing(0.75)}`} ${(props) => `${props.theme.spacing(1)}`};
1920
`;
2021

2122
const ExperimentDetailsContent = styled(Typography)`
2223
font-weight: 500;
2324
font-weight: bold;
2425
font-size: 0.9rem;
25-
line-height: ${(props) => `${props.theme.spacing(3)}`};
2626
`;
2727

2828
interface experimentDetailsDataProps {
@@ -75,13 +75,28 @@ function ExperimentDetailsData({ experimentDetails, isEditable }: experimentDeta
7575
});
7676
}
7777
};
78+
79+
function handleCopyEIDToClipboard() {
80+
navigator.clipboard
81+
.writeText(experimentDetails.eid)
82+
.then(
83+
() => copyToClipboardWithSuccessMessage(), //Success
84+
() => copyToClipboardFailedWithMessage("Failed! \n Please copy EID manually.") //Failure
85+
);
86+
}
87+
7888
return (
7989
<Grid container sx={{ mt: 2 }}>
8090
<Grid item sx={{ mr: 4 }}>
8191
<List>
8292
<ListItem sx={{ pl: 1, pr: 1 }}>
8393
<ExperimentDetailsTitle>Experiment ID: </ExperimentDetailsTitle>
84-
<ExperimentDetailsContent>{experimentDetails.eid}</ExperimentDetailsContent>
94+
<ExperimentDetailsContent>
95+
{experimentDetails.eid}
96+
</ExperimentDetailsContent>
97+
<IconButton size="small" aria-label="copy-eid" onClick={handleCopyEIDToClipboard} >
98+
<LinkIcon />
99+
</IconButton>
85100
</ListItem>
86101
<ListItem sx={{ pl: 1, pr: 1 }}>
87102
<ExperimentDetailsTitle>Time Created: </ExperimentDetailsTitle>

aqueductcore/frontend/src/components/organisms/TaskListInExperimentDetails/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const TasksListColumns: readonly TasksListColumnsType[] = [
4646
},
4747
{
4848
id: "receivedAt",
49-
label: "submission Time",
49+
label: "Submission Time",
5050
format: (createdAt) =>
5151
typeof createdAt === "string" ? dateFormatter(new Date(createdAt)) : "",
5252
},
@@ -66,7 +66,7 @@ function TaskListInExperimentDetails({ experimentUuid }: { experimentUuid: Exper
6666
}
6767
},
6868
},
69-
fetchPolicy: "network-only",
69+
fetchPolicy: "network-only"
7070
});
7171
const pageInfo = {
7272
page,

aqueductcore/frontend/src/helper/functions.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { DependencyList, FocusEvent, useEffect, useRef } from "react";
2+
import toast from "react-hot-toast";
23
import dayjs from "dayjs";
34

4-
import { SortOrder } from "types/componentTypes";
55
import { ExperimentFileType } from "types/globalTypes";
6+
import { SortOrder } from "types/componentTypes";
67

78
// ################## DOM related functions ################## //
89
export const focusInCurrentTarget = ({
@@ -84,4 +85,20 @@ export function stableSort<T>(array: readonly T[], comparator: (a: T, b: T) => n
8485
return a[1] - b[1];
8586
});
8687
return stabilizedThis.map((el) => el[0]);
87-
}
88+
}
89+
90+
export function isNullish(value: unknown): value is null | undefined {
91+
return value === null || value === undefined;
92+
}
93+
94+
// ################## Copy to Clipboard Functions ################## //
95+
export function copyToClipboardWithSuccessMessage(message?: string): void | PromiseLike<void> {
96+
toast.success(message ?? "Copied to clipboard!", {
97+
id: "clipboard",
98+
});
99+
}
100+
export function copyToClipboardFailedWithMessage(message?: string): void | PromiseLike<void> {
101+
toast.error(message ?? "Copy to clipboard Failed!", {
102+
id: "clipboard-failed",
103+
});
104+
}

aqueductcore/frontend/src/pages/TaskHistoryPage/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const TasksListColumns: readonly TasksListColumnsType[] = [
6666
},
6767
{
6868
id: "receivedAt",
69-
label: "submission Time",
69+
label: "Submission Time",
7070
format: (createdAt) =>
7171
typeof createdAt === "string" ? dateFormatter(new Date(createdAt)) : "",
7272
},

aqueductcore/frontend/src/types/componentTypes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export type FileSelectContextType = {
1919
setSelectedFile: React.Dispatch<React.SetStateAction<string | undefined>>
2020
}
2121

22-
export type logArray = Array<{
22+
export type logType = {
2323
label: string,
2424
value: string | number | undefined | null
25-
}>
25+
}

0 commit comments

Comments
 (0)