This is an automated email from the ASF dual-hosted git repository.
kerwin pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new c849501f3b Display the resource file doesn't exist message in task
create page (#15350)
c849501f3b is described below
commit c849501f3bed35024bca008477b31e1ad76ce8ff
Author: liyou <[email protected]>
AuthorDate: Tue Dec 26 11:07:43 2023 +0800
Display the resource file doesn't exist message in task create page (#15350)
---
dolphinscheduler-ui/src/locales/en_US/project.ts | 2 +-
.../task/components/node/fields/use-resources.ts | 104 ++++++++++++++++++++-
2 files changed, 100 insertions(+), 6 deletions(-)
diff --git a/dolphinscheduler-ui/src/locales/en_US/project.ts
b/dolphinscheduler-ui/src/locales/en_US/project.ts
index 222afc1707..5feac80707 100644
--- a/dolphinscheduler-ui/src/locales/en_US/project.ts
+++ b/dolphinscheduler-ui/src/locales/en_US/project.ts
@@ -432,7 +432,7 @@ export default {
resources: 'Resources',
resources_tips: 'Please select resources',
resources_limit_tips: 'Please select again, resource limit:',
- non_resources_tips: 'Please delete all non-existent resources',
+ no_resources_tips: 'Please delete all non-existent resources',
useless_resources_tips: 'Unauthorized or deleted resources',
custom_parameters: 'Custom Parameters',
copy_success: 'Copy success',
diff --git
a/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-resources.ts
b/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-resources.ts
index 2ec431bcbe..90ba0a40a7 100644
---
a/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-resources.ts
+++
b/dolphinscheduler-ui/src/views/projects/task/components/node/fields/use-resources.ts
@@ -29,7 +29,15 @@ export function useResources(
): IJsonItem {
const { t } = useI18n()
- const resourcesOptions = ref([] as IResource[])
+ interface ResourceOption {
+ name: string
+ fullName: string
+ dirctory: boolean
+ disable: boolean
+ children?: ResourceOption[]
+ }
+
+ const resourcesOptions = ref<ResourceOption[] | IResource[]>([])
const resourcesLoading = ref(false)
const taskStore = useTaskNodeStore()
@@ -48,6 +56,66 @@ export function useResources(
taskStore.updateResource(res)
}
+ const validateResourceExist = (
+ fullName: string,
+ parentDir: string[],
+ resources: ResourceOption[]
+ ): boolean => {
+ const isDirectory = (res: ResourceOption): boolean => {
+ return res.dirctory && new RegExp(`^${res.fullName}`).test(fullName)
+ }
+
+ const processDirectory = (res: ResourceOption): boolean => {
+ if (!res.children) {
+ res.children = []
+ }
+ parentDir.push(res.name)
+ return validateResourceExist(
+ fullName,
+ parentDir,
+ res.children as ResourceOption[]
+ )
+ }
+
+ if (resources.length > 0) {
+ for (const res of resources) {
+ if (isDirectory(res)) {
+ return processDirectory(res)
+ }
+
+ if (res.fullName === fullName) {
+ return true
+ }
+ }
+ }
+ addResourceNode(fullName, parentDir, resources)
+ return false
+ }
+
+ const addResourceNode = (
+ fullName: string,
+ parentDir: string[],
+ resources: ResourceOption[]
+ ) => {
+ const resourceNode = {
+ fullName: fullName,
+ name: getResourceDirAfter(fullName, parentDir),
+ dirctory: false,
+ disable: true
+ }
+ resources.push(resourceNode)
+ }
+
+ const getResourceDirAfter = (fullName: string, parentDir: string[]) => {
+ const dirctory = '/resources/' + parentDir.join('')
+ const delimiterIndex = fullName.indexOf(dirctory)
+ if (delimiterIndex !== -1) {
+ return fullName.substring(delimiterIndex + dirctory.length)
+ } else {
+ return fullName
+ }
+ }
+
onMounted(() => {
getResources()
})
@@ -69,18 +137,44 @@ export function useResources(
placeholder: t('project.node.resources_tips'),
keyField: 'fullName',
labelField: 'name',
+ disabledField: 'disable',
loading: resourcesLoading
},
validate: {
- trigger: ['input', 'blur'],
+ trigger: ['blur'],
required: required,
- validator(validate: any, value: IResource[]) {
+ validator(validate: any, value: string[]) {
+ if (value) {
+ const errorNames: string[] = []
+ value.forEach((item) => {
+ if (
+ !validateResourceExist(
+ item,
+ [],
+ resourcesOptions.value as ResourceOption[]
+ )
+ ) {
+ errorNames.push(item)
+ }
+ })
+ if (errorNames.length > 0) {
+ let errorName = ': '
+ errorNames.forEach((name) => {
+ value.splice(value.indexOf(name), 1)
+ errorName += getResourceDirAfter(name, []) + ';'
+ })
+ return new Error(
+ t('project.node.useless_resources_tips') + errorName
+ )
+ }
+ }
+
if (isRef(required) ? required.value : required) {
if (!value || value.length == 0) {
return new Error(t('project.node.resources_tips'))
}
-
- if (limit > 0 && value.length > limit) {
+ const limit_ = isRef(limit) ? limit.value : limit
+ if (limit_ > 0 && value.length > limit_) {
return new Error(t('project.node.resources_limit_tips') + limit)
}
}