michael-s-molina commented on code in PR #29900:
URL: https://github.com/apache/superset/pull/29900#discussion_r1924271099
##########
superset-frontend/src/components/FilterableTable/index.tsx:
##########
@@ -188,86 +109,52 @@ const FilterableTable = ({
return values.some(v => v.includes(lowerCaseText));
};
- // Parse any numbers from strings so they'll sort correctly
- const parseNumberFromString = (value: string | number | null) => {
- if (typeof value === 'string') {
- if (ONLY_NUMBER_REGEX.test(value)) {
- return parseFloat(value);
- }
- }
-
- return value;
- };
-
- const sortResults = (key: string, a: Datum, b: Datum) => {
- const aValue = parseNumberFromString(a[key]);
- const bValue = parseNumberFromString(b[key]);
-
- // equal items sort equally
- if (aValue === bValue) {
- return 0;
- }
-
- // nulls sort after anything else
- if (aValue === null) {
- return 1;
- }
- if (bValue === null) {
- return -1;
- }
-
- return aValue < bValue ? -1 : 1;
- };
-
- const keyword = useDebounceValue(filterText);
-
- const filteredList = useMemo(
+ const columns = useMemo(
() =>
- keyword ? list.filter((row: Datum) => hasMatch(keyword, row)) : list,
- [list, keyword],
+ orderedColumnKeys.map(key => ({
+ key,
+ label: key,
+ fieldName: key,
+ headerName: key,
+ comparator: sortResults,
+ render: ({ value, colDef }: { value: CellDataType; colDef: ColDef }) =>
+ renderResultCell({
+ cellData: value,
+ columnKey: colDef.field,
+ allowHTML,
+ getCellContent,
+ }),
+ })),
+ [orderedColumnKeys, allowHTML, getCellContent],
);
- // exclude the height of the horizontal scroll bar from the height of the
table
- // and the height of the table container if the content overflows
- const totalTableHeight =
- container.current && totalTableWidth.current >
container.current.clientWidth
- ? height - SCROLL_BAR_HEIGHT
- : height;
+ const keyword = useRef<string | undefined>(filterText);
+ keyword.current = filterText;
Review Comment:
Why do we use a reference here to keep the value between re-renders but
still modify it anyway?
##########
superset/config.py:
##########
@@ -1592,7 +1592,7 @@ def EMAIL_HEADER_MUTATOR( # pylint:
disable=invalid-name,unused-argument # noq
TALISMAN_CONFIG = {
"content_security_policy": {
"base-uri": ["'self'"],
- "default-src": ["'self'"],
+ "default-src": ["'self'", "data:"],
Review Comment:
When you include `data:` in your CSP's `default-src` or any other directive,
it allows any data URI to be loaded, regardless of its source. This means that
any data URL can be executed or rendered by the browser, which can pose
security risks such as exposing your application to cross-site scripting (XSS)
attacks.
To restrict sources to trusted domains, you can specify the domains
explicitly in the `default-src` or other specific directives (like
`script-src`, `style-src`, etc.)
```
Content-Security-Policy: default-src 'self' https://trusted.com;
```
##########
superset-frontend/src/components/GridTable/HeaderMenu.test.tsx:
##########
@@ -0,0 +1,266 @@
+/**
+ * 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 type { Column, GridApi } from 'ag-grid-community';
+import {
+ fireEvent,
+ render,
+ waitFor,
+ screen,
+} from 'spec/helpers/testing-library';
+import HeaderMenu from './HeaderMenu';
+
+jest.mock('src/components/Menu', () => {
+ const Menu = ({ children }: { children: React.ReactChild }) => (
+ <div data-test="mock-Menu">{children}</div>
+ );
+ Menu.Item = ({
+ children,
+ onClick,
+ }: {
+ children: React.ReactChild;
+ onClick: () => void;
+ }) => (
+ <button type="button" data-test="mock-Item" onClick={onClick}>
+ {children}
+ </button>
+ );
+ Menu.SubMenu = ({
+ title,
+ children,
+ }: {
+ title: React.ReactNode;
+ children: React.ReactNode;
+ }) => (
+ <div>
+ {title}
+ <button type="button" data-test="mock-SubMenu">
+ {children}
+ </button>
+ </div>
+ );
+ Menu.Divider = () => <div data-test="mock-Divider" />;
+ return { Menu };
+});
+
+jest.mock('src/components/Icons', () => ({
+ DownloadOutlined: () => <div data-test="mock-DownloadOutlined" />,
+ CopyOutlined: () => <div data-test="mock-CopyOutlined" />,
+ UnlockOutlined: () => <div data-test="mock-UnlockOutlined" />,
+ VerticalRightOutlined: () => <div data-test="mock-VerticalRightOutlined" />,
+ VerticalLeftOutlined: () => <div data-test="mock-VerticalLeftOutlined" />,
+ EyeInvisibleOutlined: () => <div data-test="mock-EyeInvisibleOutlined" />,
+ EyeOutlined: () => <div data-test="mock-EyeOutlined" />,
+ ColumnWidthOutlined: () => <div data-test="mock-column-width" />,
+}));
+
+jest.mock('src/components/Dropdown', () => ({
+ Dropdown: ({ overlay }: { overlay: React.ReactChild }) => (
+ <div data-test="mock-Dropdown">{overlay}</div>
+ ),
+}));
+
+jest.mock('src/utils/copy', () => jest.fn().mockImplementation(f => f()));
+
+const mockInvisibleColumn = {
+ getColId: jest.fn().mockReturnValue('column2'),
+ getColDef: jest.fn().mockReturnValue({ headerName: 'column2' }),
+ getDataAsCsv: jest.fn().mockReturnValue('csv'),
+} as any as Column;
+
+const mockInvisibleColumn3 = {
+ getColId: jest.fn().mockReturnValue('column3'),
+ getColDef: jest.fn().mockReturnValue({ headerName: 'column3' }),
+ getDataAsCsv: jest.fn().mockReturnValue('csv'),
+} as any as Column;
+
+const mockGridApi = {
+ autoSizeColumns: jest.fn(),
+ autoSizeAllColumns: jest.fn(),
+ getColumn: jest.fn().mockReturnValue({
+ getColDef: jest.fn().mockReturnValue({}),
+ }),
+ getColumns: jest.fn().mockReturnValue([]),
+ getDataAsCsv: jest.fn().mockReturnValue('csv'),
+ exportDataAsCsv: jest.fn().mockReturnValue('csv'),
+ getAllDisplayedColumns: jest.fn().mockReturnValue([]),
+ setColumnsPinned: jest.fn(),
+ setColumnsVisible: jest.fn(),
+ setColumnVisible: jest.fn(),
+ moveColumns: jest.fn(),
+} as any as GridApi;
+
+const mockedProps = {
+ colId: 'column1',
+ invisibleColumns: [],
+ api: mockGridApi,
+ onVisibleChange: jest.fn(),
+};
+
+afterEach(() => {
+ (mockGridApi.getDataAsCsv as jest.Mock).mockClear();
+ (mockGridApi.setColumnsPinned as jest.Mock).mockClear();
+ (mockGridApi.setColumnsVisible as jest.Mock).mockClear();
+ (mockGridApi.setColumnsVisible as jest.Mock).mockClear();
+ (mockGridApi.setColumnsPinned as jest.Mock).mockClear();
+ (mockGridApi.autoSizeColumns as jest.Mock).mockClear();
+ (mockGridApi.autoSizeAllColumns as jest.Mock).mockClear();
+ (mockGridApi.moveColumns as jest.Mock).mockClear();
+});
+
+test('renders copy data', async () => {
+ const { getByText } = render(<HeaderMenu {...mockedProps} />);
+ fireEvent.click(getByText('Copy'));
+ await waitFor(() =>
+ expect(mockGridApi.getDataAsCsv).toHaveBeenCalledTimes(1),
+ );
+ expect(mockGridApi.getDataAsCsv).toHaveBeenCalledWith({
+ columnKeys: [mockedProps.colId],
+ suppressQuotes: true,
+ });
+});
+
+test('renders buttons pinning both side', () => {
Review Comment:
```suggestion
test('renders buttons pinning both sides', () => {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]