Skip to content

Commit

Permalink
Fix app index
Browse files Browse the repository at this point in the history
  • Loading branch information
mrruby committed Jul 10, 2024
1 parent 315d752 commit 6eeef1e
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 76 deletions.
18 changes: 8 additions & 10 deletions holo-key-manager-extension/src/lib/services/key-manager-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,16 @@ const mapItemToNewItem = (item: GetKeysResponse): ArrayKeyItem => ({
happUiUrl: item.metadata.happUiUrl
});

const insertItemAtIndex = <T>(arr: T[], index: number, newItem: T): T[] => [
...arr.slice(0, index),
newItem,
...arr.slice(index)
];
const sortByAppIndex = (a: GetKeysResponse, b: GetKeysResponse) => a.appIndex - b.appIndex;

const transformItem = (item: GetKeysResponse): ArrayKeyItem => {
const newItem = mapItemToNewItem(item);
ArrayKeyItemSchema.parse(newItem);
return newItem;
};

export const transformDataToArray = (data: GetKeysResponse[]): ArrayKeyItem[] =>
data.reduce<ArrayKeyItem[]>((acc, item) => {
const newItem = mapItemToNewItem(item);
ArrayKeyItemSchema.parse(newItem);
return insertItemAtIndex(acc, item.appIndex, newItem);
}, []);
data.sort(sortByAppIndex).map(transformItem);

