Skip to content

Commit

Permalink
Merge pull request #191 from kaleido-io/status
Browse files Browse the repository at this point in the history
Add status sections to subscription & listener slides
  • Loading branch information
peterbroadhurst authored Aug 31, 2022
2 parents 8c4e718 + 8e4f69f commit 900c580
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 3 deletions.
59 changes: 59 additions & 0 deletions src/components/Lists/SubStatusList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright © 2022 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { ISubscription } from '../../interfaces';
import { IDataListItem } from '../../interfaces/lists';
import { FFCopyButton } from '../Buttons/CopyButton';
import { FFListItem } from './FFListItem';
import { FFListText } from './FFListText';
import { FFSkeletonList } from './FFSkeletonList';

interface Props {
status?: ISubscription['status'];
}

export const SubStatusList: React.FC<Props> = ({ status }) => {
const { t } = useTranslation();
const [dataList, setDataList] = useState<IDataListItem[]>(FFSkeletonList);

useEffect(() => {
if (status) {
setDataList([
{
label: status.currentOffset ? t('currentOffset') : '',
value: status.currentOffset && (
<FFListText color="primary" text={String(status.currentOffset)} />
),
button: status.currentOffset ? (
<FFCopyButton value={String(status.currentOffset)} />
) : (
<></>
),
},
]);
}
}, [status]);

return (
<>
{dataList.map(
(d, idx) => d.label !== '' && <FFListItem key={idx} item={d} />
)}
</>
);
};
9 changes: 9 additions & 0 deletions src/components/Slides/ListenerSlide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ export const ListenerSlide: React.FC<Props> = ({ listener, open, onClose }) => {
<SlideSectionHeader title={t('options')} />
<SubOptionsList options={listener.options} />
</Grid>
{listener.status?.checkpoint && (
<Grid container item pb={DEFAULT_PADDING}>
<JsonViewAccordion
isOpen
json={listener.status}
header={t('status')}
/>
</Grid>
)}
{/* API Location */}
{listener.location && (
<Grid container item pb={DEFAULT_PADDING}>
Expand Down
8 changes: 7 additions & 1 deletion src/components/Slides/SubscriptionSlide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { DEFAULT_PADDING } from '../../theme';
import { JsonViewAccordion } from '../Accordions/JsonViewerAccordion';
import { SubList } from '../Lists/SubList';
import { SubOptionsList } from '../Lists/SubOptionsList';
import { SubStatusList } from '../Lists/SubStatusList';
import { DisplaySlide } from './DisplaySlide';
import { SlideHeader } from './SlideHeader';
import { SlideSectionHeader } from './SlideSectionHeader';
Expand All @@ -45,12 +46,17 @@ export const SubscriptionSlide: React.FC<Props> = ({ sub, open, onClose }) => {
<Grid container item>
<SubList sub={sub} />
</Grid>
{sub.status && (
<Grid container item pb={DEFAULT_PADDING}>
<SlideSectionHeader title={t('status')} />
<SubStatusList status={sub.status} />
</Grid>
)}
{/* Filter options */}
<Grid container item pb={DEFAULT_PADDING}>
<SlideSectionHeader title={t('options')} />
<SubOptionsList options={sub.options} />
</Grid>

{sub.filter && (
<Grid container item pb={DEFAULT_PADDING}>
<JsonViewAccordion
Expand Down
11 changes: 11 additions & 0 deletions src/interfaces/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ export interface IContractListener {
readAhead?: number;
withData?: boolean;
};
status?: {
checkpoint?: {
block: number;
transactionIndex: number;
logIndex: number;
};
catchup?: boolean;
};
}

export interface IData {
Expand Down Expand Up @@ -483,6 +491,9 @@ export interface ISubscription {
};
created: string;
updated: string | null;
status?: {
currentOffset?: number;
};
}

export interface ITokenAccount {
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const FF_Paths = {
contractQuery: '/contracts/query',
contractListeners: '/contracts/listeners',
contractListenersByNameId: (nameOrId: string) =>
`/contracts/listeners/${nameOrId}`,
`/contracts/listeners/${nameOrId}?fetchstatus`,
// Data
data: '/data',
dataById: (id: string) => `/data/${id}`,
Expand Down Expand Up @@ -88,7 +88,7 @@ export const FF_Paths = {
operationsById: (opId: string) => `/operations/${opId}`,
// Subscriptions
subscriptions: '/subscriptions',
subscriptionsById: (subId: string) => `/subscriptions/${subId}`,
subscriptionsById: (subId: string) => `/subscriptions/${subId}?fetchstatus`,
// Tokens
tokens: '/tokens',
tokenAccounts: '/tokens/accounts',
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"copyToClipboard": "Copy to Clipboard",
"core": "Core",
"created": "Created",
"currentOffset": "Current Offset",
"customRange": "Custom Range",
"dashboard": "Dashboard",
"data": "Data",
Expand Down

0 comments on commit 900c580

Please sign in to comment.