blob: 5e7aeddacab4324d5e826a387e2be027bb308ed1 [file] [log] [blame]
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { useTheme, css, t } from '@superset-ui/core';
import { FunctionComponent, useMemo } from 'react';
import { useListViewResource } from 'src/views/CRUD/hooks';
import { ListView } from 'src/components';
import SubMenu, { SubMenuProps } from 'src/features/home/SubMenu';
import withToasts from 'src/components/MessageToasts/withToasts';
import { JsonModal } from 'src/components/JsonModal';
import { safeJsonObjectParse } from 'src/components/JsonModal/utils';
const PAGE_SIZE = 25;
type Extension = {
id: number;
name: string;
enabled: boolean;
};
interface ExtensionsListProps {
addDangerToast: (msg: string) => void;
addSuccessToast: (msg: string) => void;
}
const ExtensionsList: FunctionComponent<ExtensionsListProps> = ({
addDangerToast,
addSuccessToast,
}) => {
const theme = useTheme();
const {
state: { loading, resourceCount, resourceCollection },
fetchData,
refreshData,
} = useListViewResource<Extension>(
'extensions',
t('Extensions'),
addDangerToast,
);
const columns = useMemo(
() => [
{
Header: t('Name'),
accessor: 'name',
size: 'lg',
id: 'name',
Cell: ({
row: {
original: { name },
},
}: any) => name,
},
{
Header: t('Contributions'),
accessor: 'contributions',
size: 'lg',
id: 'contributions',
Cell: ({
row: {
original: { contributions },
},
}: any) => (
<div
css={css`
color: ${theme.colorLink};
text-decoration: underline;
`}
>
<JsonModal
modalTitle={t('Contributions')}
jsonObject={safeJsonObjectParse(contributions)!}
jsonValue={t('View')}
/>
</div>
),
},
],
[loading], // We need to monitor loading to avoid stale state in actions
);
const menuData: SubMenuProps = {
activeChild: 'Extensions',
name: t('Extensions'),
buttons: [],
};
return (
<>
<SubMenu {...menuData} />
<ListView<Extension>
columns={columns}
count={resourceCount}
data={resourceCollection}
initialSort={[{ id: 'name', desc: false }]}
pageSize={PAGE_SIZE}
fetchData={fetchData}
loading={loading}
addDangerToast={addDangerToast}
addSuccessToast={addSuccessToast}
refreshData={refreshData}
/>
</>
);
};
export default withToasts(ExtensionsList);