* added overview page * sanitized task * added workplan table * staged missing files * updated filters * fixed some types * updated mask graph * copyright * linting * install * added relay overview * linting * refactoring hooks * translations * updated coretime deps * updated tsconfig * fixed build * root tsconfig * fix tsconfig * app-coretime and app-broker * filter bug fix * prettied mask bar * updated deps * updated deps broker * removed TS filter and added graph * linting * fixed headers * fixed filter * updated coretime summary * updated relay tables * fixed bulk price display * updated regions * styling * fixed pallet version mismaatch info * fixed expand button * fixed alignment issues * yarn install * integrated some suggestions * linting * updated version * Fix Header on table * Small nit around naming * Usage bar console err fix: NaN * rearranged the layout for page broker on Coretime chain, changed UsageBar element to be more generic * filtering parachains by id * moved a type to a seprate type file * skip build and npm * generated locales * added default ui colours to test chains and kusama * abstracted logic from the rendering * default ui highlight fallback * table responsive - hiding timeslice info from the rows on mobile * version updates for react-components and react-query * exporting defaultHighlight * responsive summary * small fix for workplan filtering * separated coretime chain page * removed unused references * added useBrokerReservations call and marked reserved chains * useBrokerLease, added Legacy Lease type * showing last block for legacy leases * added processing at data retrieval * fix: missing icon * linting * organized files, minor refactor * moved filters out of the Overview componennt * minor refactor * version update * regenerated yarn lock * renamed column * linter :) * ts fixes :) --------- Co-authored-by: bee344 <alberto.penayo@parity.io> Co-authored-by: Alberto Nicolas Penayo <74352651+bee344@users.noreply.github.com> Co-authored-by: tarikgul <tariksnow37@gmail.com>
77 lines
2.3 KiB
TypeScript
77 lines
2.3 KiB
TypeScript
// Copyright 2017-2024 @polkadot/react-hooks authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { ApiPromise } from '@polkadot/api';
|
|
import type { Option, StorageKey, u16, u32, Vec } from '@polkadot/types';
|
|
import type { PalletBrokerScheduleItem } from '@polkadot/types/lookup';
|
|
import type { BN } from '@polkadot/util';
|
|
import type { CoreWorkplan } from './types.js';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import { createNamedHook, useCall, useMapKeys } from '@polkadot/react-hooks';
|
|
|
|
import { processHexMask } from './utils/dataProcessing.js';
|
|
|
|
export function sortByCore<T extends { core: number }> (dataArray?: T | T[]): T[] {
|
|
if (!dataArray) {
|
|
return [];
|
|
}
|
|
|
|
const sanitized = Array.isArray(dataArray) ? dataArray : [dataArray];
|
|
|
|
return sanitized.sort((a, b) => a.core - b.core);
|
|
}
|
|
|
|
function extractInfo (info: Vec<PalletBrokerScheduleItem>, core: number, timeslice: number): CoreWorkplan {
|
|
const mask: string[] = processHexMask(info[0]?.mask);
|
|
const assignment = info[0].assignment;
|
|
|
|
return {
|
|
core,
|
|
info: {
|
|
isPool: assignment.isPool,
|
|
isTask: assignment.isTask,
|
|
mask,
|
|
maskBits: mask.length,
|
|
task: assignment.isTask ? assignment.asTask.toString() : assignment.isPool ? 'Pool' : ''
|
|
},
|
|
timeslice
|
|
};
|
|
}
|
|
|
|
const OPT_KEY = {
|
|
transform: (keys: StorageKey<[u32, u16]>[]): [u32, u16][] =>
|
|
keys.map(({ args: [timeslice, core] }) => [timeslice, core])
|
|
};
|
|
|
|
function useWorkplanInfosImpl (api: ApiPromise, ready: boolean): CoreWorkplan[] | undefined {
|
|
const workplanKeys = useMapKeys(ready && api.query.broker.workplan, [], OPT_KEY);
|
|
|
|
const sanitizedKeys = workplanKeys?.map((value) => {
|
|
return value[0];
|
|
});
|
|
|
|
const workplanInfo = useCall<[[[u32, u16][]], Option<Vec<PalletBrokerScheduleItem>>[]]>(ready && api.query.broker.workplan.multi, [sanitizedKeys], { withParams: true });
|
|
|
|
const [state, setState] = useState<CoreWorkplan[] | undefined>();
|
|
|
|
useEffect(() => {
|
|
if (!workplanInfo?.[1] || !workplanInfo[0]?.[0]) {
|
|
return;
|
|
}
|
|
|
|
const coreInfo = workplanInfo[0][0];
|
|
|
|
setState(
|
|
sortByCore(coreInfo.map((core: BN[], index) =>
|
|
extractInfo(workplanInfo[1][index].unwrap(), core[1].toNumber(), core[0].toNumber())
|
|
))
|
|
);
|
|
}, [workplanInfo]);
|
|
|
|
return state;
|
|
}
|
|
|
|
export const useWorkplanInfos = createNamedHook('useWorkplanInfos', useWorkplanInfosImpl);
|