Skip to content

Commit

Permalink
Merge branch 'staging' of github.com:3drepo/3drepo.io into ISSUE_5287
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan-Crn committed Dec 23, 2024
2 parents f3c8bd4 + 3ebc9a1 commit 910d949
Show file tree
Hide file tree
Showing 28 changed files with 534 additions and 2,072 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"mime-types": "2.1.35",
"moment": "2.30.1",
"moment-timezone": "0.5.45",
"mongodb": "3.7.3",
"mongodb": "3.7.4",
"multer": "1.4.5-lts.1",
"nodemailer": "6.9.14",
"openapi-schema-validator": "12.1.3",
Expand Down
11 changes: 9 additions & 2 deletions backend/src/v5/models/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@

const { INTERNAL_DB } = require('../handler/db.constants');
const db = require('../handler/db');
const { logger } = require('../utils/logger');

const Notifications = {};
const NOTIFICATIONS_COLL = 'notifications';

Notifications.initialise = () => db.createIndex(INTERNAL_DB, NOTIFICATIONS_COLL,
{ user: 1, timestamp: -1 }, { runInBackground: true });
Notifications.initialise = async () => {
try {
await db.createIndex(INTERNAL_DB, NOTIFICATIONS_COLL,
{ user: 1, timestamp: -1 }, { runInBackground: true });
} catch (err) {
logger.logError(`Failed to create index for notification: ${err.message}`);
}
};

Notifications.removeAllUserNotifications = async (user) => {
await db.deleteMany(INTERNAL_DB, NOTIFICATIONS_COLL, { user });
Expand Down
9 changes: 9 additions & 0 deletions backend/tests/v5/unit/models/notifications.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ const testInitialise = () => {
expect(fn).toHaveBeenCalledWith(INTERNAL_DB, NOTIFICATIONS_COLL,
{ user: 1, timestamp: -1 }, { runInBackground: true });
});

test('should not cause issues if this operation failed', async () => {
const err = { message: generateRandomString() };
const fn = jest.spyOn(db, 'createIndex').mockRejectedValueOnce(err);
await Notifications.initialise();
expect(fn).toHaveBeenCalledTimes(1);
expect(fn).toHaveBeenCalledWith(INTERNAL_DB, NOTIFICATIONS_COLL,
{ user: 1, timestamp: -1 }, { runInBackground: true });
});
});
};

Expand Down
708 changes: 384 additions & 324 deletions backend/yarn.lock

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"@hotjar/browser": "1.0.9",
"@mui/icons-material": "5.16.7",
"@mui/lab": "5.0.0-alpha.71",
"@mui/material": "5.12.0",
"@mui/system": "5.4.1",
"@mui/material": "5.16.7",
"@mui/system": "5.16.7",
"@mui/x-date-pickers": "5.0.3",
"@popperjs/core": "2.6.0",
"@types/three": "0.167.1",
Expand All @@ -58,7 +58,6 @@
"bezier-easing": "2.1.0",
"byte-size": "8.1.0",
"connected-react-router": "6.9.1",
"contrast-color": "1.0.1",
"copy-to-clipboard": "3.2.0",
"countries-and-timezones": "3.3.0",
"dayjs": "1.11.13",
Expand Down Expand Up @@ -144,7 +143,6 @@
"@storybook/react": "7.6.20",
"@storybook/react-webpack5": "7.6.20",
"@storybook/testing-library": "0.2.1",
"@types/contrast-color": "1.0.0",
"@types/faker": "5.5.8",
"@types/jest": "26.0.24",
"@types/lodash": "4.14.171",
Expand Down
19 changes: 17 additions & 2 deletions frontend/src/v5/helpers/colors.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { contrastColor } from 'contrast-color';
import { rgbToHex as muiRgbToHex, hexToRgb as muiHexToRgb } from '@mui/material';
import { isNumber, memoize } from 'lodash';

Expand All @@ -28,7 +27,23 @@ export type RgbGroupColor = GroupColor & { color?: RgbArray };
export type HexGroupColor = GroupColor & { color?: string };

// Misc
export const isLight = (hex: string, freshold?: number) => contrastColor({ bgColor: hex, threshold: freshold ?? 127 }) !== '#FFFFFF';
export const contrastColor = ({ hex = '#FFFFFF', threshold }) => {
if (hex.indexOf('#') === 0) {
hex = hex.slice(1);
}
if (hex.length === 3) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
const r = parseInt(hex.slice(0, 2), 16);
const g = parseInt(hex.slice(2, 4), 16);
const b = parseInt(hex.slice(4, 6), 16);

return (r * 0.299 + g * 0.587 + b * 0.114) > (threshold ?? 127)
? '#000000'
: '#FFFFFF';
};

export const isLight = (hex: string, threshold?: number) => contrastColor({ hex, threshold }) !== '#FFFFFF';

export const getRandomRgbColor = () => ([
parseInt((Math.random() * 255).toFixed(0), 10),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from '@mui/material';
import { FormInputProps } from '@controls/inputs/inputController.component';

export type SelectProps = Omit<MuiSelectProps, 'children'> & FormInputProps & { children?: any[] };
export type SelectProps = Omit<MuiSelectProps, 'variant'> & FormInputProps & { children?: any[] };

export const Select = ({
required = false,
Expand All @@ -34,7 +34,7 @@ export const Select = ({
}: SelectProps) => (
<FormControl required={required} disabled={props.disabled} error={props.error} className={className}>
<InputLabel id={`${props.name}-label`}>{label}</InputLabel>
<MuiSelect renderValue={(value) => props.children.find(({ key }) => key === value)?.props.children ?? value} {...props}/>
<MuiSelect renderValue={(value) => props.children.find(({ key }) => key === value)?.props.children ?? value} {...props} />
<FormHelperText>{helperText}</FormHelperText>
</FormControl>
);
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const CalibrationHeader = () => {
<Stepper activeStep={step} alternativeLabel connector={<Connector />} >
{STEPS.map((label) => (
<Step key={label}>
<StepLabel StepIconComponent={({ icon }) => icon}>{label}</StepLabel>
<StepLabel StepIconComponent={({ icon }) => icon as any}>{label}</StepLabel>
</Step>
))}
</Stepper>
Expand Down
Loading

0 comments on commit 910d949

Please sign in to comment.