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

refactor: ticket list #1189

Merged
merged 13 commits into from
May 18, 2023
Prev Previous commit
Next Next commit
chore: convert composable to a pinia store
  • Loading branch information
ssiyad committed May 17, 2023
commit d9e04b5a46e6e6ef124a23f2348e0b3e4379eb2e
4 changes: 2 additions & 2 deletions desk/src/pages/desk/ticket-list/BottomSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</template>

<script setup lang="ts">
import { useData } from "./data";
import { useTicketListStore } from "./data";

const { tickets } = useData();
const { tickets } = useTicketListStore();
</script>
4 changes: 2 additions & 2 deletions desk/src/pages/desk/ticket-list/ColumnSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
<script setup lang="ts">
import { Popover } from "frappe-ui";
import { keys } from "lodash";
import { useData } from "./data";
import { useTicketListStore } from "./data";
import MinimalSwitch from "@/components/MinimalSwitch.vue";
import IconAdd from "~icons/espresso/add";

const { columns } = useData();
const { columns } = useTicketListStore();

function toggleColumn(column: string) {
columns[column] = !columns[column];
Expand Down
6 changes: 3 additions & 3 deletions desk/src/pages/desk/ticket-list/MainTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ import { AGENT_PORTAL_TICKET } from "@/router";
import { useTicketStatusStore } from "@/stores/ticketStatus";
import { useTicketPriorityStore } from "@/stores/ticketPriority";
import { createToast } from "@/utils/toasts";
import { useData } from "./data";
import { useTicketListStore } from "./data";
import AssignedInfo from "./AssignedInfo.vue";
import TicketSummary from "./TicketSummary.vue";
import ColumnSelector from "./ColumnSelector.vue";
Expand All @@ -142,11 +142,11 @@ const { copy } = useClipboard();
const ticketPriorityStore = useTicketPriorityStore();
const ticketStatusStore = useTicketStatusStore();
const { selected, tickets, toggleOne, selectAll, deselectAll, columns } =
useData();
useTicketListStore();

const dateFormat = "D/M/YYYY h:mm A";
const allSelected = computed(() => {
return tickets.list?.data?.length === selected.value.size;
return tickets.list?.data?.length === selected.size;
});

function toggleAllSelected(checked: boolean) {
Expand Down
8 changes: 4 additions & 4 deletions desk/src/pages/desk/ticket-list/SelectionBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ import { computed } from "vue";
import { createResource, Dropdown, FeatherIcon } from "frappe-ui";
import { useAgentStore } from "@/stores/agent";
import { createToast } from "@/utils/toasts";
import { useData } from "./data";
import { useTicketListStore } from "./data";

const agentStore = useAgentStore();
const { selected, selectAll, deselectAll } = useData();
const { selected, selectAll, deselectAll } = useTicketListStore();

const ticketsSelectedText = computed(() => {
/** Number of selected items */
const n = selected.value.size;
const n = selected.size;

/** Singular or Plural */
const s = n > 1 ? "Tickets" : "Ticket";
Expand Down Expand Up @@ -90,7 +90,7 @@ const assignOpts = computed(() =>
label: a.agent_name,
handler: () =>
bulkAssignTicketToAgent.submit({
ticket_ids: Array.from(selected.value),
ticket_ids: Array.from(selected),
agent_id: a.name,
}),
}))
Expand Down
4 changes: 2 additions & 2 deletions desk/src/pages/desk/ticket-list/TicketList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

<script setup lang="ts">
import { onMounted, onUnmounted } from "vue";
import { useData } from "./data";
import { useTicketListStore } from "./data";
import ListHeader from "./ListHeader.vue";
import TopSection from "./TopSection.vue";
import BottomSection from "./BottomSection.vue";
import SelectionBar from "./SelectionBar.vue";
import MainTable from "./MainTable.vue";

const { init, deinit, tickets } = useData();
const { init, deinit, tickets } = useTicketListStore();
const isEmptyMessage =
"🎉 Great news! There are currently no tickets to display. Keep up the good work!";

Expand Down
9 changes: 5 additions & 4 deletions desk/src/pages/desk/ticket-list/data.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ref, reactive } from "vue";
import { ref, reactive, Ref } from "vue";
import { defineStore } from "pinia";
import { useKeymapStore } from "@/stores/keymap";
import { createListManager } from "@/composables/listManager";

export function useData() {
export const useTicketListStore = defineStore("ticketList", () => {
const KEYMAPS = [
{
button: "R",
Expand Down Expand Up @@ -41,7 +42,7 @@ export function useData() {
KEYMAPS.forEach((o) => keymapStore.remove([KEYMAP_PREFIX, o.button]));
}

const selected = ref(new Set());
const selected: Ref<Set<number>> = ref(new Set([]));
function toggleOne(value) {
if (!selected.value.delete(value)) {
selected.value.add(value);
Expand Down Expand Up @@ -77,4 +78,4 @@ export function useData() {
tickets,
toggleOne,
};
}
});
Loading