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

Fix all lint warnings in UI #1388

Merged
merged 3 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 63 additions & 59 deletions src/ui/common/src/components/AnnouncementBanner/AnnouncementBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,88 +20,92 @@ export const AnnouncementBanner: React.FC<AnnouncementBannerProps> = ({
user,
}) => {
const location = useLocation();
const allowedBannerPages = ['/workflows', '/resources', '/data', '/'];

// By default do not show banner until we know that we have an announcement to show.
const [shouldShowAnnouncementBanner, setShouldShowAnnouncementBanner] =
useState<boolean>(false);
const [versionNumber, setVersionNumber] = useState<string>('');
const [latestVersion, setLatestVersion] = useState<string>('');
const [currentVersion, setCurrentVersion] = useState<string>('');

useEffect(() => {
async function fetchVersionNumber() {
async function fetchVersions() {
const pypiRes = await fetch('https://pypi.org/pypi/aqueduct-ml/json', {
method: 'GET',
});
const pyPiResponse = await pypiRes.json();
const pyPiVersionString = pyPiResponse.info.version;
const pyPiVersion = pyPiResponse.info.version;
setLatestVersion(pyPiVersion);

const res = await fetch(`${apiAddress}/api/version`, {
method: 'GET',
headers: { 'api-key': user.apiKey },
});
const aqueductVersionNumberResponse = await res.json();

const versionBannerDismissed = localStorage.getItem(
'versionBanner.dismissedVersion'
);

let showBanner = false;
if (aqueductVersionNumberResponse?.version) {
const pyPiVersionNumbers = pyPiVersionString?.split('.');

// compare strings to see if the two are equal.
// if equal, check if banner has been dismissed and return
const sameVersion =
aqueductVersionNumberResponse.version === pyPiVersionString;
const isDismissed = versionBannerDismissed === pyPiVersionString;

// First check if we should hide the banner.
if (isDismissed || sameVersion) {
showBanner = false;
} else if (pyPiVersionNumbers) {
const versionNumbersResponse =
aqueductVersionNumberResponse.version.split('.');
const majorResponse = parseInt(versionNumbersResponse[0]);
const minorResponse = parseInt(versionNumbersResponse[1]);
const patchResponse = parseInt(versionNumbersResponse[2]);

// compare the two version numbers that we have
const pyPiMajor = parseInt(pyPiVersionNumbers[0]);
const pyPiMinor = parseInt(pyPiVersionNumbers[1]);
const pyPiPatch = parseInt(pyPiVersionNumbers[2]);

// Finally check if there is in fact a new version and show banner if so.
if (
pyPiMajor > majorResponse ||
pyPiMinor > minorResponse ||
pyPiPatch > patchResponse
) {
showBanner = true;
}
}
}

setVersionNumber(pyPiVersionString);
setShouldShowAnnouncementBanner(showBanner);
if (showBanner === true && onShow) {
onShow();
const aqueductVersionResponse = await res.json();
if (aqueductVersionResponse?.version) {
setCurrentVersion(aqueductVersionResponse?.version);
}
}

if (user.apiKey) {
fetchVersionNumber();
fetchVersions();
}
}, [user.apiKey]);
}, [user]);

// Make sure user is on appropriate pages and that the banner should be shown.
if (
!shouldShowAnnouncementBanner ||
allowedBannerPages.indexOf(location.pathname) < 0
) {
if (onClose) {
useEffect(() => {
const allowedBannerPages = ['/workflows', '/resources', '/data', '/'];
const versionBannerDismissed = localStorage.getItem(
'versionBanner.dismissedVersion'
);

let showBanner = false;
if (currentVersion) {
const pyPiVersionNumbers = latestVersion?.split('.');

// compare strings to see if the two are equal.
// if equal, check if banner has been dismissed and return
const isSameVersion = currentVersion === latestVersion;
const isDismissed = versionBannerDismissed === latestVersion;

// First check if we should hide the banner.
if (isDismissed || isSameVersion) {
showBanner = false;
} else if (pyPiVersionNumbers) {
const versionNumbersResponse = currentVersion.split('.');
const majorResponse = parseInt(versionNumbersResponse[0]);
const minorResponse = parseInt(versionNumbersResponse[1]);
const patchResponse = parseInt(versionNumbersResponse[2]);

// compare the two version numbers that we have
const pyPiMajor = parseInt(pyPiVersionNumbers[0]);
const pyPiMinor = parseInt(pyPiVersionNumbers[1]);
const pyPiPatch = parseInt(pyPiVersionNumbers[2]);

// Finally check if there is in fact a new version and show banner if so.
if (
pyPiMajor > majorResponse ||
pyPiMinor > minorResponse ||
pyPiPatch > patchResponse
) {
showBanner = true;
}
}
}

if (allowedBannerPages.indexOf(location.pathname) < 0) {
showBanner = false;
}

setShouldShowAnnouncementBanner(showBanner);
if (showBanner) {
onShow();
} else {
onClose();
}
}, [currentVersion, latestVersion, onShow, onClose, location]);

// Make sure user is on appropriate pages and that the banner should be shown.
if (!shouldShowAnnouncementBanner) {
return null;
}

Expand All @@ -121,7 +125,7 @@ export const AnnouncementBanner: React.FC<AnnouncementBannerProps> = ({
>
<Box>
<Typography variant="body1" component={'span'}>
✨ Aqueduct v{versionNumber} is out!{' '}
✨ Aqueduct v{latestVersion} is out!{' '}
<Link
href={'https://github.com/aqueducthq/aqueduct/releases'}
target="_blank"
Expand Down Expand Up @@ -149,7 +153,7 @@ export const AnnouncementBanner: React.FC<AnnouncementBannerProps> = ({
onClose();
localStorage.setItem(
'versionBanner.dismissedVersion',
versionNumber ?? ''
latestVersion ?? ''
);
}
}}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/common/src/components/pages/account/AccountPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ client = aqueduct.Client(
}

fetchServerConfig();
}, []);
}, [dispatch, user]);

