Skip to content

Commit

Permalink
Improve the installation command (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
cvetty authored Jul 1, 2024
1 parent d83986d commit 9449cf3
Show file tree
Hide file tree
Showing 14 changed files with 908 additions and 745 deletions.
10 changes: 6 additions & 4 deletions krait-ui/.storybook/mocker/mocker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getRecords } from "./responses.js";
import { getRecords } from './responses.js';

const MOCKED_KRAIT_CONFIG = {
kraitPath: 'krait',
Expand Down Expand Up @@ -42,7 +42,7 @@ class Mocker {
sort_direction: this.url.searchParams.get('sort_direction') ?? null,
itemsPerPage: ipp ? parseInt(ipp) : 30,
currentPage: page ? parseInt(page) : 1,
}
};
}

#getRecordsResponse() {
Expand All @@ -56,7 +56,9 @@ class Mocker {
process() {
if (this.url.pathname.startsWith('/' + MOCKED_KRAIT_CONFIG.tablesPath)) {
return this.#getRecordsResponse();
} else if (this.url.pathname.startsWith('/' + MOCKED_KRAIT_CONFIG.kraitPath)) {
} else if (
this.url.pathname.startsWith('/' + MOCKED_KRAIT_CONFIG.kraitPath)
) {
return this.#getKraitResponse();
} else {
return new Response();
Expand All @@ -72,4 +74,4 @@ const mockedFetch = async (target, fetchInit) => {
export const init = () => {
window.Krait = MOCKED_KRAIT_CONFIG;
window.fetch = mockedFetch;
}
};
23 changes: 17 additions & 6 deletions krait-ui/.storybook/mocker/responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const getPaginationLinks = (url, previewConfiguration, pagesCount) => {
url: paginationUrl.toString(),
label: i + 1,
active: i === previewConfiguration.currentPage - 1,
})
});
}

return links;
Expand All @@ -23,13 +23,24 @@ export const getRecords = (url, previewConfiguration) => {

if (previewConfiguration.sort_column && previewConfiguration.sort_direction) {
if (previewConfiguration.sort_direction === 'asc') {
data = data.sort((a, b) => a[previewConfiguration.sort_column].localeCompare(b[previewConfiguration.sort_column]))
data = data.sort((a, b) =>
a[previewConfiguration.sort_column].localeCompare(
b[previewConfiguration.sort_column],
),
);
} else {
data = data.sort((a, b) => -1 * a[previewConfiguration.sort_column].localeCompare(b[previewConfiguration.sort_column]))
data = data.sort(
(a, b) =>
-1 *
a[previewConfiguration.sort_column].localeCompare(
b[previewConfiguration.sort_column],
),
);
}
}

const start = (previewConfiguration.currentPage - 1) * previewConfiguration.itemsPerPage;
const start =
(previewConfiguration.currentPage - 1) * previewConfiguration.itemsPerPage;
const end = start + previewConfiguration.itemsPerPage;

const response = {
Expand All @@ -50,7 +61,7 @@ export const getRecords = (url, previewConfiguration) => {

return new Response(JSON.stringify(response), {
headers: {
'content-type': 'application/json'
}
'content-type': 'application/json',
},
});
};
Loading

0 comments on commit 9449cf3

Please sign in to comment.