Skip to content

Commit

Permalink
Merge pull request #5145 from specify/fewer-log-messages
Browse files Browse the repository at this point in the history
chore: reduce console noise
  • Loading branch information
maxpatiiuk authored Jul 27, 2024
2 parents dff3564 + cfaf403 commit 0557807
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 47 deletions.
1 change: 0 additions & 1 deletion specifyweb/frontend/js_src/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@
/* Make spinner buttons larger */
[type='number']:not([readonly], .no-arrows)::-webkit-outer-spin-button,
[type='number']:not([readonly], .no-arrows)::-webkit-inner-spin-button {
-webkit-appearance: inner-spin-button !important;
@apply absolute right-0 top-0 h-full w-2;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function entrypoint(): void {

interceptLogs();

console.group('Specify App Starting');
if (process.env.NODE_ENV === 'production') {
console.group('Specify App Starting');
console.log(
'%cDocumentation for Developers:\n',
'font-weight: bold',
Expand All @@ -27,7 +27,6 @@ function entrypoint(): void {
const entrypointName =
parseDjangoDump<ReturnType<typeof getEntrypointName>>('entrypoint-name') ??
'main';
console.log(entrypointName);
unlockInitialContext(entrypointName);

globalThis.addEventListener?.('load', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ export function interceptLogs(): void {
const context = getLogContext();
const hasContext = Object.keys(context).length > 0;

// Silencing https://github.com/reactjs/react-modal/issues/808
if (
args[0] ===
"React-Modal: Cannot register modal instance that's already open"
)
return;

/**
* If actively redirecting log output, don't print to console
* (printing object to console prevents garbage collection
Expand Down
18 changes: 0 additions & 18 deletions specifyweb/frontend/js_src/lib/components/InitialContext/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
*/

import type { MimeType } from '../../utils/ajax';
import { f } from '../../utils/functools';
import { defined } from '../../utils/types';
import { formatNumber } from '../Atoms/Internationalization';
import { SECOND } from '../Atoms/timeUnits';

/**
* This belongs to ./components/toolbar/cachebuster.tsx but was moved here
Expand Down Expand Up @@ -56,7 +53,6 @@ export const unlockInitialContext = (entrypoint: typeof entrypointName): void =>
export const load = async <T>(path: string, mimeType: MimeType): Promise<T> =>
contextUnlockedPromise.then(async (entrypoint) => {
if (entrypoint !== 'main') return foreverFetch<T>();
const startTime = Date.now();

// Doing async import to avoid a circular dependency
const { ajax } = await import('../../utils/ajax');
Expand All @@ -65,21 +61,7 @@ export const load = async <T>(path: string, mimeType: MimeType): Promise<T> =>
errorMode: 'visible',
headers: { Accept: mimeType },
});
const endTime = Date.now();
const timePassed = endTime - startTime;
// A very crude detection mechanism
const isCached = timePassed < 100;

// So as not to spam the tests
if (process.env.NODE_ENV !== 'test')
console.log(
`${path} %c[${
isCached
? 'cached'
: `${formatNumber(f.round(timePassed / SECOND, 0.01))}s`
}]`,
`color: ${isCached ? '#9fa' : '#f99'}`
);
return data;
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,64 +1,71 @@
export const tableActions = ['read', 'create', 'update', 'delete'] as const;
export const collectionAccessResource = '/system/sp7/collection';
export const operationPolicies = {
'/system/sp7/collection': ['access'],
'/admin/user/password': ['update'],
'/admin/user/agents': ['update'],
'/admin/user/sp6/is_admin': ['update'],
'/record/merge': ['update', 'delete'],
'/admin/user/invite_link': ['create'],
'/admin/user/oic_providers': ['read'],
'/admin/user/password': ['update'],
'/admin/user/sp6/collection_access': ['read', 'update'],
'/report': ['execute'],
'/admin/user/sp6/is_admin': ['update'],
'/attachment_import/dataset': [
'create',
'update',
'delete',
'upload',
'rollback',
],
'/export/dwca': ['execute'],
'/export/feed': ['force_update'],
'/permissions/library/roles': ['read', 'create', 'update', 'delete'],
'/permissions/list_admins': ['read'],
'/permissions/policies/user': ['read', 'update'],
'/permissions/user/roles': ['read', 'update'],
'/permissions/roles': [
'read',
'create',
'update',
'delete',
'copy_from_library',
],
'/permissions/library/roles': ['read', 'create', 'update', 'delete'],
'/tree/edit/taxon': ['merge', 'move', 'synonymize', 'desynonymize', 'repair'],
'/permissions/user/roles': ['read', 'update'],
'/querybuilder/query': [
'execute',
'export_csv',
'export_kml',
'create_recordset',
],
'/record/merge': ['update', 'delete'],
'/report': ['execute'],
'/system/sp7/collection': ['access'],
'/tree/edit/geography': [
'merge',
'move',
'synonymize',
'desynonymize',
'repair',
],
'/tree/edit/storage': [
'/tree/edit/geologictimeperiod': [
'merge',
'move',
'synonymize',
'desynonymize',
'repair',
'bulk_move',
],
'/tree/edit/geologictimeperiod': [
'/tree/edit/lithostrat': [
'merge',
'move',
'synonymize',
'desynonymize',
'repair',
],
'/tree/edit/lithostrat': [
'/tree/edit/storage': [
'merge',
'move',
'bulk_move',
'synonymize',
'desynonymize',
'repair',
],
'/querybuilder/query': [
'execute',
'export_csv',
'export_kml',
'create_recordset',
],
'/tree/edit/taxon': ['merge', 'move', 'synonymize', 'desynonymize', 'repair'],
'/workbench/dataset': [
'create',
'update',
Expand All @@ -69,13 +76,6 @@ export const operationPolicies = {
'transfer',
'create_recordset',
],
'/attachment_import/dataset': [
'create',
'update',
'delete',
'upload',
'rollback',
],
} as const;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ const checkRegistry = async (): Promise<void> =>
).then((policies) =>
sortPolicies(policies) === sortPolicies(operationPolicies)
? undefined
: error('Front-end has outdated list of operation policies')
: error(
'Front-end list of operation policies is out of date. To resolve this error, please update "operationPolicies" in specifyweb/frontend/js_src/lib/components/Permissions/definitions.ts based on the response from the http://localhost/permissions/registry/ endpoint'
)
);

export type PermissionsQueryItem = {
Expand Down

0 comments on commit 0557807

Please sign in to comment.