-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(explorer): reorder columns. RequestKey is the relevant first col…
…umn when showing transactions. Moved sender to the end (#2754) * feat(explorer): reorder columns. RequestKey is the relevant first column when showing transactions. Moved sender to the end * feat(explorer): use proper layout for no results found * feat(explorer): do not close truncated parts
- Loading branch information
Showing
8 changed files
with
159 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@kadena/explorer': patch | ||
--- | ||
|
||
Reordering columns to present the first column as the one to link to | ||
|
||
Remove toggling close of truncated content. Will always open so users can no | ||
select and copy |
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
28 changes: 9 additions & 19 deletions
28
packages/apps/explorer/src/components/Search/NoSearchResults/NoSearchResults.tsx
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 |
---|---|---|
@@ -1,45 +1,35 @@ | ||
import { Heading, Stack } from '@kadena/kode-ui'; | ||
import { Heading, Text } from '@kadena/kode-ui'; | ||
import type { FC } from 'react'; | ||
import React from 'react'; | ||
|
||
interface NoSearchResultsProps { | ||
interface INoSearchResultsProps { | ||
type?: 'requestKey' | 'accountName' | 'blockhash'; | ||
value?: string; | ||
} | ||
|
||
export const NoSearchResults: FC<NoSearchResultsProps> = ({ type, value }) => { | ||
export const NoSearchResults: FC<INoSearchResultsProps> = ({ type, value }) => { | ||
// TODO: add buttons to navigate to other networks testnet/mainnet | ||
// Use url from router to query other networks to see if the search result is | ||
// there | ||
|
||
switch (true) { | ||
case type === 'requestKey' && value !== undefined: | ||
return ( | ||
<Stack justifyContent="center" width="100%"> | ||
<Heading as="h3">No search results for request key: {value}</Heading> | ||
</Stack> | ||
<Heading as="h3">No search results for request key: {value}</Heading> | ||
); | ||
|
||
case type === 'accountName' && value !== undefined: | ||
return ( | ||
<Stack justifyContent="center" flexDirection={'column'} width="100%"> | ||
<> | ||
<Heading as="h3">No search results for account: {value}</Heading> | ||
<Heading as="h4">Please check the account name and try again</Heading> | ||
</Stack> | ||
<Text>Please check the network and account name and try again</Text> | ||
</> | ||
); | ||
|
||
case type === 'blockhash' && value !== undefined: | ||
return ( | ||
<Stack justifyContent="center" width="100%"> | ||
<Heading as="h3">No search results for block: {value}</Heading> | ||
</Stack> | ||
); | ||
return <Heading as="h3">No search results for block: {value}</Heading>; | ||
|
||
default: | ||
return ( | ||
<Stack justifyContent="center" width="100%"> | ||
<Heading as="h3">No search results</Heading> | ||
</Stack> | ||
); | ||
return <Heading as="h3">No search results</Heading>; | ||
} | ||
}; |
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
79 changes: 79 additions & 0 deletions
79
packages/apps/explorer/src/utils/__test__/condenseString.test.ts
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,79 @@ | ||
import { condenseStrings } from '../condenseStrings'; | ||
|
||
describe('condenseString', () => { | ||
const singleWord = | ||
'thisisaverylongstringthatshouldbecondensedthisisaverylongstringthatshouldbecondensed'; | ||
const multiWord = | ||
'thisisaverylongstringthatshouldbecond ensedthisisaverylongstringthatshouldbecondensed thisIsAshorterString'; | ||
|
||
describe('with default options', () => { | ||
it('condenses a single string', () => { | ||
expect(condenseStrings(singleWord)).toBe('thisi…ensed'); | ||
}); | ||
|
||
it('condenses a string with multiple words', () => { | ||
expect(condenseStrings(multiWord)).toBe( | ||
'thisi…econd ensed…ensed thisIsAshorterString', | ||
); | ||
}); | ||
}); | ||
describe('with custom options', () => { | ||
it('minLength 10', () => { | ||
expect(condenseStrings(singleWord, { minLength: 10 })).toBe( | ||
'thisi…ensed', | ||
); | ||
expect(condenseStrings(multiWord, { minLength: 10 })).toBe( | ||
'thisi…econd ensed…ensed thisI…tring', | ||
); | ||
}); | ||
|
||
it('replacement "..."', () => { | ||
expect(condenseStrings(singleWord, { replacement: '...' })).toBe( | ||
'thisi...ensed', | ||
); | ||
expect(condenseStrings(multiWord, { replacement: '...' })).toBe( | ||
'thisi...econd ensed...ensed thisIsAshorterString', | ||
); | ||
}); | ||
|
||
it('startLength 10', () => { | ||
expect(condenseStrings(singleWord, { startLength: 10 })).toBe( | ||
'thisisaver…ensed', | ||
); | ||
expect(condenseStrings(multiWord, { startLength: 10 })).toBe( | ||
'thisisaver…econd ensedthisi…ensed thisIsAshorterString', | ||
); | ||
}); | ||
|
||
it('endLength 10', () => { | ||
expect(condenseStrings(singleWord, { endLength: 10 })).toBe( | ||
'thisi…econdensed', | ||
); | ||
expect(condenseStrings(multiWord, { endLength: 10 })).toBe( | ||
'thisi…ouldbecond ensed…econdensed thisIsAshorterString', | ||
); | ||
}); | ||
|
||
it('all options', () => { | ||
expect( | ||
condenseStrings(singleWord, { | ||
minLength: 40, | ||
replacement: '*.*', | ||
startLength: 5, | ||
endLength: 20, | ||
}), | ||
).toBe('thisi*.*hatshouldbecondensed'); | ||
|
||
expect( | ||
condenseStrings(multiWord, { | ||
minLength: 40, | ||
replacement: '*.*', | ||
startLength: 5, | ||
endLength: 20, | ||
}), | ||
).toBe( | ||
'thisisaverylongstringthatshouldbecond ensed*.*hatshouldbecondensed thisIsAshorterString', | ||
); | ||
}); | ||
}); | ||
}); |
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,43 @@ | ||
/** | ||
* Shortens long sections in a string by keeping the first 5 and last 5 characters. | ||
* @param str - string to shorten | ||
* @returns {[string, string]} - shortened string and original string | ||
*/ | ||
export function condenseStrings( | ||
str: string, | ||
options?: { | ||
minLength?: number; | ||
replacement?: string; | ||
startLength?: number; | ||
endLength?: number; | ||
}, | ||
): string { | ||
// set default options and override with provided options | ||
let config; | ||
if (options) { | ||
config = { | ||
...{ minLength: 22, replacement: '…', startLength: 5, endLength: 5 }, | ||
...options, | ||
}; | ||
} else { | ||
config = { | ||
minLength: 22, | ||
replacement: '…', | ||
startLength: 5, | ||
endLength: 5, | ||
}; | ||
} | ||
|
||
// Regex explanation: | ||
// Split on sequences of characters that are NOT letters, digits, '_' or '-'. | ||
const parts = str.split(/([^\w\d]+)/u); | ||
|
||
return parts | ||
.map((part) => { | ||
if (/^[\w\d]+$/u.test(part) && part.length > config.minLength) { | ||
return `${part.slice(0, config.startLength)}${config.replacement}${part.slice(-config.endLength)}`; | ||
} | ||
return part; | ||
}) | ||
.join(''); | ||
} |