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

Iris 3158 clear search #133

Merged
merged 7 commits into from
Sep 28, 2022
4 changes: 3 additions & 1 deletion src/network/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { find, map, maxBy } from 'lodash';
import { goToLogin } from './go-to-login';
import { Account, ErrorSoapResponse, SoapContext, SoapResponse } from '../../types';
import { Account, ErrorSoapResponse, SoapContext, SoapException, SoapResponse } from '../../types';
import { userAgent } from './user-agent';
import { report } from '../reporting';
import { useAccountStore } from '../store/account';
Expand Down Expand Up @@ -111,6 +111,8 @@ const handleResponse = <R>(api: string, res: SoapResponse<R>): R => {
}`
)
);

throw new SoapException(<ErrorSoapResponse>res);
}
if (res.Header?.context) {
const responseUsedQuota =
Expand Down
51 changes: 43 additions & 8 deletions src/search/search-app-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
*/

import { map } from 'lodash';
import React, { FC, useCallback, useMemo } from 'react';
import { Redirect, Route, Switch } from 'react-router-dom';
import { Container, Chip, Padding, Divider, Text, Button } from '@zextras/carbonio-design-system';
import React, { FC, ReactElement, useCallback, useMemo } from 'react';
import {
Button,
Chip,
Container,
Divider,
Icon,
Padding,
Text
} from '@zextras/carbonio-design-system';
import { useTranslation } from 'react-i18next';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { Redirect, Route, Switch } from 'react-router-dom';
import AppContextProvider from '../boot/app/app-context-provider';
import { useSearchStore } from './search-store';
import { SEARCH_APP_ID } from '../constants';
import { QueryChip, ResultLabelType } from '../../types';
import { useAppStore } from '../store/app';
import { QueryChip } from '../../types';
import { SEARCH_APP_ID } from '../constants';
// import { RouteLeavingGuard } from '../ui-extras/nav-guard';

// eslint-disable-next-line @typescript-eslint/ban-types
Expand All @@ -25,7 +31,21 @@ const useQuery = (): [Array<QueryChip>, Function] =>
const useDisableSearch = (): [boolean, Function] =>
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
useSearchStore((s) => [s.searchDisabled, s.setSearchDisabled]);
const ResultsHeader: FC<{ label: string }> = ({ label }) => {

const getIconAndColor = (labelType: ResultLabelType): Array<string> => {
if (labelType === ResultLabelType.WARNING) {
return ['AlertTriangle', 'warning'];
}
if (labelType === ResultLabelType.ERROR) {
return ['CloseSquare', 'error'];
}
return ['', ''];
};

const ResultsHeader: FC<{ label: string; labelType?: ResultLabelType }> = ({
label,
labelType = ResultLabelType.NORMAL
}) => {
const [t] = useTranslation();
const [query, updateQuery] = useQuery();
const [, setDisabled] = useDisableSearch();
Expand All @@ -34,6 +54,20 @@ const ResultsHeader: FC<{ label: string }> = ({ label }) => {
updateQuery([]);
setDisabled(false);
}, [updateQuery, setDisabled]);

const labelTypeElem = useMemo<ReactElement | undefined>(() => {
if (labelType === ResultLabelType.NORMAL) {
return <></>;
}

const [icon, color] = getIconAndColor(labelType);
return (
<Padding right="small">
<Icon icon={icon} size="large" color={color} />
</Padding>
);
}, [labelType]);

return (
<>
<Container
Expand All @@ -48,6 +82,7 @@ const ResultsHeader: FC<{ label: string }> = ({ label }) => {
padding={{ horizontal: 'large', vertical: 'medium' }}
>
<Container width="85%" orientation="horizontal" wrap="wrap" mainAlignment="flex-start">
{labelTypeElem}
<Text color="secondary">{label}</Text>

{map(query, (q, i) => (
Expand Down
1 change: 1 addition & 0 deletions types/exports/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const soapFetch: SoapFetch;
export const xmlSoapFetch: SoapFetch;
export const report: (error: Error, hint?: unknown) => void;
export const setAppContext: <T>(obj: T) => void;
export class SoapException {}

export const removeActions: (...ids: Array<string>) => void;
export const registerActions: (
Expand Down
9 changes: 9 additions & 0 deletions types/network/soap.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@ export type SoapNotify = {
};
deleted: string[];
};

export class SoapException extends Error {
constructor(response: ErrorSoapResponse) {
super(response?.Body.Fault.Reason.Text);
this.response = response;
}

response: ErrorSoapResponse;
}
6 changes: 6 additions & 0 deletions types/search/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export type SearchState = {
updateModule: (module: string) => void;
};

export enum ResultLabelType {
NORMAL = 'normal',
WARNING = 'warning',
ERROR = 'error'
}

// export type SelectLabelFactoryProps = {
// selected: [{ label: string; value: string }];
// open: boolean;
Expand Down