Skip to content

Commit

Permalink
feat(datagrid-preferences): initial commit
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/manager/modules/datagrid-preferences/package.json
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 packages/manager/modules/datagrid-preferences/src/index.ts
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 packages/manager/modules/datagrid-preferences/tsconfig.json
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"]
}

0 comments on commit 21fa397

Please sign in to comment.