Skip to content

Commit

Permalink
Add loader to Rules table (opensearch-project#159)
Browse files Browse the repository at this point in the history
Signed-off-by: Sinisa Andric <[email protected]>

Signed-off-by: Sinisa Andric <[email protected]>
  • Loading branch information
paladin-tech authored Nov 23, 2022
1 parent caad327 commit 26f8ba0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion public/pages/Rules/components/RulesTable/RulesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ import { CriteriaWithPagination, EuiInMemoryTable, EuiPanel } from '@elastic/eui

export interface RulesTableProps {
ruleItems: RuleTableItem[];
loading: boolean;
showRuleDetails: (ruleItem: RuleTableItem) => void;
}

export const RulesTable: React.FC<RulesTableProps> = ({ ruleItems, showRuleDetails }) => {
export const RulesTable: React.FC<RulesTableProps> = ({ ruleItems, loading, showRuleDetails }) => {
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 25 });

return (
<EuiPanel>
<EuiInMemoryTable
loading={loading}
items={ruleItems}
columns={getRulesTableColumns(showRuleDetails)}
search={getRulesTableSearchConfig()}
Expand Down
5 changes: 4 additions & 1 deletion public/pages/Rules/containers/Rules/Rules.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const Rules: React.FC<RulesProps> = (props) => {
const rulesViewModelActor = useMemo(() => new RulesViewModelActor(services), [services]);
const [allRules, setAllRules] = useState<RuleItemInfoBase[]>([]);
const [flyoutData, setFlyoutData] = useState<RuleTableItem | undefined>(undefined);
const [loading, setLoading] = useState<boolean>(false);
const ruleItems: RuleTableItem[] = useMemo(
() =>
allRules.map((rule) => ({
Expand All @@ -42,8 +43,10 @@ export const Rules: React.FC<RulesProps> = (props) => {
);

const getRules = useCallback(async () => {
setLoading(true);
const allRules = await rulesViewModelActor.fetchRules();
setAllRules(allRules);
setLoading(false);
}, [rulesViewModelActor]);

useEffect(() => {
Expand Down Expand Up @@ -113,7 +116,7 @@ export const Rules: React.FC<RulesProps> = (props) => {
<EuiSpacer size={'m'} />
</EuiFlexItem>
<EuiFlexItem>
<RulesTable ruleItems={ruleItems} showRuleDetails={setFlyoutData} />
<RulesTable loading={loading} ruleItems={ruleItems} showRuleDetails={setFlyoutData} />
</EuiFlexItem>
</EuiFlexGroup>
</>
Expand Down

0 comments on commit 26f8ba0

Please sign in to comment.