Skip to content

Commit

Permalink
add loading indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh-Bharadwaj committed Mar 20, 2024
1 parent b978fcc commit 748d20b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
37 changes: 9 additions & 28 deletions ui/app/mirrors/create/cdc/cdc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import { DBType } from '@/grpc_generated/peers';
import { Button } from '@/lib/Button';
import { Icon } from '@/lib/Icon';
import { Label } from '@/lib/Label/Label';
import { ProgressCircle } from '@/lib/ProgressCircle';
import { Dispatch, SetStateAction, useEffect, useMemo, useState } from 'react';
import { CDCConfig, MirrorSetter, TableMapRow } from '../../../dto/MirrorsDTO';
import { fetchPublications } from '../handlers';
Expand Down Expand Up @@ -40,6 +38,7 @@ export default function CDCConfigForm({
setRows,
}: MirrorConfigProps) {
const [publications, setPublications] = useState<string[]>();
const [pubLoading, setPubLoading] = useState(true);
const [show, setShow] = useState(false);
const handleChange = (val: string | boolean, setting: MirrorSetting) => {
let stateVal: string | boolean = val;
Expand Down Expand Up @@ -68,18 +67,11 @@ export default function CDCConfigForm({
return true;
};

const optionsForField = (setting: MirrorSetting) => {
switch (setting.label) {
case 'Publication Name':
return publications;
default:
return [];
}
};

useEffect(() => {
setPubLoading(true);
fetchPublications(mirrorConfig.source?.name || '').then((pubs) => {
setPublications(pubs);
setPubLoading(false);
});
}, [mirrorConfig.source?.name]);

Expand All @@ -93,7 +85,12 @@ export default function CDCConfigForm({
key={id}
handleChange={handleChange}
setting={setting}
options={optionsForField(setting)}
options={
setting.label === 'Publication Name'
? publications
: undefined
}
publicationsLoading={pubLoading}
/>
)
);
Expand Down Expand Up @@ -124,7 +121,6 @@ export default function CDCConfigForm({
key={setting.label}
handleChange={handleChange}
setting={setting}
options={optionsForField(setting)}
/>
);
})}
Expand All @@ -138,19 +134,4 @@ export default function CDCConfigForm({
/>
</>
);

if (publications === undefined)
return (
<div
style={{
display: 'flex',
alignItems: 'center',
marginTop: '2rem',
columnGap: '1rem',
}}
>
<Label>Loading publications...</Label>
<ProgressCircle variant='determinate_progress_circle' />
</div>
);
}
9 changes: 8 additions & 1 deletion ui/app/mirrors/create/cdc/fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ interface FieldProps {
setting: MirrorSetting;
handleChange: (val: string | boolean, setting: MirrorSetting) => void;
options?: string[];
publicationsLoading?: boolean;
}

const CDCField = ({ setting, handleChange, options }: FieldProps) => {
const CDCField = ({
setting,
handleChange,
options,
publicationsLoading,
}: FieldProps) => {
return setting.type === 'switch' ? (
<RowWithSwitch
label={
Expand Down Expand Up @@ -72,6 +78,7 @@ const CDCField = ({ setting, handleChange, options }: FieldProps) => {
getOptionLabel={(option) => option.label}
getOptionValue={(option) => option.option}
theme={SelectTheme}
isLoading={publicationsLoading}
/>
</div>
{setting.tips && (
Expand Down

0 comments on commit 748d20b

Please sign in to comment.