The table view in our counselor dashboard works in a similar way to the Editor.
It is made to be dynamic and powered by a JSON schema.
The component is located at: components/common/Table.vue
However, it’s wrappers are fractured within:
components/counselor
@nuxt/ui
The table is powered by nuxt ui table.
This gives us the UI and some functionality out of the box.
We still need to configure it to properly show our collections.
Schema
The schema for the different tables is in: utils/tables.ts
This contains both the data map for which fields to show as well as computed formatting functions for more complicated rows we need to run processing on to view properly.
like in the editor, the table uses the url path to determine which schema to use. Since the table is the main page of the counselor app, the path is:
https://tansy.app/{type}
Lets look at a specific example for the tasks table: https://tansy.app/tasks
in components/counselor/dashboard.vue, this path is read and set:
// Determine which section to show based on route
const currentSection = computed(() => {
const path = route.path;
if (path.includes('/appointments')) return 'appointments';
if (path.includes('/tasks')) return 'tasks';
if (path.includes('/reports')) return 'reports';
if (path.includes('/messages') || path.includes('/chat')) return 'messages';
if (path.includes('/files')) return 'files';
return 'members'; // default view
});
based on this value, we select the correct wrapper component:
<!-- Show different components based on current route -->
<CounselorMembers v-if="currentSection === 'members'" />
<CounselorAppointments v-if="currentSection === 'appointments'" />
<CounselorTasks v-if="currentSection === 'tasks'" />
<CounselorReports v-if="currentSection === 'reports'" />
<CounselorMessages v-if="currentSection === 'messages'" />
<CounselorFiles v-if="currentSection === 'files'" />
Wrapper Component
Lets look at the tasks component, located at components/counselor/tasks.vue
This component handles fetching the data and sending it to the table component
it also handles the tabs for changing the query.
and more like row clicks, and multi selecting items.
Adding a new table
In order to add a new table view to the app, you must:
Create the schema in utils/tables.ts
Add switch in components/counselors/dashboard.vue
Create a wrapper at components/counselors/{type}.vue
Create a new page for routing in pages/{type}/index.vue
This process may be simplified in the future with a more capable table component that can handle dynamic fetching for the different types, but as of now it needs the wrapper component.