Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

refactor: connector api #773

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/views/application-management/environments/pages/list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@
const action = ref(PageAction.EDIT);
const projectName = route.params.projectName as string;
const queryParams = reactive({
projectName,
namespace: projectName,
fieldSelector: '',
limit: appStore.perPage || 20,
continue: ''
Expand Down Expand Up @@ -361,8 +361,7 @@
try {
loading.value = true;
const params: any = {
...pickBy(queryParams, (val) => !!val),
sort: [sort.value]
...pickBy(queryParams, (val) => !!val)
};
const { data } = await queryEnvironments(params);
dataList.value = _.map(data.items || [], (item) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PageAction } from '@/views/config';

export default [
{
path: 'project/:projectId/connector/k8s-detail/:action',
path: 'project/:projectName/connector/k8s-detail/:action',
name: 'ProjectConnectorK8sDetail',
component: () => import('../../pages/connector/kubernetes.vue'),
meta: {
Expand All @@ -25,7 +25,7 @@ export default [
}
},
{
path: 'project/:projectId/connector/scm-detail/:action',
path: 'project/:projectName/connector/scm-detail/:action',
name: 'ProjectConnectorScmDetail',
component: () => import('../../pages/connector/version-control.vue'),
meta: {
Expand All @@ -46,7 +46,7 @@ export default [
}
},
{
path: 'project/:projectId/connector/custom-detail/:action',
path: 'project/:projectName/connector/custom-detail/:action',
name: 'ProjectConnectorCustomDetail',
component: () => import('../../pages/connector/custom.vue'),
meta: {
Expand All @@ -67,7 +67,7 @@ export default [
}
},
{
path: 'project/:projectId/connector/cloud-provider/:action',
path: 'project/:projectName/connector/cloud-provider/:action',
name: 'ProjectConnectorProviderDetail',
component: () => import('../../pages/connector/cloud-provider.vue'),
meta: {
Expand Down
23 changes: 14 additions & 9 deletions src/views/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,30 +260,35 @@ export const QAlinkMap = {
};
export const USER_DEFAULT_PROJECT = 'USER_DEFAULT_PROJECT';

const EnvironmentMaps = {
Development: 'Development',
Production: 'Production',
Staging: 'Staging'
};
export const EnvironmentTypeMap = {
development: 'common.environment.development',
production: 'common.environment.production',
staging: 'common.environment.staging'
[EnvironmentMaps.Development]: 'common.environment.development',
[EnvironmentMaps.Production]: 'common.environment.production',
[EnvironmentMaps.Staging]: 'common.environment.staging'
};

export const EnvironmentTypeList = [
{
label: 'common.environment.development',
value: 'development'
value: EnvironmentMaps.Development
},
{
label: 'common.environment.staging',
value: 'staging'
value: EnvironmentMaps.Staging
},
{
label: 'common.environment.production',
value: 'production'
value: EnvironmentMaps.Production
}
];
export const EnvironmentTypeOrder = {
development: 1,
production: 3,
staging: 2
[EnvironmentMaps.Development]: 1,
[EnvironmentMaps.Production]: 3,
[EnvironmentMaps.Staging]: 2
};

export const CommonButtonValue = {
Expand Down
3 changes: 2 additions & 1 deletion src/views/config/resource-kinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export default {
Setting: 'Setting',
Settings: 'Settings',
Project: 'Project',
Variable: 'Variable'
Variable: 'Variable',
Connector: 'Connector'
};

export const apiVersion = 'walrus.seal.io/v1';
Expand Down
4 changes: 2 additions & 2 deletions src/views/operation-hub/connectors/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ export interface ResultType {
items: ConnectorRowData[];
}

export function queryConnectors(params: QueryType, cancelToken?) {
export function queryConnectors(params: ListQuery, cancelToken?) {
const url = generateConnectorAPI({
name: params.name,
namespace: params.namespace
});

return axios.get<ListResult<DataListItem>>(url, {
return axios.get<ListResult<ConnectorRowData>>(url, {
params: _.omit(params, ['name', 'namespace']),
cancelToken,
paramsSerializer: (obj) => {
Expand Down
33 changes: 20 additions & 13 deletions src/views/operation-hub/connectors/components/table-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
>
<template #cell="{ record }">
<a-link
v-if="isLocalConnectorType(record.category)"
v-if="isLocalConnectorType(record.spec.category)"
type="text"
size="small"
:hoverable="false"
Expand All @@ -127,7 +127,9 @@
>
<template #cell="{ record }">
<span
v-if="_.includes([ConnectorCategory.Custom], record.category)"
v-if="
_.includes([ConnectorCategory.Custom], record.spec.category)
"
class="mright-5"
>
<i
Expand All @@ -136,9 +138,13 @@
></i>
</span>
<span v-else class="mright-5">
<ProviderIcon :provider="toLower(record.type)"></ProviderIcon>
<ProviderIcon
:provider="toLower(record.spec.type)"
></ProviderIcon>
</span>
<span>{{ get(gitType, record.type) || record.type }}</span>
<span>{{
get(gitType, record.spec.type) || record.spec.type
}}</span>
</template>
</a-table-column>
<a-table-column
Expand All @@ -151,7 +157,7 @@
>
<template #cell="{ record }">
<StatusLabel
v-if="record.category !== ConnectorCategory.Custom"
v-if="record.spec.category !== ConnectorCategory.Custom"
:status="get(record, 'status', {})"
></StatusLabel>
<span v-else>-</span>
Expand All @@ -167,7 +173,9 @@
>
<template #cell="{ record }">
<span>{{
$t(EnvironmentTypeMap[record.applicableEnvironmentType] || '')
$t(
EnvironmentTypeMap[record.spec.applicableEnvironmentType] || ''
)
}}</span>
</template>
</a-table-column>
Expand Down Expand Up @@ -439,7 +447,7 @@
? item.disabled?.(row)
: item.disabled;
if (item.value === 'enableFinops') {
item.label = row.enableFinOps
item.label = row.spec.enableFinOps
? 'operation.connectors.table.disableFin'
: 'operation.connectors.table.enableFin';
}
Expand Down Expand Up @@ -479,8 +487,7 @@
try {
loading.value = true;
const params: any = {
...pickBy(queryParams, (val) => !!val),
sort: [sort.value]
...pickBy(queryParams, (val) => !!val)
};
const { data } = await queryConnectors(params, axiosToken?.token);
dataList.value = _.map(data?.items || [], (item) => {
Expand Down Expand Up @@ -544,7 +551,7 @@
const handleView = (row, action?) => {
const data = _.find(
props.connectorTypeList,
(item) => item.value === row.category
(item) => item.value === row.spec.category
);
if (props.scope === 'global') {
router.push({
Expand Down Expand Up @@ -572,7 +579,7 @@
const handleCellClick = (row, col) => {
if (
col.dataIndex === 'metadata.name' &&
isLocalConnectorType(row.category)
isLocalConnectorType(row.spec.category)
) {
handleView(row);
}
Expand Down Expand Up @@ -635,7 +642,7 @@
loading.value = true;
const row = cloneDeep(data);
row.enableFinOps = enable;
row.configData = null;
row.spec.config.data = null;
await updateConnector(row);
loading.value = false;
Message.success(t('common.message.success'));
Expand All @@ -657,7 +664,7 @@
handleFetchCost(row);
break;
case 'enableFinops':
handleEnableFinOps(!row.enableFinOps, row);
handleEnableFinOps(!row.spec.enableFinOps, row);
break;
case 'reinstall':
handleReinstall(row);
Expand Down
5 changes: 3 additions & 2 deletions src/views/operation-hub/connectors/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export const ConnectorCategory = {
VersionControl: 'VersionControl',
Custom: 'Custom',
CloudProvider: 'CloudProvider',
Kubernetes: 'Kubernetes'
Kubernetes: 'Kubernetes',
Docker: 'Docker'
};

export const ConnectorType = {
Expand Down Expand Up @@ -216,7 +217,7 @@ export const actionList: MoreAction[] = [
icon: 'icon-edit',
status: 'normal',
filterFun({ itemInfo, projectID }) {
if (!ConnectorCategory[itemInfo.category]) {
if (!ConnectorCategory[itemInfo.spec.category]) {
return false;
}
return projectID
Expand Down
41 changes: 39 additions & 2 deletions src/views/operation-hub/connectors/config/interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import { DataListItem, AxiosRequestPayload } from '@/types/global';

export type ConnectorRowData = DataListItem;
export interface ConnectorRowData extends DataListItem {
spec: {
enableFinOps?: boolean;
applicableEnvironmentType: string;
category: string;
type: string;
config: {
version: string;
data: {
kubeconfig: {
visible: boolean;
value: string;
type: string;
};
};
};
};
}

export interface CustomAttrbute {
key: string;
Expand All @@ -14,7 +31,27 @@ export interface CustomAttrbute {
style?: object;
}

export type ConnectorFormData = AxiosRequestPayload;
export interface ConnectorFormData extends AxiosRequestPayload {
configDataFormat?: string;
customConfig?: string;
spec: {
enableFinOps?: boolean;
applicableEnvironmentType: string;
category: string;
type: string;
description?: string;
config: {
version: string;
data: {
[key: string]: {
visible: boolean;
value: string;
type: string;
};
};
};
};
}

export interface ConnectorTypeData {
label: string;
Expand Down
Loading
Loading