-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for specifying an entity's shortName
- Remove CatalogEntityItem as it is a needless abstraction - Refix transparent background bug after bad rebase - Improve type safety around CatalogEntities by having CatalogEntitySpec be Partial<Record<string, unknown>> - Cleanup implementation of catalogSyncToRendererInjectable - Always use EntityPreferencesStore as an injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> Make CatalogEntityRegistry.init redundent - Make all IPC injectable Signed-off-by: Sebastian Malton <sebastian@malton.name> Ensure that catalog is initialized during startFrame Signed-off-by: Sebastian Malton <sebastian@malton.name> Fix tests that overroad catalog sync - Actually use the catalog sync Signed-off-by: Sebastian Malton <sebastian@malton.name> Add behavioural tests Signed-off-by: Sebastian Malton <sebastian@malton.name> Don't assign in a computed Signed-off-by: Sebastian Malton <sebastian@malton.name> Make each store have a seperate migration version - Allows each store to only bump its version when necessary - Allows more decoupling from the extension API version so that PRs go stale slower Signed-off-by: Sebastian Malton <sebastian@malton.name> Add behavioural tests for short name length Signed-off-by: Sebastian Malton <sebastian@malton.name> Fix uses of testUsingTakeTime Signed-off-by: Sebastian Malton <sebastian@malton.name> Fix test flakiness by removing animate delay in tests Signed-off-by: Sebastian Malton <sebastian@malton.name> Update snapshots after removing timing sideeffects Signed-off-by: Sebastian Malton <sebastian@malton.name>
- Loading branch information
Showing
198 changed files
with
13,726 additions
and
7,025 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
|
||
import { computeDefaultShortName } from "../helpers"; | ||
|
||
describe("catalog helper tests", () => { | ||
describe("computeDefaultShortName", () => { | ||
it.each([ | ||
["a", "a"], | ||
["", "??"], | ||
[1, "??"], | ||
[true, "??"], | ||
["ab", "ab"], | ||
["abc", "ab"], | ||
["abcde", "ab"], | ||
["ab-cd", "ac"], | ||
["ab-cd la", "al"], | ||
["ab-cd la_1", "al"], | ||
["ab-cd la 1_3", "al1"], | ||
["ab-cd la 1_3 lk", "al1"], | ||
["ab-cd la 1_3 lk aj", "al1"], | ||
["😀 a", "😀a"], | ||
["😀😎 a", "😀a"], | ||
["🇫🇮 Finland", "🇫🇮F"], | ||
["إعجم", "إع"], | ||
])("should compute from %p into %p", (input: any, output: string) => { | ||
expect(computeDefaultShortName(input)).toBe(output); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* Copyright (c) OpenLens Authors. All rights reserved. | ||
* Licensed under MIT License. See LICENSE in root directory for more information. | ||
*/ | ||
|
||
import type { CatalogEntity } from "./catalog-entity"; | ||
import GraphemeSplitter from "grapheme-splitter"; | ||
import { hasOwnProperty, hasTypedProperty, isObject, isString, iter } from "../utils"; | ||
|
||
function getNameParts(name: string): string[] { | ||
const byWhitespace = name.split(/\s+/); | ||
|
||
if (byWhitespace.length > 1) { | ||
return byWhitespace; | ||
} | ||
|
||
const byDashes = name.split(/[-_]+/); | ||
|
||
if (byDashes.length > 1) { | ||
return byDashes; | ||
} | ||
|
||
return name.split(/@+/); | ||
} | ||
|
||
export function limitGraphemeLengthOf(src: string, count: number): string { | ||
const splitter = new GraphemeSplitter(); | ||
|
||
return iter | ||
.chain(splitter.iterateGraphemes(src)) | ||
.take(count) | ||
.join(""); | ||
} | ||
|
||
export function computeDefaultShortName(name: string) { | ||
if (!name || typeof name !== "string") { | ||
return "??"; | ||
} | ||
|
||
const [rawFirst, rawSecond, rawThird] = getNameParts(name); | ||
const splitter = new GraphemeSplitter(); | ||
const first = splitter.iterateGraphemes(rawFirst); | ||
const second = rawSecond ? splitter.iterateGraphemes(rawSecond): first; | ||
const third = rawThird ? splitter.iterateGraphemes(rawThird) : iter.newEmpty<string>(); | ||
|
||
return iter.chain(iter.take(first, 1)) | ||
.concat(iter.take(second, 1)) | ||
.concat(iter.take(third, 1)) | ||
.join(""); | ||
} | ||
|
||
export function getShortName(entity: CatalogEntity): string { | ||
return entity.metadata.shortName || computeDefaultShortName(entity.getName()); | ||
} | ||
|
||
export function getIconColourHash(entity: CatalogEntity): string { | ||
return `${entity.metadata.name}-${entity.metadata.source}`; | ||
} | ||
|
||
export function getIconBackground(entity: CatalogEntity): string | undefined { | ||
if (isObject(entity.spec.icon)) { | ||
if (hasTypedProperty(entity.spec.icon, "background", isString)) { | ||
return entity.spec.icon.background; | ||
} | ||
|
||
return hasOwnProperty(entity.spec.icon, "src") | ||
? "transparent" | ||
: undefined; | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
export function getIconMaterial(entity: CatalogEntity): string | undefined { | ||
if ( | ||
isObject(entity.spec.icon) | ||
&& hasTypedProperty(entity.spec.icon, "material", isString) | ||
) { | ||
return entity.spec.icon.material; | ||
} | ||
|
||
return undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.