Skip to content

Commit

Permalink
preliminary targeted conditional solution (#2528)
Browse files Browse the repository at this point in the history
* preliminary targeted conditional solution

* Fix conditional src being null

* Add TODO and duct tape DB bug

* fix team calc provider

* refactor TeammateDisplay

* validate conditional value

* fix gi-frontend

* address comments

* update

* update typeguards and remove 'all' from Member

* remove log, remove sheet tags

---------

Co-authored-by: Van Nguyen <[email protected]>
  • Loading branch information
frzyc and nguyentvan7 authored Nov 6, 2024
1 parent 1e12c1a commit 12298ec
Show file tree
Hide file tree
Showing 33 changed files with 1,010 additions and 654 deletions.
1 change: 0 additions & 1 deletion apps/gi-frontend/src/app/teams/[teamId]/TalentContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ function SkillDisplayCard({
document={doc}
collapse
// hideHeader={hideHeader}
setConditional={() => {}} // TODO: frzyc setConditional
/>
))}
</CardContent>
Expand Down
3 changes: 2 additions & 1 deletion libs/common/database/src/lib/DataManagerBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class DataManagerBase<
key: CacheKey,
valueOrFunc:
| Partial<StorageValue>
| ((v: StorageValue) => Partial<StorageValue> | void),
| ((v: StorageValue) => Partial<StorageValue> | void | false),
notify = true
): boolean {
const old = this.getStorage(key)
Expand All @@ -85,6 +85,7 @@ export class DataManagerBase<
}
const value =
typeof valueOrFunc === 'function' ? valueOrFunc(old) ?? old : valueOrFunc
if (value === false) return false
const validated = this.validate({ ...(old ?? {}), ...value }, key)
if (!validated) {
this.trigger(key, 'invalid', value)
Expand Down
17 changes: 17 additions & 0 deletions libs/common/util/src/lib/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,20 @@ export function pruneOrPadArray<T>(array: T[], length: number, value: T) {
else array.push(...new Array(length - array.length).fill(value))
return array
}

/**
* Move an element in the array to the front, if it exists.
* @param arr
* @param key
* @returns
*/
export function moveToFront<T>(arr: T[], key: T): T[] {
const index = arr.indexOf(key)
if (index > -1) {
// Remove the element from its current position
const [element] = arr.splice(index, 1)
// Add the element to the front of the array
arr.unshift(element)
}
return arr
}
Loading

0 comments on commit 12298ec

Please sign in to comment.