Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

877 implement automatic generation of api client radix api #882

Merged
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"deps:stale": "node scripts/deps-stale-check.js",
"apigen:cost": "npx @rtk-query/codegen-openapi ./src/store/configs/cost-openapi-config.ts",
"apigen:log": "npx @rtk-query/codegen-openapi ./src/store/configs/log-openapi-config.ts",
"apigen:radix": "npx @rtk-query/codegen-openapi ./src/store/configs/radix-openapi-config.ts",
"apigen:scan": "npx @rtk-query/codegen-openapi ./src/store/configs/scan-openapi-config.ts"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/async-resource/another-async-resource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { isNullOrUndefined } from '../../utils/object';
import { FetchQueryError, FetchQueryResult } from '../../store/types';
import { getFetchErrorData } from '../../store/utils';

type AnotherAsyncStatus = Pick<
export type AnotherAsyncStatus = Pick<
FetchQueryResult,
'error' | 'isError' | 'isLoading'
>;
Expand Down
14 changes: 6 additions & 8 deletions src/components/code/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { copyToClipboard, copyToTextFile } from '../../utils/string';

import './style.css';

export interface CodeProps {
export type CodeProps = {
autoscroll?: boolean;
copy?: boolean;
download?: boolean;
downloadCb?: () => void;
filename?: string;
resizable?: boolean;
downloadCb?: () => void;
}
};

