Skip to content

Commit

Permalink
feat: add all data handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kav91 committed Dec 17, 2023
1 parent 6ee2c5c commit 8b45888
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 164 deletions.
10 changes: 5 additions & 5 deletions launchers/maturity-launcher/nr1.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaType": "LAUNCHER",
"id": "maturity-launcher",
"description": "Evaluates maturity of your account/sub-accounts within New Relic",
"displayName": "Account Maturity",
"rootNerdletId": "maturity-nerdlet"
"schemaType": "LAUNCHER",
"id": "maturity-launcher",
"description": "Evaluates maturity of your account/sub-accounts within New Relic",
"displayName": "Account Maturity - V2 BETA",
"rootNerdletId": "maturity-nerdlet"
}
2 changes: 1 addition & 1 deletion nerdlets/maturity-nerdlet/AccountMaturity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function AccountMaturity(props) {
case 'CreateDefaultView': {
return <CreateView {...(view.props || {})} />;
}
case 'EditDefaultView': {
case 'CreateNewView': {
return <CreateView {...(view.props || {})} />;
}
case 'EditView': {
Expand Down
53 changes: 29 additions & 24 deletions nerdlets/maturity-nerdlet/CreateView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import rules from '../../../src/rules';

export default function CreateView() {
const {
viewConfigs,
runView,
email,
selectedReport,
Expand All @@ -44,7 +45,7 @@ export default function CreateView() {
const [state, setState] = useSetState({
creatingView: false,
name:
view.page === 'CreateDefaultView' || view.page === 'EditDefaultView'
view.page === 'CreateDefaultView' || view.page === 'CreateNewView'
? 'Untitled'
: selectedReport?.document?.name || '',
description: selectedReport?.document?.description || '',
Expand All @@ -61,7 +62,7 @@ export default function CreateView() {
(state.accounts.length === 0 && !state.accountsFilter);

const validateEntitySearchQuery = () => {
return new Promise((resolve) => {
return new Promise(resolve => {
const accountsClause = `and tags.accountId IN ('${state.accounts.join(
"','"
)}')`;
Expand All @@ -73,7 +74,7 @@ export default function CreateView() {
}
}
}`,
}).then((res) => {
}).then(res => {
if (res.error) {
Toast.showToast({
title: 'Bad entity search query',
Expand Down Expand Up @@ -119,17 +120,23 @@ export default function CreateView() {
return (
<>
<br />
{view.page === 'EditView' ? (
<Button
type={Button.TYPE.SECONDARY}
onClick={() => setDataState({ view: { page: 'ViewList' } })}
>
Back
</Button>
) : (
{viewConfigs.length > 1 && (
<>
<Button
type={Button.TYPE.SECONDARY}
onClick={() => setDataState({ view: { page: 'ViewList' } })}
>
Back
</Button>
&nbsp;
</>
)}
{view.page === 'CreateNewView' && (
<Button
type={Button.TYPE.SECONDARY}
onClick={() => runView({ id: 'allData', name: 'All data' })}
onClick={() =>
runView({ id: 'allData', name: 'All data' }, null, false, true)
}
>
Skip this step
</Button>
Expand All @@ -146,14 +153,14 @@ export default function CreateView() {
<TextField
label="Name"
value={state.name}
onChange={(e) => setState({ name: e.target.value })}
onChange={e => setState({ name: e.target.value })}
placeholder="e.g. DevOps Team"
/>
&nbsp;&nbsp;
<TextField
label="Description (optional)"
value={state.description}
onChange={(e) => setState({ description: e.target.value })}
onChange={e => setState({ description: e.target.value })}
placeholder="Add context to the view"
/>
&nbsp;&nbsp;
Expand All @@ -167,7 +174,7 @@ export default function CreateView() {
setDataState({ selectedAccountId: value })
}
>
{accounts.map((a) => (
{accounts.map(a => (
<SelectItem key={a.id} value={a.id}>
{a.name}
</SelectItem>
Expand Down Expand Up @@ -198,7 +205,7 @@ export default function CreateView() {
<CardBody style={{ paddingLeft: '20px', marginTop: '5px' }}>
<div style={{ paddingTop: '10px' }}>
<Grid>
{Object.keys(rules).map((key) => (
{Object.keys(rules).map(key => (
<GridItem columnSpan={3} key={key}>
<Checkbox
key={key}
Expand All @@ -211,7 +218,7 @@ export default function CreateView() {
onChange={() => {
if (state.products.includes(key)) {
setState({
products: state.products.filter((id) => id !== key),
products: state.products.filter(id => id !== key),
});
} else {
setState({ products: [...state.products, key] });
Expand Down Expand Up @@ -241,15 +248,15 @@ export default function CreateView() {
if (state.accounts.length === accounts.length) {
setState({ accounts: [] });
} else {
setState({ accounts: accounts.map((a) => a.id) });
setState({ accounts: accounts.map(a => a.id) });
}
}}
/>
</CardHeader>
<CardBody style={{ paddingLeft: '20px', marginTop: '5px' }}>
<div style={{ paddingTop: '10px' }}>
<Grid style={{ maxHeight: '100px' }}>
{accounts.map((a) => (
{accounts.map(a => (
<GridItem columnSpan={3} key={a.id}>
<Checkbox
// description={`${a.id}`}
Expand All @@ -260,9 +267,7 @@ export default function CreateView() {
onChange={() => {
if (state.accounts.includes(a.id)) {
setState({
accounts: state.accounts.filter(
(id) => id !== a.id
),
accounts: state.accounts.filter(id => id !== a.id),
});
} else {
setState({ accounts: [...state.accounts, a.id] });
Expand All @@ -289,7 +294,7 @@ export default function CreateView() {
<TextField
label="Entity Filter"
value={state.entitySearchQuery}
onChange={(e) => setState({ entitySearchQuery: e.target.value })}
onChange={e => setState({ entitySearchQuery: e.target.value })}
placeholder="e.g. tags.team = 'labs'"
/>
</CardBody>
Expand Down Expand Up @@ -371,5 +376,5 @@ export default function CreateView() {
</div>
</>
);
}, [accounts, user, state, selectedReport, email]);
}, [accounts, user, state, selectedReport, email, view.page, viewConfigs.length]);
}
2 changes: 1 addition & 1 deletion nerdlets/maturity-nerdlet/SearchBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function SearchBar(props) {
onClick={() => {
setDataState({
view: {
page: 'CreateDefaultView',
page: 'CreateView',
title: 'Create View Configuration',
},
selectedReport: {},
Expand Down
57 changes: 43 additions & 14 deletions nerdlets/maturity-nerdlet/ViewList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TableRow,
TableRowCell,
FavoriteTableRowCell,
Toast,
} from 'nr1';

import DataContext from '../../../src/context/data';
Expand Down Expand Up @@ -102,39 +103,67 @@ export default function ViewList() {
}
},
},
{ key: 'Created by', value: ({ item }) => item.document?.owner },
{
key: 'Created by',
value: ({ item }) =>
item?.id === 'allData' ? 'Account Maturity' : item.document?.owner,
},
];

const actions = [
{
label: 'Run',
onClick: (evt, { item }) => {
runView(
{
name: item.document.name,
account: selectedAccountId,
},
{ ...item },
false,
true
);
if (item.id === 'allData') {
runView({ id: 'allData', name: 'All data' }, null, false, true);
} else {
runView(
{
name: item.document.name,
account: selectedAccountId,
},
{ ...item },
false,
true
);
}
},
},
{
label: 'Edit',
onClick: (evt, { item }) => {
setDataState({ selectedReport: item, view: { page: 'EditView' } });
if (item.id === 'allData') {
Toast.showToast({
title: 'This view cannot be edited',
type: Toast.TYPE.NORMAL,
});
} else {
setDataState({ selectedReport: item, view: { page: 'EditView' } });
}
},
},
{
label: 'Delete',
type: TableRow.ACTION_TYPE.DESTRUCTIVE,
onClick: (evt, { item }) => setDataState({ deleteViewModalOpen: item }),
onClick: (evt, { item }) => {
if (item.id === 'allData') {
Toast.showToast({
title: 'This view cannot be deleted',
type: Toast.TYPE.NORMAL,
});
} else {
setDataState({ deleteViewModalOpen: item });
}
},
},
];

const filteredConfigs = viewConfigs
.filter((c) => c.document.name.toLowerCase().includes(search.toLowerCase()))
.filter(c =>
(c?.document?.name || '')
.toLowerCase()
.includes((search || '').toLowerCase())
)
.sort((a, b) => favorites.includes(b.id) - favorites.includes(a.id));

return useMemo(() => {
Expand Down Expand Up @@ -167,7 +196,7 @@ export default function ViewList() {
checked={favorites.includes(item.id)}
/>

{headers.map((header) => {
{headers.map(header => {
if (header.key === 'View') {
const previousResult = item?.history?.[0];
let onClickHandler = undefined;
Expand Down
27 changes: 18 additions & 9 deletions nerdlets/maturity-nerdlet/ViewSelector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ export default function ViewSelector() {

return useMemo(() => {
const configs = viewConfigs
.filter((v) => v && Object.keys(v).length > 0)
.map((v) => ({
.filter(v => v && Object.keys(v).length > 0)
.map(v => ({
id: v.id,
name: v.document?.name,
}));

const items = [{ id: 'allData', name: 'All data' }, ...configs];
const items = [...configs];

// const items = [{ id: 'allData', name: 'All data' }, ...configs];

const filteredItems = items.filter(({ name }) =>
name.toLowerCase().includes(viewSearch.toLowerCase())
(name||'').toLowerCase().includes((viewSearch||'').toLowerCase())
);

console.log(selectedView, view);
Expand All @@ -44,19 +46,26 @@ export default function ViewSelector() {
labelInline={true}
title={unsavedRun ? 'Select' : selectedView?.name || 'Select'}
search={viewSearch}
onSearch={(e) => setViewSearch(e.target.value)}
onSearch={e => setViewSearch(e.target.value)}
>
<DropdownSection title="Views">
{filteredItems
.sort(
(a, b) => favorites.includes(b.id) - favorites.includes(a.id)
)
.map((item) => (
.map(item => (
<DropdownItem
onClick={() => {
if (item.id !== selectedView.id) {
if (item.id === 'allData') {
runView(
{ id: 'allData', name: 'All data' },
null,
false,
true
);
} else if (item.id !== selectedView.id && item.id !== 'allData') {
const viewConfig = viewConfigs.find(
(vc) => vc.id === item.id
vc => vc.id === item.id
);

const previousResult = viewConfig?.history?.[0];
Expand All @@ -75,7 +84,7 @@ export default function ViewSelector() {
true
);
}
}
}
}}
key={item.id}
style={{
Expand Down
2 changes: 1 addition & 1 deletion nerdlets/old-maturity-nerdlet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class MaturityApplication extends React.Component {
<SectionMessage
type={SectionMessage.TYPE.WARNING}
title="You are on the old version of account maturity"
description="No further support will be provided on this version."
description="No further support will be provided on this version"
actions={[
{
label: 'Launch the new version',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"name": "nr1-maturity",
"description": "New Relic Account Maturity App",
"version": "0.14.0",
"version": "0.14.0-beta-2",
"scripts": {
"start": "nr1 nerdpack:serve",
"eslint-check": "eslint nerdlets/ src/",
Expand Down
Loading

0 comments on commit 8b45888

Please sign in to comment.