Skip to content

Commit

Permalink
FIX: client js packages fixes and welcome screen style
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetkuslular committed Sep 29, 2022
1 parent 43b4a2e commit 2934723
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 68 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"compression": "^1.7.4",
"cookie-parser": "1.4.3",
"copy-webpack-plugin": "4.5.2",
"core-js": "3.20.3",
"css-loader": "6.5.1",
"css-minimizer-webpack-plugin": "3.4.1",
"eev": "0.1.5",
Expand Down
33 changes: 16 additions & 17 deletions src/universal/core/apiService/apiManager/BaseApiManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,44 @@ import {
JSON_CONTENT_TYPE,
REQUEST_TYPES_WITH_BODY
} from '../../../utils/constants';
import voltranConfig from '../../../../../voltran.config';
import CookieService from '../../../service/CookieService';
import pickByIndexOf from '../../../utils/lodash/pickByIndexOf';
import omitByIndexOf from '../../../utils/lodash/omitByIndexOf';

function createBaseConfig() {
return {};
}

class BaseApiManager {
constructor(customConfig) {
constructor(config) {
const headers = {
common: {
...createBaseConfig.headers,
...(customConfig ? customConfig.headers : null)
...(config ? config.headers : null)
}
};

if (!process.env.BROWSER) {
headers['Accept-Encoding'] = 'gzip, deflate';
}

if (process.env.BROWSER && voltranConfig.setCookiesToHeader) {
const cookieMap = CookieService.getAllItems();

Object.keys(cookieMap).forEach(key => {
if (voltranConfig.setCookiesToHeaderKeys.length > 0) {
voltranConfig.setCookiesToHeaderKeys.map(item => {
if (key.indexOf(item) === 0) {
headers[key] = cookieMap[key];
}
});
} else {
headers[key] = cookieMap[key];
}
if (process.env.BROWSER && config?.addCookiesToHeader) {
let cookies = CookieService.getAllItems();
if (config?.includeCookies?.length > 0) {
cookies = pickByIndexOf(cookies, config?.includeCookies);
}
if (config?.excludeCookies?.length > 0) {
cookies = omitByIndexOf(cookies, config?.excludeCookies);
}

Object.keys(cookies).forEach(key => {
headers[key] = cookies[key];
});
}

this.api = this.createInstance({
...createBaseConfig(),
...customConfig,
...config,
headers
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import createCache from '../utils/createCache';
const { services, serviceConfigs } = require('__APP_CONFIG__');

const getCache = func => {
const cache = createCache(ClientApiManager, services, serviceConfigs?.client, func);
const { client, defaultConfig } = serviceConfigs;
const config = {
...defaultConfig,
...client
};
const cache = createCache(ClientApiManager, services, config, func);

return cache;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import createCache from '../utils/createCache';
const { services, serviceConfigs } = require('__APP_CONFIG__');

const getCache = func => {
const cache = createCache(ServerApiManager, services, serviceConfigs?.server, func);
const { server, defaultConfig } = serviceConfigs;
const config = {
...defaultConfig,
...server
};
const cache = createCache(ServerApiManager, services, config, func);

return cache;
};
Expand Down
15 changes: 2 additions & 13 deletions src/universal/partials/Welcome/PartialCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ import { ServerStyleSheet } from 'styled-components';
import partials from './partials';
import groupBy from '../../utils/lodash/groupBy';

const STATUS_COLOR = {
live: '#8dc63f',
dev: '#FF6000',
page: '#00abff',
1: '#9b59b6',
2: '#c0392b',
3: '#16a085'
};

const sheet = new ServerStyleSheet();

const Welcome = () => {
Expand All @@ -26,10 +17,8 @@ const Welcome = () => {
className="link"
>
<div className="card">
<div className="card-header">
<div className="badge" style={{ backgroundColor: STATUS_COLOR[status] }}>
{title}
</div>
<div className="ribbon-wrapper">
<div className={`ribbon color-${status}`}> {title}</div>
</div>
<div className="card-title">{item.name}</div>
<div className="card-subtitle">
Expand Down
62 changes: 55 additions & 7 deletions src/universal/partials/Welcome/welcomeStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const welcomeStyle = () => {
--theme-bg-color: #fafafb;
--body-font: "Poppins", sans-serif;
--body-color: #2f2f33;
--active-color: #0162ff;
--active-light-color: #e1ebfb;
--active-color: #4e4e4e;
--active-light-color: #f1f1f1;
--header-bg-color: #fff;
--border-color: #d8d8d8;
--alert-bg-color: #e8f2ff;
Expand Down Expand Up @@ -157,7 +157,7 @@ const welcomeStyle = () => {
}
.group-title {
font-size: 24px;
font-weight: 600;
font-weight: 700;
}
.link {
color: inherit;
Expand Down Expand Up @@ -190,12 +190,13 @@ const welcomeStyle = () => {
}
.card {
padding: 20px 16px;
padding: 16px 16px;
background-color: var(--header-bg-color);
border-radius: 8px;
cursor: pointer;
transition: 0.2s;
text-decoration: none;
position: relative;
}
.card:hover {
transform: scale(1.02);
Expand All @@ -207,8 +208,7 @@ const welcomeStyle = () => {
}
.card-title {
font-weight: 600;
margin-top: 16px;
font-size: 14px;
font-size: 16px;
}
.card-subtitle {
color: var(--subtitle-color);
Expand All @@ -220,14 +220,62 @@ const welcomeStyle = () => {
display: flex;
align-items: flex-start;
}
.ribbon-wrapper {
width: 85px;
height: 88px;
overflow: hidden;
position: absolute;
top: 0;
right: 0;
}
.ribbon {
font-size: 10px;
font-weight: bold;
color: var(--header-bg-color);;
text-align: center;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
position: relative;
padding: 0;
left: 26px;
top: 14px;
width: 80px;
-webkit-box-shadow: 0px 0px 3px rgba(0,0,0,0.3);
-moz-box-shadow: 0px 0px 3px rgba(0,0,0,0.3);
box-shadow: 0px 0px 3px rgba(0,0,0,0.3);
}
.color-live{
background-color: #badc58;
}
.color-dev{
background-color: #f0932b;
}
.color-page{
background-color: #00abff;
}
.color-1{
background-color: #9b59b6;
}
.color-2{
background-color: #c0392b;
}
.color-3{
background-color: #16a085;
}
.badge{
display: flex;
align-items: center;
justify-content: center;
background-color: #f50;
font-weight: 600;
margin-top: 16px;
font-size: 14px;
font-size: 10px;
padding: 5px 10px;
color: white;
border-radius: 5px;
Expand Down
4 changes: 3 additions & 1 deletion src/universal/utils/lodash/omit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const keyControl = (keys, key) => {
};

function omit(obj, ...keys) {
return Object.fromEntries(Object.entries(obj).filter(([k]) => keyControl(keys, k)));
return obj == null
? {}
: Object?.fromEntries(Object.entries(obj).filter(([k]) => keyControl(keys, k)));
}

export default omit;
22 changes: 22 additions & 0 deletions src/universal/utils/lodash/omitByIndexOf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function omitByIndexOf(object, keys) {
if (object == null) {
return {};
}

const result = Object.keys(object).reduce((result, cookiesKey) => {
if (object[cookiesKey]) {
if (keys.some(item => cookiesKey.indexOf(item) === -1)) {
return {
...result,
[cookiesKey]: object[cookiesKey]
};
}
return result;
}
return result;
}, {});

return result;
}

export default omitByIndexOf;
24 changes: 24 additions & 0 deletions src/universal/utils/lodash/pick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function pickObject(object, keys) {
return keys.reduce((obj, key) => {
if (Array.isArray(key)) {
return {
...obj,
...pickObject(object, key)
};
}

if (object && Object.prototype.hasOwnProperty.call(object, key)) {
return {
...obj,
[key]: object[key]
};
}
return obj;
}, {});
}

function pick(object, ...keys) {
return object == null ? {} : pickObject(object, keys);
}

export default pick;
22 changes: 22 additions & 0 deletions src/universal/utils/lodash/pickByIndexOf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function pickByIndexOf(object, keys) {
if (object == null) {
return {};
}

const result = Object.keys(object).reduce((result, cookiesKey) => {
if (object[cookiesKey]) {
if (keys.some(item => cookiesKey.indexOf(item) !== -1)) {
return {
...result,
[cookiesKey]: object[cookiesKey]
};
}
return result;
}
return result;
}, {});

return result;
}

export default pickByIndexOf;
28 changes: 3 additions & 25 deletions webpack.client.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,19 @@ const appConfigFilePath = `${voltranConfig.appConfigFile.entry}/${env}.conf.js`;
const appConfig = require(appConfigFilePath);
const commonConfig = require('./webpack.common.config');
const postCssConfig = require('./postcss.config');
const babelConfig = require('./babel.server.config');

const voltranClientConfigPath = voltranConfig.webpackConfiguration.client;
const voltranClientConfig = voltranClientConfigPath
? require(voltranConfig.webpackConfiguration.client)
: '';

const normalizeUrl = require('./lib/os.js');
const replaceString = require('./config/string.js');

const fragmentManifest = require(voltranConfig.routing.dictionary);
const fixFragmentManifest = require('./src/universal/core/route/dictionary');

const isDebug = voltranConfig.dev;
const isDebug = appConfig.dev;
const reScript = /\.(js|jsx|mjs)$/;
const distFolderPath = voltranConfig.distFolder;
const isProd = process.env.BROWSER && process.env.VOLTRAN_ENV === 'prod';
const hideCssPrefixOnTest = voltranConfig.hideCssPrefixOnTest;

Expand Down Expand Up @@ -73,27 +70,8 @@ const appConfigFileTarget = `${voltranConfig.appConfigFile.output.path}/${voltra

fs.copyFileSync(appConfigFilePath, appConfigFileTarget);

chunks.client.unshift('regenerator-runtime/runtime.js', 'core-js/stable', 'intersection-observer');

if (isDebug) {
const appConfigJSONContent = require(appConfigFileTarget);

for (const service in appConfigJSONContent.services) {
appConfigJSONContent.services[service].clientUrl =
appConfigJSONContent.services[service].serverUrl;
}

const moduleExportsText = 'module.exports';
const appConfigFileContent = fs.readFileSync(appConfigFileTarget).toString();
const moduleExportsIndex = appConfigFileContent.indexOf(moduleExportsText);

let context = appConfigFileContent.substr(0, moduleExportsIndex + moduleExportsText.length);
context += '=';
context += JSON.stringify(appConfigJSONContent);
context += ';';

fs.writeFileSync(appConfigFileTarget, context);

chunks.client.unshift('regenerator-runtime/runtime.js');
chunks.client.push('webpack-hot-middleware/client');
}

Expand Down Expand Up @@ -234,7 +212,7 @@ const clientConfig = merge(commonConfig, voltranClientConfig, {
? []
: [
new CleanWebpackPlugin({
verbose: false,
verbose: true,
dangerouslyAllowCleanPatternsOutsideProject: true
})
]),
Expand Down
3 changes: 1 addition & 2 deletions webpack.server.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const postCssConfig = require('./postcss.config');
const packageJson = require(path.resolve(process.cwd(), 'package.json'));
const replaceString = require('./config/string.js');

const distFolderPath = voltranConfig.distFolder;
const isDebug = voltranConfig.dev;
const isProd = process.env.BROWSER && process.env.VOLTRAN_ENV === 'prod';
const hideCssPrefixOnTest = voltranConfig.hideCssPrefixOnTest;
Expand Down Expand Up @@ -122,7 +121,7 @@ const serverConfig = merge(commonConfig, voltranServerConfig, {

plugins: [
new CleanWebpackPlugin({
verbose: false,
verbose: true,
dangerouslyAllowCleanPatternsOutsideProject: true
}),

Expand Down

0 comments on commit 2934723

Please sign in to comment.