Skip to content

Commit

Permalink
fix: links without paths can be navigated (#462)
Browse files Browse the repository at this point in the history
* chore: remove unnecessary any cast

* chore: fix return type on isTruthy

* fix: links without paths can be navigated

Fixes #461
  • Loading branch information
SgtPooki authored Nov 21, 2024
1 parent b37f7c0 commit 1effbe7
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/object-info/links-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const Row: React.FC<RowProps> = ({ onLinkClick, startIndex, index, rowHeight, li
key={key}
className={`pv2 pointer items-center f7 ${styles.rowGrid} bb b--near-white`}
style={{ position: 'absolute', top: key * rowHeight, width: '100%', backgroundColor }}
onClick={() => { onLinkClick(link as any) }}
onClick={() => { onLinkClick(link) }}
>
<div className={`mid-gray tr pr1 f7 ${styles.gridCellRow} monospace}`}>
{key}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function isFalsy <T> (str: T | null | string | undefined): str is null {
return false
}

export function isTruthy <T> (str: T | null | string | undefined): boolean {
export function isTruthy <T> (str: T | null | string | undefined): str is string {
return !isFalsy(str)
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/normalise-dag-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function normaliseDagPb (node: PBNode, cid: string, type: CodecType): Nor
*/
export function normaliseDagPbLinks (links: PBLink[], sourceCid: string): NormalizedDagLink[] {
return links.map((link, index) => ({
path: link.Name ?? `Links/${index}`,
path: isTruthy(link.Name) ? link.Name : `Links/${index}`,
source: sourceCid,
target: toCidStrOrNull(link.Hash) ?? '',
size: BigInt(link.Tsize ?? 0),
Expand Down
1 change: 0 additions & 1 deletion src/lib/resolve-ipld-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export async function ipldGetNodeAndRemainder (helia: Helia, sourceCid: CID | st
const encodedValue = await getRawBlock(helia, cidInstance)
const value = codecWrapper.decode(encodedValue)

// @ts-expect-error - limiting code changes, ignore this error
const codecWrapperResolveResult = await codecWrapper.resolve(isTruthy(path) ? path : '/', encodedValue)
// TODO: there was a type error previously uncaught
const resolveValue: any = {}
Expand Down

0 comments on commit 1effbe7

Please sign in to comment.