Skip to content

Commit

Permalink
WIP feat(pix-editor): integrate new endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
nlepage authored and Jeremiejade committed Jan 30, 2025
1 parent 424fafe commit b89198b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 123 deletions.
20 changes: 18 additions & 2 deletions pix-editor/app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { inject as service } from '@ember/service';
import JSONAPIAdapter from '@ember-data/adapter/json-api';

const FIND_GROUP_SIZE = 300;

export default class ApplicationAdapter extends JSONAPIAdapter {
@service session;
@service ajaxQueue;
Expand All @@ -16,7 +18,21 @@ export default class ApplicationAdapter extends JSONAPIAdapter {
return headers;
}

ajax() {
return this.ajaxQueue.add(() => super.ajax(...arguments));
// will be used only if this.coalesceFindRequests is true
groupRecordsForFindMany(store, snapshots) {
const groups = [];
for (let i = 0; i < snapshots.length; i += FIND_GROUP_SIZE) {
groups.push(snapshots.slice(i, i + FIND_GROUP_SIZE));
}
return groups;
}

async findMany(store, type, ids, snapshots) {
const url = this.buildURL(type.modelName, ids, snapshots, 'findMany');
return this.ajax(url, 'GET', { data: { filter: { ids } } });
}

ajax(...args) {
return this.ajaxQueue.add(() => super.ajax(...args));
}
}
13 changes: 0 additions & 13 deletions pix-editor/app/adapters/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,4 @@ import ApplicationAdapter from './application';

export default class ChallengeAdapter extends ApplicationAdapter {
coalesceFindRequests = true;

groupRecordsForFindMany(store, snapshots) {
const groups = [];
for (let i = 0; i < snapshots.length; i += 100) {
groups.push(snapshots.slice(i, i + 100));
}
return groups;
}

async findMany(store, type, ids, snapshots) {
const url = this.buildURL(type.modelName, ids, snapshots, 'findMany');
return this.ajax(url, 'GET', { data: { filter: { ids } } });
}
}
32 changes: 3 additions & 29 deletions pix-editor/app/adapters/skill.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
import AirtableAdapter from './airtable';
import ApplicationAdapter from './application';

export default class SkillAdapter extends AirtableAdapter {

fields = [
'Record Id',
'Nom',
'Statut de l\'indice',
'Epreuves (id persistant)',
'Date',
'Description',
'Statut de la description',
'Comprendre',
'En savoir plus',
'Tube',
'Level',
'Status',
'Internationalisation',
'id persistant',
'Version',
];

urlForCreateRecord(model, snapshot) {
if (snapshot.adapterOptions?.clone) return '/api/skills/clone';
return super.urlForCreateRecord(model, snapshot);
}

pathForType() {
return 'Acquis';
}
export default class SkillAdapter extends ApplicationAdapter {
coalesceFindRequests = true;
}
17 changes: 5 additions & 12 deletions pix-editor/app/components/sidebar/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,13 @@ export default class SidebarSearchComponent extends Component {
@service store;
@service router;

#stringValue(value) {
return `"${
value.replace(/\r/g, '')
.replace(/["\\]/g, '\\$&')
.replace(/\n/g, '\\n')
.replace(/\t/g, '\\t')
}"`;
}

async searchSkillsByName(skillName) {
const skills = await this.store.query('skill', {
filterByFormula: `FIND(${this.#stringValue(skillName.toLowerCase())}, LOWER(Nom))`,
maxRecords: 20,
sort: [{ field: 'Nom', direction: 'asc' }],
filter: {
name: skillName,
},
page: { limit: 20 },
sort: 'name',
});
return skills.map((skill) => ({
isSkill: true,
Expand Down
67 changes: 0 additions & 67 deletions pix-editor/app/serializers/skill.js

This file was deleted.

0 comments on commit b89198b

Please sign in to comment.