Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix column visibility settings #52

Merged
merged 1 commit into from
Dec 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/BaseTable/hooks/useColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const useColumns = ({
}),
[schemaProperties, viewKind, viewKindElement, viewDescr, viewDescrElement],
);
//говно - надо поменять

const setColumnsVisible = useCallback(
(idxs: any) =>
setVisibleColumns((prevVisibleColumns: any) => {
Expand All @@ -56,8 +56,8 @@ export const useColumns = ({
);

const menuItems = useMemo(
() => getConfigMenuItems({ columns: parsedColumns, setColumnsVisible }),
[parsedColumns, setColumnsVisible],
() => getConfigMenuItems({ columns: visibleColumns, setColumnsVisible }),
[visibleColumns, setColumnsVisible],
);
const systemColumn = useMemo(() => getSystemColumn({ menuItems }), [menuItems]);
const selectionColumn = useMemo(
Expand Down
5 changes: 4 additions & 1 deletion src/BaseTable/utils/createColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { JsObject } from '@agentlab/sparql-jsld-client';
import { EditableCell } from '../components/cells/EditableTableCell';
import { createViewKindElement } from './createViewKindElement';
import { getColumnFilterProps } from './getFilterColumnProps';
import isEmpty from 'lodash/isEmpty';

type Props = {
property: string;
Expand All @@ -23,11 +24,13 @@ export const createColumn = ({
viewDescr,
viewDescrElement,
}: Props) => {
const order = viewKindElement?.options?.order || [];
const options = viewKindElement?.options?.[property] || {};
const disabled = (isEmpty(options) && !order.includes(property)) || !!options?.disabled;
const newColumn: JsObject = {
editable: false,
hidden: false,
disabled: false,
disabled,
width: 200,
resizable: true,
title: propertySchema.title || property,
Expand Down
149 changes: 3 additions & 146 deletions stories/TableRemoteMktp.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,39 +114,7 @@ const viewKinds = [
resizeableHeader: true,
style: { height: '100%' },
multiSelect: true,
order: [
'imageUrl',
'name',
'amountValueMoving30',
'commentsCount',
'price',
/*'saleValue',
'categoryPopularity',
'starsValue',
'questionsCount',
'lastMonthSalesAmount',
'lastMonthSalesValue',
'perMonthSalesAmount',
'perMonthSalesValue',
'prevMonthSalesAmount',
'prevMonthSalesValue',
'salesAmountDiff',
'totalSales',
'totalSalesDiff',
'stocks',
'stocksDiffOrders',
'stocksDiffReturns',
'country',
'brand',
'seller',
'identifier',
'rootId',
'photosCount',
'firstParsedAt',
'lastMonthParsedAt',
'parsedAt',
'prevParsedAt',*/
],
order: ['imageUrl', 'name', 'amountValueMoving30', 'commentsCount', 'price'],
imageUrl: {
width: 100,
formatter: 'image',
Expand Down Expand Up @@ -174,124 +142,13 @@ const viewKinds = [
sortable: true,
editable: false,
},
/*identifier: {
identifier: {
formatter: 'link',
//dataToFormatter: { link: 'identifier' },
sortable: true,
editable: false,
disabled: true,
},
country: {
width: 60,
sortable: true,
editable: false,
},
brand: {
formatter: 'link',
sortable: true,
editable: false,
},
saleValue: {
width: 60,
sortable: true,
editable: false,
},
seller: {
formatter: 'link',
sortable: true,
editable: false,
},
categoryPopularity: {
width: 100,
editable: false,
},
starsValue: {
width: 100,
sortable: true,
editable: false,
},
questionsCount: {
width: 100,
sortable: true,
editable: false,
},
lastMonthSalesAmount: {
width: 150,
sortable: true,
editable: false,
},
lastMonthSalesValue: {
width: 150,
sortable: true,
editable: false,
},
perMonthSalesAmount: {
width: 150,
sortable: true,
editable: false,
},
perMonthSalesValue: {
width: 150,
sortable: true,
editable: false,
},
prevMonthSalesAmount: {
width: 150,
sortable: true,
editable: false,
},
prevMonthSalesValue: {
width: 150,
sortable: true,
editable: false,
},
salesAmountDiff: {
width: 150,
sortable: true,
editable: false,
},
totalSales: {
width: 100,
sortable: true,
editable: false,
},
totalSalesDiff: {
width: 150,
sortable: true,
editable: false,
},
stocks: {
width: 100,
sortable: true,
editable: false,
},
stocksDiffOrders: {
width: 100,
sortable: true,
editable: false,
},
stocksDiffReturns: {
width: 100,
sortable: true,
editable: false,
},
rootId: {
editable: false,
},
photosCount: {
editable: false,
},
firstParsedAt: {
editable: false,
},
lastMonthParsedAt: {
editable: false,
},
parsedAt: {
editable: false,
},
prevParsedAt: {
editable: false,
},*/
},
},
],
Expand Down