function scrollToBottom(elementRef: Element): void {
// HACK elementRef.scrollHeight is incorrect when called directly
Expand All @@ -27,9 +27,9 @@ export const Code: FunctionComponent<CodeProps & { children?: string }> = ({
autoscroll,
copy,
download,
filename,
resizable,
downloadCb,
filename = 'undefined',
resizable,
children,
}) => {
const [scrollOffsetFromBottom, setScrollOffsetFromBottom] = useState(0);
Expand Down Expand Up @@ -60,9 +60,7 @@ export const Code: FunctionComponent<CodeProps & { children?: string }> = ({
<Button
variant="ghost"
onClick={() =>
downloadCb
? downloadCb()
: copyToTextFile(`${filename}.txt`, children)
downloadCb ? downloadCb() : copyToTextFile(filename, children)
}
>
<Icon data={downloadIcon} /> Download
Expand Down
26 changes: 26 additions & 0 deletions src/components/code/log-helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { BaseQueryFn, QueryDefinition } from '@reduxjs/toolkit/query';
import { UseLazyQuery } from '@reduxjs/toolkit/dist/query/react/buildHooks';

import { errorToast } from '../global-top-nav/styled-toaster';
import { getFetchErrorMessage } from '../../store/utils';
import { copyToTextFile } from '../../utils/string';

export function downloadLazyLogCb<
T extends ReturnType<
UseLazyQuery<QueryDefinition<unknown, BaseQueryFn, string, string>>
>[0],
>(filename: string, func: T, ...args: Parameters<T>): () => Promise<void> {
return async () => {
const { data, error, isError, isSuccess } = await func(
args?.[0],
args?.[1]
);

if (isSuccess && data) {
copyToTextFile(filename, data);
} else if (isError) {
const message = getFetchErrorMessage(error);
errorToast(`Failed to download: ${message}`);
}
};
}
58 changes: 0 additions & 58 deletions src/components/component/log.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/component/scheduled-job/payload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const Payload: FunctionComponent<PayloadProps> = ({

return (
<div className="payload-content">
<Code copy download={false} autoscroll resizable>
<Code copy autoscroll resizable>
{data ?? ''}
</Code>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/home-icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ export class HomeIcon extends Component<{}, { svgLogo?: string }> {
}

private async fetchLogo(date: Date): Promise<typeof import('*.svg')> {
const fileName = isEasterTime(date)
const filename = isEasterTime(date)
? 'logo-radix-easter'
: isHalloween(date)
? 'logo-radix-halloween'
: isDecember(date)
? 'logo-radix-christmas'
: 'logo-radix';
return await import(`./logos/${fileName}.svg`);
return await import(`./logos/${filename}.svg`);
}

override componentDidMount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ const LogDownloadButton: FunctionComponent<{

function saveLog(
query: Pick<FetchQueryResult, 'data' | 'error' | 'isError' | 'isSuccess'>,
fileName: string,
filename: string,
errMsg = 'Failed to download log'
): void {
if (query.isSuccess) {
const extension = !fileName.endsWith('.txt') ? '.txt' : '';
copyToTextFile(`${fileName}${extension}`, query.data as string);
copyToTextFile(filename, query.data as string);
} else if (query.isError) {
const { code, message } = getFetchErrorData(query.error);
errorToast(`${errMsg}: ${code && `[${code}] `}${message}`);
Expand Down Expand Up @@ -237,8 +236,8 @@ const ReplicaLogTableRow: FunctionComponent<
replicaName: name,
});

const fileName = `${appName}_${envName}_${componentName}_${name}`;
saveLog(response, fileName);
const filename = `${appName}_${envName}_${componentName}_${name}.txt`;
saveLog(response, filename);
}}
disabled={isFetching}
/>
Expand Down Expand Up @@ -300,8 +299,8 @@ const ReplicaContainerTableRow: FunctionComponent<
containerId: id,
});

const fileName = `${appName}_${envName}_${componentName}_${replicaName}_${id}`;
saveLog(response, fileName);
const filename = `${appName}_${envName}_${componentName}_${replicaName}_${id}.txt`;
saveLog(response, filename);
}}
disabled={isFetching}
/>
Expand Down
43 changes: 21 additions & 22 deletions src/components/page-oauth-replica/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import { Typography } from '@equinor/eds-core-react';
import * as PropTypes from 'prop-types';
import { FunctionComponent, useEffect, useState } from 'react';

import { useGetOAuthFullLogs } from './use-get-oauth-full-logs';
import { usePollOAuthLogs } from './use-poll-oauth-logs';

import AsyncResource from '../async-resource/simple-async-resource';
import { LogDownloadOverrideType } from '../component/log';
import { Breadcrumb } from '../breadcrumb';
import { downloadLazyLogCb } from '../code/log-helper';
import { useGetEnvironment } from '../page-environment/use-get-environment';
import { Replica } from '../replica';
import { ReplicaSummaryNormalizedModel } from '../../models/radix-api/deployments/replica-summary';
import { routes } from '../../routes';
import { radixApi, useGetOAuthPodLogQuery } from '../../store/radix-api';
import { connectRouteParams, routeParamLoader } from '../../utils/router';
import { getEnvsUrl } from '../../utils/routing';
import { routeWithParams, smallReplicaName } from '../../utils/string';
Expand All @@ -27,24 +25,14 @@ export const PageOAuthAuxiliaryReplica: FunctionComponent<
PageOAuthAuxiliaryReplicaProps
> = ({ appName, envName, componentName, replicaName }) => {
const [environmentState] = useGetEnvironment(appName, envName);
const [pollLogsState] = usePollOAuthLogs(
appName,
envName,
componentName,
replicaName
);
const [getFullLogsState, downloadFullLog] = useGetOAuthFullLogs(
appName,
envName,
componentName,
replicaName
const pollLogsState = useGetOAuthPodLogQuery(
{ appName, envName, componentName, podName: replicaName, lines: '1000' },
{
skip: !appName || !envName || !componentName || !replicaName,
pollingInterval: 5000,
}
);
const downloadOverride: LogDownloadOverrideType = {
status: getFullLogsState.status,
content: getFullLogsState.data,
onDownload: () => downloadFullLog(),
error: getFullLogsState.error,
};
const [getLog] = radixApi.endpoints.getOAuthPodLog.useLazyQuery();

const [replica, setReplica] = useState<ReplicaSummaryNormalizedModel>();
useEffect(() => {
Expand Down Expand Up @@ -83,7 +71,18 @@ export const PageOAuthAuxiliaryReplica: FunctionComponent<
<Replica
logState={pollLogsState}
replica={replica}
downloadOverride={downloadOverride}
downloadCb={downloadLazyLogCb(
`${replica.name}.txt`,
getLog,
{
appName,
envName,
componentName,
podName: replicaName,
file: 'true',
},
false
)}
title={
<>
<Typography>OAuth2 Service</Typography>
Expand Down
18 changes: 0 additions & 18 deletions src/components/page-oauth-replica/use-get-oauth-full-logs.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/components/page-oauth-replica/use-poll-oauth-logs.ts

This file was deleted.

44 changes: 21 additions & 23 deletions src/components/page-replica/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import { Typography } from '@equinor/eds-core-react';
import * as PropTypes from 'prop-types';
import { FunctionComponent, useEffect, useState } from 'react';

import { useGetReplicaFullLog } from './use-get-replica-full-log';
import { usePollReplicaLogs } from './use-poll-replica-logs';

import AsyncResource from '../async-resource/simple-async-resource';
import { Breadcrumb } from '../breadcrumb';
import { LogDownloadOverrideType } from '../component/log';
import { downloadLazyLogCb } from '../code/log-helper';
import { useGetEnvironment } from '../page-environment/use-get-environment';
import { Replica } from '../replica';
import { ReplicaSummaryNormalizedModel } from '../../models/radix-api/deployments/replica-summary';
import { routes } from '../../routes';
import { radixApi, useReplicaLogQuery } from '../../store/radix-api';
import { connectRouteParams, routeParamLoader } from '../../utils/router';
import { getEnvsUrl } from '../../utils/routing';
import { routeWithParams, smallReplicaName } from '../../utils/string';
Expand All @@ -30,25 +28,14 @@ const PageReplica: FunctionComponent<PageReplicaProps> = ({
replicaName,
}) => {
const [environmentState] = useGetEnvironment(appName, envName);
const [pollLogsState] = usePollReplicaLogs(
appName,
envName,
componentName,
replicaName
);
const [getFullLogsState, downloadFullLog] = useGetReplicaFullLog(
appName,
envName,
componentName,
replicaName
const pollLogsState = useReplicaLogQuery(
{ appName, envName, componentName, podName: replicaName, lines: '1000' },
{
skip: !appName || !envName || !componentName || !replicaName,
pollingInterval: 5000,
}
);

const downloadOverride: LogDownloadOverrideType = {
status: getFullLogsState.status,
content: getFullLogsState.data,
onDownload: () => downloadFullLog(),
error: getFullLogsState.error,
};
const [getLog] = radixApi.endpoints.replicaLog.useLazyQuery();

const [replica, setReplica] = useState<ReplicaSummaryNormalizedModel>();
useEffect(() => {
Expand Down Expand Up @@ -85,7 +72,18 @@ const PageReplica: FunctionComponent<PageReplicaProps> = ({
<Replica
logState={pollLogsState}
replica={replica}
downloadOverride={downloadOverride}
downloadCb={downloadLazyLogCb(
`${replica.name}.txt`,
getLog,
{
appName,
envName,
componentName,
podName: replicaName,
file: 'true',
},
false
)}
title={
<Typography>
Replica <strong>{smallReplicaName(replicaName)}</strong>,
Expand Down
Loading