Skip to content

Commit

Permalink
Wire up new tags API to settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
dlabrecq committed Aug 14, 2023
1 parent b4b262b commit 21a47a8
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 138 deletions.
6 changes: 6 additions & 0 deletions src/api/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ export const enum SettingsType {
awsCategoryKeys = 'awsCategoryKeys',
awsCategoryKeysEnable = 'awsCategoryKeysEnable',
awsCategoryKeysDisable = 'awsCategoryKeysDisable',
tags = 'tags',
tagsEnable = 'tagsEnable',
tagsDisable = 'tagsDisable',
}

export const SettingsTypePaths: Partial<Record<SettingsType, string>> = {
[SettingsType.awsCategoryKeys]: 'settings/aws_category_keys/',
[SettingsType.awsCategoryKeysEnable]: 'settings/aws_category_keys/enable/',
[SettingsType.awsCategoryKeysDisable]: 'settings/aws_category_keys/disable/',
[SettingsType.tags]: 'settings/tags',
[SettingsType.tagsEnable]: 'settings/tags/enable/',
[SettingsType.tagsDisable]: 'settings/tags/disable/',
};

export function fetchSettings(settingsType: SettingsType, query: string) {
Expand Down
7 changes: 3 additions & 4 deletions src/routes/settings/costCategory/costCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ const CostCategory: React.FC<CostCategoryProps> = ({ canWrite }) => {

const getPagination = (isDisabled = false, isBottom = false) => {
const count = settings?.meta ? settings.meta.count : 0;
const limit = settings?.meta?.limit ? settings.meta.limit : baseQuery.limit; // Todo: API doesn't provide limit
const offset = settings?.meta?.offset ? settings.meta.offset : baseQuery.offset; // Todo: API doesn't provide offset
const limit = settings?.meta ? settings.meta.limit : baseQuery.limit;
const offset = settings?.meta ? settings.meta.offset : baseQuery.offset;
const page = Math.trunc(offset / limit + 1);

return (
Expand Down Expand Up @@ -180,7 +180,7 @@ const CostCategory: React.FC<CostCategoryProps> = ({ canWrite }) => {
};

const handleOnSetPage = pageNumber => {
const newQuery = queryUtils.handleOnSetPage(query, settings, pageNumber);
const newQuery = queryUtils.handleOnSetPage(query, settings, pageNumber, true);
setQuery(newQuery);
};

Expand All @@ -206,7 +206,6 @@ const CostCategory: React.FC<CostCategoryProps> = ({ canWrite }) => {
const categories = getCategories();
const isDisabled = categories.length === 0;

// Note: Providers are fetched via the AccountSettings component used by all routes
if (settingsError) {
return <NotAvailable />;
}
Expand Down
11 changes: 4 additions & 7 deletions src/routes/settings/costCategory/costCategoryTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React from 'react';
import type { WrappedComponentProps } from 'react-intl';
import { injectIntl } from 'react-intl';
import { DataTable } from 'routes/components/dataTable';
import { styles } from 'routes/components/dataTable/dataTable.styles';
import type { RouterComponentProps } from 'utils/router';
import { withRouter } from 'utils/router';

Expand All @@ -28,12 +29,6 @@ interface CostCategoryState {

type CostCategoryProps = CostCategoryOwnProps;

export const CostCategoryColumnIds = {
infrastructure: 'infrastructure',
monthOverMonth: 'monthOverMonth',
supplementary: 'supplementary',
};

class CostCategoryBase extends React.Component<CostCategoryProps, CostCategoryState> {
public state: CostCategoryState = {
columns: [],
Expand Down Expand Up @@ -68,14 +63,15 @@ class CostCategoryBase extends React.Component<CostCategoryProps, CostCategorySt
name: '', // Selection column
},
{
orderBy: 'key', // Todo: update sort name
orderBy: 'key',
name: intl.formatMessage(messages.detailsResourceNames, { value: 'name' }),
...(categories.length && { isSortable: true }),
},
{
orderBy: 'enabled',
name: intl.formatMessage(messages.detailsResourceNames, { value: 'status' }),
...(categories.length && { isSortable: true }),
style: styles.lastItemColumn,
},
];

Expand All @@ -92,6 +88,7 @@ class CostCategoryBase extends React.Component<CostCategoryProps, CostCategorySt
) : (
<Label>{intl.formatMessage(messages.disabled)}</Label>
),
style: styles.lastItem,
},
],
item,
Expand Down
Loading

0 comments on commit 21a47a8

Please sign in to comment.