mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	refactor: finish ApplicationList and add it to routes
This commit is contained in:
		
							parent
							
								
									fb403255ef
								
							
						
					
					
						commit
						f342d4d904
					
				@ -1,5 +1,4 @@
 | 
			
		||||
import React, { Component, useEffect } from 'react';
 | 
			
		||||
import PropTypes from 'prop-types';
 | 
			
		||||
import React, { useEffect, useMemo, useState } from 'react';
 | 
			
		||||
import { CircularProgress } from '@material-ui/core';
 | 
			
		||||
import { Warning } from '@material-ui/icons';
 | 
			
		||||
 | 
			
		||||
@ -10,28 +9,52 @@ import HeaderTitle from '../common/HeaderTitle';
 | 
			
		||||
import useApplications from '../../hooks/api/getters/useApplications/useApplications';
 | 
			
		||||
 | 
			
		||||
const ApplicationList = () => {
 | 
			
		||||
    //missing useSettings
 | 
			
		||||
    const { applications, refetchApplications } = useApplications();
 | 
			
		||||
 | 
			
		||||
    const [filter, setFilter] = useState('');
 | 
			
		||||
    useEffect(() => {
 | 
			
		||||
        refetchApplications();
 | 
			
		||||
        // eslint-disable-next-line
 | 
			
		||||
    }, []);
 | 
			
		||||
 | 
			
		||||
    if (!applications) {
 | 
			
		||||
    const filteredApplications = useMemo(() => {
 | 
			
		||||
        const regExp = new RegExp(filter, 'i');
 | 
			
		||||
        return filter
 | 
			
		||||
            ? applications?.filter(a => regExp.test(a.appName))
 | 
			
		||||
            : applications;
 | 
			
		||||
    }, [applications, filter]);
 | 
			
		||||
 | 
			
		||||
    const Empty = () => (
 | 
			
		||||
        <React.Fragment>
 | 
			
		||||
            <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>
 | 
			
		||||
        </React.Fragment>
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    if (!filteredApplications) {
 | 
			
		||||
        return <CircularProgress variant="indeterminate" />;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return (
 | 
			
		||||
        <>
 | 
			
		||||
            <div className={commonStyles.searchField}>
 | 
			
		||||
                <SearchField
 | 
			
		||||
                    value={this.props.settings.filter}
 | 
			
		||||
                    updateValue={this.props.updateSetting.bind(this, 'filter')}
 | 
			
		||||
                />
 | 
			
		||||
                <SearchField value={filter} updateValue={setFilter} />
 | 
			
		||||
            </div>
 | 
			
		||||
            <PageContent headerContent={<HeaderTitle title="Applications" />}>
 | 
			
		||||
                <div className={commonStyles.fullwidth}>
 | 
			
		||||
                    {applications.length > 0 ? (
 | 
			
		||||
                        <AppsLinkList apps={applications} />
 | 
			
		||||
                    {filteredApplications.length > 0 ? (
 | 
			
		||||
                        <AppsLinkList apps={filteredApplications} />
 | 
			
		||||
                    ) : (
 | 
			
		||||
                        <Empty />
 | 
			
		||||
                    )}
 | 
			
		||||
@ -42,29 +65,3 @@ const ApplicationList = () => {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default ApplicationList;
 | 
			
		||||
 | 
			
		||||
const Empty = () => (
 | 
			
		||||
    <React.Fragment>
 | 
			
		||||
        <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>
 | 
			
		||||
    </React.Fragment>
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
class ClientStrategies extends Component {
 | 
			
		||||
    static propTypes = {
 | 
			
		||||
        applications: PropTypes.array,
 | 
			
		||||
        fetchAll: PropTypes.func.isRequired,
 | 
			
		||||
        settings: PropTypes.object.isRequired,
 | 
			
		||||
        updateSetting: PropTypes.func.isRequired,
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -8,8 +8,8 @@ import useApplicationsApi from '../../hooks/api/actions/useApplicationsApi/useAp
 | 
			
		||||
const ApplicationUpdate = ({ application }) => {
 | 
			
		||||
    const { storeApplicationMetaData } = useApplicationsApi();
 | 
			
		||||
    const { appName, icon, url, description } = application;
 | 
			
		||||
    const [localUrl, setLocalUrl] = useState(url);
 | 
			
		||||
    const [localDescription, setLocalDescription] = useState(description);
 | 
			
		||||
    const [localUrl, setLocalUrl] = useState(url || '');
 | 
			
		||||
    const [localDescription, setLocalDescription] = useState(description || '');
 | 
			
		||||
    const commonStyles = useCommonStyles();
 | 
			
		||||
 | 
			
		||||
    return (
 | 
			
		||||
 | 
			
		||||
@ -34,8 +34,7 @@ const EditApplication = () => {
 | 
			
		||||
    const { refetchApplication, application } = useApplication(name);
 | 
			
		||||
    const { appName, url, description, icon = 'apps', createdAt } = application;
 | 
			
		||||
    const { hasAccess } = useContext(AccessContext);
 | 
			
		||||
    const { storeApplicationMetaData, deleteApplication } =
 | 
			
		||||
        useApplicationsApi();
 | 
			
		||||
    const { deleteApplication } = useApplicationsApi();
 | 
			
		||||
 | 
			
		||||
    const [loading, setLoading] = useState(true);
 | 
			
		||||
    const [showDialog, setShowDialog] = useState(false);
 | 
			
		||||
 | 
			
		||||
@ -7,7 +7,7 @@ import SearchIcon from '@material-ui/icons/Search';
 | 
			
		||||
 | 
			
		||||
import { useStyles } from './styles';
 | 
			
		||||
 | 
			
		||||
function SearchField({ updateValue, className }) {
 | 
			
		||||
function SearchField({ updateValue, className = '' }) {
 | 
			
		||||
    const styles = useStyles();
 | 
			
		||||
 | 
			
		||||
    const [localValue, setLocalValue] = useState('');
 | 
			
		||||
 | 
			
		||||
@ -8,7 +8,6 @@ import HistoryPage from '../../page/history';
 | 
			
		||||
import HistoryTogglePage from '../../page/history/toggle';
 | 
			
		||||
import ShowArchive from '../../page/archive/show';
 | 
			
		||||
import Archive from '../../page/archive';
 | 
			
		||||
import Applications from '../../page/applications';
 | 
			
		||||
import ContextFields from '../../page/context';
 | 
			
		||||
import ListTagTypes from '../../page/tag-types';
 | 
			
		||||
import Addons from '../../page/addons';
 | 
			
		||||
@ -47,6 +46,7 @@ import CreateProject from '../project/Project/CreateProject/CreateProject';
 | 
			
		||||
import CreateFeature from '../feature/CreateFeature/CreateFeature/CreateFeature';
 | 
			
		||||
import EditFeature from '../feature/CreateFeature/EditFeature/EditFeature';
 | 
			
		||||
import EditApplication from '../application/EditApplication';
 | 
			
		||||
import ApplicationList from '../application/ApplicationList';
 | 
			
		||||
 | 
			
		||||
export const routes = [
 | 
			
		||||
    // Project
 | 
			
		||||
@ -203,7 +203,7 @@ export const routes = [
 | 
			
		||||
    {
 | 
			
		||||
        path: '/applications',
 | 
			
		||||
        title: 'Applications',
 | 
			
		||||
        component: Applications,
 | 
			
		||||
        component: ApplicationList,
 | 
			
		||||
        type: 'protected',
 | 
			
		||||
        layout: 'main',
 | 
			
		||||
        menu: { mobile: true, advanced: true },
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user