Skip to content

Commit

Permalink
Fixes #37664 - switch to using js-cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
MariaAga authored and adamruzicka committed Nov 26, 2024
1 parent 538b5a1 commit 8e97632
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
8 changes: 0 additions & 8 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ function onContentLoad() {

password_caps_lock_hint();

tfm.i18n.intl.ready.then(function() {
var tz = jstz.determine();
$.cookie('timezone', tz.name(), {
path: '/',
secure: location.protocol === 'https:',
});
});

$('.full-value').SelectOnClick();
activate_select2(':root');

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"graphql-tag": "^2.11.0",
"intl": "~1.2.5",
"jed": "^1.1.1",
"js-cookie": "^3.0.5",
"os-browserify": "^0.3.0",
"react-intl": "^2.8.0"
},
Expand Down
2 changes: 2 additions & 0 deletions webpack/assets/javascripts/bundle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'core-js/shim';
import 'regenerator-runtime/runtime';
import Cookies from 'js-cookie';

import compute from './foreman_compute_resource';
import componentRegistry from './react_app/components/componentRegistry';
Expand Down Expand Up @@ -56,4 +57,5 @@ window.tfm = Object.assign(window.tfm || {}, {
componentRegistry,
store,
lookupKeys,
Cookies,
});
7 changes: 4 additions & 3 deletions webpack/assets/javascripts/hosts/tableCheckboxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/* eslint-disable jquery/no-in-array */

import $ from 'jquery';
import Cookies from 'js-cookie';

import {
sprintf,
Expand Down Expand Up @@ -43,7 +44,7 @@ export function hostChecked({ id, checked }) {
multipleAlert.data('multiple', false);
}
}
$.cookie(cookieName, JSON.stringify(foremanSelectedHosts), {
Cookies.set(cookieName, JSON.stringify(foremanSelectedHosts), {
secure: window.location.protocol === 'https:',
});
toggleActions();
Expand All @@ -62,7 +63,7 @@ function rmHostId(id) {

function readFromCookie() {
try {
const r = $.cookie(cookieName);
const r = Cookies.get(cookieName);
if (r) return $.parseJSON(r);
return [];
} catch (err) {
Expand Down Expand Up @@ -116,7 +117,7 @@ $(document).on('ContentLoad', () => {
});

function removeForemanHostsCookie() {
$.removeCookie(cookieName);
Cookies.remove(cookieName);
}

export function resetSelection() {
Expand Down
6 changes: 6 additions & 0 deletions webpack/assets/javascripts/react_app/common/I18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/* eslint-disable import/no-dynamic-require */
import Jed from 'jed';
import { addLocaleData } from 'react-intl';
import Cookies from 'js-cookie';
import jstz from 'jstz';
import forceSingleton from './forceSingleton';

class IntlLoader {
Expand All @@ -18,6 +20,10 @@ class IntlLoader {
await this.fetchIntl();
const localeData = require(/* webpackChunkName: 'react-intl/locale/[request]' */ `react-intl/locale-data/${this.locale}`);
addLocaleData(localeData);
Cookies.set('timezone', jstz.determine().name(), {
path: '/',
secure: window.location.protocol === 'https:',
});
return true;
}

Expand Down

0 comments on commit 8e97632

Please sign in to comment.