Skip to content

Commit

Permalink
[frontend] linter fixed, session storage function updated, some var n…
Browse files Browse the repository at this point in the history
…ames edited (#3167)
  • Loading branch information
ValentinBouzinFiligran committed Mar 27, 2024
1 parent f343632 commit a2fd08f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { useFormatter } from 'src/components/i18n';
type InvestigationRollBackExpandDialogProps = {
closeDialog: () => void;
handleRollBackToPreExpansionState: () => void;
isRollBackPreExpandStateDialogOpen: boolean;
isOpen: boolean;
};

const InvestigationRollBackExpandDialog = ({ closeDialog, handleRollBackToPreExpansionState, isRollBackPreExpandStateDialogOpen }: InvestigationRollBackExpandDialogProps) => {
const InvestigationRollBackExpandDialog = ({ closeDialog, handleRollBackToPreExpansionState, isOpen }: InvestigationRollBackExpandDialogProps) => {
const { t_i18n, fldt } = useFormatter();

const handleSubmit = () => {
Expand All @@ -31,7 +31,7 @@ const InvestigationRollBackExpandDialog = ({ closeDialog, handleRollBackToPreExp
return (
<Dialog
PaperProps={{ elevation: 1 }}
open={isRollBackPreExpandStateDialogOpen}
open={isOpen}
onClose={closeDialog}
fullWidth={true}
maxWidth="sm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1837,12 +1837,14 @@ class InvestigationGraphComponent extends Component {
this.fetchObjectRelCounts(newElements);
}
if (newElementsIds.length > 0) {
setStackDataInSessionStorage({ valueToStore: {
dateTime: new Date().getTime(),
investigatedEntitiesIdsList: newElementsIds,
},
key: 'preExpansionStateList',
stackValue: 10 });
setStackDataInSessionStorage(
'preExpansionStateList',
{
dateTime: new Date().getTime(),
newElementsIds,
},
2,
);

this.graphData = buildGraphData(
this.graphObjects,
Expand Down Expand Up @@ -2083,7 +2085,7 @@ class InvestigationGraphComponent extends Component {
</Dialog>

<InvestigationRollBackExpandDialog
isRollBackPreExpandStateDialogOpen={isRollBackPreExpandStateDialogOpen}
isOpen={isRollBackPreExpandStateDialogOpen}
closeDialog={this.handleCloseRollBackToPreExpansionStateDialog.bind(this)}
handleRollBackToPreExpansionState={this.handleRollBackToPreExpansionState.bind(this)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -872,10 +872,15 @@ class InvestigationGraphBar extends Component {
)}
<Tooltip title={t('Restore the state of the graphic before the last expansion')}>
<span>
<IconButton color="primary" onClick={handleOpenRollBackToPreExpansionStateDialog} size="large" disabled={isRollBackToLastPreExpansionStateEnabled}>
<Undo />
</IconButton>
</span>
<IconButton
color="primary"
disabled={isRollBackToLastPreExpansionStateEnabled}
onClick={handleOpenRollBackToPreExpansionStateDialog}
size="large"
>
<Undo />
</IconButton>
</Tooltip>
<Tooltip title={t('Expand')}>
<span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ describe('Session Storage', () => {

describe('When I set a data in session storage', () => {
beforeEach(() => {
setStackDataInSessionStorage({
valueToStore: { test: 'value1' },
key: testKey,
stackValue,
});
setStackDataInSessionStorage(testKey, { test: 'value1' }, stackValue);
});

describe('If I get datas with my key from session storage', () => {
it('contains the my value', () => {
it('contains my value', () => {
const storedData = sessionStorage.getItem('testKey');
expect(storedData).to.not.equal(null);

Expand All @@ -35,11 +31,7 @@ describe('Session Storage', () => {
describe('When I set three data in session storage with a stack value of 2', () => {
beforeEach(() => {
Array.from(Array(3).keys()).forEach((_, i) => {
setStackDataInSessionStorage({
valueToStore: { test: `value${i}` },
key: testKey,
stackValue,
});
setStackDataInSessionStorage(testKey, { test: `value${i}` }, stackValue);
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
type SetDataOnSessionStorageParams = {
valueToStore: unknown;
key: string;
stackValue: number;
};
const setStackDataInSessionStorage = ({ valueToStore, key, stackValue }: SetDataOnSessionStorageParams): void => {
const setStackDataInSessionStorage = (key: string, valueToStore: unknown, stackValue: number): void => {
const storedStackData = sessionStorage.getItem(key);
const currentStoredStackData = storedStackData ? JSON.parse(storedStackData) : [];

currentStoredStackData.unshift(valueToStore);

if (currentStoredStackData.length > stackValue) currentStoredStackData.pop();
const newStackDataToStore = currentStoredStackData.slice(0, stackValue);

sessionStorage.setItem(key, JSON.stringify(currentStoredStackData));
sessionStorage.setItem(key, JSON.stringify(newStackDataToStore));
};

export default setStackDataInSessionStorage;

0 comments on commit a2fd08f

Please sign in to comment.