Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ describe('BSONValue', function () {
{ type: 'Boolean', value: true, expected: 'true' },
{ type: 'Array', value: [1, 2, 3], expected: 'Array (3)' },
{ type: 'Array', value: [], expected: 'Array (empty)' },
{ type: 'Object', value: {}, expected: 'Object (empty)' },
{ type: 'Object', value: { a: 1 }, expected: 'Object (1)' },
{ type: 'Object', value: { a: 1, b: 2 }, expected: 'Object (2)' },
];

valuesToRender.forEach(function ({ expected, ...props }) {
Expand Down
17 changes: 16 additions & 1 deletion packages/compass-components/src/components/bson-value.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,21 @@ const ArrayValue: React.FunctionComponent<PropsByValueType<'Array'>> = ({
);
};

const ObjectValue: React.FunctionComponent<PropsByValueType<'Object'>> = ({
value,
}) => {
const lengthString = useMemo(() => {
const keys = Object.keys(value ?? {});
Comment thread
mabaasit marked this conversation as resolved.
return `(${keys.length === 0 ? 'empty' : keys.length})`;
}, [value]);

return (
<BSONValueContainer title={`Object ${lengthString}`}>
Object {lengthString}
</BSONValueContainer>
);
};

const BSONValue: React.FunctionComponent<ValueProps> = (props) => {
switch (props.type) {
case 'ObjectId':
Expand Down Expand Up @@ -574,7 +589,7 @@ const BSONValue: React.FunctionComponent<ValueProps> = (props) => {
case 'Array':
return <ArrayValue value={props.value}></ArrayValue>;
case 'Object':
return <UnknownValue type={props.type} value={props.type}></UnknownValue>;
return <ObjectValue value={props.value}></ObjectValue>;
default:
return (
<UnknownValue type={props.type} value={props.value}></UnknownValue>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ function useHadronElement(el: HadronElementType) {

const isValid = el.isCurrentTypeValid();

const originalValue =
el.currentType === 'Array'
? [...(el.elements || [])]
: el.currentType === 'Object'
? Object.fromEntries(
Array.from(el.elements || []).map((e) => [
e.currentKey,
e.currentValue,
])
)
: el.currentValue;

return {
id: el.uuid,
key: {
Expand All @@ -129,8 +141,7 @@ function useHadronElement(el: HadronElementType) {
},
value: {
value: editor.value(),
originalValue:
el.currentType === 'Array' ? [...(el.elements || [])] : el.currentValue,
originalValue,
change(newVal: string) {
editor.edit(newVal);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('GuideCueService', function () {
groupId: 'group-one',
isIntersecting: true,
};
guideCueService.addCue(cue as any);
guideCueService.addCue(cue);

expect((guideCueService as any)._cues).to.deep.equal([
{
Expand All @@ -138,7 +138,7 @@ describe('GuideCueService', function () {
};
guideCueStorage.markCueAsVisited(cue.cueId, cue.groupId);

guideCueService.addCue(cue as any);
guideCueService.addCue(cue);
expect((guideCueService as any)._cues).to.deep.equal([
{
...cue,
Expand All @@ -156,7 +156,7 @@ describe('GuideCueService', function () {
};
const dispatchEventSpy = Sinon.spy(guideCueService, 'dispatchEvent');

guideCueService.addCue(cue as any);
guideCueService.addCue(cue);

expect(dispatchEventSpy.calledOnce).to.be.true;

Expand Down Expand Up @@ -198,9 +198,9 @@ describe('GuideCueService', function () {
// Add cue3. As its added, we already have an active cue and it
// also fires an event for same cue (cue1).

guideCueService.addCue(cue2 as any);
guideCueService.addCue(cue1 as any);
guideCueService.addCue(cue3 as any);
guideCueService.addCue(cue2);
guideCueService.addCue(cue1);
guideCueService.addCue(cue3);

expect(spy.callCount).to.be.equal(2);

Expand Down Expand Up @@ -249,15 +249,15 @@ describe('GuideCueService', function () {
step: 2,
groupId: 'group-two',
isIntersecting: true,
} as any);
});
expect(guideCueService.getCountOfSteps('group-two')).to.equal(1);

guideCueService.addCue({
cueId: 'one',
step: 1,
groupId: 'group-two',
isIntersecting: true,
} as any);
});
expect(guideCueService.getCountOfSteps('group-two')).to.equal(2);
});

Expand Down Expand Up @@ -369,7 +369,7 @@ describe('GuideCueService', function () {
let markCueAsVisited: Sinon.SinonSpy;
beforeEach(function () {
markCueAsVisited = Sinon.spy(guideCueStorage, 'markCueAsVisited');
guideCueService.addCue(cue as any);
guideCueService.addCue(cue);
guideCueService.markCueAsVisited(cue.cueId, cue.groupId);
});

Expand Down Expand Up @@ -505,9 +505,9 @@ describe('GuideCueService', function () {

beforeEach(function () {
markCueAsVisited = Sinon.spy(guideCueStorage, 'markCueAsVisited');
guideCueService.addCue(cue1 as any);
guideCueService.addCue(cue2 as any);
guideCueService.addCue(cue3 as any);
guideCueService.addCue(cue1);
guideCueService.addCue(cue2);
guideCueService.addCue(cue3);
guideCueService.markAllCuesAsVisited();
});

Expand Down Expand Up @@ -548,9 +548,9 @@ describe('GuideCueService', function () {
const cue3 = { cueId: 'three', step: 1, isIntersecting: true };

beforeEach(function () {
guideCueService.addCue(cue1 as any);
guideCueService.addCue(cue2 as any);
guideCueService.addCue(cue3 as any);
guideCueService.addCue(cue1);
guideCueService.addCue(cue2);
guideCueService.addCue(cue3);

expect((guideCueService as any)._activeCue).to.deep.equal({
...cue1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('IndexKeysBadge Component', function () {
value: 'text',
},
];
render(<IndexKeysBadge keys={keys as any} />);
render(<IndexKeysBadge keys={keys} />);

const keysList = screen.getByRole('list');

Expand Down
2 changes: 1 addition & 1 deletion packages/compass-components/src/hooks/use-sort.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export function useSortedItems<T extends Record<string, unknown>>(
}
// Otherwise use default sort method based on the value type
if (typeof a[name] === 'string') {
return sortString(a[name] as string, b[name] as string, order);
return sortString(a[name], b[name] as string, order);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why the first argument cast was removed but the second was kept?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, all of these changes (removing ts cast) are due to reformat.

}
return sortUnknown(a[name], b[name], order);
});
Expand Down
Loading