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

#726 filter losing focus #200

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions vue/dynamicforms/src/components/api_consumer/consumer-logic-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class ConsumerLogicApi extends ConsumerLogicBase implements APIConsumer.Consumer

private readonly api: ViewSetApi<any>;

private requestId: number = 0;

constructor(baseURL: string | Ref<string>, trailingSlash: boolean = true) {
super();
/**
Expand All @@ -30,7 +32,22 @@ class ConsumerLogicApi extends ConsumerLogicBase implements APIConsumer.Consumer
this.trailingSlash = trailingSlash;
}

async fetch() {
async fetch(url?: string) {
const reqId = ++this.requestId;
let result;
if (url !== undefined) {
result = await this.fetchNewRows(url);
} else {
result = await this.fetchRecords();
}
if (this.requestId === reqId) {
// we are the latest request to the backend
return result;
}
return undefined;
}

async fetchRecords() {
try {
// TODO: this does not take into account current filtering and ordering for the table
this.loading = true;
Expand Down Expand Up @@ -79,10 +96,13 @@ class ConsumerLogicApi extends ConsumerLogicBase implements APIConsumer.Consumer
}

async reload() {
this.rows = new TableRows(
this,
await this.fetch(),
);
const result = await this.fetch();
if (result) {
this.rows = new TableRows(
this,
result,
);
}
}

async getRecord(pkValue: string) {
Expand Down
8 changes: 5 additions & 3 deletions vue/dynamicforms/src/components/table/definitions/rows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ export default class TableRows {
async loadMoreRows(isVisible: boolean) {
if (!isVisible || !this.next) return;
const newRows = await (<APIConsumer.ConsumerLogicAPIInterface> this.logic).fetchNewRows(this.next);
this.updateRows(newRows.results);
this.next = newRows.next; // replace next so we can load another set of rows
this.decorate(newRows.results);
if (newRows !== undefined) {
this.updateRows(newRows.results);
this.next = newRows.next; // replace next so we can load another set of rows
this.decorate(newRows.results);
}
}

updateRows(newRows: DfTable.RowDataInterface[]) {
Expand Down
Loading