useEffect(() => {
if (!updatingNotifications) {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/common/src/components/pages/resource/id/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const ResourceDetailsPage: React.FC<ResourceDetailsPageProps> = ({
})
);
}
}, [selectedResource]);
}, [dispatch, selectedResource, resourceId, user]);

// Load the server config to check if the selected resource is currently being used as storage.
// If that is the case, we hide the option to delete the resource from the user.
Expand All @@ -156,7 +156,7 @@ const ResourceDetailsPage: React.FC<ResourceDetailsPageProps> = ({
}

fetchServerConfig();
}, [user.apiKey]);
}, [dispatch, user]);

const {
data: workflowAndDagIDs,
Expand Down
4 changes: 2 additions & 2 deletions src/ui/common/src/components/pages/resources/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const ResourcesPage: React.FC<Props> = ({ user, Layout = DefaultLayout }) => {
}

fetchServerConfig();
}, [user]);
}, [dispatch, user]);

useEffect(() => {
document.title = 'Resources | Aqueduct';
Expand All @@ -73,7 +73,7 @@ const ResourcesPage: React.FC<Props> = ({ user, Layout = DefaultLayout }) => {
}

// If the last storage migration failed, display the error message.
const { data, error, isLoading } = useStorageMigrationListQuery({
const { data, isLoading } = useStorageMigrationListQuery({
apiKey: user.apiKey,
limit: '1', // only fetch the latest result.
});
Expand Down
16 changes: 4 additions & 12 deletions src/ui/common/src/components/pages/workflow/id/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function useWorkflowIds(apiKey: string): useWorkflowIdsOutputs {
});
return;
}
}, [wfIdParam, dagResultIdParam, dagResult, dagIdParam, dag]);
}, [navigate, wfIdParam, dagResultIdParam, dagResult, dagIdParam, dag]);

