🩹 front: use logger instead of console (#50)
This commit is contained in:
committed by
ericlinagora
parent
e6234f97e4
commit
9048ce7094
@@ -6,6 +6,9 @@ import {
|
|||||||
DriveFileAccessLevelForPublicLink,
|
DriveFileAccessLevelForPublicLink,
|
||||||
DriveItem,
|
DriveItem,
|
||||||
} from '@features/drive/types';
|
} 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) =>
|
const entityMatcher = (entityType: AuthEntity['type'], entityId?: string) =>
|
||||||
(entity: AuthEntity) =>
|
(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
|
/** Updates the level of entities matching the given type and id, or adds the return
|
||||||
* of updater with no argument.
|
* 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(
|
function upsertEntities(
|
||||||
entities: AuthEntity[] | undefined,
|
entities: AuthEntity[] | undefined,
|
||||||
@@ -34,7 +37,7 @@ function upsertEntities(
|
|||||||
const matcher = entityMatcher(entityType, entityId);
|
const matcher = entityMatcher(entityType, entityId);
|
||||||
const mapped = entities.map(item => {
|
const mapped = entities.map(item => {
|
||||||
if (!matcher(item)) return 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;
|
found = true;
|
||||||
return updater(item);
|
return updater(item);
|
||||||
}).filter(x => x);
|
}).filter(x => x);
|
||||||
@@ -83,12 +86,12 @@ const itemWithEntityAccessChanged = (
|
|||||||
},
|
},
|
||||||
} as DriveItem);
|
} 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) => {
|
const getAccessLevelOfUniqueForType = (item: DriveItem | undefined, entityType: AuthEntity['type'], entityId?: string) => {
|
||||||
if (!item) return undefined;
|
if (!item) return undefined;
|
||||||
const accesses = item.access_info.entities.filter(entityMatcher(entityType, entityId));
|
const accesses = item.access_info.entities.filter(entityMatcher(entityType, entityId));
|
||||||
if (accesses.length != 1 && entityType != "channel")
|
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;
|
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 */
|
/** Return a list of all DriveItemAccessInfo for users sorted by id */
|
||||||
export const getAllUserAccesses = (item: DriveItem) => accessInfosOfEntitiesOfType(item, "user");
|
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);
|
export const getUserAccessLevel = (item: DriveItem, userId: string) => getAccessLevelOfUniqueForType(item, "user", userId);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -4,6 +4,7 @@ import 'moment/min/locales';
|
|||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { uniqueId } from 'lodash';
|
import { uniqueId } from 'lodash';
|
||||||
|
|
||||||
|
import Logger from '@features/global/framework/logger-service';
|
||||||
import Languages from 'features/global/services/languages-service';
|
import Languages from 'features/global/services/languages-service';
|
||||||
|
|
||||||
import BaseBlock from '@molecules/grouped-rows/base';
|
import BaseBlock from '@molecules/grouped-rows/base';
|
||||||
@@ -16,6 +17,8 @@ import { ConfirmModal } from 'app/atoms/modal/confirm';
|
|||||||
|
|
||||||
import Styles from './styles';
|
import Styles from './styles';
|
||||||
|
|
||||||
|
const getLogger = () => Logger.getLogger('expiry-editor-row');
|
||||||
|
|
||||||
export const ExpiryEditorRow = (props: {
|
export const ExpiryEditorRow = (props: {
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
value: number;
|
value: number;
|
||||||
@@ -54,7 +57,7 @@ export const ExpiryEditorRow = (props: {
|
|||||||
setIsEditing(false);
|
setIsEditing(false);
|
||||||
},
|
},
|
||||||
(e: unknown) => {
|
(e: unknown) => {
|
||||||
console.error("Error while saving expiry date:", e);
|
getLogger().error("Error while saving expiry date:", e);
|
||||||
setIsWaitingForSave(false);
|
setIsWaitingForSave(false);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
+5
-2
@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react';
|
|||||||
import { uniqueId } from 'lodash';
|
import { uniqueId } from 'lodash';
|
||||||
|
|
||||||
import Languages from 'features/global/services/languages-service';
|
import Languages from 'features/global/services/languages-service';
|
||||||
|
import Logger from '@features/global/framework/logger-service';
|
||||||
|
|
||||||
import BaseBlock from '@molecules/grouped-rows/base';
|
import BaseBlock from '@molecules/grouped-rows/base';
|
||||||
import { Base } from '@atoms/text';
|
import { Base } from '@atoms/text';
|
||||||
@@ -13,6 +14,8 @@ import { ConfirmModal } from 'app/atoms/modal/confirm';
|
|||||||
|
|
||||||
import Styles from './styles';
|
import Styles from './styles';
|
||||||
|
|
||||||
|
const getLogger = () => Logger.getLogger('password-editor-row');
|
||||||
|
|
||||||
export const PasswordEditorRow = (props: {
|
export const PasswordEditorRow = (props: {
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
password?: string;
|
password?: string;
|
||||||
@@ -51,7 +54,7 @@ export const PasswordEditorRow = (props: {
|
|||||||
setIsEditingPassword(false);
|
setIsEditingPassword(false);
|
||||||
},
|
},
|
||||||
(e: unknown) => {
|
(e: unknown) => {
|
||||||
console.error("Error while saving password:", e);
|
getLogger().error("Error while saving password:", e);
|
||||||
setIsWaitingForPasswordSave(false);
|
setIsWaitingForPasswordSave(false);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -70,7 +73,7 @@ export const PasswordEditorRow = (props: {
|
|||||||
savePassword(password);
|
savePassword(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
<BaseBlock
|
<BaseBlock
|
||||||
className={"m-4" + (disabled ? Styles.Disabled.Yes : "")}
|
className={"m-4" + (disabled ? Styles.Disabled.Yes : "")}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
|||||||
Reference in New Issue
Block a user