diff --git a/examples/src/pages/tests/utils/debug.spec.ts b/examples/src/pages/tests/utils/debug.spec.ts index c7a9985e..2456dfb1 100644 --- a/examples/src/pages/tests/utils/debug.spec.ts +++ b/examples/src/pages/tests/utils/debug.spec.ts @@ -64,6 +64,34 @@ export default test.describe.parallel('debug', () => { ]); }); + test.only('should allow * use in the middle', () => { + let args: string[] = []; + debug.enable = 'channel1:*:x'; + debug.logFn = (...x: string[]) => { + args = x; + }; + const oneax = debug('channel1:a:x'); + const onebx = debug('channel1:b:x'); + const oneaz = debug('channel1:a:z'); + const onecx = debug('channel1:c:x'); + + oneax('1ax'); + expect(args).toEqual(['%c[channel1:a:x]', 'color: red', '1ax']); + + onebx('1bx'); + expect(args).toEqual(['%c[channel1:b:x]', 'color: green', '1bx']); + + oneaz('1az'); + // expect no changes, since z is not enabled + expect(args).toEqual(['%c[channel1:b:x]', 'color: green', '1bx']); + + oneaz('1az'); + // expect no changes, since z is not enabled + expect(args).toEqual(['%c[channel1:b:x]', 'color: green', '1bx']); + + onecx('1cx'); + expect(args).toEqual(['%c[channel1:c:x]', 'color: red', '1cx']); + }); test('should only log for enabled channels', () => { let args: string[] = []; debug.enable = 'channel2,channel1:*'; diff --git a/source/src/components/InfiniteTable/index.tsx b/source/src/components/InfiniteTable/index.tsx index 4a073e32..f32360b8 100644 --- a/source/src/components/InfiniteTable/index.tsx +++ b/source/src/components/InfiniteTable/index.tsx @@ -89,7 +89,6 @@ import { HScrollSyncContent } from './components/HScrollSyncContent'; import { useGridScroll } from './hooks/useGridScroll'; import { useVisibleColumnSizes } from './hooks/useVisibleColumnSizes'; - export const InfiniteTableClassName = internalProps.rootClassName; const HOVERED_CLASS_NAMES = [RowHoverCls, 'InfiniteColumnCell--hovered']; diff --git a/source/src/utils/debugPackage.ts b/source/src/utils/debugPackage.ts index 771eaecf..a373ade2 100644 --- a/source/src/utils/debugPackage.ts +++ b/source/src/utils/debugPackage.ts @@ -141,10 +141,16 @@ const enabledChannelsCache = new Map(); * If the permission token does not contain the channel, it returns undefined. * * @param channel A specific channel like "a:b:c" - cannot contain wildcards - * @param permissionToken a permission token like "a:b:c" or "d:e:f" or "d:x:*" or "*" - the value can contain wildcards, but cannot have comma separated values + * @param permissionToken a permission token like "a:b:c" or "d:e:f" or "d:x:*" or "d:*:f" or "*" - the value can contain wildcards, but cannot have comma separated values * */ -function isChannelTargeted(channel: string, permissionToken: string) { +function isChannelTargeted( + channel: string, + permissionToken: string, +): boolean | undefined { + if (channel === permissionToken) { + return true; + } const parts = channel.split(CHANNEL_SEPARATOR); const partsMap = new DeepMap(); partsMap.set(parts, true); @@ -153,14 +159,32 @@ function isChannelTargeted(channel: string, permissionToken: string) { const hasWildcard = new Set(tokenParts).has(CHANNEL_WILDCARD); + const indexOfToken = tokenParts.indexOf(CHANNEL_WILDCARD); const storagePartsWithoutWildcard = hasWildcard - ? tokenParts.slice(0, tokenParts.indexOf(CHANNEL_WILDCARD)) + ? tokenParts.slice(0, indexOfToken) : tokenParts; if ( partsMap.getKeysStartingWith(storagePartsWithoutWildcard, hasWildcard) .length > 0 ) { + const remainingParts = tokenParts.slice(indexOfToken + 1); + if (remainingParts.length) { + // there are some remaining parts after the wildcard token in the permission token + // so we need to check for that + // we do that by replacing the current token with the actual part that was matched + + const tokenWithOnePartReplaced = tokenParts + .map((part, index) => { + if (index === indexOfToken) { + return parts[index]; + } + return part; + }) + .join(CHANNEL_SEPARATOR); + return isChannelTargeted(channel, tokenWithOnePartReplaced); + } + return true; } return undefined;