Skip to content

Commit

Permalink
[INLONG-8804][Dashboard] Separate plugin images and UI components (#9006
Browse files Browse the repository at this point in the history
)

* [INLONG-8804][Dashboard] Separate plugin images and UI components

* [INLONG-8804][Dashboard] Change the image key to "label" in the CheckCard component
  • Loading branch information
richardji202 authored Oct 9, 2023
1 parent 4802277 commit 2ab581e
Show file tree
Hide file tree
Showing 25 changed files with 36 additions and 11 deletions.
19 changes: 19 additions & 0 deletions inlong-dashboard/src/plugins/images/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.
*/
export const loadImage = (img: string) => import(`./${img}.png`);
2 changes: 2 additions & 0 deletions inlong-dashboard/src/plugins/sinks/common/SinkDefaultInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { DataWithBackend } from '@/plugins/DataWithBackend';
import { RenderRow } from '@/plugins/RenderRow';
import { RenderList } from '@/plugins/RenderList';
import { loadImage } from '@/plugins/images';
import i18n from '@/i18n';
import CheckCard from '@/ui/components/CheckCard';
import { statusList, genStatusTag } from './status';
Expand Down Expand Up @@ -68,6 +69,7 @@ export class SinkDefaultInfo implements DataWithBackend, RenderRow, RenderList {
.map(item => ({
label: item.label,
value: item.value,
image: loadImage(item.label),
})),
}),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { DataWithBackend } from '@/plugins/DataWithBackend';
import { RenderRow } from '@/plugins/RenderRow';
import { RenderList } from '@/plugins/RenderList';
import { loadImage } from '@/plugins/images';
import CheckCard from '@/ui/components/CheckCard';
import { statusList, genStatusTag } from './status';
import { sources, defaultValue } from '..';
Expand Down Expand Up @@ -66,6 +67,7 @@ export class SourceDefaultInfo implements DataWithBackend, RenderRow, RenderList
.map(item => ({
label: item.label,
value: item.value,
image: loadImage(item.label),
})),
}),
})
Expand Down Expand Up @@ -133,6 +135,7 @@ export class SourceDefaultInfo implements DataWithBackend, RenderRow, RenderList
.map(item => ({
label: item.label,
value: item.value,
image: loadImage(item.label),
})),
});
}
Expand All @@ -152,6 +155,7 @@ export class SourceDefaultInfo implements DataWithBackend, RenderRow, RenderList
.map(item => ({
label: item.label,
value: item.value,
image: loadImage(item.label),
})),
});
}
Expand Down
22 changes: 11 additions & 11 deletions inlong-dashboard/src/ui/components/CheckCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import styles from './index.module.less';
export interface CheckCardOption {
label: string;
value: string | number;
image?: string | Promise<{ default: string }>;
}

export interface CheckCardProps {
Expand Down Expand Up @@ -62,17 +63,16 @@ const CheckCard: React.FC<CheckCardProps> = ({ options, value, onChange, disable
*/
(async () => {
setLogoMap(
(
await Promise.allSettled(options.map(option => import(`./logo/${option.label}.png`)))
).reduce((res, item) => {
if (item.status === 'fulfilled') {
const {
value: { default: url },
} = item;
res[url.split('/').pop().split('.').shift()] = url;
}
return res;
}, {}),
(await Promise.allSettled(options.map(option => option.image))).reduce(
(res, item, index) => {
if (item.status === 'fulfilled' && item.value) {
const url = typeof item.value === 'string' ? item.value : item.value.default;
res[options[index].label] = url;
}
return res;
},
{},
),
);
})();
}, [options]);
Expand Down

0 comments on commit 2ab581e

Please sign in to comment.