Skip to content

Commit

Permalink
release version canary
Browse files Browse the repository at this point in the history
  • Loading branch information
radubrehar committed Jun 28, 2024
1 parent 2961b11 commit c0d4ad5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
28 changes: 28 additions & 0 deletions examples/src/pages/tests/utils/debug.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:*';
Expand Down
1 change: 0 additions & 1 deletion source/src/components/InfiniteTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
30 changes: 27 additions & 3 deletions source/src/utils/debugPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,16 @@ const enabledChannelsCache = new Map<string, boolean>();
* 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<string, boolean>();
partsMap.set(parts, true);
Expand All @@ -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;
Expand Down

0 comments on commit c0d4ad5

Please sign in to comment.