mirror of
https://github.com/Joxit/docker-registry-ui.git
synced 2025-05-03 18:39:57 +03:00
feat(utils): add taglistOrderVariants function to format taglist order
This commit is contained in:
parent
a77103a2d4
commit
2b63fb725c
3 changed files with 56 additions and 1 deletions
|
@ -9,7 +9,8 @@
|
||||||
"format-riot": "find src rollup rollup.config.js -name '*.riot' -exec prettier --config .prettierrc -w --parser html {} \\;",
|
"format-riot": "find src rollup rollup.config.js -name '*.riot' -exec prettier --config .prettierrc -w --parser html {} \\;",
|
||||||
"start": "rollup -c -w --environment ROLLUP_SERVE:true",
|
"start": "rollup -c -w --environment ROLLUP_SERVE:true",
|
||||||
"build": "rollup -c",
|
"build": "rollup -c",
|
||||||
"build:electron": "npm run build && cd examples/electron && npm install && npm run dist"
|
"build:electron": "npm run build && cd examples/electron && npm install && npm run dist",
|
||||||
|
"test": "mocha"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -31,6 +32,7 @@
|
||||||
"@rollup/plugin-node-resolve": "^15.0.1",
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
||||||
"@rollup/plugin-terser": "^0.2.1",
|
"@rollup/plugin-terser": "^0.2.1",
|
||||||
"core-js": "^3.27.1",
|
"core-js": "^3.27.1",
|
||||||
|
"mocha": "^10.2.0",
|
||||||
"node-sass": "^8.0.0",
|
"node-sass": "^8.0.0",
|
||||||
"prettier": "^2.8.1",
|
"prettier": "^2.8.1",
|
||||||
"riot": "^7.1.0",
|
"riot": "^7.1.0",
|
||||||
|
|
|
@ -220,3 +220,22 @@ export function truthy(value) {
|
||||||
export function stringToArray(value) {
|
export function stringToArray(value) {
|
||||||
return value && typeof value === 'string' ? value.split(',') : [];
|
return value && typeof value === 'string' ? value.split(',') : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const taglistOrderVariants = (taglistOrder) => {
|
||||||
|
switch (taglistOrder) {
|
||||||
|
case 'desc':
|
||||||
|
case 'alpha-desc':
|
||||||
|
return 'alpha-desc;num-desc';
|
||||||
|
case 'asc':
|
||||||
|
case 'num-asc':
|
||||||
|
return 'num-asc;alpha-asc';
|
||||||
|
default:
|
||||||
|
if (!taglistOrder) {
|
||||||
|
return 'num-asc;alpha-asc';
|
||||||
|
} else if (taglistOrder.indexOf(';') === -1) {
|
||||||
|
return taglistOrder.startsWith('num-') ? `${taglistOrder};alpha-asc` : `${taglistOrder};num-asc`;
|
||||||
|
} else {
|
||||||
|
return taglistOrder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
34
test/utils.test.js
Normal file
34
test/utils.test.js
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import { taglistOrderVariants } from '../src/scripts/utils.js';
|
||||||
|
import assert from 'assert';
|
||||||
|
|
||||||
|
describe('utils tests', () => {
|
||||||
|
describe('taglistOrderVariants', () => {
|
||||||
|
it(`should return the input when it's well formed and num first`, () => {
|
||||||
|
const expected = ['num-asc;alpha-asc', 'num-asc;alpha-desc', 'num-desc;alpha-asc', 'num-desc;alpha-asc'];
|
||||||
|
expected.forEach(
|
||||||
|
(e) => assert.deepEqual(taglistOrderVariants(e), e)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should return the input when it's well formed and alpha first`, () => {
|
||||||
|
const expected = ['alpha-asc;num-asc', 'alpha-asc;num-desc', 'alpha-desc;num-asc', 'alpha-desc;num-asc'];
|
||||||
|
expected.forEach(
|
||||||
|
(e) => assert.deepEqual(taglistOrderVariants(e), e)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correct variant of `num-asc;alpha-asc`', () => {
|
||||||
|
const expected = 'num-asc;alpha-asc';
|
||||||
|
['asc', 'num-asc'].forEach(
|
||||||
|
(e) => assert.deepEqual(taglistOrderVariants(e), expected)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return correct variant of `alpha-desc;num-desc`', () => {
|
||||||
|
const expected = 'alpha-desc;num-desc';
|
||||||
|
['desc', 'alpha-desc'].forEach(
|
||||||
|
(e) => assert.deepEqual(taglistOrderVariants(e), expected)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue