Skip to content

Commit

Permalink
Add api-query-parameters attribute (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
cvetty authored Aug 11, 2024
1 parent 922c8bc commit cdd29c5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
7 changes: 7 additions & 0 deletions krait-ui/src/actions/fetch-records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ export default class FetchRecords extends BaseAction<
this.setSorting(this.context.sorting, url);
this.setPagination(this.context.pagination, url);

for (const parameter in this.context.queryParameters.value) {
url.searchParams.set(
parameter,
String(this.context.queryParameters.value[parameter]),
);
}

return url;
}
}
17 changes: 14 additions & 3 deletions krait-ui/src/components/dynamic-table/DynamicTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,23 @@ const props = defineProps({
required: false,
default: false,
},
apiQueryParameters: {
type: Object,
required: false,
default: {},
},
});
const { columns, isLoading, records, visibleColumns, isAuthorized } = useTable(
props.apiEndpoint,
);
const {
columns,
isLoading,
records,
visibleColumns,
isAuthorized,
queryParameters,
} = useTable(props.apiEndpoint);
const { dispatch } = useDispatcher(props.apiEndpoint);
queryParameters.value = props.apiQueryParameters;
const initFiltersListener = () => {
if (!props.filtersForm) {
Expand Down
2 changes: 2 additions & 0 deletions krait-ui/src/mixins/useTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const getState = (): Table.ITableContext => {
const isLoading = ref<boolean>(false);
const links = ref<Responses.ILinks>({});
const isAuthorized = ref<boolean>(true);
const queryParameters = ref<Table.IQueryParameters>({});

return {
columns,
Expand All @@ -39,6 +40,7 @@ const getState = (): Table.ITableContext => {
records,
links,
isAuthorized,
queryParameters,
};
};

Expand Down
5 changes: 5 additions & 0 deletions krait-ui/src/types/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export interface IColumn {
width?: number;
}

export interface IQueryParameters {
[key: string]: string | number;
}

export interface ITableContext {
isLoading: Ref<UnwrapRef<boolean>>;
pagination: UnwrapNestedRefs<IPagination> & {};
Expand All @@ -37,4 +41,5 @@ export interface ITableContext {
sorting: UnwrapNestedRefs<ISorting> & {};
visibleColumns: Ref<UnwrapRef<string[]>>;
isAuthorized: Ref<boolean>;
queryParameters: Ref<IQueryParameters>;
}

0 comments on commit cdd29c5

Please sign in to comment.