diff --git a/.eslintrc.yml b/.eslintrc.yml index da0d32284..93d5a668d 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -105,6 +105,11 @@ overrides: 'no-await-in-loop': 'off' 'react/jsx-no-useless-fragment': ['error', { allowExpressions: true }] 'regex/invalid': ['error', [{ 'regex': ' getNodesCount(), - { - onError(error) { - notifyError('Failure', error as Error, 'Failed to get nodes count'); - }, - } - ); - - return { nodesCount: data || 0, isLoading }; -} - export function useIntegratedLicenseInfo() { - const { isLoading: isLoadingNodes, nodesCount } = useNodesCounts(); + const { isLoading: isLoadingNodes, data: nodesCount = 0 } = useNodesCount(); const { isLoading: isLoadingLicense, info } = useLicenseInfo(); if ( diff --git a/app/portainer/rest/status.js b/app/portainer/rest/status.js deleted file mode 100644 index 387b524b9..000000000 --- a/app/portainer/rest/status.js +++ /dev/null @@ -1,15 +0,0 @@ -angular.module('portainer.app').factory('Status', [ - '$resource', - 'API_ENDPOINT_STATUS', - function StatusFactory($resource, API_ENDPOINT_STATUS) { - 'use strict'; - return $resource( - API_ENDPOINT_STATUS + '/:action', - {}, - { - get: { method: 'GET' }, - version: { method: 'GET', params: { action: 'version' } }, - } - ); - }, -]); diff --git a/app/portainer/services/api/status.service.ts b/app/portainer/services/api/status.service.ts deleted file mode 100644 index 8e3190d6b..000000000 --- a/app/portainer/services/api/status.service.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { useQuery } from 'react-query'; - -import axios, { parseAxiosError } from '../axios'; - -export interface NodesCountResponse { - nodes: number; -} - -export async function getNodesCount() { - try { - const { data } = await axios.get(buildUrl('nodes')); - return data.nodes; - } catch (error) { - throw parseAxiosError(error as Error); - } -} - -export interface StatusResponse { - Edition: string; - Version: string; - InstanceID: string; -} - -export async function getStatus() { - try { - const { data } = await axios.get(buildUrl()); - - data.Edition = 'Community Edition'; - - return data; - } catch (error) { - throw parseAxiosError(error as Error); - } -} - -export function useStatus( - select?: (status: StatusResponse) => T -) { - return useQuery(['status'], () => getStatus(), { select }); -} - -export interface VersionResponse { - // Whether portainer has an update available - UpdateAvailable: boolean; - // The latest version available - LatestVersion: string; - ServerVersion: string; - DatabaseVersion: string; - Build: { - BuildNumber: string; - ImageTag: string; - NodejsVersion: string; - YarnVersion: string; - WebpackVersion: string; - GoVersion: string; - }; -} - -export async function getVersionStatus() { - try { - const { data } = await axios.get(buildUrl('version')); - return data; - } catch (error) { - throw parseAxiosError(error as Error); - } -} - -export function useVersionStatus() { - return useQuery(['version'], () => getVersionStatus()); -} - -function buildUrl(action?: string) { - let url = '/status'; - - if (action) { - url += `/${action}`; - } - - return url; -} diff --git a/app/portainer/services/api/statusService.js b/app/portainer/services/api/statusService.js index 4042135a9..a91d71f18 100644 --- a/app/portainer/services/api/statusService.js +++ b/app/portainer/services/api/statusService.js @@ -1,42 +1,27 @@ -import { StatusVersionViewModel, StatusViewModel } from '../../models/status'; +import { getSystemStatus } from '@/react/portainer/system/useSystemStatus'; +import { StatusViewModel } from '../../models/status'; -angular.module('portainer.app').factory('StatusService', [ - '$q', - 'Status', - function StatusServiceFactory($q, Status) { - 'use strict'; - var service = {}; +angular.module('portainer.app').factory('StatusService', StatusServiceFactory); - service.status = function () { - var deferred = $q.defer(); +/* @ngInject */ +function StatusServiceFactory($q) { + 'use strict'; + var service = {}; - Status.get() - .$promise.then(function success(data) { - var status = new StatusViewModel(data); - deferred.resolve(status); - }) - .catch(function error(err) { - deferred.reject({ msg: 'Unable to retrieve application status', err: err }); - }); + service.status = function () { + var deferred = $q.defer(); - return deferred.promise; - }; + getSystemStatus() + .then(function success(data) { + var status = new StatusViewModel(data); + deferred.resolve(status); + }) + .catch(function error(err) { + deferred.reject({ msg: 'Unable to retrieve application status', err: err }); + }); - service.version = function () { - var deferred = $q.defer(); + return deferred.promise; + }; - Status.version() - .$promise.then(function success(data) { - var status = new StatusVersionViewModel(data); - deferred.resolve(status); - }) - .catch(function error(err) { - deferred.reject({ msg: 'Unable to retrieve application version info', err: err }); - }); - - return deferred.promise; - }; - - return service; - }, -]); + return service; +} diff --git a/app/react/components/form-components/FormControl/FormControl.module.css b/app/react/components/form-components/FormControl/FormControl.module.css deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/react/components/form-components/FormControl/FormControl.stories.tsx b/app/react/components/form-components/FormControl/FormControl.stories.tsx index 70ae3d7ed..db628381f 100644 --- a/app/react/components/form-components/FormControl/FormControl.stories.tsx +++ b/app/react/components/form-components/FormControl/FormControl.stories.tsx @@ -12,15 +12,31 @@ export default { interface TextFieldProps { label: string; tooltip?: string; + vertical?: boolean; + required?: boolean; + error?: string; } export { TextField, SelectField }; -function TextField({ label, tooltip = '' }: TextFieldProps) { +function TextField({ + label, + tooltip = '', + required, + error, + vertical, +}: TextFieldProps) { const [value, setValue] = useState(''); const inputId = 'input'; return ( - + +