fix(striker-ui): add job indicator, complete message to StrikerInitForm

main
Tsu-ba-me 2 years ago
parent bc1b8bec20
commit 453562eb08
  1. 5
      striker-ui/components/JobSummary.tsx
  2. 46
      striker-ui/components/StrikerInitForm.tsx

@ -20,6 +20,7 @@ type AnvilJobs = {
}; };
type JobSummaryOptionalPropsWithDefault = { type JobSummaryOptionalPropsWithDefault = {
getJobUrl?: (epoch: number) => string;
openInitially?: boolean; openInitially?: boolean;
refreshInterval?: number; refreshInterval?: number;
}; };
@ -41,6 +42,7 @@ type JobSummaryForwardedRefContent = {
const JOB_LIST_LENGTH = '20em'; const JOB_LIST_LENGTH = '20em';
const JOB_SUMMARY_DEFAULT_PROPS: Required<JobSummaryOptionalPropsWithDefault> & const JOB_SUMMARY_DEFAULT_PROPS: Required<JobSummaryOptionalPropsWithDefault> &
JobSummaryOptionalPropsWithoutDefault = { JobSummaryOptionalPropsWithoutDefault = {
getJobUrl: (epoch) => `${API_BASE_URL}/job?start=${epoch}`,
onFetchSuccessAppend: undefined, onFetchSuccessAppend: undefined,
openInitially: false, openInitially: false,
refreshInterval: 10000, refreshInterval: 10000,
@ -49,6 +51,7 @@ const JOB_SUMMARY_DEFAULT_PROPS: Required<JobSummaryOptionalPropsWithDefault> &
const JobSummary = forwardRef<JobSummaryForwardedRefContent, JobSummaryProps>( const JobSummary = forwardRef<JobSummaryForwardedRefContent, JobSummaryProps>(
( (
{ {
getJobUrl = JOB_SUMMARY_DEFAULT_PROPS.getJobUrl,
onFetchSuccessAppend, onFetchSuccessAppend,
openInitially = JOB_SUMMARY_DEFAULT_PROPS.openInitially, openInitially = JOB_SUMMARY_DEFAULT_PROPS.openInitially,
refreshInterval = JOB_SUMMARY_DEFAULT_PROPS.refreshInterval, refreshInterval = JOB_SUMMARY_DEFAULT_PROPS.refreshInterval,
@ -64,7 +67,7 @@ const JobSummary = forwardRef<JobSummaryForwardedRefContent, JobSummaryProps>(
const loadTimestamp = useMemo(() => Math.floor(Date.now() / 1000), []); const loadTimestamp = useMemo(() => Math.floor(Date.now() / 1000), []);
periodicFetch<AnvilJobs>(`${API_BASE_URL}/job?start=${loadTimestamp}`, { periodicFetch<AnvilJobs>(getJobUrl(loadTimestamp), {
onError: () => { onError: () => {
setAnvilJobs({}); setAnvilJobs({});
}, },

@ -1,6 +1,10 @@
import { Assignment as AssignmentIcon } from '@mui/icons-material';
import { Grid } from '@mui/material'; import { Grid } from '@mui/material';
import { FC, useCallback, useMemo, useRef, useState } from 'react'; import { FC, useCallback, useMemo, useRef, useState } from 'react';
import API_BASE_URL from '../lib/consts/API_BASE_URL';
import { BLACK } from '../lib/consts/DEFAULT_THEME';
import api from '../lib/api'; import api from '../lib/api';
import ConfirmDialog from './ConfirmDialog'; import ConfirmDialog from './ConfirmDialog';
import ContainedButton from './ContainedButton'; import ContainedButton from './ContainedButton';
@ -10,6 +14,12 @@ import GeneralInitForm, {
GeneralInitFormValues, GeneralInitFormValues,
} from './GeneralInitForm'; } from './GeneralInitForm';
import handleAPIError from '../lib/handleAPIError'; import handleAPIError from '../lib/handleAPIError';
import IconButton from './IconButton';
import IconWithIndicator, {
IconWithIndicatorForwardedRefContent,
} from './IconWithIndicator';
import JobSummary, { JobSummaryForwardedRefContent } from './JobSummary';
import Link from './Link';
import MessageBox, { Message } from './MessageBox'; import MessageBox, { Message } from './MessageBox';
import NetworkInitForm, { import NetworkInitForm, {
NetworkInitFormForwardedRefContent, NetworkInitFormForwardedRefContent,
@ -35,6 +45,9 @@ const StrikerInitForm: FC = () => {
const generalInitFormRef = useRef<GeneralInitFormForwardedRefContent>({}); const generalInitFormRef = useRef<GeneralInitFormForwardedRefContent>({});
const networkInitFormRef = useRef<NetworkInitFormForwardedRefContent>({}); const networkInitFormRef = useRef<NetworkInitFormForwardedRefContent>({});
const jobIconRef = useRef<IconWithIndicatorForwardedRefContent>({});
const jobSummaryRef = useRef<JobSummaryForwardedRefContent>({});
const buildSubmitSection = useMemo( const buildSubmitSection = useMemo(
() => () =>
isSubmittingForm ? ( isSubmittingForm ? (
@ -70,6 +83,15 @@ const StrikerInitForm: FC = () => {
<Panel> <Panel>
<PanelHeader> <PanelHeader>
<HeaderText text="Initialize striker" /> <HeaderText text="Initialize striker" />
<IconButton
onClick={({ currentTarget }) => {
jobSummaryRef.current.setAnchor?.call(null, currentTarget);
jobSummaryRef.current.setOpen?.call(null, true);
}}
variant="normal"
>
<IconWithIndicator icon={AssignmentIcon} ref={jobIconRef} />
</IconButton>
</PanelHeader> </PanelHeader>
<FlexBox> <FlexBox>
<GeneralInitForm <GeneralInitForm
@ -223,6 +245,23 @@ const StrikerInitForm: FC = () => {
.put('/init', requestBody) .put('/init', requestBody)
.then(() => { .then(() => {
setIsSubmittingForm(false); setIsSubmittingForm(false);
setSubmitMessage({
children: (
<>
Successfully registered the configuration job! You can check
the progress at the top right icon. Once the job completes,
you can access the{' '}
<Link
href="/login"
sx={{ color: BLACK, display: 'inline-flex' }}
>
login page
</Link>
.
</>
),
type: 'info',
});
}) })
.catch((error) => { .catch((error) => {
const errorMessage = handleAPIError(error); const errorMessage = handleAPIError(error);
@ -233,6 +272,13 @@ const StrikerInitForm: FC = () => {
}} }}
titleText="Confirm striker initialization" titleText="Confirm striker initialization"
/> />
<JobSummary
getJobUrl={(epoch) => `${API_BASE_URL}/init/job?start=${epoch}`}
onFetchSuccessAppend={(jobs) => {
jobIconRef.current.indicate?.call(null, Object.keys(jobs).length > 0);
}}
ref={jobSummaryRef}
/>
</> </>
); );
}; };

Loading…
Cancel
Save