export const getKeys = async (params: GetKeysObjectParams, signature: string) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion holo-key-manager-extension/static/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Holo key manager",
"description": "A browser extension to manage holo keys",
"version": "0.0.66",
"version": "0.0.67",
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAiAtKvbHNTN3O2BLRZH7RkLczaMLenSeZu+YP+KomPQPZ18nt4DY9boIN/+GWts7gCzEeQq59l8edGdF2P7xAbsRxYR88+zFEbxMtIyfyqJZIlzXwnvPJkwGu/S6arNtX48K7q1+xnJEE7VyeYSj6/i2LR+LmPigCzY9JCP7+SmWVeYbdm3kZmReK0ecfh15RXSNjZpXJUgrbea/RVxweggYKnmhhOUBmuJSCLoWTXIuJPBMwGQK1O2GKBqHOq94bPVSF7j+4WzSpPan70ZZJX/reFsOFE/idfFN6wbizjR1Ne50Po03kudEmfQgoqUhVpd0wP8A3YbqE7ODdZcCPPwIDAQAB",
"manifest_version": 3,
"action": {
Expand Down
250 changes: 185 additions & 65 deletions holo-key-manager-extension/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,103 +7,223 @@ describe('transformDataToIndexedArray', () => {
it('should transform GetKeysResponse array to ArrayKeyItem array in proper index order', () => {
const input: GetKeysResponse[] = [
{
newKey: 'newKey2',
appName: 'App2',
installedAppId: 'app2-id',
newKey: 'uhCAk3aVMxWBcaVJO8w4LNoVKLCYjulCDLFPh4RFaJJCI2iz5ynNi',
appName: 'Cloud Console',
installedAppId: 'uhCkkSwHw3d3yz-tg26QxvY0ZZyO85pbmhQXYDwj4mdnQrQx4uF6L',
appIndex: 1,
metadata: { keyName: 'Dev key 1', happUiUrl: 'https://cloud-console.dev.holotest.net/' }
},
{
newKey: 'uhCAk92DB69aJS2FS4NbzKpaG4HrKQK2MfvmpUopqRE1q2J9rn5No',
appName: 'Cloud Console',
installedAppId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
appIndex: 6,
metadata: {
keyName: 'key2',
happLogo: 'logo2.png',
happUiUrl: 'http://app2.com'
keyName: 'production_3',
happUiUrl: 'https://cloud-console.holo.host/dashboard'
}
},
{
newKey: 'newKey1',
appName: 'App1',
installedAppId: 'app1-id',
appIndex: 0,
newKey: 'uhCAkNfo8VXANXSKhg1oAAei_2J-VfJFaCIuniz_Gjxe3rgQUHECX',
appName: 'Cloud Console',
installedAppId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
appIndex: 4,
metadata: {
keyName: 'key1',
happLogo: 'logo1.png',
happUiUrl: 'http://app1.com'
keyName: 'production_1',
happUiUrl: 'https://cloud-console.holo.host/dashboard'
}
},
{
newKey: 'newKey3',
appName: 'App3',
installedAppId: 'app3-id',
appIndex: 3,
newKey: 'uhCAkPRUjoZ9pOuH8wWXGmm56gXgSscIpIN_fPmKVBEUX4zSSqMIN',
appName: 'Cloud Console',
installedAppId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
appIndex: 9,
metadata: { keyName: 'BBB2', happUiUrl: 'https://cloud-console.holo.host/happ' }
},
{
newKey: 'uhCAkS2GZSJDKRx8IN8UOOwO8DHT704oirXRHUSAeJ0HZydGAvRt2',
appName: 'your-happName',
installedAppId: 'your-happId1231231',
appIndex: 12,
metadata: {
keyName: 'key1',
happLogo: 'logo1.png',
happUiUrl: 'http://app1.com'
keyName: '3',
happLogo: 'https://example.com/logo.png',
happUiUrl: 'https://example.com/description.html'
}
},
{
newKey: 'newKey4',
appName: 'App4',
installedAppId: 'app4-id',
appIndex: 2,
newKey: 'uhCAkbTHwjA2NBT_MlMY69wOvqULf-vjG8TinVnrx2J9KMjiHioPR',
appName: 'Cloud Console',
installedAppId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
appIndex: 5,
metadata: {
keyName: 'key4',
happLogo: 'logo4.png',
happUiUrl: 'http://app4.com'
keyName: 'production_2',
happUiUrl: 'https://cloud-console.holo.host/dashboard'
}
},
{
newKey: 'newKey5',
appName: 'App5',
installedAppId: 'app5-id',
appIndex: 4,
newKey: 'uhCAkeHiOOLoU7K2gmowwTbiZtUzqLak0AW6_x5jS6_HtJIi0VbBk',
appName: 'Cloud Console',
installedAppId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
appIndex: 8,
metadata: { keyName: 'BBB1', happUiUrl: 'https://cloud-console.holo.host/happ' }
},
{
newKey: 'uhCAkeUCQ-edtkax_JaVOE-9zLc9HadhZ8zJl7HS5poy5LmI8kgae',
appName: 'your-happName',
installedAppId: 'your-happId1231231',
appIndex: 11,
metadata: {
keyName: 'key5',
happLogo: 'logo5.png',
happUiUrl: 'http://app5.com'
keyName: '2',
happLogo: 'https://example.com/logo.png',
happUiUrl: 'https://example.com/description.html'
}
},
{
newKey: 'uhCAkfdQJJL3AQREM1Lua9B6Z8H_bz6OFA2Qy4wBKTdCelgxIfSNe',
appName: 'Cloud Console',
installedAppId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
appIndex: 3,
metadata: { keyName: 'prod 2', happUiUrl: 'https://cloud-console.holo.host/dashboard' }
},
{
newKey: 'uhCAkjXABrfnTEds9Irmf20fW6z9GmFymWnKDL16uLLPlnmN3y4wQ',
appName: 'Cloud Console',
installedAppId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
appIndex: 7,
metadata: { keyName: 'aaaa1', happUiUrl: 'https://cloud-console.holo.host/happ' }
},
{
newKey: 'uhCAkpy0pdRqsD3Nkpt9b7mqOxPFAT15u9cSE3OgOmXuKiIfJE9c3',
appName: 'Cloud Console',
installedAppId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
appIndex: 2,
metadata: { keyName: 'prod 1', happUiUrl: 'https://cloud-console.holo.host/' }
},
{
newKey: 'uhCAkqK-8ErdVyKVN7QGM5EVXLqdFrCkYF4RMCPIwpt8LclEB7bfQ',
appName: 'your-happName',
installedAppId: 'your-happId1231231',
appIndex: 10,
metadata: {
keyName: '1',
happLogo: 'https://example.com/logo.png',
happUiUrl: 'https://example.com/description.html'
}
},
{
newKey: 'uhCAkzSOTorctsWN-ASn7s-FxI6Av9VkXFvi5Vdq4boJyO8jzPkZu',
appName: 'Cloud Console',
installedAppId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
appIndex: 0,
metadata: { keyName: 'key 1', happUiUrl: 'https://cloud-console.holo.host/' }
}
];

const expectedOutput = [
{
newKey: 'newKey1',
happId: 'app1-id',
happName: 'App1',
keyName: 'key1',
happLogo: 'logo1.png',
happUiUrl: 'http://app1.com'
happId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
happName: 'Cloud Console',
happLogo: undefined,
newKey: 'uhCAkzSOTorctsWN-ASn7s-FxI6Av9VkXFvi5Vdq4boJyO8jzPkZu',
keyName: 'key 1',
happUiUrl: 'https://cloud-console.holo.host/'
},
{
newKey: 'newKey2',
happId: 'app2-id',
happName: 'App2',
keyName: 'key2',
happLogo: 'logo2.png',
happUiUrl: 'http://app2.com'
happId: 'uhCkkSwHw3d3yz-tg26QxvY0ZZyO85pbmhQXYDwj4mdnQrQx4uF6L',
happName: 'Cloud Console',
happLogo: undefined,
newKey: 'uhCAk3aVMxWBcaVJO8w4LNoVKLCYjulCDLFPh4RFaJJCI2iz5ynNi',
keyName: 'Dev key 1',
happUiUrl: 'https://cloud-console.dev.holotest.net/'
},
{
newKey: 'newKey4',
happId: 'app4-id',
happName: 'App4',
keyName: 'key4',
happLogo: 'logo4.png',
happUiUrl: 'http://app4.com'
happId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
happName: 'Cloud Console',
happLogo: undefined,
newKey: 'uhCAkpy0pdRqsD3Nkpt9b7mqOxPFAT15u9cSE3OgOmXuKiIfJE9c3',
keyName: 'prod 1',
happUiUrl: 'https://cloud-console.holo.host/'
},
{
newKey: 'newKey3',
happId: 'app3-id',
happName: 'App3',
keyName: 'key1',
happLogo: 'logo1.png',
happUiUrl: 'http://app1.com'
happId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
happName: 'Cloud Console',
happLogo: undefined,
newKey: 'uhCAkfdQJJL3AQREM1Lua9B6Z8H_bz6OFA2Qy4wBKTdCelgxIfSNe',
keyName: 'prod 2',
happUiUrl: 'https://cloud-console.holo.host/dashboard'
},
{
happId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
happName: 'Cloud Console',
happLogo: undefined,
newKey: 'uhCAkNfo8VXANXSKhg1oAAei_2J-VfJFaCIuniz_Gjxe3rgQUHECX',
keyName: 'production_1',
happUiUrl: 'https://cloud-console.holo.host/dashboard'
},
{
happId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
happName: 'Cloud Console',
happLogo: undefined,
newKey: 'uhCAkbTHwjA2NBT_MlMY69wOvqULf-vjG8TinVnrx2J9KMjiHioPR',
keyName: 'production_2',
happUiUrl: 'https://cloud-console.holo.host/dashboard'
},
{
happId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
happName: 'Cloud Console',
happLogo: undefined,
newKey: 'uhCAk92DB69aJS2FS4NbzKpaG4HrKQK2MfvmpUopqRE1q2J9rn5No',
keyName: 'production_3',
happUiUrl: 'https://cloud-console.holo.host/dashboard'
},
{
happId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
happName: 'Cloud Console',
happLogo: undefined,
newKey: 'uhCAkjXABrfnTEds9Irmf20fW6z9GmFymWnKDL16uLLPlnmN3y4wQ',
keyName: 'aaaa1',
happUiUrl: 'https://cloud-console.holo.host/happ'
},
{
happId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
happName: 'Cloud Console',
happLogo: undefined,
newKey: 'uhCAkeHiOOLoU7K2gmowwTbiZtUzqLak0AW6_x5jS6_HtJIi0VbBk',
keyName: 'BBB1',
happUiUrl: 'https://cloud-console.holo.host/happ'
},
{
happId: 'uhCkkJlEYXJyglP3ECCNBobeeEp-z85CVm_SsViHpxDyPK6Mzzkyp',
happName: 'Cloud Console',
happLogo: undefined,
newKey: 'uhCAkPRUjoZ9pOuH8wWXGmm56gXgSscIpIN_fPmKVBEUX4zSSqMIN',
keyName: 'BBB2',
happUiUrl: 'https://cloud-console.holo.host/happ'
},
{
happId: 'your-happId1231231',
happName: 'your-happName',
happLogo: 'https://example.com/logo.png',
newKey: 'uhCAkqK-8ErdVyKVN7QGM5EVXLqdFrCkYF4RMCPIwpt8LclEB7bfQ',
keyName: '1',
happUiUrl: 'https://example.com/description.html'
},
{
happId: 'your-happId1231231',
happName: 'your-happName',
happLogo: 'https://example.com/logo.png',
newKey: 'uhCAkeUCQ-edtkax_JaVOE-9zLc9HadhZ8zJl7HS5poy5LmI8kgae',
keyName: '2',
happUiUrl: 'https://example.com/description.html'
},

{
newKey: 'newKey5',
happId: 'app5-id',
happName: 'App5',
keyName: 'key5',
happLogo: 'logo5.png',
happUiUrl: 'http://app5.com'
happId: 'your-happId1231231',
happName: 'your-happName',
happLogo: 'https://example.com/logo.png',
newKey: 'uhCAkS2GZSJDKRx8IN8UOOwO8DHT704oirXRHUSAeJ0HZydGAvRt2',
keyName: '3',
happUiUrl: 'https://example.com/description.html'
}
];

Expand Down

0 comments on commit 6eeef1e

Please sign in to comment.