-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(datagrid-preferences): initial commit
BREAKING CHANGE: create module Signed-off-by: Cyril Biencourt <[email protected]>
- Loading branch information
Cyril Biencourt
committed
Jul 27, 2023
1 parent
4a06e88
commit 21fa397
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
packages/manager/modules/datagrid-preferences/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "@ovh-ux/datagrid-preferences", | ||
"version": "0.0.0", | ||
"private": true, | ||
"description": "Store and retrieve datagrid configuration", | ||
"homepage": "https://github.com/ovh/manager/tree/master/packages/manager/modules/datagrid-preferences#readme", | ||
"bugs": { | ||
"url": "https://github.com/ovh/manager/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/ovh/manager.git", | ||
"directory": "packages/manager/modules/datagrid-preferences" | ||
}, | ||
"license": "BSD-3-Clause", | ||
"sideEffects": false, | ||
"main": "dist/index.js", | ||
"module": "dist/index.js", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "tsc", | ||
"dev": "tsc", | ||
"dev:watch": "tsc --watch", | ||
"prepare": "yarn run build", | ||
"start": "lerna exec --stream --scope='@ovh-ux/datagrid-preferences' --include-dependencies -- yarn run build", | ||
"start:dev": "lerna exec --stream --scope='@ovh-ux/datagrid-preferences' --include-dependencies -- yarn run dev", | ||
"start:watch": "lerna exec --stream --parallel --scope='@ovh-ux/datagrid-preferences' --include-dependencies -- yarn run dev:watch" | ||
}, | ||
"dependencies": { | ||
"lodash-es": "^4.17.15" | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
packages/manager/modules/datagrid-preferences/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { debounce, snakeCase } from 'lodash-es'; | ||
|
||
const PREFIX = 'DATAGRID_CONFIG_'; | ||
const DEBOUNCE = 2000; | ||
|
||
export const retrieveColumnsConfig = async (datagridId: string) => { | ||
const key = `${PREFIX}${snakeCase(datagridId).toUpperCase()}`; | ||
const config = await fetch(`/engine/api/me/preferences/manager/${key}`, { | ||
headers: { | ||
'Content-Type': 'application/json;charset=utf-8', | ||
Accept: 'application/json', | ||
}, | ||
credentials: 'same-origin', | ||
}); | ||
|
||
if (config.ok) { | ||
const { value } = await config.json(); | ||
return JSON.parse(value); | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
export const saveColumnsConfig = debounce( | ||
async (datagridId: string, columnsConfig: unknown) => { | ||
const key = `${PREFIX}${snakeCase(datagridId).toUpperCase()}`; | ||
const ret = await fetch(`/engine/api/me/preferences/manager`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json;charset=utf-8', | ||
Accept: 'application/json', | ||
}, | ||
credentials: 'same-origin', | ||
body: JSON.stringify({ | ||
key, | ||
value: JSON.stringify(columnsConfig), | ||
}), | ||
}); | ||
|
||
if (ret.ok) { | ||
return ret.json(); | ||
} | ||
|
||
return null; | ||
}, | ||
DEBOUNCE, | ||
); |
20 changes: 20 additions & 0 deletions
20
packages/manager/modules/datagrid-preferences/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2015", | ||
"moduleResolution": "Node", | ||
"lib": ["dom"], | ||
"module": "esnext", | ||
"removeComments": true, | ||
"outDir": "dist", | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"noImplicitAny": true, | ||
"sourceMap": true, | ||
"allowJs": true, | ||
"declaration": true, | ||
"skipLibCheck": true, | ||
"declarationDir": "dist/types" | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules", "dist"] | ||
} |