Skip to content

Commit

Permalink
feat(explorer): do not close truncated parts
Browse files Browse the repository at this point in the history
  • Loading branch information
alber70g committed Dec 20, 2024
1 parent 6354c5c commit 40d0d65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 43 deletions.
8 changes: 8 additions & 0 deletions .changeset/soft-tomatoes-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@kadena/explorer': patch
---

Reordering columns to present the first column as the one to link to

Remove toggling close of truncated content. Will always open so users can no
select and copy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CopyButton } from '@/components/CopyButton/CopyButton';
import { Stack, Text } from '@kadena/kode-ui';
import classNames from 'classnames';
import type { FC } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import React, { useState } from 'react';
import {
descriptionDetailsClass,
descriptionDetailsExpandedClass,
Expand All @@ -14,54 +14,13 @@ interface IProps {
field: IDataRenderComponentField;
}

const storageKey = 'expandedfields';

export const ExpandTruncatedField: FC<IProps> = ({ field }) => {
const [isExpanded, setIsExpanded] = useState(false);

const toggleExpand = (): void => {
let storage: string[] = JSON.parse(
localStorage.getItem(storageKey) ?? '[]',
);

const key = field.key ? field.key : field.id ?? '';

if (isExpanded) {
storage = storage.filter((v) => v !== key);
} else {
storage.push(key);
}

localStorage.setItem(storageKey, JSON.stringify(storage));

window.dispatchEvent(new Event(storageKey));
setIsExpanded((v) => !isExpanded);
setIsExpanded((v) => true);
};

const checkStorage = () => {
const storage: string[] = JSON.parse(
localStorage.getItem(storageKey) ?? '[]',
);

setIsExpanded(storage.includes(field.key));
};
const storageListener = useCallback((event: StorageEvent | Event) => {
if (event.type !== storageKey && 'key' in event && event.key !== storageKey)
return;

checkStorage();
}, []);

useEffect(() => {
checkStorage();
window.addEventListener(storageKey, storageListener);
window.addEventListener('storage', storageListener);
return () => {
window.removeEventListener(storageKey, storageListener);
window.removeEventListener('storage', storageListener);
};
}, [storageListener]);

return (
<Stack
onClick={toggleExpand}
Expand Down

0 comments on commit 40d0d65

Please sign in to comment.