Skip to content

Commit 7e02f41

Browse files
author
Max
authored
Merge pull request #14 from Zhuzhenghao/main
refactor: extract all deletion logic for better maintainability
2 parents 6d7e97b + 21f281c commit 7e02f41

10 files changed

Lines changed: 63 additions & 105 deletions

File tree

src/api/finetune-experiment.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/* eslint-disable no-use-before-define */
2-
import type {
3-
Condition, ListMeta, ObjectMeta,
4-
} from 'kubernetes-types/meta/v1';
2+
import type { Condition, ListMeta, ObjectMeta } from 'kubernetes-types/meta/v1';
53
import { K8sClient } from '@/plugins/axios/client';
64
import { FinetuneJob, Status as FinetuneJobStatus, ScoringConfig } from './finetune-job';
75

@@ -41,21 +39,25 @@ export interface FinetuneExperiment {
4139
status?: Status;
4240
}
4341

42+
export type FinetuneJobWithName = FinetuneJob & { name: string };
43+
4444
/**
4545
* FinetuneExperimentSpec defines the desired state of FinetuneExperiment
4646
*/
4747
export interface Spec {
4848
/**
4949
* Defining multiple finetunejobs in a single experiment.
5050
*/
51-
finetuneJobs: FinetuneJob[];
51+
finetuneJobs: FinetuneJobWithName[];
5252
/**
5353
* Define the scoring plugin used for this experiment.
5454
*/
5555
scoringConfig: ScoringConfig;
5656
pending?: boolean;
5757
}
5858

59+
export type FinetuneJobStatusWithName = {status?: FinetuneJobStatus;} & { name?: string };
60+
5961
/**
6062
* FinetuneExperimentStatus defines the observed state of FinetuneExperiment
6163
*/
@@ -65,7 +67,7 @@ export interface Status {
6567
*/
6668
bestVersion: BestVersion;
6769
conditions: Condition[];
68-
jobsStatus: FinetuneJobStatus[];
70+
jobsStatus: FinetuneJobStatusWithName[];
6971
state: State;
7072
}
7173

@@ -84,7 +86,7 @@ export enum State {
8486
Failed = 'FAILED',
8587
Processing = 'PROCESSING',
8688
Success = 'SUCCESS',
87-
Pending = 'PENDING'
89+
Pending = 'PENDING',
8890
}
8991

9092
export const apiVersion = 'finetune.datatunerx.io/v1beta1';

src/api/finetune-job.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export interface FinetuneJob {
3030
* FinetuneJobStatus defines the observed state of FinetuneJob
3131
*/
3232
status?: Status;
33-
valid?: boolean;
3433
}
3534

