1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00
unleash.unleash/frontend/src/component/application/ApplicationList/ApplicationList.tsx

68 lines
2.6 KiB
TypeScript
Raw Normal View History

2022-02-09 16:15:07 +01:00
import { useMemo, useState } from 'react';
import { CircularProgress } from '@mui/material';
import { Warning } from '@mui/icons-material';
import { AppsLinkList, styles as themeStyles } from 'component/common';
import { SearchField } from 'component/common/SearchField/SearchField';
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';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
export const ApplicationList = () => {
2022-02-10 10:05:50 +01:00
const { applications, loading } = useApplications();
const [filter, setFilter] = useState('');
const filteredApplications = useMemo(() => {
const regExp = new RegExp(filter, 'i');
return filter
? applications?.filter(a => regExp.test(a.appName))
: applications;
}, [applications, filter]);
const renderNoApplications = () => (
2022-02-09 16:15:07 +01:00
<>
<section style={{ textAlign: 'center' }}>
<Warning titleAccess="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
</>
);
if (!filteredApplications) {
return <CircularProgress variant="indeterminate" />;
}
return (
<>
<div className={themeStyles.searchField}>
<SearchField initialValue={filter} updateValue={setFilter} />
</div>
<PageContent header={<PageHeader title="Applications" />}>
<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>}
elseShow={renderNoApplications()}
2022-02-10 10:05:50 +01:00
/>
}
/>
</div>
</PageContent>
</>
);
};