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: create legacy evaluate expression & add legacy-warning UI #4631

Merged
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 @@ -3,6 +3,7 @@ import { PButton, PSpinner } from '@cloudforet/mirinae';

interface Props {
disabled: boolean;
isLegacyDataTable?: boolean;
changed: boolean;
loading: boolean;
}
Expand Down Expand Up @@ -34,15 +35,16 @@ const handleUpdateDataTable = () => {
{{ $t('COMMON.WIDGETS.DELETE') }}
</p-button>
<div class="form-button-wrapper">
<p-button style-type="transparent"
<p-button v-if="!props.isLegacyDataTable"
style-type="transparent"
icon-left="ic_refresh"
@click="handleClickResetDataTable"
>
{{ $t('COMMON.WIDGETS.RESET') }}
</p-button>
<p-button style-type="secondary"
class="apply-button"
:disabled="props.disabled"
:disabled="props.disabled || props.isLegacyDataTable"
@click="handleUpdateDataTable"
>
<div class="button-contents-wrapper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface Props {
dataType: DataTableDataType;
dataTableName: string;
selected: boolean;
isLegacyDataTable?: boolean;
}
const props = defineProps<Props>();
const emit = defineEmits<{(e: 'update:dataTableName', value: string): void;}>();
Expand Down Expand Up @@ -129,6 +130,7 @@ const handleClickNameConfirm = async () => {
</p-tooltip>
<p-icon-button class="edit-button"
style-type="transparent"
:disabled="props.isLegacyDataTable"
name="ic_edit-text"
size="sm"
@click="handleClickNameEdit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type {
import type {
DataTableOperator, JoinType, ConcatOptions, JoinOptions, QueryOptions, EvalOptions,
DataTableTransformOptions,
EvaluateExpression,
} from '@/common/modules/widgets/types/widget-model';


Expand Down Expand Up @@ -87,6 +88,14 @@ const state = reactive({
dataTableId: undefined,
} as TransformDataTableInfo,
failStatus: false,
isLegacyDataTable: computed(() => {
if (state.operator === 'EVAL') return false;
const evalExpressions = (props.item.options as DataTableTransformOptions).EVAL?.expressions;
if (!evalExpressions?.length) return false;
const isLegacyEval = typeof evalExpressions[0] === 'string';
if (isLegacyEval) return true;
return false;
}),
});

