Skip to content

Commit

Permalink
Use GridConfig and gridConfig to avoid confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Dec 1, 2023
1 parent 06c729a commit 9b40f78
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 34 deletions.
10 changes: 5 additions & 5 deletions client/src/components/Grid/GridList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function createTarget(propsData) {
describe("GridList", () => {
it("basic rendering", async () => {
const wrapper = createTarget({
config: testGrid,
gridConfig: testGrid,
});
const findInput = wrapper.find("[data-description='filter text input']");
expect(findInput.attributes().placeholder).toBe("search tests");
Expand Down Expand Up @@ -142,7 +142,7 @@ describe("GridList", () => {

it("header rendering", async () => {
const wrapper = createTarget({
config: testGrid,
gridConfig: testGrid,
});
await wrapper.vm.$nextTick();
for (const [fieldIndex, field] of Object.entries(testGrid.fields)) {
Expand All @@ -152,7 +152,7 @@ describe("GridList", () => {

it("operation handling", async () => {
const wrapper = createTarget({
config: testGrid,
gridConfig: testGrid,
});
await wrapper.vm.$nextTick();
const dropdown = wrapper.find("[data-description='grid cell 0-2']");
Expand All @@ -174,7 +174,7 @@ describe("GridList", () => {

it("filter handling", async () => {
const wrapper = createTarget({
config: testGrid,
gridConfig: testGrid,
});
await wrapper.vm.$nextTick();
const filterInput = wrapper.find("[data-description='filter text input']");
Expand All @@ -187,7 +187,7 @@ describe("GridList", () => {

it("pagination", async () => {
const wrapper = createTarget({
config: testGrid,
gridConfig: testGrid,
limit: 2,
});
await wrapper.vm.$nextTick();
Expand Down
32 changes: 16 additions & 16 deletions client/src/components/Grid/GridList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { BAlert, BButton, BLink, BPagination } from "bootstrap-vue";
import { computed, onMounted, onUnmounted, ref, watch } from "vue";
import { useRouter } from "vue-router/composables";
import { Config, FieldHandler, Operation, RowData } from "./configs/types";
import { FieldHandler, GridConfig, Operation, RowData } from "./configs/types";
import GridBoolean from "./GridElements/GridBoolean.vue";
import GridLink from "./GridElements/GridLink.vue";
Expand All @@ -26,7 +26,7 @@ library.add(faCaretDown, faCaretUp, faShieldAlt);
interface Props {
// provide a grid configuration
config: Config;
gridConfig: GridConfig;
// debounce delay
delay?: number;
// rows per page to be shown
Expand Down Expand Up @@ -57,8 +57,8 @@ const loading = ref(true);
const isAvailable = computed(() => !loading.value && totalRows.value > 0);
// sort references
const sortBy = ref(props.config ? props.config.sortBy : "");
const sortDesc = ref(props.config ? props.config.sortDesc : false);
const sortBy = ref(props.gridConfig ? props.gridConfig.sortBy : "");
const sortDesc = ref(props.gridConfig ? props.gridConfig.sortDesc : false);
// filtering refs and handlers
const filterText = ref("");
Expand All @@ -74,7 +74,7 @@ const hideMessage = useDebounceFn(() => {
* Manually set filter value, used for tags and `SharingIndicators`
*/
function applyFilter(filter: string, value: string | boolean, quoted = false) {
const filtering = props.config?.filtering;
const filtering = props.gridConfig?.filtering;
const quotedValue = quoted ? `'${value}'` : value;
if (filtering) {
filterText.value = filtering.setFilterValue(filterText.value, filter, quotedValue.toString()) || "";
Expand All @@ -85,10 +85,10 @@ function applyFilter(filter: string, value: string | boolean, quoted = false) {
* Request grid data
*/
async function getGridData() {
if (props.config) {
if (props.gridConfig) {
try {
const offset = props.limit * (currentPage.value - 1);
const [responseData, responseTotal] = await props.config.getData(
const [responseData, responseTotal] = await props.gridConfig.getData(
offset,
props.limit,
searchTerm.value,
Expand Down Expand Up @@ -184,19 +184,19 @@ watch(operationMessage, () => {
</script>

<template>
<div :id="config.id" class="d-flex flex-column overflow-auto">
<div :id="gridConfig.id" class="d-flex flex-column overflow-auto">
<BAlert v-if="!!errorMessage" variant="danger" show>{{ errorMessage }}</BAlert>
<BAlert v-if="!!operationMessage" :variant="operationStatus" fade show>{{ operationMessage }}</BAlert>
<div class="grid-header d-flex justify-content-between pb-2">
<div>
<h1 class="m-0" data-description="grid title">
{{ config.title }}
{{ gridConfig.title }}
</h1>
<FilterMenu
class="py-2"
:name="config.plural"
:placeholder="`search ${config.plural.toLowerCase()}`"
:filter-class="config.filtering"
:name="gridConfig.plural"
:placeholder="`search ${gridConfig.plural.toLowerCase()}`"
:filter-class="gridConfig.filtering"
:filter-text.sync="filterText"
:loading="loading"
:show-advanced.sync="showAdvanced"
Expand All @@ -205,7 +205,7 @@ watch(operationMessage, () => {
</div>
<div v-if="!showAdvanced" class="py-3">
<BButton
v-for="(action, actionIndex) in config.actions"
v-for="(action, actionIndex) in gridConfig.actions"
:key="actionIndex"
class="m-1"
size="sm"
Expand All @@ -228,11 +228,11 @@ watch(operationMessage, () => {
<table v-else class="grid-table">
<thead>
<th
v-for="(fieldEntry, fieldIndex) in config.fields"
v-for="(fieldEntry, fieldIndex) in gridConfig.fields"
:key="fieldIndex"
class="text-nowrap px-2"
:data-description="`grid header ${fieldIndex}`">
<span v-if="config.sortKeys.includes(fieldEntry.key)">
<span v-if="gridConfig.sortKeys.includes(fieldEntry.key)">
<BLink @click="onSort(fieldEntry.key)">
<span>{{ fieldEntry.title || fieldEntry.key }}</span>
<span v-if="sortBy === fieldEntry.key">
Expand All @@ -246,7 +246,7 @@ watch(operationMessage, () => {
</thead>
<tr v-for="(rowData, rowIndex) in gridData" :key="rowIndex" :class="{ 'grid-dark-row': rowIndex % 2 }">
<td
v-for="(fieldEntry, fieldIndex) in config.fields"
v-for="(fieldEntry, fieldIndex) in gridConfig.fields"
:key="fieldIndex"
class="px-2 py-3"
:style="{ width: `${fieldEntry.width}%` }">
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/Grid/configs/adminUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Filtering, { contains, equals, toBool, type ValidFilter } from "@/utils/f
import { withPrefix } from "@/utils/redirect";
import { errorMessageAsString } from "@/utils/simple-error";

import type { ActionArray, Config, FieldArray } from "./types";
import type { ActionArray, FieldArray, GridConfig } from "./types";

const { emit } = useEventBus<string>("grid-router-push");

Expand Down Expand Up @@ -323,7 +323,7 @@ const validFilters: Record<string, ValidFilter<string | boolean | undefined>> =
/**
* Grid configuration
*/
const config: Config = {
const gridConfig: GridConfig = {
id: "users-grid",
actions: actions,
fields: fields,
Expand All @@ -336,4 +336,4 @@ const config: Config = {
title: "Users",
};

export default config;
export default gridConfig;
2 changes: 1 addition & 1 deletion client/src/components/Grid/configs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface Action {

export type ActionArray = Array<Action>;

export interface Config {
export interface GridConfig {
id: string;
actions?: ActionArray;
fields: FieldArray;
Expand Down
7 changes: 4 additions & 3 deletions client/src/components/Grid/configs/visualizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Filtering, { contains, equals, expandNameTag, toBool, type ValidFilter }
import { withPrefix } from "@/utils/redirect";
import { errorMessageAsString, rethrowSimple } from "@/utils/simple-error";

import type { ActionArray, Config, FieldArray } from "./types";
import type { ActionArray, FieldArray, GridConfig } from "./types";

const { emit } = useEventBus<string>("grid-router-push");

Expand Down Expand Up @@ -237,7 +237,7 @@ const validFilters: Record<string, ValidFilter<string | boolean | undefined>> =
/**
* Grid configuration
*/
const config: Config = {
const gridConfig: GridConfig = {
id: "visualizations-grid",
actions: actions,
fields: fields,
Expand All @@ -249,4 +249,5 @@ const config: Config = {
sortKeys: ["create_time", "title", "update_time"],
title: "Saved Visualizations",
};
export default config;

export default gridConfig;
6 changes: 3 additions & 3 deletions client/src/components/Grid/configs/visualizationsPublished.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { fetcher } from "@/api/schema";
import Filtering, { contains, expandNameTag, type ValidFilter } from "@/utils/filtering";
import { withPrefix } from "@/utils/redirect";

import type { Config, FieldArray } from "./types";
import type { FieldArray, GridConfig } from "./types";

/**
* Api endpoint handlers
Expand Down Expand Up @@ -86,7 +86,7 @@ const validFilters: Record<string, ValidFilter<string | boolean | undefined>> =
/**
* Grid configuration
*/
const config: Config = {
const gridConfig: GridConfig = {
id: "visualizations-published-grid",
fields: fields,
filtering: new Filtering(validFilters, undefined, false, false),
Expand All @@ -98,4 +98,4 @@ const config: Config = {
title: "Published Visualizations",
};

export default config;
export default gridConfig;
4 changes: 2 additions & 2 deletions client/src/entry/analysis/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,14 +466,14 @@ export function getRouter(Galaxy) {
path: "visualizations/list",
component: GridList,
props: {
config: visualizationsGrid,
gridConfig: visualizationsGrid,
},
},
{
path: "visualizations/list_published",
component: GridList,
props: {
config: visualizationsPublishedGrid,
gridConfig: visualizationsPublishedGrid,
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion client/src/entry/analysis/routes/admin-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default [
path: "users",
component: GridList,
props: {
config: adminUsersGrid,
gridConfig: adminUsersGrid,
},
},
{
Expand Down

0 comments on commit 9b40f78

Please sign in to comment.