Skip to content

Commit

Permalink
feat: update data handling to ensure default empty arrays in stores
Browse files Browse the repository at this point in the history
Signed-off-by: Wanjin Noh <[email protected]>
  • Loading branch information
WANZARGEN committed Dec 2, 2024
1 parent 87eaf65 commit 26b191e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const fields: DataTableField[] = [
</div>
</div>
<p-data-table :fields="fields"
:items="[]"
:items="tasks"
/>
</p-pane-layout>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useTaskCategoryPageStore } from '@/services/ops-flow/stores/admin/task-
const taskCategoryPageStore = useTaskCategoryPageStore();
const taskCategoryPageGetters = taskCategoryPageStore.getters;
const taskTypeFields = computed<DataTableField[]>(() => [
{
Expand Down Expand Up @@ -55,8 +56,8 @@ const taskTypeFields = computed<DataTableField[]>(() => [
티켓 양식으로 티켓에 포함된 필드와 데이터를 결정합니다. 여러 티켓 양식을 만들 수 있습니다. <br>
예를 들어 서비스별로 서로 다른 양식을 만들 수 있습니다. 그런 경우에는 최종 사용자가 적절한 양식을 선택하여 요청을 제출합니다.
</p>
<p-data-table :loading="!taskCategoryPageStore.getters.taskTypes"
:items="taskCategoryPageStore.getters.taskTypes"
<p-data-table :loading="!taskCategoryPageGetters.taskTypes"
:items="taskCategoryPageGetters.taskTypes"
:fields="taskTypeFields"
>
<template #col-buttons-format="{ item }">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const usePackageStore = defineStore('package', () => {
try {
const result = await fetchList({});
if (result.status === 'succeed') {
state.items = result.response.results;
state.items = result.response.results ?? [];
}
} catch (e) {
ErrorHandler.handleError(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ export const useTaskCategoryStore = defineStore('task-category', () => {
if (result.status === 'succeed') {
state.loading = false;
if (params) {
return result.response.results;
return result.response.results ?? [];
}
state.items = result.response.results;
return result.response.results;
state.items = result.response.results ?? [];
return result.response.results ?? [];
}
return undefined;
} catch (e) {
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/services/ops-flow/stores/task-type-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const useTaskTypeStore = defineStore('task-type', () => {
const result = await fetchList({ query: { filter: [{ k: 'category_id', v: _categoryIds, o: 'in' }] } });
if (result.status === 'succeed') {
_categoryIds.forEach((categoryId) => {
state.itemsByCategoryId[categoryId] ??= result.response.results?.filter((item) => item.category_id === categoryId);
state.itemsByCategoryId[categoryId] ??= result.response.results?.filter((item) => item.category_id === categoryId) ?? [];
});
state.itemsByCategoryId = { ...state.itemsByCategoryId }; // trigger reactivity
state.loading = false;
Expand All @@ -66,9 +66,9 @@ export const useTaskTypeStore = defineStore('task-type', () => {
state.loading = true;
const result = await fetchList({ query: { filter: [{ k: 'category_id', v: categoryId, o: 'eq' }] } });
if (result.status === 'succeed') {
state.itemsByCategoryId = { ...state.itemsByCategoryId, [categoryId]: result.response.results };
state.itemsByCategoryId = { ...state.itemsByCategoryId, [categoryId]: result.response.results ?? [] };
state.loading = false;
return result.response.results;
return result.response.results ?? [];
}
return undefined;
} catch (e) {
Expand Down

0 comments on commit 26b191e

Please sign in to comment.