Skip to content

Commit

Permalink
Merge pull request #5 from CrystallizeAPI/fix/import-grouping
Browse files Browse the repository at this point in the history
fix: grouping items
  • Loading branch information
Plopix authored May 29, 2024
2 parents f5bf955 + df86502 commit b4c7dd4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
17 changes: 12 additions & 5 deletions components/crystallize-import/src/ui/import/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DataMatchingForm } from './components/DataForm';
import { FileChooser } from './components/FileChooser';
import { useImport } from './provider';
import { useEffect, useState } from 'react';

const messageFactory = (decoded: any) => {
switch (decoded.event) {
case 'started':
Expand Down Expand Up @@ -43,6 +44,7 @@ export const App = () => {
const { shapes, folders } = state;
const [streamLogs, setStreamLogs] = useState<any[]>([]);
const data = useEventSource(`/api/import/stream/${state.importId}`, { event: 'log' });
const [grouping, setGrouping] = useState<string>(state.headers[0] ?? '');

useEffect(() => {
if (state.done) {
Expand All @@ -52,6 +54,11 @@ export const App = () => {
setStreamLogs((prev) => [...prev, data]);
}
}, [data, state.done]);

useEffect(() => {
dispatch.updateGroupProductsBy(grouping);
}, [grouping]);

return (
<div style={{ fontFamily: 'system-ui, sans-serif', lineHeight: '1.4', padding: '0px 50px 200px' }}>
<ActionBar shapes={shapes} folders={folders} />
Expand Down Expand Up @@ -98,14 +105,14 @@ export const App = () => {
<label></label>
</div>
<div className="max-w-sm">
<label className="pb-4 block ">
Group products by variants <br />
<label className="pb-4 block">
Group products by: <br />
</label>

<select
className="grey"
onChange={(e) => dispatch.updateGroupProductsBy(e.target.value)}
className="grey w-[200px]"
onChange={(e) => setGrouping(e.target.value)}
disabled={!state.rows?.length}
value={grouping}
>
<option defaultChecked={true} disabled value="">
Select a column
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { useState } from 'react';
import { Popover } from 'react-tiny-popover';
import cn from 'classnames';

import { AiFillCaretDown } from 'react-icons/ai';
import { BsTrash, BsTrashFill } from 'react-icons/bs';
import { BsTrash } from 'react-icons/bs';
import { useImport } from '../../provider';
import { useState } from 'react';
import { FieldMapping, FIELD_MAPPINGS } from '../../../../contracts/ui-types';
import { ComponentChoiceComponentConfig, Shape } from '@crystallize/schema';
import { Shape } from '@crystallize/schema';

interface ColumnMapperProps {
title: string;
Expand Down Expand Up @@ -144,7 +143,11 @@ export const ColumnHeader = ({ title }: ColumnHeaderProps) => {
.filter((shape) => shape.type === 'folder')
.map((shape) => (
<li
className={`popover-item ${subFolderMapped?.shapeIdentifier === shape.identifier ? 'font-bold ' : ''}`}
className={`popover-item ${
subFolderMapped?.shapeIdentifier === shape.identifier
? 'font-bold '
: ''
}`}
key={shape.identifier}
onClick={() => {
const newMapping = [
Expand Down

0 comments on commit b4c7dd4

Please sign in to comment.