Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit d42831c

Browse files
committed
update: reset unfold when the expand/metadata are toggled
update: search by @id and _self query depends on deprecated value update: refetch the ES type list depends on deprecated value update: fix styling
1 parent 8707038 commit d42831c

File tree

6 files changed

+114
-48
lines changed

6 files changed

+114
-48
lines changed

src/shared/components/ResourceEditor/index.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ const ResourceEditor: React.FunctionComponent<ResourceEditorProps> = props => {
6868
}
6969
}
7070
};
71+
const onFormatChangeFold = (expanded: boolean) => {
72+
if (codeMirorRef.current) {
73+
codeMirorRef.current.execCommand('foldAll');
74+
codeMirorRef.current.foldCode(0);
75+
setFoldCodeMiror(() => false);
76+
}
77+
onFormatChange?.(expanded);
78+
};
79+
const onMetadataChangeFold = (checked: boolean) => {
80+
if (codeMirorRef.current) {
81+
codeMirorRef.current.execCommand('foldAll');
82+
codeMirorRef.current.foldCode(0);
83+
setFoldCodeMiror(() => false);
84+
}
85+
onMetadataChange?.(checked);
86+
};
7187
const renderCodeMirror = (value: string) => {
7288
return (
7389
<Spin spinning={busy}>
@@ -103,6 +119,11 @@ const ResourceEditor: React.FunctionComponent<ResourceEditorProps> = props => {
103119
setEditing(false);
104120
setStringValue(JSON.stringify(rawData, null, 2)); // Update copy of the rawData for the editor.
105121
setParsedValue(rawData); // Update parsed value for submit.
122+
// onFormatChange?.(false);
123+
// onMetadataChange?.(false);
124+
return () => {
125+
setFoldCodeMiror(false);
126+
};
106127
}, [rawData]); // only runs when Editor receives new resource to edit
107128

108129
const handleChange = (editor: any, data: any, value: any) => {
@@ -163,7 +184,7 @@ const ResourceEditor: React.FunctionComponent<ResourceEditorProps> = props => {
163184
checkedChildren="Metadata"
164185
unCheckedChildren="Show Metadata"
165186
checked={showMetadata}
166-
onChange={onMetadataChange}
187+
onChange={checked => onMetadataChangeFold(checked)}
167188
style={switchMarginRight}
168189
/>
169190
)}
@@ -172,7 +193,7 @@ const ResourceEditor: React.FunctionComponent<ResourceEditorProps> = props => {
172193
checkedChildren="Expanded"
173194
unCheckedChildren="Expand"
174195
checked={expanded}
175-
onChange={onFormatChange}
196+
onChange={expaned => onFormatChangeFold(expanded)}
176197
style={switchMarginRight}
177198
/>
178199
)}

src/shared/components/ResourceList/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@ import {
2222
SwitcherOutlined,
2323
} from '@ant-design/icons';
2424
import { ResourceList, Resource } from '@bbp/nexus-sdk';
25+
import { debounce } from 'lodash';
2526

2627
import RenameableItem from '../Renameable';
2728
import ListItem from '../List/Item';
2829
import ResourceCardComponent from '../ResourceCard';
2930
import { getResourceLabel } from '../../utils';
3031
import TypesIconList from '../Types/TypesIcon';
3132
import useMeasure from '../../hooks/useMeasure';
33+
import { DEFAULT_LIST } from '../../../shared/containers/ResourceListBoardContainer';
3234
import Copy from '../Copy';
33-
import { debounce } from 'lodash';
3435

3536
import './ResourceList.less';
3637

@@ -244,7 +245,6 @@ const ResourceListComponent: React.FunctionComponent<{
244245
React.useLayoutEffect(() => {
245246
debounceHeightChange();
246247
}, [wrapperHeight]);
247-
248248
return (
249249
<div className="resource-list-height-tester" ref={wrapperHeightRef}>
250250
<div className="resource-list">

src/shared/components/SchemaLink/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const SchemaLink: React.FunctionComponent<{
55
resource: Resource;
66
goToSchema?(): void;
77
}> = ({ resource: { _constrainedBy: constrainedBy }, goToSchema }) =>
8-
constrainedBy.includes('unconstrained.json') ? (
8+
constrainedBy?.includes('unconstrained.json') ? (
99
<span>No schema defined for validation</span>
1010
) : (
1111
<a

src/shared/containers/ResourceListContainer.tsx

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,35 @@ const ResourceListContainer: React.FunctionComponent<{
140140
bool: {
141141
should: [
142142
{
143-
term: {
144-
'@id': list.query.q,
143+
bool: {
144+
must: [
145+
{
146+
term: {
147+
_deprecated: list.query.deprecated,
148+
},
149+
},
150+
{
151+
term: {
152+
'@id': list.query.q,
153+
},
154+
},
155+
],
145156
},
146157
},
147158
{
148-
term: {
149-
_self: list.query.q,
159+
bool: {
160+
must: [
161+
{
162+
term: {
163+
_deprecated: list.query.deprecated,
164+
},
165+
},
166+
{
167+
term: {
168+
_self: list.query.q,
169+
},
170+
},
171+
],
150172
},
151173
},
152174
],
@@ -301,7 +323,7 @@ const ResourceListContainer: React.FunctionComponent<{
301323
shareableLink={shareableLink}
302324
>
303325
<TypeDropdownFilterContainer
304-
deprecated={!!list.query.deprecated}
326+
deprecated={Boolean(list.query.deprecated)}
305327
orgLabel={orgLabel}
306328
projectLabel={projectLabel}
307329
onChange={handleTypeChange}

src/shared/containers/TypeDropdownFilter.tsx

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,69 @@
11
import * as React from 'react';
2-
import { useNexus } from '@bbp/react-nexus';
3-
import {
4-
DEFAULT_ELASTIC_SEARCH_VIEW_ID,
5-
ElasticSearchViewQueryResponse,
6-
} from '@bbp/nexus-sdk';
2+
import { useNexusContext } from '@bbp/react-nexus';
3+
import { DEFAULT_ELASTIC_SEARCH_VIEW_ID, NexusClient } from '@bbp/nexus-sdk';
74

85
import DropdownFilter from '../components/DropdownFilter';
96
import { TypeDropdownItem } from '../components/DropdownFilter/DropdownItem';
7+
import { useQuery } from 'react-query';
108

119
// must be explicitly set for elasticSearch, default is 10
1210
const RESULTS_SIZE = 10000;
1311

14-
const TypeDropdownFilterContainer: React.FunctionComponent<{
12+
const fetchESVTypes = ({
13+
nexus,
14+
orgLabel,
15+
projectLabel,
16+
deprecated,
17+
}: {
18+
nexus: NexusClient;
1519
orgLabel: string;
1620
projectLabel: string;
1721
deprecated: boolean;
18-
value?: string;
19-
onChange(value: string): void;
20-
}> = ({ orgLabel, projectLabel, onChange, deprecated, value }) => {
21-
const { loading: busy, data, error } = useNexus<
22-
ElasticSearchViewQueryResponse<any>
23-
>(nexus =>
24-
nexus.View.elasticSearchQuery(
25-
orgLabel,
26-
projectLabel,
27-
encodeURIComponent(DEFAULT_ELASTIC_SEARCH_VIEW_ID),
28-
{
29-
aggregations: {
30-
types: {
31-
filter: {
32-
term: { _deprecated: deprecated },
33-
},
34-
aggregations: {
35-
filteredByDeprecation: {
36-
terms: {
37-
field: '@type',
38-
size: RESULTS_SIZE,
39-
},
22+
}) =>
23+
nexus.View.elasticSearchQuery(
24+
orgLabel,
25+
projectLabel,
26+
encodeURIComponent(DEFAULT_ELASTIC_SEARCH_VIEW_ID),
27+
{
28+
aggregations: {
29+
types: {
30+
filter: {
31+
term: { _deprecated: deprecated },
32+
},
33+
aggregations: {
34+
filteredByDeprecation: {
35+
terms: {
36+
field: '@type',
37+
size: RESULTS_SIZE,
4038
},
4139
},
4240
},
4341
},
44-
}
45-
)
42+
},
43+
}
4644
);
45+
const TypeDropdownFilterContainer: React.FunctionComponent<{
46+
orgLabel: string;
47+
projectLabel: string;
48+
deprecated: boolean;
49+
value?: string;
50+
onChange(value: string): void;
51+
}> = ({ orgLabel, projectLabel, onChange, deprecated, value }) => {
52+
const nexus = useNexusContext();
53+
54+
const { data } = useQuery({
55+
queryKey: [
56+
'resource-list-query-types',
57+
{
58+
deprecated,
59+
orgLabel,
60+
projectLabel,
61+
desv_id: DEFAULT_ELASTIC_SEARCH_VIEW_ID,
62+
},
63+
],
64+
queryFn: () => fetchESVTypes({ nexus, orgLabel, projectLabel, deprecated }),
65+
refetchOnWindowFocus: true,
66+
});
4767

4868
return (
4969
<DropdownFilter

src/shared/utils/index.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,19 @@ export function getDestinationParam(): string {
258258
*/
259259
export function getUsername(user: string): string {
260260
let userName;
261-
if (user.length === 0) {
262-
userName = 'Unknown';
263-
} else {
264-
try {
265-
[userName] = user.split('/').slice(-1);
266-
} catch (e) {
267-
userName = user;
261+
if (user) {
262+
if (user.length === 0) {
263+
userName = 'Unknown';
264+
} else {
265+
try {
266+
[userName] = user.split('/').slice(-1);
267+
} catch (e) {
268+
userName = user;
269+
}
268270
}
271+
return userName;
269272
}
270-
return userName;
273+
return '';
271274
}
272275

273276
export function blacklistKeys(raw: { [key: string]: any }, keys: string[]) {

0 commit comments

Comments
 (0)