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

Commit

Permalink
chore: serivice same request
Browse files Browse the repository at this point in the history
  • Loading branch information
hibig committed Aug 16, 2023
1 parent 5e6e112 commit facc2a1
Show file tree
Hide file tree
Showing 19 changed files with 147 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</template>
</GroupTitle>
<div class="svc-wrapper">
<a-spin :loading="asyncLoading" style="width: 100%">
<a-spin :loading="completeDataLoading" style="width: 100%">
<a-grid :cols="24" :row-gap="8" :col-gap="8">
<a-grid-item v-for="item in editServiceList" :key="item.id" :span="6">
<serviceThumb
Expand Down Expand Up @@ -251,18 +251,26 @@
import GroupTitle from '@/components/group-title/index.vue';
import formCreate from '@/components/form-create/index.vue';
import serviceThumb from '../../services/components/service-thumb.vue';
import { ServiceRowData } from '../../services/config/interface';
import useServiceData from '../../services/hooks/use-service-data';
type refItem = Element | ComponentPublicInstance | null;
const CloneType = {
SERVICE: 'service',
ENVIRONMENT: 'environment'
};
const props = defineProps({
serviceList: {
type: Array as PropType<ServiceRowData[]>,
serviceIds: {
type: Array as PropType<string[]>,
default() {
return [];
}
},
cloneType: {
type: String as PropType<'service' | 'environment'>,
default() {
return 'environment';
}
},
showCheck: {
type: Boolean,
default() {
Expand All @@ -280,6 +288,8 @@
generateVariablesGroup,
setFormAttributes,
initCompleteData,
completeDataLoading,
serviceDataList,
serviceInfo,
formData,
pageAction,
Expand Down Expand Up @@ -492,23 +502,30 @@
generateVariablesGroup(PageAction.EDIT);
show.value = false;
};
defineExpose({
getSelectServiceData
});
watch(
() => props.serviceList,
() => {
selectedList.value.clear();
_.each(props.serviceList, (item) => {
const setSelectServiceList = () => {
selectedList.value.clear();
if (props.cloneType === CloneType.ENVIRONMENT) {
_.each(serviceDataList.value, (item) => {
selectedList.value.add(item.id);
});
editServiceList.value = _.cloneDeep(props.serviceList);
},
{
immediate: true
editServiceList.value = _.cloneDeep(serviceDataList.value);
return;
}
if (props.cloneType === CloneType.SERVICE) {
selectedList.value = new Set(props.serviceIds);
editServiceList.value = _.filter(serviceDataList.value, (item) =>
selectedList.value.has(item.id)
);
}
);
initCompleteData();
};
const init = async () => {
await initCompleteData();
setSelectServiceList();
};
defineExpose({
getSelectServiceData
});
init();
</script>
<style lang="less" scoped>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface EnvironFormData {
description: string;
connectorIDs: string[];
connectors: any[];
edges: any[];
edges?: any[];
labels?: Record<string, any>;
services?: any[];
}
35 changes: 10 additions & 25 deletions src/views/application-management/environments/pages/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@
>
<CloneService
ref="serviceRef"
:service-list="serviceList"
:async-loading="asyncLoading"
clone-type="environment"
:style="{ width: `${InputWidth.XLARGE}px`, overflow: 'auto' }"
></CloneService>
</a-form-item>
Expand Down Expand Up @@ -387,23 +386,7 @@
};
}
};
const getEnvironmentServices = async () => {
if (!route.params.environmentId) return;
asyncLoading.value = true;
try {
const params = {
projectID: route.params.projectId as string,
environmentID: route.params.environmentId as string,
page: -1
};
const { data } = await queryServices(params);
serviceList.value = data.items || [];
} catch (error) {
serviceList.value = [];
} finally {
asyncLoading.value = false;
}
};
const getConnectors = async () => {
try {
const params = {
Expand Down Expand Up @@ -438,9 +421,10 @@
remove(selectedList.value, (id) => record.id === id);
formref.value.validateField('connectorIDs');
};
const handleCloneEnvironment = async () => {
const handleCloneEnvironment = async (data) => {
const services = serviceRef.value.getSelectServiceData();
formData.value.services = _.cloneDeep(services);
data.services = _.cloneDeep(services);
return data;
};
const handleSubmit = async () => {
Expand All @@ -450,13 +434,15 @@
if (!res && !validateTrigger.value) {
try {
submitLoading.value = true;
const data = _.omit(formData.value, ['edges']);
if (environmentId) {
handleCloneEnvironment();
handleCloneEnvironment(data);
}
if (id && !environmentId) {
await updateEnvironment(formData.value);
await updateEnvironment(data);
} else {
await createEnvironment(formData.value);
await createEnvironment(data);
}
copyFormData = cloneDeep(formData.value);
tabBarStore.deleteTag(0, {
Expand Down Expand Up @@ -515,7 +501,6 @@
});
const init = async () => {
setBreadCrumbList();
getEnvironmentServices();
await getConnectors();
await getItemEnvironmentInfo();
getLabelList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
v-model="formData.name"
:label="$t('common.table.name')"
:required="true"
:disabled="action === 'edit'"
style="width: 100%"
:max-length="63"
show-word-limit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ export default function useProjectData() {
const params = {
page: 1,
perPage: 10,
projectID: route.params.projectId as string,
environmentID: route.params.environmentId as string,
extract: ['-attributes', '-projectId', '-status', '-template'],
...queryparams
};
Expand Down
54 changes: 17 additions & 37 deletions src/views/application-management/services/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ export const updateService = (data) => {
export const queryItemService = (params) => {
return axios.get(`${SERVICE_API_PREFIX()}${SERVICE_API}/${params.id}`, {
params: {
...params,
...getPermissionRouteParams()
...params
},
paramsSerializer: (obj) => {
return qs.stringify(obj);
Expand All @@ -102,8 +101,7 @@ export const queryApplicationServices = (params) => {
export const queryItemApplicationService = (params) => {
return axios.get(`${SERVICE_API_PREFIX()}${SERVICE_API}/${params.id}`, {
params: {
...params,
...getPermissionRouteParams()
...params
},
paramsSerializer: (obj) => {
return qs.stringify(obj);
Expand All @@ -116,8 +114,7 @@ export const queryInstanceOutputs = (params) => {
`${SERVICE_API_PREFIX()}${SERVICE_API}/${params.id}/outputs`,
{
params: {
...params,
...getPermissionRouteParams()
...params
},
paramsSerializer: (obj) => {
return qs.stringify(obj);
Expand All @@ -135,9 +132,7 @@ export const deleteServiceItem = (data) => {

export const upgradeApplicationInstance = (data) => {
return axios.put(
`${SERVICE_API_PREFIX()}${SERVICE_API}/${data.id}/upgrade?${qs.stringify(
getPermissionRouteParams()
)}`,
`${SERVICE_API_PREFIX()}${SERVICE_API}/${data.id}/upgrade`,
data
);
};
Expand All @@ -147,9 +142,7 @@ export const cloneApplicationInstance = (data: {
name: string;
}) => {
return axios.post(
`${SERVICE_API_PREFIX()}${SERVICE_API}/${data.id}/clone?${qs.stringify(
getPermissionRouteParams()
)}`,
`${SERVICE_API_PREFIX()}${SERVICE_API}/${data.id}/clone`,
data
);
};
Expand All @@ -159,8 +152,7 @@ export const diffServiceSpec = (params: { serviceID: string }) => {
`${SERVICE_API_PREFIX()}${SERVICE_API}/${params.serviceID}/diff-latest`,
{
params: {
...params,
...getPermissionRouteParams()
...params
},
paramsSerializer: (obj) => {
return qs.stringify(obj);
Expand All @@ -174,8 +166,7 @@ export const queryServiceResourceGraph = (params: { serviceID: string }) => {
`${SERVICE_API_PREFIX()}${SERVICE_API}/${params.serviceID}/graph`,
{
params: {
...params,
...getPermissionRouteParams()
...params
},
paramsSerializer: (obj) => {
return qs.stringify(obj);
Expand All @@ -189,8 +180,7 @@ export const queryEnvironmentServiceGraph = (params: {
}) => {
return axios.get(`${SERVICE_API_PREFIX()}/graph`, {
params: {
...params,
...getPermissionRouteParams()
...params
},
paramsSerializer: (obj) => {
return qs.stringify(obj);
Expand All @@ -217,8 +207,7 @@ export const queryServiceRevisions = (
`${SERVICE_API_PREFIX()}${SERVICE_API}/${params.serviceID}/revisions`,
{
params: {
...params,
...getPermissionRouteParams()
...params
},
cancelToken: token,
paramsSerializer: (obj) => {
Expand All @@ -230,8 +219,7 @@ export const queryServiceRevisions = (
export const queryApplicationRevisionsDetail = (params: { id: string }) => {
return axios.get(`${SERVICE_RESOURCE_API_PREFIX()}/revisions/${params.id}`, {
params: {
...params,
...getPermissionRouteParams()
...params
},
paramsSerializer: (obj) => {
return qs.stringify(obj);
Expand All @@ -252,8 +240,7 @@ export const diffRevisionSpec = (params: { id: string; serviceID: string }) => {
}/diff-latest`,
{
params: {
...params,
...getPermissionRouteParams()
...params
},
paramsSerializer: (obj) => {
return qs.stringify(obj);
Expand All @@ -271,8 +258,7 @@ export const queryRevisionChange = (params: {
}/diff-previous`,
{
params: {
...params,
...getPermissionRouteParams()
...params
},
paramsSerializer: (obj) => {
return qs.stringify(obj);
Expand All @@ -289,7 +275,6 @@ export const rollbackService = (data: {
`${SERVICE_API_PREFIX()}${SERVICE_API}/${
data.serviceID
}/rollback?${qs.stringify({
...getPermissionRouteParams(),
revisionID: data.revisionID
})}`
);
Expand All @@ -304,8 +289,7 @@ export const queryServiceResource = (
`${SERVICE_API_PREFIX()}${SERVICE_API}/${params.serviceID}/resources`,
{
params: {
...params,
...getPermissionRouteParams()
...params
},
cancelToken: token,
paramsSerializer: (obj) => {
Expand All @@ -320,8 +304,7 @@ export const queryServiceResourceKeys = (params: { id: string }) => {
`${SERVICE_RESOURCE_API_PREFIX()}/resources/${params.id}/keys`,
{
params: {
...params,
...getPermissionRouteParams()
...params
},
paramsSerializer: (obj) => {
return qs.stringify(obj);
Expand All @@ -335,8 +318,7 @@ export const queryServiceResourceLogs = (params: { id: string }) => {
`${SERVICE_RESOURCE_API_PREFIX()}/resources/${params.id}/log`,
{
params: {
...params,
...getPermissionRouteParams()
...params
},
paramsSerializer: (obj) => {
return qs.stringify(obj);
Expand All @@ -349,8 +331,7 @@ export const queryServiceResourceExec = (params: { id: string }) => {
`${SERVICE_RESOURCE_API_PREFIX()}/resources/${params.id}/exec`,
{
params: {
...params,
...getPermissionRouteParams()
...params
},
paramsSerializer: (obj) => {
return qs.stringify(obj);
Expand All @@ -369,8 +350,7 @@ export const queryInstanceEndpoints = (
}/access-endpoints`,
{
params: {
...params,
...getPermissionRouteParams()
...params
},
cancelToken: token,
paramsSerializer: (obj) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export default function useFetchResource() {
});
getHelmResourceIDs();
};
const createResourceChunkConnection = () => {
const createResourceChunkRequest = () => {
requestCacheList.value = [];
try {
setChunkRequest({
Expand All @@ -255,7 +255,7 @@ export default function useFetchResource() {
});
return {
fetchData,
createResourceChunkConnection,
createResourceChunkRequest,
loading,
dataList
};
Expand Down
Loading

0 comments on commit facc2a1

Please sign in to comment.