mirror of https://github.com/portainer/portainer
feat(app): enforce using of props in r2a [EE-3215] (#6943)
parent
01dc9066b7
commit
dc98850489
|
@ -57,6 +57,9 @@ export function EdgeCheckinIntervalField({
|
||||||
export const EdgeCheckinIntervalFieldAngular = r2a(EdgeCheckinIntervalField, [
|
export const EdgeCheckinIntervalFieldAngular = r2a(EdgeCheckinIntervalField, [
|
||||||
'value',
|
'value',
|
||||||
'onChange',
|
'onChange',
|
||||||
|
'isDefaultHidden',
|
||||||
|
'tooltip',
|
||||||
|
'label',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
function useOptions(isDefaultHidden: boolean) {
|
function useOptions(isDefaultHidden: boolean) {
|
||||||
|
|
|
@ -73,4 +73,6 @@ export const FileUploadFieldAngular = r2a(FileUploadField, [
|
||||||
'value',
|
'value',
|
||||||
'title',
|
'title',
|
||||||
'required',
|
'required',
|
||||||
|
'accept',
|
||||||
|
'inputId',
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -3,7 +3,6 @@ import clsx from 'clsx';
|
||||||
import { isLimitedToBE } from '@/portainer/feature-flags/feature-flags.service';
|
import { isLimitedToBE } from '@/portainer/feature-flags/feature-flags.service';
|
||||||
import { BEFeatureIndicator } from '@/portainer/components/BEFeatureIndicator';
|
import { BEFeatureIndicator } from '@/portainer/components/BEFeatureIndicator';
|
||||||
import { FeatureId } from '@/portainer/feature-flags/enums';
|
import { FeatureId } from '@/portainer/feature-flags/enums';
|
||||||
import { r2a } from '@/react-tools/react2angular';
|
|
||||||
|
|
||||||
import './Switch.css';
|
import './Switch.css';
|
||||||
|
|
||||||
|
@ -55,14 +54,3 @@ export function Switch({
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SwitchAngular = r2a(Switch, [
|
|
||||||
'name',
|
|
||||||
'checked',
|
|
||||||
'id',
|
|
||||||
'disabled',
|
|
||||||
'dataCy',
|
|
||||||
'onChange',
|
|
||||||
'feature',
|
|
||||||
'className',
|
|
||||||
]);
|
|
||||||
|
|
|
@ -5,8 +5,6 @@ import { EnvironmentList } from './EnvironmentList';
|
||||||
export { EnvironmentList };
|
export { EnvironmentList };
|
||||||
|
|
||||||
export const EnvironmentListAngular = react2angular(EnvironmentList, [
|
export const EnvironmentListAngular = react2angular(EnvironmentList, [
|
||||||
'tags',
|
|
||||||
'onClickItem',
|
'onClickItem',
|
||||||
'onRefresh',
|
'onRefresh',
|
||||||
'groups',
|
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -6,7 +6,6 @@ export { CreateTeamForm };
|
||||||
|
|
||||||
export const CreateTeamFormAngular = r2a(CreateTeamForm, [
|
export const CreateTeamFormAngular = r2a(CreateTeamForm, [
|
||||||
'users',
|
'users',
|
||||||
'actionInProgress',
|
|
||||||
'onSubmit',
|
'onSubmit',
|
||||||
'teams',
|
'teams',
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -3,9 +3,7 @@ import { react2angular } from '@/react-tools/react2angular';
|
||||||
import { CreateAccessToken } from './CreateAccessToken';
|
import { CreateAccessToken } from './CreateAccessToken';
|
||||||
|
|
||||||
const CreateAccessTokenAngular = react2angular(CreateAccessToken, [
|
const CreateAccessTokenAngular = react2angular(CreateAccessToken, [
|
||||||
'userId',
|
|
||||||
'onSubmit',
|
'onSubmit',
|
||||||
'onSuccess',
|
|
||||||
'onError',
|
'onError',
|
||||||
]);
|
]);
|
||||||
export { CreateAccessToken, CreateAccessTokenAngular };
|
export { CreateAccessToken, CreateAccessTokenAngular };
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import { IComponentOptions, IController } from 'angular';
|
import { IComponentOptions, IController } from 'angular';
|
||||||
import { Suspense } from 'react';
|
import { Suspense } from 'react';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
import { RootProvider } from './RootProvider';
|
import { RootProvider } from './RootProvider';
|
||||||
|
|
||||||
|
@ -25,15 +26,26 @@ function toProps(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function react2angular<T>(
|
type PropNames<T> = Exclude<keyof T, number | symbol>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* react2angular is used to bind a React component to an AngularJS component
|
||||||
|
* it used in an AngularJS module definition:
|
||||||
|
*
|
||||||
|
* `.component('componentName', react2angular(ComponentName, ['prop1', 'prop2']))`
|
||||||
|
*
|
||||||
|
* if the second parameter has any ts errors check that the component has the correct props
|
||||||
|
*/
|
||||||
|
export function react2angular<T, U extends PropNames<T>[]>(
|
||||||
Component: React.ComponentType<T>,
|
Component: React.ComponentType<T>,
|
||||||
propNames: string[]
|
propNames: U & ([PropNames<T>] extends [U[number]] ? unknown : PropNames<T>)
|
||||||
): IComponentOptions {
|
): IComponentOptions & { name: string } {
|
||||||
const bindings = Object.fromEntries(propNames.map((key) => [key, '<']));
|
const bindings = Object.fromEntries(propNames.map((key) => [key, '<']));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
bindings,
|
bindings,
|
||||||
controller: Controller,
|
controller: Controller,
|
||||||
|
name: _.camelCase(Component.displayName || Component.name),
|
||||||
};
|
};
|
||||||
|
|
||||||
/* @ngInject */
|
/* @ngInject */
|
||||||
|
|
Loading…
Reference in New Issue