Skip to content

Commit

Permalink
feat(pivot-data-table): create pivot form (transform data-table) (#5215)
Browse files Browse the repository at this point in the history
* fix(pivot-data-table): edit pivot option type & create pivot default value

Signed-off-by: samuel.park <[email protected]>

* feat(data-table): create data table transform form wrapper

Signed-off-by: samuel.park <[email protected]>

* feat(pivot): create pivot data-table form

Signed-off-by: samuel.park <[email protected]>

* fix(transform-contents): apply pivot form

Signed-off-by: samuel.park <[email protected]>

* chore: remove console.debug

Signed-off-by: samuel.park <[email protected]>

* fix(form-wrapper): edit wrapper component structure

Signed-off-by: samuel.park <[email protected]>

* fix(pivot-data-table): create other pivot fields (operator, order-by, dynamic-fields)

Signed-off-by: samuel.park <[email protected]>

* chore: edit typo

Signed-off-by: samuel.park <[email protected]>

* chore: add annotation

Signed-off-by: samuel.park <[email protected]>

* chore: edit missing code

Signed-off-by: samuel.park <[email protected]>

* feat: add icons (ic_sort-ascending, ic_sort-descending)

Signed-off-by: samuel.park <[email protected]>

* chore: fix style

Signed-off-by: samuel.park <[email protected]>

* chore: apply review

Signed-off-by: samuel.park <[email protected]>

* chore: fix typo

Signed-off-by: samuel.park <[email protected]>

---------

Signed-off-by: samuel.park <[email protected]>
  • Loading branch information
piggggggggy authored Dec 13, 2024
1 parent a841bb0 commit e657b17
Show file tree
Hide file tree
Showing 11 changed files with 560 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import WidgetFormDataTableCardHeaderTitle
from '@/common/modules/widgets/_components/WidgetFormDataTableCardHeaderTitle.vue';
import WidgetFormDataTableCardTransformForm
from '@/common/modules/widgets/_components/WidgetFormDataTableCardTransformForm.vue';
import WidgetFormDataTableCardTransformPivotForm
from '@/common/modules/widgets/_components/WidgetFormDataTableCardTransformPivotForm.vue';
import {
DATA_TABLE_TYPE, DATA_TABLE_FIELD_TYPE,
DATA_TABLE_TYPE, DATA_TABLE_FIELD_TYPE, type DATA_TABLE_OPERATOR, DEFAULT_TRANSFORM_DATA_TABLE_VALUE_MAP,
} from '@/common/modules/widgets/_constants/data-table-constant';
import { useWidgetGenerateStore } from '@/common/modules/widgets/_store/widget-generate-store';
import type {
Expand All @@ -29,7 +31,7 @@ import type {
import type {
DataTableOperator, JoinType, ConcatOptions, JoinOptions, QueryOptions, EvalOptions,
DataTableTransformOptions,
EvaluateExpression, AddLabelsOptions, AdditionalLabels,
EvaluateExpression, AddLabelsOptions, AdditionalLabels, PivotOptions,
} from '@/common/modules/widgets/types/widget-model';
Expand Down Expand Up @@ -127,6 +129,10 @@ const evalState = reactive({
}] as EvalExpressions[],
});
const valueState = reactive({
pivot: DEFAULT_TRANSFORM_DATA_TABLE_VALUE_MAP.PIVOT as Omit<PivotOptions, 'data_table_id'>,
});
const addLabelsState = reactive({
labels: [{
name: '', value: '',
Expand All @@ -148,6 +154,17 @@ const originState = reactive({
const _labels = (props.item.options as DataTableTransformOptions).ADD_LABELS?.labels ?? {};
return Object.entries(_labels).map(([name, value]) => ({ name, value }));
}),
pivot: computed<Omit<PivotOptions, 'data_table_id'>|undefined>(() => {
const _pivot = (props.item.options as DataTableTransformOptions).PIVOT as PivotOptions|undefined;
if (!_pivot) return undefined;
return {
fields: _pivot.fields,
select: _pivot.select,
limit: _pivot.limit,
functions: _pivot.functions,
order_by: _pivot.order_by,
};
}),
});
const setFailStatus = (status: boolean) => {
Expand Down Expand Up @@ -317,6 +334,7 @@ const setInitialDataTableForm = () => {
key: getRandomId(), name: '', fieldType: DATA_TABLE_FIELD_TYPE.DATA, expression: '', isCollapsed: false,
}];
addLabelsState.labels = originState.labels.length ? cloneDeep(originState.labels) : [{ name: '', value: '' }];
valueState.pivot = originState.pivot ? cloneDeep(originState.pivot) : DEFAULT_TRANSFORM_DATA_TABLE_VALUE_MAP.PIVOT;
};
onMounted(() => {
Expand Down Expand Up @@ -351,8 +369,13 @@ defineExpose({
:is-legacy-data-table="state.isLegacyDataTable"
/>
</div>

<widget-form-data-table-card-transform-form :data-table-id="state.dataTableId"
<widget-form-data-table-card-transform-pivot-form v-if="state.operator === DATA_TABLE_OPERATOR.PIVOT"
:data-table-id="state.dataTableId"
:data-table-info.sync="state.dataTableInfo"
:form-data.sync="valueState.pivot"
/>
<widget-form-data-table-card-transform-form v-else
:data-table-id="state.dataTableId"
:operator="state.operator"
:data-table-info.sync="state.dataTableInfo"
:join-type.sync="joinState.joinType"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const widgetGenerateState = widgetGenerateStore.state;
const storeState = reactive({
dataTables: computed(() => widgetGenerateState.dataTables),
isJoinRestriced: computed<boolean|undefined>(() => widgetGenerateState.joinRestrictedMap[props.dataTableId]),
isJoinRestricted: computed<boolean|undefined>(() => widgetGenerateState.joinRestrictedMap[props.dataTableId]),
});
Expand Down Expand Up @@ -191,7 +191,7 @@ watch(() => props.dataTableInfo, (newVal) => {
:class="{'select-button': true,
selected: !!state.secondarySelected,
error: (state.secondarySelected && !storeState.dataTables.some((dataTable) => dataTable.data_table_id === state.secondarySelected?.[0]?.name))
|| storeState.isJoinRestriced
|| storeState.isJoinRestricted
}"
@click="handleClickSelectButton(true)"
>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<script setup lang="ts">
import { computed, reactive } from 'vue';
import { PI } from '@cloudforet/mirinae';
import { useProxyValue } from '@/common/composables/proxy-state';
import WidgetFormDataTableCardTransformDataTableDropdown
from '@/common/modules/widgets/_components/WidgetFormDataTableCardTransformDataTableDropdown.vue';
import type { TransformDataTableInfo } from '@/common/modules/widgets/types/widget-data-table-type';
import type {
DataTableOperator,
} from '@/common/modules/widgets/types/widget-model';
interface Props {
dataTableId: string;
dataTableInfo: TransformDataTableInfo;
operator: DataTableOperator;
}
const props = defineProps<Props>();
const emit = defineEmits<{(e: 'update:data-table-info', value: TransformDataTableInfo): void; }>();
const state = reactive({
proxyDataTableInfo: useProxyValue<TransformDataTableInfo>('dataTableInfo', props, emit),
operatorMap: computed(() => {
if (props.operator === 'CONCAT') return { name: 'Concatenate', icon: 'ic_db-concat' };
if (props.operator === 'JOIN') return { name: 'Join', icon: 'ic_join' };
if (props.operator === 'QUERY') return { name: 'Query', icon: 'ic_db-where' };
if (props.operator === 'EVAL') return { name: 'Evaluate', icon: 'ic_db-evaluation' };
if (props.operator === 'PIVOT') return { name: 'Pivot', icon: '' }; // TODO: Add icon
if (props.operator === 'VALUE_MAPPING') return { name: 'Value Mapping', icon: '' }; // TODO: Add icon
if (props.operator === 'ADD_LABELS') return { name: 'Add Labels', icon: '' }; // TODO: Add icon
return { name: '', icon: '' };
}),
});
</script>

<template>
<div class="widget-form-data-table-card-transform-form">
<div class="data-table-select-form">
<div class="operator">
<p-i :name="state.operatorMap.icon"
width="1rem"
height="1rem"
/>
<span>{{ state.operatorMap.name }}</span>
</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"
/>
</div>
<slot name="default" />
</div>
</div>
</template>

<style lang="postcss" scoped>
.widget-form-data-table-card-transform-form {
padding: 0.75rem 1rem;
.data-table-select-form {
.operator {
@apply inline-flex items-center gap-1 rounded-md border border-gray-150 bg-gray-100 text-label-sm font-bold text-gray-700;
padding: 0.25rem 0.5rem;
margin-bottom: 0.5rem;
}
.data-table-dropdown-wrapper {
margin-bottom: 1rem;
}
}
}
</style>
Loading

0 comments on commit e657b17

Please sign in to comment.