2022-06-10 15:23:12 +02:00
|
|
|
import { useEffect, useMemo, useState } from 'react';
|
2023-03-22 15:37:40 +01:00
|
|
|
import { CircularProgress, Link } from '@mui/material';
|
2022-05-02 15:52:41 +02:00
|
|
|
import { Warning } from '@mui/icons-material';
|
|
|
|
import { AppsLinkList, styles as themeStyles } from 'component/common';
|
2022-05-09 14:38:12 +02:00
|
|
|
import { PageContent } from 'component/common/PageContent/PageContent';
|
|
|
|
import { PageHeader } from 'component/common/PageHeader/PageHeader';
|
2022-03-28 10:49:59 +02:00
|
|
|
import useApplications from 'hooks/api/getters/useApplications/useApplications';
|
2022-05-02 12:52:33 +02:00
|
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
2022-06-10 15:23:12 +02:00
|
|
|
import { useSearchParams } from 'react-router-dom';
|
|
|
|
import { Search } from 'component/common/Search/Search';
|
2022-12-28 11:35:27 +01:00
|
|
|
import { safeRegExp } from '@server/util/escape-regex';
|
2022-06-10 15:23:12 +02:00
|
|
|
|
|
|
|
type PageQueryType = Partial<Record<'search', string>>;
|
2022-02-04 12:45:08 +01:00
|
|
|
|
2022-02-10 10:36:53 +01:00
|
|
|
export const ApplicationList = () => {
|
2022-02-10 10:05:50 +01:00
|
|
|
const { applications, loading } = useApplications();
|
2022-06-10 15:23:12 +02:00
|
|
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
|
|
const [searchValue, setSearchValue] = useState(
|
|
|
|
searchParams.get('search') || ''
|
|
|
|
);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const tableState: PageQueryType = {};
|
|
|
|
if (searchValue) {
|
|
|
|
tableState.search = searchValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
setSearchParams(tableState, {
|
|
|
|
replace: true,
|
|
|
|
});
|
|
|
|
}, [searchValue, setSearchParams]);
|
2022-02-04 12:45:08 +01:00
|
|
|
|
2022-02-04 16:26:51 +01:00
|
|
|
const filteredApplications = useMemo(() => {
|
2022-12-28 11:35:27 +01:00
|
|
|
const regExp = safeRegExp(searchValue, 'i');
|
2022-06-10 15:23:12 +02:00
|
|
|
return searchValue
|
2022-02-04 16:26:51 +01:00
|
|
|
? applications?.filter(a => regExp.test(a.appName))
|
|
|
|
: applications;
|
2022-06-10 15:23:12 +02:00
|
|
|
}, [applications, searchValue]);
|
2022-02-04 16:26:51 +01:00
|
|
|
|
2022-02-10 10:36:53 +01:00
|
|
|
const renderNoApplications = () => (
|
2022-02-09 16:15:07 +01:00
|
|
|
<>
|
2022-02-04 16:26:51 +01:00
|
|
|
<section style={{ textAlign: 'center' }}>
|
2022-04-21 08:26:49 +02:00
|
|
|
<Warning titleAccess="Warning" /> <br />
|
2022-02-04 16:26:51 +01:00
|
|
|
<br />
|
|
|
|
Oh snap, it does not seem like you have connected any
|
|
|
|
applications. To connect your application to Unleash you will
|
|
|
|
require a Client SDK.
|
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
You can read more about how to use Unleash in your application
|
|
|
|
in the{' '}
|
2023-03-22 15:37:40 +01:00
|
|
|
<Link href="https://docs.getunleash.io/docs/sdks/">
|
2022-02-04 16:26:51 +01:00
|
|
|
documentation.
|
2023-03-22 15:37:40 +01:00
|
|
|
</Link>
|
2022-02-04 16:26:51 +01:00
|
|
|
</section>
|
2022-02-09 16:15:07 +01:00
|
|
|
</>
|
2022-02-04 16:26:51 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (!filteredApplications) {
|
2022-02-04 12:45:08 +01:00
|
|
|
return <CircularProgress variant="indeterminate" />;
|
|
|
|
}
|
2022-02-04 16:26:51 +01:00
|
|
|
|
2022-08-31 16:10:01 +02:00
|
|
|
let applicationCount =
|
|
|
|
filteredApplications.length < applications.length
|
|
|
|
? `${filteredApplications.length} of ${applications.length}`
|
|
|
|
: applications.length;
|
|
|
|
|
2022-02-04 12:45:08 +01:00
|
|
|
return (
|
|
|
|
<>
|
2022-06-10 15:23:12 +02:00
|
|
|
<PageContent
|
|
|
|
header={
|
|
|
|
<PageHeader
|
2022-08-31 16:10:01 +02:00
|
|
|
title={`Applications (${applicationCount})`}
|
2022-06-10 15:23:12 +02:00
|
|
|
actions={
|
|
|
|
<Search
|
|
|
|
initialValue={searchValue}
|
|
|
|
onChange={setSearchValue}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
2022-05-02 15:52:41 +02:00
|
|
|
<div className={themeStyles.fullwidth}>
|
2022-02-10 10:05:50 +01:00
|
|
|
<ConditionallyRender
|
|
|
|
condition={filteredApplications.length > 0}
|
|
|
|
show={<AppsLinkList apps={filteredApplications} />}
|
|
|
|
elseShow={
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={loading}
|
|
|
|
show={<div>...loading</div>}
|
2022-02-10 10:36:53 +01:00
|
|
|
elseShow={renderNoApplications()}
|
2022-02-10 10:05:50 +01:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2022-02-04 12:45:08 +01:00
|
|
|
</div>
|
|
|
|
</PageContent>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|