Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): improve the editing of labels and variables #6810

Merged
merged 1 commit into from
Jan 17, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,54 @@
<el-col :span="6">
<InputText
:model-value="key"
:placeholder="t('key')"
@update:model-value="(changed) => updateKey(key, changed)"
/>
</el-col>
<el-col :span="16">
<InputText
:v-model="value"
:model-value="value"
:placeholder="t('value')"
@update:model-value="(changed) => updateValue(key, changed)"
/>
</el-col>
<el-col :span="2" class="col align-self-center delete">
<DeleteOutline @click="removeLabel(key)" />
<DeleteOutline @click="removePair(key)" />
</el-col>
</el-row>

<Add what="label" @add="addLabel()" />
<Add :what="props.property" @add="addPair()" />
</div>
</template>

<script setup lang="ts">
import {PropType} from "vue";

import {LabelField} from "../../utils/types";
import {PairField} from "../../utils/types";

import {DeleteOutline} from "../../utils/icons";

import InputText from "./InputText.vue";
import Add from "../Add.vue";

import {useI18n} from "vue-i18n";
const {t} = useI18n({useScope: "global"});

const emits = defineEmits(["update:modelValue"]);
const props = defineProps({
modelValue: {
type: Array as PropType<LabelField["value"]>,
type: Array as PropType<PairField["value"][]>,
default: undefined,
},
label: {type: String, required: true},
property: {type: String, required: true},
required: {type: Boolean, default: false},
});

const addLabel = () => {
const addPair = () => {
emits("update:modelValue", {...props.modelValue, "": ""});
};
const removeLabel = (key: any) => {
const removePair = (key: any) => {
const values = {...props.modelValue};
delete values[key];

Expand Down
7 changes: 4 additions & 3 deletions ui/src/components/code/components/inputs/InputText.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<span v-if="required" class="me-1 text-danger">*</span>
<span class="label">{{ label }}</span>
<span v-if="label" class="label">{{ label }}</span>
<div class="mt-1 mb-2 wrapper">
<el-input v-model="input" @input="handleInput" :disabled />
<el-input v-model="input" @input="handleInput" :placeholder :disabled />
</div>
</template>

Expand All @@ -12,7 +12,8 @@
const emits = defineEmits(["update:modelValue"]);
const props = defineProps({
modelValue: {type: [String, Number, Boolean], default: undefined},
label: {type: String, default: ""},
label: {type: String, default: undefined},
placeholder: {type: String, default: ""},
required: {type: Boolean, default: false},
disabled: {type: Boolean, default: false},
});
Expand Down
10 changes: 5 additions & 5 deletions ui/src/components/code/segments/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@
import Collapse from "../components/collapse/Collapse.vue";
import InputText from "../components/inputs/InputText.vue";
import InputSwitch from "../components/inputs/InputSwitch.vue";
import InputLabel from "../components/inputs/InputLabel.vue";
import InputPair from "../components/inputs/InputPair.vue";

import Editor from "../../inputs/Editor.vue";
import MetadataInputs from "../../flows/MetadataInputs.vue";
import MetadataVariables from "../../flows/MetadataVariables.vue";

import Task from "./Task.vue";

Expand Down Expand Up @@ -94,9 +93,10 @@
style: {height: "100px"},
},
labels: {
component: shallowRef(InputLabel),
component: shallowRef(InputPair),
value: props.metadata.labels,
label: t("no_code.fields.general.labels"),
property: t("no_code.labels.label"),
},
inputs: {
component: shallowRef(MetadataInputs),
Expand All @@ -114,10 +114,10 @@
style: {height: "100px"},
},
variables: {
component: shallowRef(MetadataVariables),
component: shallowRef(InputPair),
value: props.metadata.variables,
label: t("no_code.fields.general.variables"),
variables: props.metadata.variables,
property: t("no_code.labels.variable"),
},
// concurrency: {
// component: shallowRef(InputSwitch), // TODO: To improve slot content
Expand Down
1 change: 1 addition & 0 deletions ui/src/components/code/styles/code.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ $code-font-sm: var(--el-font-size-small);
--el-disabled-text-color: #{$code-gray-700};

.el-input__inner {
color: $code-gray-700;
font-size: $code-font-sm;
}
}
Expand Down
13 changes: 5 additions & 8 deletions ui/src/components/code/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@ export type Field = {
disabled?: boolean;
};

export type LabelField = Omit<Field, "value"> & {
value: [string, string][];
export type PairField = Omit<Field, "value"> & {
value: Record<string, string>;
property: string;
};

type InputField = Field & {
inputs: any[];
};

type VariableField = Field & {
variables: any[];
};

type ConcurrencyField = Field & {
root: string;
schema: object;
Expand All @@ -48,10 +45,10 @@ export type Fields = {
namespace: Field;
description: Field;
retry: EditorField;
labels: LabelField;
labels: PairField;
inputs: InputField;
outputs: EditorField;
variables: VariableField;
variables: PairField;
concurrency?: ConcurrencyField; // TODO: Make it not optional
pluginDefaults: EditorField;
disabled: Field;
Expand Down
4 changes: 3 additions & 1 deletion ui/src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,9 @@
"adding": "+ Add a {what}",
"labels": {
"yaml": "YAML Editor",
"no_code": "No Code Editor"
"no_code": "No Code Editor",
"label": "Label",
"variable": "Variable"
},
"sections": {
"main": "Main properties",
Expand Down
Loading