Skip to content

Commit

Permalink
Formatted files + eslint modified
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Frederiksen authored and maxfrederiksen-ess committed Jan 16, 2025
1 parent ebd50b4 commit 26cf6f7
Show file tree
Hide file tree
Showing 157 changed files with 5,862 additions and 5,046 deletions.
362 changes: 205 additions & 157 deletions src/api/ologApi.js

Large diffs are not rendered by default.

104 changes: 49 additions & 55 deletions src/api/ologApi.test.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,57 @@
import { describe, test, expect } from "vitest";
import { removeEmptyKeys } from "./ologApi";

describe("removeEmtpyKeys util", () => {
test("Empty lists are removed", () => {
const result = removeEmptyKeys({
foo: ["bar"],
baz: []
});

test("Empty lists are removed", () => {

const result = removeEmptyKeys({
foo: ["bar"],
baz: []
})

expect(result).toEqual({
foo: ["bar"]
})

expect(result).toEqual({
foo: ["bar"]
});

test("empty strings are removed", () => {

const result = removeEmptyKeys({
foo: "bar",
baz: ""
})

expect(result).toEqual({
foo: "bar"
})

});

test("empty strings are removed", () => {
const result = removeEmptyKeys({
foo: "bar",
baz: ""
});

test("null and undefined values are removed", () => {

const result = removeEmptyKeys({
foo: "bar",
baz: null,
phooey: undefined
})

expect(result).toEqual({
foo: "bar"
})


expect(result).toEqual({
foo: "bar"
});
});

test("null and undefined values are removed", () => {
const result = removeEmptyKeys({
foo: "bar",
baz: null,
phooey: undefined
});

test("exceptions are excluded", () => {

const result = removeEmptyKeys({
foo: "bar",
baz: null,
phooey: undefined,
whamo: []
}, ["baz", "phooey", "whamo"]);

expect(result).toEqual({
foo: "bar",
baz: null,
phooey: undefined,
whamo: []
})


expect(result).toEqual({
foo: "bar"
});
});

test("exceptions are excluded", () => {
const result = removeEmptyKeys(
{
foo: "bar",
baz: null,
phooey: undefined,
whamo: []
},
["baz", "phooey", "whamo"]
);

expect(result).toEqual({
foo: "bar",
baz: null,
phooey: undefined,
whamo: []
});
});
});
});
61 changes: 29 additions & 32 deletions src/beta/components/common/UserAvatar.jsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
import { Avatar } from "@mui/material";
import React from "react";

/*
* Demonstration by MUI of transforming string into a unique hex value
*/
const stringToColor = (string) => {
let hash = 0;
let i;

/* eslint-disable no-bitwise */
for (i = 0; i < string.length; i += 1) {
hash = string.charCodeAt(i) + ((hash << 5) - hash);
}

let color = '#';

for (i = 0; i < 3; i += 1) {
const value = (hash >> (i * 8)) & 0xff;
color += `00${value.toString(16)}`.slice(-2);
}
/* eslint-enable no-bitwise */

return color;
}
let hash = 0;
let i;

/* eslint-disable no-bitwise */
for (i = 0; i < string.length; i += 1) {
hash = string.charCodeAt(i) + ((hash << 5) - hash);
}

let color = "#";

for (i = 0; i < 3; i += 1) {
const value = (hash >> (i * 8)) & 0xff;
color += `00${value.toString(16)}`.slice(-2);
}
/* eslint-enable no-bitwise */

const UserAvatar = ({user, size=36, ...props}) => {
return color;
};

return (
<Avatar
alt={user.userName}
sx={{ width: size, height: size, bgcolor: stringToColor(user.userName) }}
{...props}
>
{user.userName.slice(0,2)}
</Avatar>
)
}
const UserAvatar = ({ user, size = 36, ...props }) => {
return (
<Avatar
alt={user.userName}
sx={{ width: size, height: size, bgcolor: stringToColor(user.userName) }}
{...props}
>
{user.userName.slice(0, 2)}
</Avatar>
);
};

export default UserAvatar;
export default UserAvatar;
2 changes: 0 additions & 2 deletions src/beta/components/log/EntryTypeChip.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Chip } from "@mui/material";
import React from "react";

export const EntryTypeChip = ({ value, ...props }) => (
<Chip
label={`${value}`}
Expand Down
55 changes: 37 additions & 18 deletions src/beta/components/log/LogDetails/AttachmentsGallery.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,49 @@ import {
Link,
Stack,
styled,
Typography,
Typography
} from "@mui/material";
import React, { useState } from "react";
import { FileImage } from "components/Attachment";
import Modal from "components/shared/Modal";
import { useState } from "react";
import NavigateNextIcon from "@mui/icons-material/NavigateNext";
import NavigateBeforeIcon from "@mui/icons-material/NavigateBefore";
import { FileImage } from "components/Attachment";
import Modal from "components/shared/Modal";

const Image = styled(({ attachment, className }) => {
return (
<img className={className} alt={attachment.filename} src={attachment.url} />
<img
className={className}
alt={attachment.filename}
src={attachment.url}
/>
);
})(({ size, fullSize, maxHeight, maxWidth }) => {
if (fullSize) {
return {
objectFit: "contain",
maxHeight,
maxWidth,
maxWidth
};
} else {
return {
height: size,
width: size,
objectFit: "cover",
objectFit: "cover"
};
}
});

const FileLink = ({ attachment, size }) => (
<Link href={attachment.url} download>
<Link
href={attachment.url}
download
>
<FileImage
alt={`file: ${attachment.filename}`}
fontSize={size}
sx={{
height: size,
width: size,
width: size
}}
/>
</Link>
Expand Down Expand Up @@ -71,7 +78,7 @@ const GalleryView = ({ attachments, onPrevious, onNext, currentIndex }) => {
attachment,
fullSize: true,
maxHeight: "500px",
maxWidth: "100%",
maxWidth: "100%"
}}
/>
</Box>
Expand Down Expand Up @@ -134,14 +141,21 @@ const AttachmentsGallery = ({ attachments, size = 100 }) => {

return (
<Stack onKeyUp={onKeyPress}>
<ImageList gap={5} cols={10} sx={{ marginBottom: 0 }}>
<ImageList
gap={5}
cols={10}
sx={{ marginBottom: 0 }}
>
{imageAttachments.map((attachment, index) => (
<ImageListItem
key={attachment.id}
onClick={() => onClick(index)}
sx={{ cursor: "pointer" }}
>
<Image attachment={attachment} size={size} />
<Image
attachment={attachment}
size={size}
/>
<ImageListItemBar
position="below"
title={renderAttachmentTitle(attachment)}
Expand All @@ -150,22 +164,27 @@ const AttachmentsGallery = ({ attachments, size = 100 }) => {
"& div": {
fontSize: "0.8rem",
fontStyle: "italic",
paddingBottom: 0,
},
paddingBottom: 0
}
}}
/>
</ImageListItem>
))}
{fileAttachments.map((attachment) => (
<Stack
key={attachment.id}
sx={{
cursor: "pointer",
"&:hover > a > div > .file-overlay": {
display: "block",
},
display: "block"
}
}}
>
<FileLink key={attachment.id} attachment={attachment} size={size} />
<FileLink
key={attachment.id}
attachment={attachment}
size={size}
/>
<Stack flexDirection="row">
<Typography
pl={2}
Expand All @@ -192,7 +211,7 @@ const AttachmentsGallery = ({ attachments, size = 100 }) => {
currentIndex,
setCurrentIndex,
onPrevious,
onNext,
onNext
}}
/>
}
Expand Down
21 changes: 13 additions & 8 deletions src/beta/components/log/LogDetails/CopyUrlButton.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import React, { useEffect, useState } from "react";
import { useEffect, useState } from "react";
import { Alert, Button, Tooltip, styled, tooltipClasses } from "@mui/material";
import ContentCopyOutlined from "@mui/icons-material/ContentCopyOutlined";

const StyledTooltip = styled(({ className, ...props }) => {
return <Tooltip {...props} classes={{ popper: className }} />;
})(({ theme }) => ({
return (
<Tooltip
{...props}
classes={{ popper: className }}
/>
);
})(() => ({
[`& .${tooltipClasses.tooltip}`]: {
backgroundColor: "transparent",
},
backgroundColor: "transparent"
}
}));

const CopyUrlButton = ({ url }) => {
Expand Down Expand Up @@ -44,8 +49,8 @@ const CopyUrlButton = ({ url }) => {
padding: "5px 10px",
"& .MuiAlert-icon": {
fontSize: "1.2rem",
marginRight: "10px",
},
marginRight: "10px"
}
}}
>
URL copied!
Expand All @@ -56,7 +61,7 @@ const CopyUrlButton = ({ url }) => {
disableHoverListener
disableTouchListener
PopperProps={{
disablePortal: true,
disablePortal: true
}}
>
<Button
Expand Down
Loading

0 comments on commit 26cf6f7

Please sign in to comment.