2022-02-09 16:15:07 +01:00
|
|
|
import { useMemo, useState } from 'react';
|
2022-02-04 12:45:08 +01:00
|
|
|
import { CircularProgress } from '@material-ui/core';
|
|
|
|
import { Warning } from '@material-ui/icons';
|
|
|
|
|
2022-02-09 16:15:07 +01:00
|
|
|
import { AppsLinkList, styles as commonStyles } from '../../common';
|
|
|
|
import SearchField from '../../common/SearchField/SearchField';
|
|
|
|
import PageContent from '../../common/PageContent/PageContent';
|
|
|
|
import HeaderTitle from '../../common/HeaderTitle';
|
|
|
|
import useApplications from '../../../hooks/api/getters/useApplications/useApplications';
|
2022-02-10 10:05:50 +01:00
|
|
|
import ConditionallyRender from '../../common/ConditionallyRender';
|
2022-02-04 12:45:08 +01:00
|
|
|
|
|
|
|
const ApplicationList = () => {
|
2022-02-10 10:05:50 +01:00
|
|
|
const { applications, loading } = useApplications();
|
2022-02-04 16:26:51 +01:00
|
|
|
const [filter, setFilter] = useState('');
|
2022-02-04 12:45:08 +01:00
|
|
|
|
2022-02-04 16:26:51 +01:00
|
|
|
const filteredApplications = useMemo(() => {
|
|
|
|
const regExp = new RegExp(filter, 'i');
|
|
|
|
return filter
|
|
|
|
? applications?.filter(a => regExp.test(a.appName))
|
|
|
|
: applications;
|
|
|
|
}, [applications, filter]);
|
|
|
|
|
2022-02-09 16:15:07 +01:00
|
|
|
const RenderNoApplications = () => (
|
|
|
|
<>
|
2022-02-04 16:26:51 +01:00
|
|
|
<section style={{ textAlign: 'center' }}>
|
|
|
|
<Warning /> <br />
|
|
|
|
<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{' '}
|
|
|
|
<a href="https://docs.getunleash.io/docs/sdks/">
|
|
|
|
documentation.
|
|
|
|
</a>
|
|
|
|
</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-02-04 12:45:08 +01:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className={commonStyles.searchField}>
|
2022-02-04 16:26:51 +01:00
|
|
|
<SearchField value={filter} updateValue={setFilter} />
|
2022-02-04 12:45:08 +01:00
|
|
|
</div>
|
|
|
|
<PageContent headerContent={<HeaderTitle title="Applications" />}>
|
|
|
|
<div className={commonStyles.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>}
|
|
|
|
elseShow={<RenderNoApplications />}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2022-02-04 12:45:08 +01:00
|
|
|
</div>
|
|
|
|
</PageContent>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ApplicationList;
|