Skip to content

Commit

Permalink
fix(react): support rendering unknown columns
Browse files Browse the repository at this point in the history
  • Loading branch information
jrea committed Aug 18, 2022
1 parent 0d484de commit 6a2ec0b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 14 additions & 0 deletions packages/react/src/components/InstanceTable/InstanceTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ const InstanceTable = React.memo(function InstanceTable(props: Props) {
}
return baseArr;
}
if (columns) {
return columns.map((header: string | GridColDef): GridColDef => {
if (typeof header === 'object') {
return header;
}
return {
minWidth: 200,
field: header,
headerName: header,
flex: 1,
};
});
}
return [];
}, [additionalColumns, columns, entityData, processColumns]);

Expand All @@ -92,6 +105,7 @@ const InstanceTable = React.memo(function InstanceTable(props: Props) {
}
return `No ${entity} found`;
}

return (
<TableSkeleton isFetching={isFetching} numberOfRows={flatInstances.length}>
{flatInstances.length === 0 ? (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';
import { useQuery } from '@tanstack/react-query';

import { useNile } from '../../context';
import Queries from '../../lib/queries';
import Queries, { useQuery } from '../../lib/queries';

import InstanceTable from './InstanceTable';
import { InstanceTableProps } from './types';
Expand Down Expand Up @@ -34,9 +33,7 @@ export default function InstanceTableDataFetcher(

const { data: entityData, isFetching: isEntityFetching } = useQueryHook(
Queries.GetEntity(entity),
() => {
return nile.entities.getEntity({ type: String(entity) });
}
() => nile.entities.getEntity({ type: String(entity) })
);

const { data: instances, isFetching: isInstancesFetching } = useQueryHook(
Expand All @@ -47,7 +44,6 @@ export default function InstanceTableDataFetcher(
org: String(org),
})
);

return (
<InstanceTable
instances={instances}
Expand Down

0 comments on commit 6a2ec0b

Please sign in to comment.