Skip to content

Commit

Permalink
Fix: enhance the drawer page of the addon (#620)
Browse files Browse the repository at this point in the history
* Fix: enhance the drawer page of the addon

Signed-off-by: barnettZQG <[email protected]>

* Fix: reset the schema after version changed

Signed-off-by: barnettZQG <[email protected]>

Signed-off-by: barnettZQG <[email protected]>
  • Loading branch information
barnettZQG authored Oct 22, 2022
1 parent aa7390c commit 348d9ac
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 66 deletions.
26 changes: 13 additions & 13 deletions src/api/addons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { post, get, rdelete, put } from './request';
import { addons, addonRegistries, enabledAddon } from './productionLink';
import { getDomain } from '../utils/common';
import type { EnableAddonRequest } from '../interface/addon';

const baseURLOject = getDomain();
const base = baseURLOject.MOCK || baseURLOject.APIBASE;
Expand All @@ -23,20 +24,24 @@ export function getAddonsList(params: any) {

export function getAddonsDetails(params: { name: string; version?: string }) {
const gurl = `${base + addons}/${params.name}`;
return get(gurl, params).then((res) => res);
return get(
gurl,
params.version
? {
params: {
version: params.version,
},
}
: {},
).then((res) => res);
}

export function disableAddon(params: { name: string }) {
const gurl = `${base + addons}/${params.name}/disable`;
return post(gurl, params).then((res) => res);
}

export function enableAddon(params: {
name: string;
version: string;
clusters?: string[];
properties: any;
}) {
export function enableAddon(params: EnableAddonRequest) {
const gurl = `${base + addons}/${params.name}/enable`;
const req: any = { args: params.properties, version: params.version };
if (params.clusters) {
Expand All @@ -45,12 +50,7 @@ export function enableAddon(params: {
return post(gurl, req).then((res) => res);
}

export function upgradeAddon(params: {
name: string;
version: string;
clusters?: string[];
properties: any;
}) {
export function upgradeAddon(params: EnableAddonRequest) {
const gurl = `${base + addons}/${params.name}/update`;
const req: any = { args: params.properties, version: params.version };
if (params.clusters) {
Expand Down
9 changes: 0 additions & 9 deletions src/common.less
Original file line number Diff line number Diff line change
Expand Up @@ -470,15 +470,6 @@ a {
display: inline-block;
}

.next-drawer-close {
right: 24px;

.next-drawer-close-icon.next-icon::before {
width: 16px !important;
height: 16px !important;
font-size: 16px !important;
}
}
.next-btn.danger-btn {
color: @dangerColor !important;
border: @dangerColor 1px solid !important;
Expand Down
43 changes: 43 additions & 0 deletions src/components/Drawer/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,46 @@
height: 60px;
background: #fff;
}

.next-drawer {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
.next-drawer-header {
position: absolute;
top: 0;
z-index: 1000;
display: flex;
flex: 0;
align-items: center;
width: 100%;
height: 55px;
padding: 16px 24px;
font-size: 16px;
line-height: 22px;
border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}
.next-drawer-body {
flex: 1;
min-width: 0;
min-height: 0;
margin-top: 71px;
padding: 24px;
overflow: auto;
}
}

.next-drawer-close {
right: 26px !important;

.next-drawer-close-icon.next-icon::before {
color: #000;
font-weight: 800 !important;
font-size: 24px !important;
line-height: 24px !important;
&:hover {
color: var(--primary-color);
}
}
}
11 changes: 11 additions & 0 deletions src/interface/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export interface Addon {
registryName?: string;
availableVersions?: string[];
url?: string;
system?: {
vela?: string;
kubernetes?: string;
};
}

export interface AddonStatus {
Expand Down Expand Up @@ -69,3 +73,10 @@ export interface AddonBaseStatus {
name: string;
phase: 'disabled' | 'enabled' | 'enabling' | 'suspend' | 'disabling';
}

export interface EnableAddonRequest {
name: string;
version: string;
properties: Record<string, any>;
clusters?: string[];
}
4 changes: 4 additions & 0 deletions src/lib.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
:root {
--primary-color: #1b58f4;
--warning-color: var(--message-warning-color-icon-inline, #fac800);
}
@border-radius-8: 8px;
@F7F7F7: #f7f7f7;
@F9F8FF: #f9f8ff;
Expand Down
11 changes: 8 additions & 3 deletions src/pages/Addons/components/detail/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@
img {
width: 100%;
}
ol, ul {
ol,
ul {
list-style: decimal;
}
p {
font-size: 14px;
}
}
.addon-readme li>p {
.addon-readme li > p {
font-size: 14px;
}
}

.warning-text {
color: var(--warning-color);
}
137 changes: 99 additions & 38 deletions src/pages/Addons/components/detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Grid,
Dropdown,
Menu,
Icon,
} from '@b-design/ui';
import type { Rule } from '@alifd/field';
import { If } from 'tsx-control-statements/components';
Expand All @@ -27,13 +28,12 @@ import ReactMarkdown from 'react-markdown';
import remarkGfm from 'remark-gfm';
import Empty from '../../../../components/Empty';
import DrawerWithFooter from '../../../../components/Drawer';
import Group from '../../../../extends/Group';
import Translation from '../../../../components/Translation';
import UISchema from '../../../../components/UISchema';
import type { Addon, AddonStatus } from '../../../../interface/addon';
import type { Addon, AddonStatus, EnableAddonRequest } from '../../../../interface/addon';
import locale from '../../../../utils/locale';
import StatusShow from '../../../../components/StatusShow';
import type { ApplicationStatus } from '../../../../interface/application';
import type { ApplicationStatus, UIParam } from '../../../../interface/application';
import i18n from '../../../../i18n';
import type { NameAlias } from '../../../../interface/env';
import Permission from '../../../../components/Permission';
Expand Down Expand Up @@ -68,6 +68,8 @@ type State = {
allClusters?: NameAlias[];
enabledClusters?: string[];
endpoints?: Endpoint[];
propertiesMode: 'code' | 'native';
schema?: UIParam[];
};

class AddonDetailDialog extends React.Component<Props, State> {
Expand All @@ -77,6 +79,7 @@ class AddonDetailDialog extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
propertiesMode: 'native',
addonDetailInfo: {
name: '',
},
Expand All @@ -103,7 +106,7 @@ class AddonDetailDialog extends React.Component<Props, State> {
getAddonsDetails({ name: this.props.addonName, version: version })
.then((res: Addon) => {
if (res) {
this.setState({ addonDetailInfo: res, loading: false });
this.setState({ addonDetailInfo: res, schema: res.uiSchema, loading: false });
if (!this.state.version && res.version) {
this.setState({ version: res.version });
}
Expand Down Expand Up @@ -212,17 +215,21 @@ class AddonDetailDialog extends React.Component<Props, State> {
return;
}
this.setState({ upgradeLoading: true });
upgradeAddon({
const params: EnableAddonRequest = {
name: this.props.addonName,
version: this.state.version,
clusters: this.state.clusters,
properties: values.properties,
}).then(() => {
};
if (this.state.addonDetailInfo?.deployTo?.runtimeCluster) {
params.clusters = this.state.clusters;
}
upgradeAddon(params).then(() => {
this.loadAddonStatus();
this.setState({ upgradeLoading: false });
});
});
};

enableAddon = async (properties: any) => {
if (!this.state.version) {
Message.warning(i18n.t('Please firstly select want to enable version'));
Expand All @@ -237,12 +244,15 @@ class AddonDetailDialog extends React.Component<Props, State> {
}
this.setState({ statusLoading: true }, () => {
if (this.state.version) {
enableAddon({
const params: EnableAddonRequest = {
name: this.props.addonName,
version: this.state.version,
clusters: this.state.clusters,
properties: properties,
}).then(() => {
};
if (this.state.addonDetailInfo?.deployTo?.runtimeCluster) {
params.clusters = this.state.clusters;
}
enableAddon(params).then(() => {
this.loadAddonStatus();
});
}
Expand Down Expand Up @@ -270,7 +280,9 @@ class AddonDetailDialog extends React.Component<Props, State> {
};
changeVersion = (version: string) => {
this.setState({ version: version }, () => {
this.loadAddonDetail();
this.setState({ schema: undefined }, () => {
this.loadAddonDetail();
});
});
};

Expand All @@ -296,6 +308,8 @@ class AddonDetailDialog extends React.Component<Props, State> {
allClusters,
enabledClusters,
endpoints,
propertiesMode,
schema,
} = this.state;
const { showAddon, addonName } = this.props;
const validator = (rule: Rule, value: any, callback: (error?: string) => void) => {
Expand Down Expand Up @@ -477,6 +491,18 @@ class AddonDetailDialog extends React.Component<Props, State> {
value={version}
/>
</Form.Item>
{addonDetailInfo?.system && (
<span className="warning-text">
This version requirements: (
{addonDetailInfo?.system.vela
? `KubeVela: ${addonDetailInfo?.system.vela}`
: ''}
{addonDetailInfo?.system.kubernetes
? ` Kubernetes: ${addonDetailInfo?.system.kubernetes}`
: ''}
)
</span>
)}
</If>

<If condition={addonDetailInfo?.deployTo?.runtimeCluster}>
Expand All @@ -491,34 +517,69 @@ class AddonDetailDialog extends React.Component<Props, State> {
</If>
</Card>

<If condition={addonDetailInfo?.uiSchema}>
<Group
title={<Translation>Properties</Translation>}
description={<Translation>Set the addon configuration parameters</Translation>}
required={true}
closed={status === 'enabled'}
alwaysShow={true}
disableAddon={true}
hasToggleIcon={true}
<If condition={schema}>
<Card
contentHeight={'auto'}
className="withActions"
title="Properties"
subTitle={
schema
? [
<Button
style={{ marginTop: '-12px' }}
onClick={() => {
if (propertiesMode === 'native') {
this.setState({ propertiesMode: 'code' });
} else {
this.setState({ propertiesMode: 'native' });
}
}}
>
<If condition={propertiesMode === 'native'}>
<Icon
style={{ color: '#1b58f4' }}
type={'display-code'}
title={'Switch to the coding mode'}
/>
</If>
<If condition={propertiesMode === 'code'}>
<Icon
style={{ color: '#1b58f4' }}
type={'laptop'}
title={'Switch to the native mode'}
/>
</If>
</Button>,
]
: []
}
>
<Form field={this.form}>
{this.state.mode && (
<UISchema
{...this.form.init('properties', {
rules: [
{
validator: validator,
message: 'Please check addon properties',
},
],
})}
ref={this.uiSchemaRef}
uiSchema={addonDetailInfo?.uiSchema}
mode={this.state.mode}
/>
)}
</Form>
</Group>
<Row>
<If condition={schema}>
{this.state.mode && (
<UISchema
{...this.form.init(`properties`, {
rules: [
{
validator: validator,
message: i18n.t('Please check the addon properties'),
},
],
})}
enableCodeEdit={propertiesMode === 'code'}
uiSchema={schema}
definition={{
name: addonDetailInfo?.name || '',
type: 'addon',
description: addonDetailInfo?.description || '',
}}
ref={this.uiSchemaRef}
mode={this.state.mode}
/>
)}
</If>
</Row>
</Card>
</If>
<If condition={addonDetailInfo?.dependencies}>
<Card
Expand Down
Loading

0 comments on commit 348d9ac

Please sign in to comment.