const modalState = reactive({
Expand Down Expand Up @@ -118,19 +127,7 @@ const originState = reactive({
conditions: computed(() => ((props.item.options as DataTableTransformOptions).QUERY?.conditions ?? []).map((condition) => ({
value: condition,
}))),
expressions: computed(() => convertLegacyEvaluateDataTable((props.item.options as DataTableTransformOptions).EVAL?.expressions ?? [])),
});

const convertLegacyEvaluateDataTable = (expressions: any[]) => expressions.map((expression) => {
if (typeof expression === 'string') {
const _name = (expression.split('=')[0] ?? '').trim();
const _expression = (expression.split('=')[1] ?? '').trim();
return {
name: _name,
fieldType: EVAL_EXPRESSION_TYPE.DATA,
expression: _expression,
};
} return expression;
expressions: computed<EvaluateExpression[]|string[]>(() => (props.item.options as DataTableTransformOptions).EVAL?.expressions ?? []),
});

const setFailStatus = (status: boolean) => {
Expand Down Expand Up @@ -275,7 +272,9 @@ const setInitialDataTableForm = () => {
state.dataTableInfo = originState.dataTableInfo;
joinState.joinType = originState.joinType;
queryState.conditions = originState.conditions.length ? originState.conditions.map((cond) => ({ ...cond, key: getRandomId() })) : [{ key: getRandomId(), value: '' }];
evalState.expressions = originState.expressions.length ? originState.expressions.map((expression) => ({ ...expression, key: getRandomId() })) : [{
evalState.expressions = originState.expressions.length ? originState.expressions.map((expression) => ({
...expression, isCollapsed: false, fieldType: expression.field_type, key: getRandomId(),
})) : [{
key: getRandomId(), name: '', fieldType: EVAL_EXPRESSION_TYPE.DATA, expression: '', isCollapsed: false,
}];
};
Expand Down Expand Up @@ -309,16 +308,20 @@ defineExpose({
:data-type="DATA_TABLE_TYPE.TRANSFORMED"
:selected="props.selected"
:data-table-name.sync="state.dataTableName"
:is-legacy-data-table="state.isLegacyDataTable"
/>
</div>

<widget-form-data-table-card-transform-form :data-table-id="state.dataTableId"
:operator="state.operator"
:data-table-info.sync="state.dataTableInfo"
:join-type.sync="joinState.joinType"
:conditions.sync="queryState.conditions"
:expressions.sync="evalState.expressions"
:is-legacy-data-table="state.isLegacyDataTable"
/>
<widget-form-data-table-card-footer :disabled="state.applyDisabled"
:is-legacy-data-table="state.isLegacyDataTable"
:changed="state.optionsChanged"
:loading="state.loading"
@delete="handleClickDeleteDataTable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface Props {
dataTableId: string;
operator: DataTableOperator;
dataTableInfo: TransformDataTableInfo;
isLegacyDataTable?: boolean;
}
const props = defineProps<Props>();

Expand Down Expand Up @@ -74,6 +75,7 @@ const secondContainerRef = ref<HTMLElement|null>(null);

/* Events */
const handleClickSelectButton = (isSecondary?: boolean) => {
if (props.isLegacyDataTable) return;
if (isSecondary) {
state.secondaryVisibleMenu = !state.secondaryVisibleMenu;
return;
Expand Down Expand Up @@ -152,6 +154,7 @@ watch(() => props.dataTableInfo, (newVal) => {
<div ref="targetRef"
:class="{'select-button': true,
selected: !!state.selected,
disabled: props.isLegacyDataTable,
error: state.selected && !storeState.dataTables.some((dataTable) => dataTable.data_table_id === state.selected?.[0]?.name)
}"
@click="handleClickSelectButton(false)"
Expand Down Expand Up @@ -251,6 +254,10 @@ watch(() => props.dataTableInfo, (newVal) => {
}
}

&.disabled {
@apply cursor-not-allowed;
}

&.selected {
@apply bg-indigo-100 border-indigo-400;
.text {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ import type {
DataTableOperator, JoinType,
} from '@/common/modules/widgets/types/widget-model';

import { yellow } from '@/styles/colors';

interface Props {
dataTableId: string;
operator: DataTableOperator;
dataTableInfo: TransformDataTableInfo;
joinType: JoinType|undefined;
conditions: QueryCondition[];
expressions: EvalExpressions[];
isLegacyDataTable?: boolean;
}

const props = defineProps<Props>();
Expand Down Expand Up @@ -117,10 +120,34 @@ const handleClickAddCondition = () => {
/>
<span>{{ state.operatorMap.name }}</span>
</div>
<div v-if="props.isLegacyDataTable"
class="legacy-data-table-warning"
>
<div class="warning-title">
<p-i name="ic_warning-filled"
width="1.25rem"
height="1.25rem"
:color="yellow[500]"
/>
<span>
<i18n path="COMMON.WIDGETS.DATA_TABLE.FORM.LEGACY_WARNING_TITLE">
<template #operator>{{ state.operatorMap.name }}</template>
</i18n>
</span>
</div>
<p class="warning-description">
<i18n path="COMMON.WIDGETS.DATA_TABLE.FORM.LEGACY_WARNING_DESC">
<template #operator>
{{ state.operatorMap.name }}
</template>
</i18n>
</p>
</div>
<div class="data-table-dropdown-wrapper">
<widget-form-data-table-card-transform-data-table-dropdown :data-table-id="props.dataTableId"
:operator="props.operator"
:data-table-info.sync="state.proxyDataTableInfo"
:is-legacy-data-table="props.isLegacyDataTable"
/>
</div>
<p-field-group v-if="props.operator === DATA_TABLE_OPERATOR.JOIN"
Expand Down Expand Up @@ -173,6 +200,7 @@ const handleClickAddCondition = () => {
</p-field-group>
<widget-form-data-table-card-transform-form-evaluate v-if="props.operator === DATA_TABLE_OPERATOR.EVAL"
:expressions.sync="evalState.proxyExpressions"
:is-legacy-data-table="props.isLegacyDataTable"
/>
</div>
</div>
Expand Down Expand Up @@ -216,5 +244,19 @@ const handleClickAddCondition = () => {
margin-bottom: 0.5rem;
}
}

.legacy-data-table-warning {
@apply w-full bg-yellow-100 rounded;
padding: 0.5rem 1rem;
margin-bottom: 0.5rem;
.warning-title {
@apply flex items-center gap-1 text-label-lg font-bold text-yellow-700;
margin-bottom: 0.25rem;
}
.warning-description {
@apply text-paragraph-md text-gray-900;
padding-left: 1.5rem;
}
}
}
</style>
Loading
Loading