Commit f50a1d59 authored by Matija Obreza's avatar Matija Obreza

Merge branch '700-missing-flags' into 'master'

Missing flags

Closes #700

See merge request genesys-pgr/genesys-ui!680
parents 46f9bfa3 ae43f68a
...@@ -4,6 +4,7 @@ const webpackMerge = require('webpack-merge'); ...@@ -4,6 +4,7 @@ const webpackMerge = require('webpack-merge');
const MinifyPlugin = require('terser-webpack-plugin'); const MinifyPlugin = require('terser-webpack-plugin');
const commonConfig = require('./webpack-base.config.js'); const commonConfig = require('./webpack-base.config.js');
const CopyWebpackPlugin = require('copy-webpack-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin');
const fs = require('fs');
// other // other
const IS_PRODUCTION = process.env.NODE_ENV === 'production'; const IS_PRODUCTION = process.env.NODE_ENV === 'production';
...@@ -58,7 +59,10 @@ module.exports = { ...@@ -58,7 +59,10 @@ module.exports = {
'process.env': { 'process.env': {
NODE_ENV: JSON.stringify(IS_PRODUCTION ? 'production' : 'development'), NODE_ENV: JSON.stringify(IS_PRODUCTION ? 'production' : 'development'),
ALLOW_ROBOTS: JSON.stringify(ALLOW_ROBOTS ? 'true' : 'false'), ALLOW_ROBOTS: JSON.stringify(ALLOW_ROBOTS ? 'true' : 'false'),
} },
'ISO3_FLAGS': JSON.stringify(fs.readdirSync(path.join(process.cwd(), 'assets/images/flags')).map((s) => {
return s.slice(0, -4);
})),
}), }),
new CopyWebpackPlugin([ new CopyWebpackPlugin([
......
...@@ -311,6 +311,12 @@ module.exports = { ...@@ -311,6 +311,12 @@ module.exports = {
new ReactLoadable.ReactLoadablePlugin({ new ReactLoadable.ReactLoadablePlugin({
filename: 'react-loadable.json', filename: 'react-loadable.json',
}), }),
new webpack.DefinePlugin({
ISO3_FLAGS: JSON.stringify(fs.readdirSync(path.join(process.cwd(), 'assets/images/flags')).map((s) => {
return s.slice(0, -4);
}))
}),
], ],
optimization: { optimization: {
......
// The static list of flags available in assets/images/flags
// generated by webpack.DefinePlugin
declare const ISO3_FLAGS: string[];
...@@ -12,6 +12,7 @@ import {User} from 'model/user/User'; ...@@ -12,6 +12,7 @@ import {User} from 'model/user/User';
import GeoRegion from 'model/geo/GeoRegion'; import GeoRegion from 'model/geo/GeoRegion';
import Article from 'model/cms/Article'; import Article from 'model/cms/Article';
import OAuthClient from 'model/oauth/OAuthClient'; import OAuthClient from 'model/oauth/OAuthClient';
import { flagAssetExists } from 'utilities/iso3Flags';
const SubsetLink = ({to: subset, uuid = null, edit = false, children = null}: { to?: Subset, uuid?: string, edit?: boolean, children?: any }) => { const SubsetLink = ({to: subset, uuid = null, edit = false, children = null}: { to?: Subset, uuid?: string, edit?: boolean, children?: any }) => {
...@@ -122,10 +123,13 @@ const CountryLink = ({ country, noflag, children }: { country: Country | string, ...@@ -122,10 +123,13 @@ const CountryLink = ({ country, noflag, children }: { country: Country | string,
name = country.name; name = country.name;
code = country.code3; code = country.code3;
} }
return ( return (
<Link to={ `/iso3166/${code}` }> <Link to={ `/iso3166/${code}` }>
<span style={ {display: 'inline-block'} }> <span style={ {display: 'inline-block'} }>
{ !noflag && <img src={ `images/flags/${code}.png` } style={ { maxWidth: '1.25rem', padding: '0 0.25rem', verticalAlign: 'bottom' } } /> } { !noflag && flagAssetExists(code) && (
<img src={ `images/flags/${code}.png` } style={ { maxWidth: '1.25rem', padding: '0 0.25rem', verticalAlign: 'bottom' } } />
) }
{ children || name } { children || name }
</span> </span>
</Link> </Link>
......
export const flagAssetExists = (iso3) => {
if (typeof ISO3_FLAGS !== 'undefined') {
return ISO3_FLAGS && ISO3_FLAGS.some((code) => code === iso3);
} else {
return true;
}
};
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
"types": [ "types": [
"node", "node",
"webpack-env" "webpack-env"
],
"typeRoots" : [
"./src/typings"
] ]
}, },
"exclude": [ "exclude": [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment