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(AAS List): Handle protected repositories in aas list #77

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
4 changes: 2 additions & 2 deletions src/app/[locale]/_components/DashboardInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const DashboardInput = () => {
const navigate = useRouter();

const browseAasUrl = async (searchString: string) => {
const { isSuccess, result } = await performFullAasSearch(searchString.trim());
if (!isSuccess) throw new LocalizedError(messages.mnestix.aasUrlNotFound);
const { isSuccess, result } = await performFullAasSearch(searchString.trim());
if (!isSuccess) throw new LocalizedError('url-not-found');

if (result.aas) {
setAas(result.aas);
Expand Down
18 changes: 9 additions & 9 deletions src/app/[locale]/_components/ManualAasInput.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { Box, IconButton, InputAdornment, TextField } from '@mui/material';
import { FormattedMessage, useIntl } from 'react-intl';
import { FormattedMessage } from 'react-intl';
import React, { useEffect, useRef, useState } from 'react';
import { ArrowForward } from '@mui/icons-material';
import { messages } from 'lib/i18n/localization';
import CloseIcon from '@mui/icons-material/Close';
import { SquaredIconButton } from 'components/basics/Buttons';
import { LocalizedError } from 'lib/util/LocalizedError';
import { useNotificationSpawner } from 'lib/hooks/UseNotificationSpawner';
import { showError } from 'lib/util/ErrorHandlerUtil';
import { useShowError } from 'lib/hooks/UseShowError';
import { useTranslations } from 'next-intl';

export function ManualAasInput(props: { onSubmit: (input: string) => Promise<void> }) {
const [inputValue, setInputValue] = useState<string>('');
const [isLoading, setIsLoading] = useState<boolean>(false);
const [isError, setIsError] = useState<boolean>(false);
const [errorText, setErrorText] = useState<string>('');
const intl = useIntl();
const inputRef = useRef<HTMLInputElement>(null);
const notificationSpawner = useNotificationSpawner();

const { showError } = useShowError();
const t = useTranslations('errors');

useEffect(() => {
inputRef?.current?.focus();
}, []);
Expand All @@ -38,9 +38,9 @@ export function ManualAasInput(props: { onSubmit: (input: string) => Promise<voi
await props.onSubmit(inputValue);
} catch (e) {
setIsLoading(false);
const msg = e instanceof LocalizedError ? e.descriptor : messages.mnestix.unexpectedError;
setError(intl.formatMessage(msg));
if (!(e instanceof LocalizedError)) showError(e, notificationSpawner);
const msg = e instanceof LocalizedError ? e.descriptor : 'unexpected-error';
setError(t(msg));
if (!(e instanceof LocalizedError)) showError(e);
}
};

Expand Down
12 changes: 5 additions & 7 deletions src/app/[locale]/_components/QrScanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import { Box, CircularProgress, IconButton, useTheme } from '@mui/material';
import { QrStream } from 'app/[locale]/_components/QrStream';
import CancelIcon from '@mui/icons-material/Cancel';
import { useNotificationSpawner } from 'lib/hooks/UseNotificationSpawner';
import { messages } from 'lib/i18n/localization';
import { useIntl } from 'react-intl';
import { LocalizedError } from 'lib/util/LocalizedError';
import { keyframes, styled } from '@mui/system';
import { ThemeProvider } from '@mui/material/styles';
import CircleIcon from '@mui/icons-material/Circle';
import { useTranslations } from 'next-intl';

enum State {
Stopped,
Expand All @@ -24,7 +23,7 @@ export function QrScanner(props: { onScan: (scanResult: string) => Promise<void>
const [state, setState] = useState<State>(State.Stopped);

const notificationSpawner = useNotificationSpawner();
const intl = useIntl();
const t = useTranslations('errors');

const theme = useTheme();
const size = props.size || 250;
Expand All @@ -34,7 +33,7 @@ export function QrScanner(props: { onScan: (scanResult: string) => Promise<void>
setState(State.ShowVideo);
} else {
notificationSpawner.spawn({
message: intl.formatMessage(messages.mnestix.qrScanner.errorOnQrScannerOpen),
message: t('qr-scanner.error-on-qr-scanner-open'),
severity: 'error',
});
setState(State.Stopped);
Expand Down Expand Up @@ -87,10 +86,9 @@ export function QrScanner(props: { onScan: (scanResult: string) => Promise<void>
await props.onScan(result);
setState(State.Stopped);
} catch (e) {
const msg =
e instanceof LocalizedError ? e.descriptor : messages.mnestix.qrScanner.defaultCallbackErrorMsg;
const msg = e instanceof LocalizedError ? e.descriptor : 'qr-scanner.default-callback-error-msg';
notificationSpawner.spawn({
message: intl.formatMessage(msg),
message: t(msg),
severity: 'error',
});
setState(State.LoadScanner);
Expand Down
12 changes: 5 additions & 7 deletions src/app/[locale]/asset/_components/RedirectToViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
'use client';
import { useAsyncEffect } from 'lib/hooks/UseAsyncEffect';
import { encodeBase64 } from 'lib/util/Base64Util';
import { useNotificationSpawner } from 'lib/hooks/UseNotificationSpawner';
import { Box } from '@mui/material';
import { showError } from 'lib/util/ErrorHandlerUtil';
import { NotFoundError } from 'lib/errors/NotFoundError';
import { useState } from 'react';
import { CenteredLoadingSpinner } from 'components/basics/CenteredLoadingSpinner';
Expand All @@ -13,17 +11,17 @@ import { useAasOriginSourceState, useAasState } from 'components/contexts/Curren
import { performDiscoveryAasSearch } from 'lib/services/search-actions/searchActions';
import { wrapSuccess } from 'lib/util/apiResponseWrapper/apiResponseWrapper';
import { LocalizedError } from 'lib/util/LocalizedError';
import { messages } from 'lib/i18n/localization';
import { useShowError } from 'lib/hooks/UseShowError';

export const RedirectToViewer = () => {
const navigate = useRouter();
const searchParams = useSearchParams();
const assetIdParam = searchParams.get('assetId')?.toString();
const notificationSpawner = useNotificationSpawner();
const [isLoading, setIsLoading] = useState(false);
const [isError, setIsError] = useState(false);
const [, setAas] = useAasState();
const [, setAasOriginUrl] = useAasOriginSourceState();
const { showError } = useShowError();

useAsyncEffect(async () => {
try {
Expand All @@ -32,19 +30,19 @@ export const RedirectToViewer = () => {
} catch (e) {
setIsLoading(false);
setIsError(true);
showError(e, notificationSpawner);
showError(e);
}
}, []);

async function navigateToViewerOfAsset(assetId: string | undefined): Promise<void> {
const { isSuccess, result: aasIds } = await getAasIdsOfAsset(assetId);

if (!isSuccess) throw new LocalizedError(messages.mnestix.aasUrlNotFound);
if (!isSuccess) throw new LocalizedError('url-not-found');

assertAtLeastOneAasIdExists(aasIds);
const targetUrl = determineViewerTargetUrl(aasIds);
setAas(null);
setAasOriginUrl(null)
setAasOriginUrl(null);
navigate.replace(targetUrl);
}

Expand Down
17 changes: 8 additions & 9 deletions src/app/[locale]/compare/_components/CompareView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ import { CompareSubmodelsAccordion } from 'app/[locale]/compare/_components/Comp
import { CompareAasAddDialog } from 'app/[locale]/compare/_components/add-aas/CompareAasAddDialog';
import { useCompareAasContext } from 'components/contexts/CompareAasContext';
import { useEffect, useState } from 'react';
import { useNotificationSpawner } from 'lib/hooks/UseNotificationSpawner';
import { useSearchParams } from 'next/navigation';
import { showError } from 'lib/util/ErrorHandlerUtil';
import { LocalizedError } from 'lib/util/LocalizedError';
import { performFullAasSearch } from 'lib/services/search-actions/searchActions';
import { useShowError } from 'lib/hooks/UseShowError';

export function CompareView() {
const { compareAas, addSeveralAas, deleteAas, addAas } = useCompareAasContext();
const [isLoadingAas, setIsLoadingAas] = useState(false);
const notificationSpawner = useNotificationSpawner();
const searchParams = useSearchParams();
const aasIds = searchParams.getAll('aasId').map((aasId) => {
return decodeURIComponent(aasId);
});
const [addModalOpen, setAddModalOpen] = useState(false);
const { showError } = useShowError();

useEffect(() => {
async function _fetchAas() {
Expand All @@ -32,14 +31,14 @@ export function CompareView() {
addSeveralAas(aasIds);
}
} catch (e) {
showError(e, notificationSpawner);
showError(e);
} finally {
setIsLoadingAas(false);
}
}

_fetchAas().catch((reason) => {
showError(reason, notificationSpawner);
showError(reason);
});
}, []);

Expand All @@ -57,21 +56,21 @@ export function CompareView() {

const handleAddAas = async (aasId: string) => {
const { isSuccess, result } = await performFullAasSearch(aasId);
if (!isSuccess) throw new LocalizedError(messages.mnestix.aasUrlNotFound);
if (!isSuccess) throw new LocalizedError('url-not-found');

if (!result.aas) {
throw new LocalizedError(messages.mnestix.compare.moreAasFound);
throw new LocalizedError('compare-error.more-aas-found');
}

const aasExists = compareAas.find((compareAas) => compareAas.aas.id === result.aas!.id);
if (aasExists) {
throw new LocalizedError(messages.mnestix.compare.aasAlreadyAdded);
throw new LocalizedError('compare-error.aas-already-added');
}

try {
await addAas(result.aas, result.aasData);
} catch (e) {
throw new LocalizedError(messages.mnestix.compare.aasAddError);
throw new LocalizedError('compare-error.aas-add-error');
}

setAddModalOpen(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@ import { CenteredLoadingSpinner } from 'components/basics/CenteredLoadingSpinner
import { useEnv } from 'app/env/provider';
import { useState } from 'react';
import { AasListEntry } from 'lib/api/generated-api/clients.g';
import { useNotificationSpawner } from 'lib/hooks/UseNotificationSpawner';
import { Box } from '@mui/material';
import { showError } from 'lib/util/ErrorHandlerUtil';
import { useAsyncEffect } from 'lib/hooks/UseAsyncEffect';
import { SelectProductType } from 'app/[locale]/list/_components-deprecated/SelectProductType';
import { AasListComparisonHeader } from 'app/[locale]/list/_components-deprecated/AasListComparisonHeader';
import AasList from 'app/[locale]/list/_components-deprecated/AasList';
import { useIntl } from 'react-intl';
import { messages } from 'lib/i18n/localization';
import { getAasListEntries } from 'lib/services/list-service/aasListApiActions';
import { useShowError } from 'lib/hooks/UseShowError';

export const AasListViewDeprecated = () => {
const [isLoadingList, setIsLoadingList] = useState(false);
const [aasList, setAasList] = useState<AasListEntry[]>();
const [aasListFiltered, setAasListFiltered] = useState<AasListEntry[]>();
const [selectedAasList, setSelectedAasList] = useState<string[]>();
const notificationSpawner = useNotificationSpawner();
const env = useEnv();
const intl = useIntl();
const { showError } = useShowError();

useAsyncEffect(async () => {
try {
Expand All @@ -31,7 +30,7 @@ export const AasListViewDeprecated = () => {
setAasList(list);
setAasListFiltered(list);
} catch (e) {
showError(e, notificationSpawner);
showError(e);
} finally {
setIsLoadingList(false);
}
Expand Down
Loading
Loading