3635
/**

src/locales/en-US/views/Hyperparameter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
"name": "Name",
1010
"fineTuningType": "Fine-tuning",
11+
"referencedTask": "Referenced Task",
1112
"parameters": "Parameters Preview",
1213
"hyperparameterGroup": "Hyperparameter",
1314
"configuration": "Configuration",

src/locales/zh-CN/views/Hyperparameter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
"name": "名称",
1010
"fineTuningType": "微调类型",
11+
"referencedTask":"被引用任务",
1112
"parameters": "参数预览",
1213
"hyperparameterGroup": "超参组",
1314
"configuration": "参数配置",

src/views/dataset/DatasetDetail.vue

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
11
<script lang="ts" setup>
22
import { useRoute, useRouter } from 'vue-router';
3-
import { computed, ref } from 'vue';
3+
import { computed, onBeforeMount } from 'vue';
44
import { useI18n } from 'vue-i18n';
55
import { useNamespaceStore } from '@/stores/namespace';
6-
import { Dataset, datasetClient } from '@/api/dataset';
7-
import { nError } from '@/utils/useNoty';
8-
import { useDeleteDataset } from './composition/dataset';
6+
import { storeToRefs } from 'pinia';
7+
import { useDataset, useDeleteDataset } from './composition/dataset';
98
109
const { t } = useI18n();
1110
const router = useRouter();
1211
const route = useRoute();
1312
14-
const namespaceStore = useNamespaceStore();
13+
const { namespace } = storeToRefs(useNamespaceStore());
14+
const name = route.params.name as string;
1515
16-
const dataset = ref<Dataset>();
16+
const { dataset, fetchDataset } = useDataset();
1717
18-
const loadDataset = () => {
19-
datasetClient.read(namespaceStore.namespace, route.params.name as string).then((res) => {
20-
dataset.value = res.data;
21-
});
22-
};
23-
24-
try {
25-
loadDataset();
26-
} catch (error) {
27-
nError(t('views.Dataset.loadDatasetError'));
28-
}
29-
30-
const name = computed(() => dataset.value?.metadata?.name);
18+
onBeforeMount(() => {
19+
fetchDataset(namespace.value, name);
20+
});
3121
3222
const infos = computed(() => {
3323
const languages = dataset.value?.spec?.datasetMetadata.languages?.map((lang) => t(`views.Dataset.${lang}`)).join(', ') ?? '-';
@@ -96,22 +86,15 @@ const subsets = computed(() => dataset.value?.spec?.datasetMetadata.datasetInfo?
9686
const onEdit = () => {
9787
router.push({
9888
name: 'DatasetCreate',
99-
query: {
100-
name: name.value,
101-
},
89+
query: { name },
10290
});
10391
};
10492
10593
const toList = () => {
106-
router.push({
107-
name: 'DatasetList',
108-
});
94+
router.push({ name: 'DatasetList' });
10995
};
11096
111-
const { onConfirmDelete } = useDeleteDataset(
112-
namespaceStore.namespace,
113-
toList,
114-
);
97+
const { onConfirmDelete } = useDeleteDataset(namespace.value, toList);
11598
11699
</script>
117100

src/views/finetune-experiment/FinetuneExperimentList.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { FinetuneExperiment, finetuneExperimentClient } from '@/api/finetune-exp
88
import { useQueryTable } from '@/hooks/useQueryTable';
99
import { createDialog } from '@dao-style/extend';
1010
import { useI18n } from 'vue-i18n';
11-
import { hyperparameterClient } from '@/api/hyperparameter';
1211
import FinetuneExperimentItem from './components/FinetuneExperimentItem.vue';
1312
import { useFinetuneExperiment } from './composition/finetune';
1413
@@ -28,7 +27,7 @@ const onCreate = () => {
2827
});
2928
};
3029
31-
const deleteFn = (name: string) => hyperparameterClient.delete(namespace.value, name).then(() => {
30+
const deleteFn = (name: string) => finetuneExperimentClient.delete(namespace.value, name).then(() => {
3231
handleRefresh();
3332
});
3433

src/views/finetune-experiment/components/FinetuneExperimentItem.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const onDelete = () => {
2828
const readyJobs = computed(() => {
2929
const { jobsStatus } = props.data.status ?? {};
3030
31-
return jobsStatus?.filter((job) => job.state === FinetuneJobState.Successful).length ?? 0;
31+
return jobsStatus?.filter((job) => job.status?.state === FinetuneJobState.Successful).length ?? 0;
3232
});
3333
3434
const infos = computed(() => {

src/views/finetune-experiment/components/FinetuneJobItem.vue

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
<script lang="ts" setup>
2+
import { FinetuneJobWithName } from '@/api/finetune-experiment';
23
import { PropType, computed } from 'vue';
3-
import { FinetuneJob } from '@/api/finetune-job';
44
import { useI18n } from 'vue-i18n';
55
66
const props = defineProps({
77
data: {
8-
type: Object as PropType<FinetuneJob>,
8+
type: Object as PropType<FinetuneJobWithName>,
99
default: () => ({}),
1010
},
1111
});
1212
const { t } = useI18n();
1313
1414
const infos = computed(() => {
15-
const { data: { spec } } = props;
15+
const {
16+
data: { spec },
17+
} = props;
1618
const llms = spec?.finetune?.finetuneSpec.llm;
1719
const datasets = spec?.finetune.finetuneSpec.dataset;
1820
const hyperparameters = spec?.finetune.finetuneSpec.hyperparameter?.hyperparameterRef;
@@ -38,7 +40,9 @@ const infos = computed(() => {
3840
return items;
3941
});
4042
const infosTwo = computed(() => {
41-
const { data: { spec } } = props;
43+
const {
44+
data: { spec },
45+
} = props;
4246
4347
const items = [
4448
{
@@ -60,10 +64,15 @@ const infosTwo = computed(() => {
6064
use-font
6165
>
6266
<template #title>
63-
cfh
64-
<dao-state-icon :type="'success'">
65-
{{ t('common.run') }}
66-
</dao-state-icon>
67+
<div class="finetune-job-item__header">
68+
<div class="finetune-job-item__header__text dataset-item__header__text--link">
69+
{{ props.data.name }}
70+
</div>
71+
72+
<dao-state-icon :type="'success'">
73+
{{ t("common.run") }}
74+
</dao-state-icon>
75+
</div>
6776
</template>
6877

6978
<dao-card-item class="finetune-experiment-item__base-info">
@@ -114,55 +123,41 @@ const infosTwo = computed(() => {
114123
</dao-card>
115124
</template>
116125

117-
<style lang="scss">
126+
<style lang="scss" scoped>
118127
.finetune-job-item {
128+
margin-top: 20px;
119129
margin-right: 20px;
120130
margin-left: 20px;
121131
122-
&.finetune-job-item{
123-
margin-top: 20px;
124-
}
125-
126132
// &__base-info.dao-card-item {
127133
// flex: 1.25 1 0;
128134
// }
129135
130136
&__header {
131-
display: flex;
137+
display: flex;
132138
align-items: center;
133-
font-weight: 700;
139+
font-weight: 600;
134140
color: var(--dao-text-pageTitle);
135141
136142
&__text {
137143
display: inline-block;
138144
max-width: 75%;
145+
margin-right: 10px;
139146
overflow: hidden;
140-
color: var(--dao-text-primary);
141147
text-decoration: none;
142148
text-overflow: ellipsis;
143149
white-space: nowrap;
144150
145-
&.active {
151+
&--link {
152+
color: var(--dao-text-primary);
153+
cursor: pointer;
154+
146155
&:hover,
147156
&:active {
148157
color: var(--dao-primary-blue-040);
149158
}
150159
}
151160
}
152161
}
153-
154-
&__text {
155-
font-size: 28px;
156-
font-weight: bold;
157-
}
158-
159-
&__size {
160-
color: var(--dao-green-030);
161-
}
162-
163-
}
164-
165-
.dao-key-value-layout.is-horizontal .dao-key-value-layout-item__label {
166-
width: 110px;
167162
}
168163
</style>

src/views/finetune-experiment/composition/finetune.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export const useFinetuneJob = () => {
6060
metadata: {
6161
name: '',
6262
},
63-
valid: true,
6463
spec: {
6564
finetune: {
6665
finetuneSpec: {

src/views/hyperparameter/HyperparameterDetail.vue

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,24 @@
11
<script setup lang="ts">
22
import { useRoute, useRouter } from 'vue-router';
3-
import { computed, ref } from 'vue';
3+
import { computed, onBeforeMount } from 'vue';
44
import { useDateFormat } from '@dao-style/extend';
55
import { useI18n } from 'vue-i18n';
66
import { useNamespaceStore } from '@/stores/namespace';
7-
import {
8-
Hyperparameter, hyperparameterClient,
9-
} from '@/api/hyperparameter';
10-
import { nError } from '@/utils/useNoty';
11-
import { retrieveQuantization, useDeleteHyperparameter } from './composition/hyperparameter';
7+
import { storeToRefs } from 'pinia';
8+
import { retrieveQuantization, useDeleteHyperparameter, useHyperparameter } from './composition/hyperparameter';
129
1310
const router = useRouter();
1411
const route = useRoute();
15-
const namespaceStore = useNamespaceStore();
1612
const { t } = useI18n();
1713
18-
const hyperparameter = ref<Hyperparameter | null>(null);
14+
const { namespace } = storeToRefs(useNamespaceStore());
15+
const name = route.params.name as string;
1916
20-
// 获取超参数详细信息
21-
const fetchDataset = async () => {
22-
try {
23-
const res = await hyperparameterClient.read(
24-
namespaceStore.namespace,
25-
route.params.name as string,
26-
);
17+
const { hyperparameter, fetchHyperparameter } = useHyperparameter();
2718
28-
hyperparameter.value = res.data;
29-
} catch (error) {
30-
nError(
31-
t('common.notyError', {
32-
name: t('common.fetch'),
33-
action: t('views.Hyperparameter.hyperparameterGroup'),
34-
}),
35-
error,
36-
);
37-
}
38-
};
39-
40-
fetchDataset();
41-
42-
const name = computed(() => hyperparameter.value?.metadata.name);
19+
onBeforeMount(() => {
20+
fetchHyperparameter(namespace.value, name);
21+
});
4322
4423
// 基本信息
4524
const infos = computed(() => {
@@ -50,14 +29,14 @@ const infos = computed(() => {
5029
return [
5130
{
5231
label: t('views.Hyperparameter.name'),
53-
value: name.value,
32+
value: data.metadata.name,
5433
},
5534
{
5635
label: t('views.Hyperparameter.fineTuningType'),
5736
value: data.spec.objective.type,
5837
},
5938
{
60-
label: '被引用任务',
39+
label: t('views.Hyperparameter.referencedTask'),
6140
value: data.metadata.labels,
6241
slotId: 'tag',
6342
},
@@ -154,7 +133,7 @@ const onEdit = () => {
154133
router.push({
155134
name: 'HyperparameterCreate',
156135
query: {
157-
name: name.value,
136+
name,
158137
},
159138
});
160139
};
@@ -166,7 +145,7 @@ const toList = () => {
166145
};
167146
168147
const { onConfirmDelete } = useDeleteHyperparameter(
169-
namespaceStore.namespace,
148+
namespace.value,
170149
toList,
171150
);
172151
</script>

0 commit comments

Comments
 (0)