return {
workflowId: wfIdParam,
Expand Down Expand Up @@ -181,11 +181,7 @@ export function useWorkflowNodesResults(
}

export function useLatestDagResultOrDag(apiKey: string, workflowId: string) {
const {
data: dagResults,
error: dagResultsError,
isLoading: dagResultsLoading,
} = useDagResultsGetQuery({
const { data: dagResults } = useDagResultsGetQuery({
apiKey: apiKey,
workflowId: workflowId,
});
Expand All @@ -194,17 +190,13 @@ export function useLatestDagResultOrDag(apiKey: string, workflowId: string) {

const dagIdFromLatestDagResult = latestDagResult?.dag_id;

const {
data: dags,
error: dagsError,
isLoading: dagsLoading,
} = useDagsGetQuery(
const { data: dags } = useDagsGetQuery(
{
apiKey: apiKey,
workflowId: workflowId,
},
{
skip: dagIdFromLatestDagResult,
skip: !!dagIdFromLatestDagResult,
}
);

Expand Down
2 changes: 1 addition & 1 deletion src/ui/common/src/components/pages/workflow/id/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const WorkflowPage: React.FC<WorkflowPageProps> = ({
refetchWorkflow();
setCurrentTab('Details');
}
}, [editWorkflowSuccess]);
}, [refetchWorkflow, editWorkflowSuccess]);

// This workflow doesn't exist.
if (wfError) {
Expand Down
8 changes: 2 additions & 6 deletions src/ui/common/src/components/pages/workflows/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,14 @@ const WorkflowsPage: React.FC<Props> = ({ user, Layout = DefaultLayout }) => {

const latestDagId = latestDagResult?.dag_id ?? noRunDag?.id;

const {
data: dag,
error: dagError,
isLoading: dagLoading,
} = useDagGetQuery(
const { data: dag } = useDagGetQuery(
{
apiKey: user.apiKey,
workflowId: workflowId,
dagId: latestDagId,
},
{
skip: !latestDagId || noRunDag,
skip: !latestDagId || !!noRunDag,
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const DeleteResourceDialog: React.FC<Props> = ({
}

fetchServerConfig();
}, []);
}, [dispatch, user]);

const deleteResourceStatus = useSelector(
(state: RootState) => state.resourceReducer.deletionStatus
Expand Down
13 changes: 4 additions & 9 deletions src/ui/common/src/components/resources/dialogs/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import React, { MouseEventHandler, useEffect, useState } from 'react';
import { FormProvider, useForm } from 'react-hook-form';
import { useDispatch, useSelector } from 'react-redux';
import * as Yup from 'yup';
import { ObjectShape } from 'yup/lib/object';

import { useResourceWorkflowsGetQuery } from '../../../handlers/AqueductApi';
import {
Expand Down Expand Up @@ -46,7 +47,7 @@ type Props = {
showMigrationDialog?: () => void;
resourceToEdit?: Resource;
dialogContent: React.FC<ResourceDialogProps<ResourceConfig>>;
validationSchema: Yup.ObjectSchema<any>;
validationSchema: Yup.ObjectSchema<ObjectShape>;
};

const ResourceDialog: React.FC<Props> = ({
Expand Down Expand Up @@ -152,21 +153,15 @@ const ResourceDialog: React.FC<Props> = ({
const subscription = methods.watch(async () => {
const checkIsFormValid = async () => {
const isValidForm = await methods.trigger();
if (isValidForm && submitDisabled) {
// Form is valid, enable the submit button.
setSubmitDisabled(false);
} else {
// Form is still invalid, disable the submit button.
setSubmitDisabled(true);
}
setSubmitDisabled(!isValidForm);
};

checkIsFormValid();
});

// Unsubscribe and handle lifecycle changes.
return () => subscription.unsubscribe();
}, [methods.watch]);
}, [methods]);

useEffect(() => {
if (isSucceeded(connectStatus)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const GCSDialog: React.FC<GCSDialogProps> = ({
if (setMigrateStorage) {
setMigrateStorage(initialUseAsStorage === 'true');
}
}, [setMigrateStorage]);
}, [setMigrateStorage, initialUseAsStorage]);

return (
<Box sx={{ mt: 2 }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ export const OnDemandKubernetesDialog: React.FC<
return;
};

const handleGCPClick = () => {
setCurrentStep(K8S_TYPES.ONDEMAND_K8S_GCP);
setValue('k8s_type', K8S_TYPES.ONDEMAND_K8S_GCP);
};

switch (currentStep) {
case 'INITIAL':
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const S3Dialog: React.FC<S3DialogProps> = ({
if (setMigrateStorage) {
setMigrateStorage(initialUseAsStorage === 'true');
}
}, [setMigrateStorage]);
}, [setMigrateStorage, initialUseAsStorage]);

const configProfileInput = (
<ResourceTextInputField
Expand Down
7 changes: 5 additions & 2 deletions src/ui/common/src/components/resources/dialogs/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as Yup from 'yup';
import { ObjectShape } from 'yup/lib/object';

export function requiredAtCreate(
schema,
schema: Yup.ObjectSchema<ObjectShape>,
editMode: boolean,
msg?: string | undefined
): any {
): Yup.ObjectSchema<ObjectShape> {
return editMode ? schema : schema.required(msg);
}
Loading