🩹 front: use logger instead of console (#50)

This commit is contained in:
Eric Doughty-Papassideris
2024-05-07 13:29:18 +02:00
committed by ericlinagora
parent e6234f97e4
commit 9048ce7094
3 changed files with 17 additions and 8 deletions
@@ -6,6 +6,9 @@ import {
DriveFileAccessLevelForPublicLink,
DriveItem,
} from '@features/drive/types';
import Logger from '@features/global/framework/logger-service';
const getLogger = () => Logger.getLogger('access-info-helpers');
const entityMatcher = (entityType: AuthEntity['type'], entityId?: string) =>
(entity: AuthEntity) =>
@@ -14,7 +17,7 @@ const entityMatcher = (entityType: AuthEntity['type'], entityId?: string) =>
/** Updates the level of entities matching the given type and id, or adds the return
* of updater with no argument.
*
* If an item is not unique, all are modified and a console warning is printed except for `entityType` "channel".
* If an item is not unique, all are modified and a logger warning is printed except for `entityType` "channel".
*/
function upsertEntities(
entities: AuthEntity[] | undefined,
@@ -34,7 +37,7 @@ function upsertEntities(
const matcher = entityMatcher(entityType, entityId);
const mapped = entities.map(item => {
if (!matcher(item)) return item;
if (found && entityType != "channel") console.warn(`DriveItem has more than one access_info entry for '${entityType}' id = ${entityId}:`, item);
if (found && entityType != "channel") getLogger().warn(`DriveItem has more than one access_info entry for '${entityType}' id = ${entityId}:`, item);
found = true;
return updater(item);
}).filter(x => x);
@@ -83,12 +86,12 @@ const itemWithEntityAccessChanged = (
},
} as DriveItem);
// Note this just assumes uniqueness and just logs in the console if that is not the case and uses the first one.
// Note this just assumes uniqueness and just logs if that is not the case and uses the first one.
const getAccessLevelOfUniqueForType = (item: DriveItem | undefined, entityType: AuthEntity['type'], entityId?: string) => {
if (!item) return undefined;
const accesses = item.access_info.entities.filter(entityMatcher(entityType, entityId));
if (accesses.length != 1 && entityType != "channel")
console.warn(`DriveItem doesn't have exactly one access_info entry for '${entityType}${entityId ? " id: " + entityId : ""}':`, item);
getLogger().warn(`DriveItem doesn't have exactly one access_info entry for '${entityType}${entityId ? " id: " + entityId : ""}':`, item);
return accesses[0]?.level;
}
@@ -99,7 +102,7 @@ export const changeUserAccess = (item: DriveItem, userId: string, level: DriveFi
/** Return a list of all DriveItemAccessInfo for users sorted by id */
export const getAllUserAccesses = (item: DriveItem) => accessInfosOfEntitiesOfType(item, "user");
/** Return the access level for the provided user; an entry is expected to exist (or there is a `console.warn`) */
/** Return the access level for the provided user; an entry is expected to exist (or there is a `logger.warn`) */
export const getUserAccessLevel = (item: DriveItem, userId: string) => getAccessLevelOfUniqueForType(item, "user", userId);
@@ -4,6 +4,7 @@ import 'moment/min/locales';
import { useEffect, useRef, useState } from 'react';
import { uniqueId } from 'lodash';
import Logger from '@features/global/framework/logger-service';
import Languages from 'features/global/services/languages-service';
import BaseBlock from '@molecules/grouped-rows/base';
@@ -16,6 +17,8 @@ import { ConfirmModal } from 'app/atoms/modal/confirm';
import Styles from './styles';
const getLogger = () => Logger.getLogger('expiry-editor-row');
export const ExpiryEditorRow = (props: {
disabled?: boolean;
value: number;
@@ -54,7 +57,7 @@ export const ExpiryEditorRow = (props: {
setIsEditing(false);
},
(e: unknown) => {
console.error("Error while saving expiry date:", e);
getLogger().error("Error while saving expiry date:", e);
setIsWaitingForSave(false);
},
);
@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react';
import { uniqueId } from 'lodash';
import Languages from 'features/global/services/languages-service';
import Logger from '@features/global/framework/logger-service';
import BaseBlock from '@molecules/grouped-rows/base';
import { Base } from '@atoms/text';
@@ -13,6 +14,8 @@ import { ConfirmModal } from 'app/atoms/modal/confirm';
import Styles from './styles';
const getLogger = () => Logger.getLogger('password-editor-row');
export const PasswordEditorRow = (props: {
disabled?: boolean;
password?: string;
@@ -51,7 +54,7 @@ export const PasswordEditorRow = (props: {
setIsEditingPassword(false);
},
(e: unknown) => {
console.error("Error while saving password:", e);
getLogger().error("Error while saving password:", e);
setIsWaitingForPasswordSave(false);
},
);
@@ -70,7 +73,7 @@ export const PasswordEditorRow = (props: {
savePassword(password);
}
return <>
return <>
<BaseBlock
className={"m-4" + (disabled ? Styles.Disabled.Yes : "")}
disabled={disabled}